当前位置: 首页>>代码示例>>Golang>>正文


Golang Vector.RawVector方法代码示例

本文整理汇总了Golang中github.com/gonum/matrix/mat64.Vector.RawVector方法的典型用法代码示例。如果您正苦于以下问题:Golang Vector.RawVector方法的具体用法?Golang Vector.RawVector怎么用?Golang Vector.RawVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gonum/matrix/mat64.Vector的用法示例。


在下文中一共展示了Vector.RawVector方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: onesDotUnitary

// onesDotUnitary performs the equivalent of a Ddot of v with
// a ones vector of equal length. v must have have a unitary
// vector increment.
func onesDotUnitary(alpha float64, v *mat64.Vector) float64 {
	var sum float64
	for _, f := range v.RawVector().Data {
		sum += alpha * f
	}
	return sum
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:10,代码来源:page.go

示例2: dokMulMatVec

func dokMulMatVec(y *mat64.Vector, alpha float64, transA bool, a *DOK, x *mat64.Vector) {
	r, c := a.Dims()
	if transA {
		if r != x.Len() || c != y.Len() {
			panic("sparse: dimension mismatch")
		}
	} else {
		if r != y.Len() || c != x.Len() {
			panic("sparse: dimension mismatch")
		}
	}

	if alpha == 0 {
		return
	}

	xRaw := x.RawVector()
	yRaw := y.RawVector()
	if transA {
		for ij, aij := range a.data {
			yRaw.Data[ij[1]*yRaw.Inc] += alpha * aij * xRaw.Data[ij[0]*xRaw.Inc]
		}
	} else {
		for ij, aij := range a.data {
			yRaw.Data[ij[0]*yRaw.Inc] += alpha * aij * xRaw.Data[ij[1]*xRaw.Inc]
		}
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:28,代码来源:dok.go

示例3: dotUnitary

// dotUnitary performs a simplified scatter-based Ddot operations on
// v and the receiver. v must have have a unitary vector increment.
func (r compressedRow) dotUnitary(v *mat64.Vector) float64 {
	var sum float64
	vec := v.RawVector().Data
	for _, e := range r {
		sum += vec[e.index] * e.value
	}
	return sum
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:10,代码来源:page.go

示例4: Scatter

// Scatter copies the values of x into the corresponding locations in the dense
// vector y. Both vectors must have the same dimension.
func Scatter(y *mat64.Vector, x *Vector) {
	if x.N != y.Len() {
		panic("sparse: vector dimension mismatch")
	}

	raw := y.RawVector()
	for i, index := range x.Indices {
		raw.Data[index*raw.Inc] = x.Data[i]
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:12,代码来源:level1.go

示例5: Dot

// Dot computes the dot product of the sparse vector x with the dense vector y.
// The vectors must have the same dimension.
func Dot(x *Vector, y *mat64.Vector) (dot float64) {
	if x.N != y.Len() {
		panic("sparse: vector dimension mismatch")
	}

	raw := y.RawVector()
	for i, index := range x.Indices {
		dot += x.Data[i] * raw.Data[index*raw.Inc]
	}
	return
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:13,代码来源:level1.go

示例6: Gather

// Gather gathers entries given by indices of the dense vector y into the sparse
// vector x. Indices must not be nil.
func Gather(x *Vector, y *mat64.Vector, indices []int) {
	if indices == nil {
		panic("sparse: slice is nil")
	}

	x.reuseAs(y.Len(), len(indices))
	copy(x.Indices, indices)
	raw := y.RawVector()
	for i, index := range x.Indices {
		x.Data[i] = raw.Data[index*raw.Inc]
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:14,代码来源:level1.go

示例7: Axpy

// Axpy scales the sparse vector x by alpha and adds the result to the dense
// vector y. If alpha is zero, y is not modified.
func Axpy(y *mat64.Vector, alpha float64, x *Vector) {
	if x.N != y.Len() {
		panic("sparse: vector dimension mismatch")
	}

	if alpha == 0 {
		return
	}
	raw := y.RawVector()
	for i, index := range x.Indices {
		raw.Data[index*raw.Inc] += alpha * x.Data[i]
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:15,代码来源:level1.go

示例8: csrMulMatVec

func csrMulMatVec(y *mat64.Vector, alpha float64, transA bool, a *CSR, x *mat64.Vector) {
	r, c := a.Dims()
	if transA {
		if r != x.Len() || c != y.Len() {
			panic("sparse: dimension mismatch")
		}
	} else {
		if r != y.Len() || c != x.Len() {
			panic("sparse: dimension mismatch")
		}
	}

	if alpha == 0 {
		return
	}

	yRaw := y.RawVector()
	if transA {
		row := Vector{N: y.Len()}
		for i := 0; i < r; i++ {
			start := a.rowIndex[i]
			end := a.rowIndex[i+1]
			row.Data = a.values[start:end]
			row.Indices = a.columns[start:end]
			Axpy(y, alpha*x.At(i, 0), &row)
		}
	} else {
		row := Vector{N: x.Len()}
		for i := 0; i < r; i++ {
			start := a.rowIndex[i]
			end := a.rowIndex[i+1]
			row.Data = a.values[start:end]
			row.Indices = a.columns[start:end]
			yRaw.Data[i*yRaw.Inc] += alpha * Dot(&row, x)
		}
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:37,代码来源:csr.go

示例9: mulVecUnitary

// mulVecUnitary multiplies the receiver by the src vector, storing
// the result in dst. It assumes src and dst are the same length as m
// and that both have unitary vector increments.
func (m rowCompressedMatrix) mulVecUnitary(dst, src *mat64.Vector) {
	dMat := dst.RawVector().Data
	for i, r := range m {
		dMat[i] = r.dotUnitary(src)
	}
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:9,代码来源:page.go

示例10: VectorToMatrix

func VectorToMatrix(vector *mat64.Vector) *mat64.Dense {
	vec := vector.RawVector()
	return mat64.NewDense(1, len(vec.Data), vec.Data)
}
开发者ID:CTLife,项目名称:golearn,代码行数:4,代码来源:utilities.go


注:本文中的github.com/gonum/matrix/mat64.Vector.RawVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。