Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
// 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)
}