boost boost::subtract(const boost& rhs) const {\ if(rhs.num_rows() != this->num_rows()){ throw std::invalid_argument("Number of rows do not match"); } else { return std::move(boost(this->data() - rhs.data())); } }
boost boost::mult(const boost& rhs) const { if (rhs.num_rows() != num_cols()) { throw std::invalid_argument("Column of left matrix does not match row of right matrix"); } else { bnu::matrix<float> prod(num_rows(), rhs.num_cols()); bnu::noalias(prod) = bnu::prod(this->data(), rhs.data()); return std::move(boost(prod)); } }
boost boost::solve_x(const boost& B) const { if(this->num_rows() != this->num_cols()) throw std::invalid_argument("A must be square in Ax = B"); if(this->num_cols() != B.num_rows()) throw std::invalid_argument("B.rows must equal A.cols in Ax = B"); if(B.num_cols() != 1) throw std::invalid_argument("B must be n x 1 vector in Ax = B"); bnu::matrix<float> A(this->data()); bnu::matrix<float> y = bnu::trans(B.data()); bnu::vector<float> b(B.num_rows()); std::copy(y.begin1(), y.end1(), b.begin()); bnu::permutation_matrix<> piv(b.size()); bnu::lu_factorize(A, piv); bnu::lu_substitute(A, piv, b); bnu::matrix<float> x(this->num_rows(), 1); std::copy(b.begin(), b.end(), x.begin1()); return std::move(boost(x)); }
boost boost::concat(const boost& mat) const { if (mat.num_rows() != this->num_rows()) { throw std::invalid_argument("Number of rows do not match"); } else { int rows = this->num_rows(); int cols = this->num_cols(); int new_cols = cols + mat.num_cols(); bnu::matrix<float> c(rows, new_cols); bnu::project(c, bnu::range(0, rows), bnu::range(0, cols)) = this->data(); bnu::project(c, bnu::range(0, rows), bnu::range(cols, new_cols)) = mat.data(); return std::move(boost(c)); } }