cmat operator+(const imat &a, const cmat &b) { it_assert_debug(a.cols() == b.cols() && a.rows() == b.rows(), "operator+(): sizes does not match"); cmat temp(b); for (int i = 0;i < a.rows();i++) { for (int j = 0;j < a.cols();j++) { temp(i, j) += std::complex<double>(static_cast<double>(a(i, j)), 0.0); } } return temp; }
mat operator+(const imat &a, const mat &b) { it_assert_debug(a.cols() == b.cols() && a.rows() == b.rows(), "operator+(): sizes does not match"); mat temp(b); for (int i = 0;i < a.rows();i++) { for (int j = 0;j < a.cols();j++) { temp(i, j) += (double)a(i, j); } } return temp; }
cfixmat operator*(const cfixmat &a, const imat &b) { it_assert_debug(a.cols() == b.rows(), "operator*: wrong sizes"); cfixmat r(a.rows(), b.cols()); CFix tmp; int i, j, k; CFix *tr = r._data(); const CFix *t1; const int *t2 = b._data(); for (i = 0; i < r.cols(); i++) { for (j = 0; j < r.rows(); j++) { tmp = CFix(0); t1 = a._data() + j; for (k = a.cols(); k > 0; k--) { tmp += *(t1) * *(t2++); t1 += a.rows(); } *(tr++) = tmp; t2 -= b.rows(); } t2 += b.rows(); } return r; }
cfixmat operator+(const cfixmat &a, const imat &b) { it_assert_debug(a.cols() == b.cols() && a.rows() == b.rows(), "operator+(): sizes do not match"); cfixmat temp(a); for (int i = 0; i < a.rows(); i++) { for (int j = 0; j < a.cols(); j++) { temp(i, j) += b(i, j); } } return temp; }
imat Unit::recursive_find_p_vectors (const imat &per) { arma::imat result(per.n_rows,pow(3,per.n_cols)-1); result.col(0) = per.col(0); result.col(1) = -per.col(0); if(per.n_cols != 1) { imat tmp1 = recursive_find_p_vectors(per.cols(1,per.n_cols-1)); imat tmp2 = tmp1; result.cols(2,1+tmp1.n_cols) = tmp1; tmp1.each_col() += per.col(0); result.cols(2+tmp1.n_cols,1+tmp1.n_cols*2) = tmp1; tmp2.each_col() -= per.col(0); result.cols(2+tmp1.n_cols*2,1+tmp1.n_cols*3) = tmp2; } return result; };