func (m *matrixImpl) Subtract(n types.Matrix) types.Matrix { validates.ShapeShouldBeSame(m, n) cursor := n.NonZeros() for cursor.HasNext() { element, row, column := cursor.Get() m.Update(row, column, m.Get(row, column)-element) } return m }
func (m *matrixImpl) Equal(n types.Matrix) bool { validates.ShapeShouldBeSame(m, n) cursor := n.All() for cursor.HasNext() { element, row, column := cursor.Get() if m.Get(row, column) != element { return false } } return true }
func (m *matrixImpl) Multiply(n types.Matrix) types.Matrix { validates.ShapeShouldBeMultipliable(m, n) rows := m.Rows() columns := n.Columns() r := Zeros(rows, columns) cursor := n.NonZeros() for cursor.HasNext() { element, j, k := cursor.Get() for i := 0; i < rows; i++ { r.Update(i, k, r.Get(i, k)+m.Get(i, j)*element) } } return r }