M2_arrayintOrNull FreeModule::select_by_degrees(M2_arrayintOrNull lo, M2_arrayintOrNull hi) const { const Ring *R = get_ring(); const Monoid *D = R->degree_monoid(); std::vector<size_t> result; int ndegrees = D->n_vars(); int *exp = newarray_atomic(int,ndegrees); for (int i=0; i<rank(); i++) { D->to_expvector(degree(i), exp); #if 0 for (int i=0; i<ndegrees; i++) printf("%d ", exp[i]); if (degree_in_box(ndegrees, exp, lo, hi)) printf("yes\n"); else printf("no\n"); #endif if (degree_in_box(ndegrees, exp, lo, hi)) result.push_back(i); } M2_arrayint selection = stdvector_to_M2_arrayint(result); deletearray(exp); return selection; }
engine_RawArrayIntPairOrNull rawLQUPFactorizationInPlace(MutableMatrix *A, M2_bool transpose) { #ifdef HAVE_FFLAS_FFPACK // Suppose A is m x n // then we get A = LQUP = LSP, see e.g. http://www.ens-lyon.fr/LIP/Pub/Rapports/RR/RR2006/RR2006-28.pdf // P and Q are permutation info using LAPACK's convention:, see // http://www.netlib.org/lapack/explore-html/d0/d39/_v_a_r_i_a_n_t_s_2lu_2_r_e_c_2dgetrf_8f.html // P is n element permutation on column: size(P)=min(m,n); // for 1 <= i <= min(m,n), col i of the matrix was interchanged with col P(i). // Qt is m element permutation on rows (inverse permutation) // for 1 <= i <= min(m,n), col i of the matrix was interchanged with col P(i). A->transpose(); DMat<M2::ARingZZpFFPACK> *mat = A->coerce< DMat<M2::ARingZZpFFPACK> >(); if (mat == 0) { throw exc::engine_error("LUDivine not defined for this ring"); // ERROR("LUDivine not defined for this ring"); // return 0; } size_t nelems = mat->numColumns(); if (mat->numRows() < mat->numColumns()) nelems = mat->numRows(); std::vector<size_t> P(nelems, -1); std::vector<size_t> Qt(nelems, -1); // ignore return value (rank) of: LUdivine(mat->ring().field(), FFLAS::FflasNonUnit, (transpose ? FFLAS::FflasTrans : FFLAS::FflasNoTrans), mat->numRows(), mat->numColumns(), mat->array(), mat->numColumns(), &P[0], &Qt[0]); engine_RawArrayIntPairOrNull result = new engine_RawArrayIntPair_struct; result->a = stdvector_to_M2_arrayint(Qt); result->b = stdvector_to_M2_arrayint(P); return result; #endif return 0; }
inline M2_arrayintOrNull LU(const DMat<RT>& A, DMat<RT>& L, DMat<RT>& U) { std::vector<size_t> perm; DMatLinAlg<RT> LUdecomp(A); LUdecomp.matrixPLU(perm, L, U); return stdvector_to_M2_arrayint(perm); }
inline M2_arrayintOrNull rankProfile(const DMat<RT>& A, bool row_profile) { std::vector<size_t> profile; if (row_profile) { // First transpose A DMat<RT> B(A.ring(), A.numColumns(), A.numRows()); MatrixOps::transpose(A,B); DMatLinAlg<RT> LUdecomp(B); LUdecomp.columnRankProfile(profile); return stdvector_to_M2_arrayint(profile); } else { DMatLinAlg<RT> LUdecomp(A); LUdecomp.columnRankProfile(profile); return stdvector_to_M2_arrayint(profile); } }
TEST(Util, m2array2stdvec_check) { std::vector<int> a{-145385,3,6,4, -2}; M2_arrayint b = stdvector_to_M2_arrayint(a); auto c = M2_arrayint_to_stdvector<int>(b); EXPECT_EQ(a,c); }
TEST(Util, m2array2stdvec_big) { std::vector<long> a{-1453853049583,3,6,4, -2}; M2_arrayint b = stdvector_to_M2_arrayint(a); std::vector<long> c = M2_arrayint_to_stdvector<long>(b); EXPECT_FALSE(a == c); }
TEST(Util, m2arrayint_zero) { std::vector<int> a{}; M2_arrayint b = stdvector_to_M2_arrayint(a); std::vector<int> c = M2_arrayint_to_stdvector<int>(b); EXPECT_EQ(a,c); }
TEST(Util, m2array2stdvec) { std::vector<int> a{1,3,6,4}; M2_arrayint b = stdvector_to_M2_arrayint(a); std::vector<int> c = M2_arrayint_to_stdvector<int>(b); EXPECT_EQ(a,c); }