示例#1
0
文件: dense.go 项目: cpalone/matrix
func (d *Matrix) addSparse(other matrix.Matrix) matrix.Matrix {
	sum := d.Copy()
	for e := range other.IterItems() {
		sum.Set(e.Row, e.Col, sum.Get(e.Row, e.Col)+e.Val)
	}
	return sum
}
示例#2
0
文件: dense.go 项目: cpalone/matrix
// Add returns a new Matrix that is the sum of this Matrix and other.
func (d *Matrix) Add(other matrix.Matrix) matrix.Matrix {
	if other.IsSparse() {
		return d.addSparse(other)
	}
	dother := other.(*Matrix)
	return d.addDense(dother)
}