5#include <M2/math-include.h>
49 o <<
"[unprintable matrix]";
61 if (r < 0 || r >= M->
n_rows())
63 ERROR(
"matrix row index %d out of range 0 .. %d", r, M->
n_rows() - 1);
66 if (c < 0 || c >= M->
n_cols())
68 ERROR(
"matrix column index %d out of range 0 .. %d",
91 if(nrows < 0 || ncols < 0)
93 ERROR(
"internal error: matrix has a negative size %d by %d",
98 engine_RawRingElementArrayArray entries =
100 entries->len = nrows;
103 for(
int r = 0; r < nrows; r++)
105 engine_RawRingElementArray currRow =
107 currRow->len = ncols;
108 std::fill_n(currRow->array, ncols,
zero);
109 entries->array[r] = currRow;
112 for(
int c = 0; c < ncols; c++)
114 const vec &column = M->
elem(c);
115 for(
const vecterm &term : column)
117 if(term.comp < 0 || term.comp >= nrows)
119 ERROR(
"internal error: matrix contains invalid entries:"
120 "row index %d out of range 0 .. %d",
126 entries->array[term.comp]->array[c] =
143#warning prefer_dense not yet used
145 return Matrix::identity(F);
154#warning prefer_dense not yet used
156 return Matrix::zero(F,
G);
161 const engine_RawRingElementArray M,
166#warning prefer_dense not yet used
168 return Matrix::make(target, ncols, M);
174 const engine_RawRingElementArray M,
179#warning prefer_dense not yet used
181 return Matrix::make(target, source, deg, M);
189 const engine_RawRingElementArray entries,
194#warning prefer_dense not yet used
196 return Matrix::make_sparse(target, ncols, rows, cols, entries);
205 const engine_RawRingElementArray entries,
210#warning prefer_dense not yet used
212 return Matrix::make_sparse(target, source, deg, rows, cols, entries);
220#warning not implemented yet
237#warning prefer_dense not yet used
239 return M->
remake(target, source, deg);
255#warning prefer_dense not yet used
269 double fraction_non_zero,
275#warning preference not yet used
277 return Matrix::random(R, r, c, fraction_non_zero, special_type);
332 unsigned int n = Ms->len;
335 ERROR(
"matrix concat: expects at least one matrix");
342 for (
unsigned int i = 0; i < n; i++)
344 const Matrix *M = Ms->array[i];
347 ERROR(
"matrix concat: different base rings");
352 ERROR(
"matrix concat: row sizes are not equal");
355 for (
int j = 0; j < M->
n_cols(); j++)
370 const engine_RawMatrixArray Ms)
376 unsigned int n = Ms->len;
379 ERROR(
"matrix direct sum: expects at least one matrix");
384 for (
unsigned int i = 1; i < n; i++)
385 if (R != Ms->array[i]->get_ring())
387 ERROR(
"matrix direct sum: different base rings");
390 for (
unsigned int i = 1; i < n; i++)
456 return Matrix::flip(F,
G);
471 return Matrix::wedge_product(
p, q, F);
525#warning "check with 0.9.2 about what this should even do"
529 ERROR(
"expected same ring");
532 return Matrix::koszul_monomials(nskew, M, N);
573 return M->
sort(deg_order, mon_order);
599 int n_minors_to_compute,
611 p, strategy, n_minors_to_compute,
612 first_row_set, first_col_set);
632 return M->
diff(N, 1);
638 return M->
diff(N, 0);
652 return M->
coeffs(vars, monoms);
664 return M->Matrix::basis(lo_degree, hi_degree, wt, vars, do_truncation, limit);
696 if (coeffs ==
nullptr)
return nullptr;
759 "const Matrix /* or null */ * IM2_Matrix_remove_content(const Matrix *M) -- not implemented yet"
773 Matrix::iterator i(f);
774 for (
int c = 0; c < f->
n_cols(); c++)
780 ERROR(
"cannot promote given matrix");
802 Matrix::iterator i(f);
803 for (
int c = 0; c < f->
n_cols(); c++)
851 gmp_RR infinity_threshold,
927 (void) nConstantsAndInputs;
1072 for (
size_t r = 0; r < MC->getMat().numRows(); ++r)
1074 result.push_back(MC->getMat().entry(r, col).re);
1075 result.push_back(MC->getMat().entry(r, col).im);
const Matrix * toMatrix(const FreeModule *target, const BasicPolyList &Fs)
Ring-agnostic polynomial-list transport type plus its streaming collector and emitter.
BasicPolyList parseMsolveFile(std::string filename)
BasicPolyList parseMsolveFromString(std::string contents)
Parsers from text (string or file) into a BasicPolyList, including the Msolve input format.
Engine-boundary C API for the Numerical Algebraic Geometry subsystem.
Numerical Algebraic Geometry: homotopy continuation PathTracker and supporting numeric types.
Type declarations for the SLP DAG, its evaluator hierarchy, and the homotopy abstraction.
Append-only GC-backed byte buffer used throughout the engine for text output.
unsigned int hash() const
const Ring * get_ring() const
const_monomial degree(int i) const
Engine-side free module R^n over a Ring.
virtual void text_out(buffer &o) const =0
virtual bool track(const MutableMatrix *inputs, MutableMatrix *outputs, MutableMatrix *output_extras, gmp_RR init_dt, gmp_RR min_dt, gmp_RR epsilon, int max_corr_steps, gmp_RR infinity_threshold, bool checkPrecision)=0
aring-style adapter for double-precision complex numbers, stored as (double, double) pairs.
MutableEngineObject wrapper that owns a Homotopy via unique_ptr.
MutableEngineObject wrapper that owns a PointArray via unique_ptr.
MutableEngineObject wrapper holding a raw SLEvaluator*.
MutableEngineObject wrapper that owns an SLProgram via unique_ptr.
const_monomial degree_shift() const
const Ring * get_ring() const
ring_elem elem(int i, int j) const
Matrix * minors(int p, int strategy) const
Matrix * remove_monomial_factors(bool make_squarefree_only) const
Matrix * top_coefficients(Matrix *&monoms) const
M2_arrayintOrNull support() const
const Matrix * remake(const FreeModule *target, const FreeModule *source, M2_arrayint deg) const
const Matrix * remove_content() const
Matrix * module_tensor(const Matrix *m) const
Matrix * monomials(M2_arrayint vars) const
M2_arrayint elim_keep(int nparts) const
bool is_homogeneous() const
const Matrix * split_off_content(const Matrix *&result) const
Matrix * symm(int n) const
Matrix * pfaffians(int p) const
Matrix * homogenize(int v, const std::vector< int > &wts) const
const FreeModule * rows() const
Matrix * exterior(int p, int strategy) const
Matrix * diff(const Matrix *m, int use_coef) const
Matrix * lead_term(int n=-1) const
ring_elem pfaffian() const
M2_arrayint sort(int degorder, int monorder) const
void text_out(buffer &o) const
Matrix * transpose() const
const FreeModule * cols() const
Matrix * koszul(int p) const
Matrix * tensor(const Matrix *m) const
Matrix * compress() const
Matrix * divide_by_var(int n, int maxd, int &maxdivided) const
bool is_equal(const Matrix &m) const
M2_arrayint elim_vars(int nparts) const
Matrix * reshape(const FreeModule *G, const FreeModule *H) const
const Matrix * content() const
Matrix * remove_scalar_multiples() const
Matrix * coeffs(M2_arrayint vars, const Matrix *monoms) const
Matrix * sub_matrix(M2_arrayint r, M2_arrayint c) const
void compute_column_degrees()
void set_column_degree(int i, const_monomial deg)
void set_entry(int r, int c, ring_elem a)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
unsigned int hash() const
virtual M2SLEvaluator * createSLEvaluator(M2SLProgram *P, M2_arrayint constsPos, M2_arrayint varsPos) const =0
virtual M2SLEvaluator * createCompiledSLEvaluator(M2_string libName, int nInputs, int nOutputs) const =0
Abstract base class for mutable matrices over an arbitrary engine Ring, the in-place counterpart of t...
static PathTracker * make(const Matrix *)
Numerical homotopy-continuation path tracker for systems of polynomial equations.
std::vector< double > RealVector
int lookup(const RealVector &a) const
void text_out(buffer &o) const
int lookup_or_append(const RealVector &a)
Container of numerical points equipped with an -tolerance and a random weight vector used to bucket a...
virtual bool promote(const Ring *R, const ring_elem f, ring_elem &result) const =0
virtual FreeModule * make_FreeModule() const
virtual bool lift(const Ring *R, const ring_elem f, ring_elem &result) const =0
vec copy_vec(const vecterm *v) const
const Monoid * degree_monoid() const
static RingElement * make_raw(const Ring *R, ring_elem f)
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
virtual Homotopy * createHomotopy(SLEvaluator *Hxt, SLEvaluator *HxH)=0
virtual bool evaluate(const MutableMatrix *inputs, MutableMatrix *outputs)=0
virtual SLEvaluator * specialize(const MutableMatrix *parameters) const =0
virtual void text_out(buffer &o) const =0
void evaluate(int n, const element_type *values, element_type *out)
GATE_POSITION addMProduct(const M2_arrayint)
GATE_POSITION addDet(const M2_arrayint)
void text_out(buffer &) const
GATE_POSITION addDivide(const M2_arrayint)
void setOutputPositions(const M2_arrayint)
GATE_POSITION addMSum(const M2_arrayint)
A straight-line program: a directed acyclic graph of arithmetic gates over a fixed list of inputs and...
static StraightLineProgram * make(const PolyRing *R, ring_elem e)
void text_out(buffer &o) const
DMat<ACoeffRing> — dense-matrix template plus the umbrella that wires in every per-ring specialisatio...
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
void mpz_reallocate_limbs(mpz_ptr _z)
Inline helpers that move GMP / MPFR / MPFI limbs from malloc-managed storage into the bdwgc heap.
const Matrix * IM2_Matrix_monomials(M2_arrayint vars, const Matrix *M)
gmp_ZZ rawSLPDetGate(M2SLProgram *S, M2_arrayint a)
M2_string rawPathTrackerToString(PathTracker *p)
const Matrix * IM2_Matrix_homogenize(const Matrix *M, int var, M2_arrayint wts)
unsigned int rawStraightLineProgramHash(StraightLineProgram *slp)
M2_bool IM2_Matrix_is_implemented_as_dense(const Matrix *M)
const Matrix * IM2_Matrix_remove_content(const Matrix *M)
PathTracker * rawPathTracker(const Matrix *HH)
const Matrix * IM2_Matrix_koszul(int p, const Matrix *M)
int IM2_Matrix_n_rows(const Matrix *M)
const Matrix * rawMatrixReadMsolveString(const Ring *R, M2_string contents)
const Matrix * IM2_Matrix_tensor(const Matrix *M, const Matrix *N)
M2_string IM2_Matrix_to_string(const Matrix *M)
const FreeModule * IM2_Matrix_get_target(const Matrix *M)
gmp_ZZ rawSLPDivideGate(M2SLProgram *S, M2_arrayint a)
const Matrix * IM2_Matrix_submatrix1(const Matrix *M, M2_arrayint cols)
M2_arrayintOrNull IM2_Matrix_sort_columns(const Matrix *M, int deg_order, int mon_order)
engine_RawMatrixPairOrNull rawTopCoefficients(const Matrix *M)
const Matrix * rawCoefficients(M2_arrayint vars, const Matrix *monoms, const Matrix *M)
M2SLEvaluator * rawSLEvaluatorSpecialize(M2SLEvaluator *H, const MutableMatrix *parameters)
const Matrix * rawMatrixRemoveContent(const Matrix *M)
unsigned int rawPointArrayHash(M2PointArray *pa)
const Matrix * IM2_Matrix_make2(const FreeModule *target, const FreeModule *source, M2_arrayint deg, const engine_RawRingElementArray M, int preference)
StraightLineProgram * rawSLP(const Matrix *consts, M2_arrayint program)
const Matrix * IM2_Matrix_submatrix(const Matrix *M, M2_arrayint rows, M2_arrayint cols)
gmp_ZZ rawSLPProductGate(M2SLProgram *S, M2_arrayint a)
const Matrix * rawRemoveMonomialFactors(const Matrix *m, M2_bool make_squarefree_only)
const Matrix * IM2_Matrix_concat(const engine_RawMatrixArray Ms)
const Matrix * IM2_Matrix_make_sparse1(const FreeModule *target, int ncols, M2_arrayint rows, M2_arrayint cols, const engine_RawRingElementArray entries, int preference)
gmp_ZZ rawSLPsetOutputPositions(M2SLProgram *S, M2_arrayint a)
const RingElement * IM2_Matrix_get_entry(const Matrix *M, int r, int c)
const Matrix * IM2_Matrix_minors(int p, const Matrix *M, int strategy)
const Matrix * IM2_Matrix_transpose(const Matrix *M)
const Matrix * IM2_Matrix_reshape(const Matrix *M, const FreeModule *F, const FreeModule *G)
M2_string rawSLProgramToString(M2SLProgram *slp)
M2_bool rawSLEvaluatorEvaluate(M2SLEvaluator *sle, const MutableMatrix *inputs, MutableMatrix *outputs)
int IM2_Matrix_is_equal(const Matrix *M, const Matrix *N)
const Matrix * IM2_Matrix_exterior(int p, const Matrix *M, int strategy)
unsigned int rawMatrixHash(const Matrix *M)
const Matrix * IM2_Matrix_contract(const Matrix *M, const Matrix *N)
M2PointArray * rawPointArray(double epsilon, int n)
const Matrix * rawBasis(const Matrix *M, M2_arrayint lo_degree, M2_arrayint hi_degree, M2_arrayint wt, M2_arrayint vars, M2_bool do_truncation, int limit)
unsigned int rawHomotopyHash(M2Homotopy *)
const Matrix * IM2_Matrix_remake2(const FreeModule *target, const FreeModule *source, M2_arrayint deg, const Matrix *M, int preference)
const Matrix * rawMatrixContent(const Matrix *M)
M2_string rawStraightLineProgramToString(StraightLineProgram *slp)
int IM2_Matrix_n_cols(const Matrix *M)
M2SLEvaluator * rawSLEvaluator(M2SLProgram *SLP, M2_arrayint constsPos, M2_arrayint varsPos, const MutableMatrix *consts)
M2SLProgram * rawSLProgram(unsigned long nConstantsAndInputs)
M2_string rawHomotopyToString(M2Homotopy *H)
engine_RawMatrixAndInt IM2_Matrix_divide_by_var(const Matrix *M, int var, int maxdegree)
const Matrix * rawMatrixReadMsolveFile(const Ring *R, M2_string filename)
gmp_ZZ rawSLPSumGate(M2SLProgram *S, M2_arrayint a)
PathTracker * rawPathTrackerPrecookedSLPs(StraightLineProgram *slp_pred, StraightLineProgram *slp_corr)
PathTracker /////////////////////////////////////////////////////.
const Matrix * IM2_Matrix_direct_sum(const engine_RawMatrixArray Ms)
M2_arrayint IM2_Matrix_get_degree(const Matrix *M)
M2_arrayint IM2_Matrix_elim_vars(int nparts, const Matrix *M)
unsigned int rawSLEvaluatorHash(M2SLEvaluator *)
const Matrix * IM2_Matrix_make_sparse2(const FreeModule *target, const FreeModule *source, M2_arrayint deg, M2_arrayint rows, M2_arrayint cols, const engine_RawRingElementArray entries, int preference)
M2_bool rawHomotopyTrack(M2Homotopy *H, const MutableMatrix *inputs, MutableMatrix *outputs, MutableMatrix *output_extras, gmp_RR init_dt, gmp_RR min_dt, gmp_RR epsilon, int max_corr_steps, gmp_RR infinity_threshold, M2_bool checkPrecision)
const Matrix * IM2_Matrix_zero(const FreeModule *F, const FreeModule *G, int preference)
engine_RawRingElementArrayArrayOrNull IM2_Matrix_get_entries(const Matrix *M)
const Matrix * IM2_Matrix_remake1(const FreeModule *target, const Matrix *M, int preference)
unsigned int rawPathTrackerHash(PathTracker *p)
PointArray::RealVector getRealVector(const MutableMatrix *M, int col)
const Matrix * IM2_Matrix_diff(const Matrix *M, const Matrix *N)
const Matrix * rawKoszulMonomials(int nskew, const Matrix *M, const Matrix *N)
const Matrix * IM2_Matrix_initial(int nparts, const Matrix *M)
const RingElement * IM2_Matrix_pfaffian(const Matrix *M)
const Matrix * rawModuleTensor(const Matrix *M, const Matrix *N)
const Matrix * rawEvaluateSLP(StraightLineProgram *SLP, const Matrix *vals)
int rawPointArrayLookupOrAppend(M2PointArray *pa, const MutableMatrix *M, int col)
PathTracker * rawPathTrackerProjective(const Matrix *S, const Matrix *T, gmp_RR productST)
const Matrix * IM2_Matrix_flip(const FreeModule *F, const FreeModule *G)
M2_string rawSLEvaluatorToString(M2SLEvaluator *sle)
M2_arrayint IM2_Matrix_keep_vars(int nparts, const Matrix *M)
M2Homotopy * rawHomotopy(M2SLEvaluator *Hx, M2SLEvaluator *Hxt, M2SLEvaluator *HxH)
const Matrix * IM2_Matrix_symm(int p, const Matrix *M)
M2_bool IM2_Matrix_is_graded(const Matrix *M)
int rawPointArrayLookup(M2PointArray *pa, const MutableMatrix *M, int col)
const Matrix * rawMatrixSplitContent(const Matrix *M, const Matrix **result)
gmp_ZZ rawSLPInputGate(M2SLProgram *S)
M2SLEvaluator * rawCompiledSLEvaluator(M2_string libName, int nInputs, int nOutputs, const MutableMatrix *empty)
const Matrix * rawMatrixCompress(const Matrix *M)
M2_string rawPointArrayToString(M2PointArray *pa)
const Matrix * IM2_Matrix_promote(const FreeModule *newTarget, const Matrix *f)
const Matrix * IM2_Matrix_pfaffians(int p, const Matrix *M)
M2_bool IM2_Matrix_is_zero(const Matrix *M)
const Matrix * rawWedgeProduct(int p, int q, const FreeModule *F)
const Matrix * rawRemoveScalarMultiples(const Matrix *m)
const FreeModule * IM2_Matrix_get_source(const Matrix *M)
const Matrix * IM2_Matrix_identity(const FreeModule *F, int preference)
unsigned int rawSLProgramHash(M2SLProgram *)
const Matrix * IM2_Matrix_random(const Ring *R, int r, int c, double fraction_non_zero, int special_type, int preference)
const Matrix * rawMinors(int p, const Matrix *M, int strategy, int n_minors_to_compute, M2_arrayintOrNull first_row_set, M2_arrayintOrNull first_col_set)
const Matrix * IM2_Matrix_lift(int *success_return, const FreeModule *newTarget, const Matrix *f)
const Matrix * IM2_Matrix_make1(const FreeModule *target, int ncols, const engine_RawRingElementArray M, int preference)
M2_arrayintOrNull rawMatrixIndices(const Matrix *f)
M2_arrayint to_degree_vector(const Monoid *M, const_monomial d)
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define getmemarraytype(S, len)
#define getmemstructtype(S)
M2_arrayint M2_arrayintOrNull
struct engine_RawMatrixAndInt_struct * engine_RawMatrixAndInt
engine_RawMatrixPair engine_RawMatrixPairOrNull
engine_RawRingElementArrayArray engine_RawRingElementArrayArrayOrNull
struct engine_RawMatrixPair_struct * engine_RawMatrixPair
MutableMatrix — abstract base of every mutable matrix the engine hands across the boundary.
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Engine-boundary C API for constructing, transforming, and inspecting immutable Matrix objects.
Matrix — the engine's immutable homomorphism F -> G between free modules.
Engine-boundary C API for constructing and inspecting Monoid objects.
MutableMat<Mat> — the templated bridge from DMat / SMat to the abstract MutableMatrix.
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
ring_elem — the universal value type carried by every Ring* in the engine.
std::string string_M2_to_std(const M2_string s)
std::vector< T > M2_arrayint_to_stdvector(M2_arrayint arr)