double DotProduct(const SparseMatrix& lhs, const SparseMatrix& rhs) { double result = 0.; for (int lQ = 0; lQ < lhs.nrows(); ++lQ) for (int rQ = 0; rQ < lhs.ncols (); ++rQ) if (lhs.allowed(lQ, rQ) && rhs.allowed(lQ, rQ)) result += MatrixDotProduct(lhs.operator_element(lQ, rQ), rhs.operator_element(lQ, rQ)); return result; }
void ScaleAdd(double d, const SparseMatrix& a, SparseMatrix& b) { for (int lQ = 0; lQ < a.nrows(); ++lQ) for (int rQ = 0; rQ < a.ncols(); ++rQ) if (a.allowed(lQ, rQ)) { if (!b.allowed(lQ, rQ)) cout <<"Not a valid addition"<<endl; assert(b.allowed(lQ, rQ)); MatrixScaleAdd(d, a.operator_element(lQ, rQ), b.operator_element(lQ, rQ)); } }
void Scale(double d, SparseMatrix& a) { for (int lQ = 0; lQ < a.nrows(); ++lQ) for (int rQ = 0; rQ < a.ncols(); ++rQ) if (a.allowed(lQ, rQ)) MatrixScale(d, a.operator_element(lQ, rQ)); }