15#include "singularconfig.h"
28static spasm* conv_matrix2spasm(
matrix M,
const ring
R)
32 spasm_triplet *
T = spasm_triplet_alloc(
i,
j, 1,
R->cf->ch, 1);
33 for (
int ii=1;ii<=
i;ii++)
35 for(
int jj=1;jj<=
j;jj++)
40 spasm_add_entry(
T,ii-1,jj-1,(spasm_GFp)(
long)
pGetCoeff(
p));
44 spasm*
A=spasm_compress(
T);
45 spasm_triplet_free(
T);
49static spasm* conv_smatrix2spasm(ideal
M,
const ring
R)
53 spasm_triplet *
T = spasm_triplet_alloc(
i,
j, 1,
R->cf->ch, 1);
54 for(
int jj=0;jj<
j;jj++)
60 spasm_add_entry(
T,ii-1,jj,(spasm_GFp)(
long)
pGetCoeff(
p));
64 spasm*
A=spasm_compress(
T);
65 spasm_triplet_free(
T);
69static matrix conv_spasm2matrix(spasm *
A,
const ring
R)
76 for (
int i = 0;
i < n;
i++)
78 for (
int px = Ap[
i]; px < Ap[
i + 1]; px++)
80 spasm_GFp
x = (Ax !=
NULL) ? Ax[px] : 1;
87static ideal conv_spasm2smatrix(spasm *
A,
const ring
R)
94 for (
int i = 0;
i < n;
i++)
96 for (
int px = Ap[
i]; px < Ap[
i + 1]; px++)
98 spasm_GFp
x = (Ax !=
NULL) ? Ax[px] : 1;
107static number get_spasm_entry(spasm *
A,
int i,
int j,
const ring
R)
114 spasm_GFp *Ax =
A->x;
117 for (
int px = Ap[
i]; px < Ap[
i + 1]; px++)
119 spasm_GFp
x = (Ax !=
NULL) ? Ax[px] : 1;
127static spasm* sp_kernel(spasm*
A,
const ring
R)
131 int*
p = (
int*)spasm_malloc(n *
sizeof(
int));
132 int * qinv = (
int*)spasm_malloc(
m *
sizeof(
int));
133 spasm_find_pivots(
A,
p, qinv);
137 spasm* A_clean = spasm_permute(
A,
p, SPASM_IDENTITY_PERMUTATION, SPASM_WITH_NUMERICAL_VALUES);
139 for (
int i = 0;
i < n;
i++)
141 if (spasm_row_weight(
A,
i) == 0)
150 spasm* A_t = spasm_transpose(
A, SPASM_WITH_NUMERICAL_VALUES);
151 spasm_find_pivots(A_t, qinv,
p);
153 spasm* K = spasm_kernel(A_t, qinv);
156 spasm* K = spasm_kernel(
A,
p);
163static spasm* sp_rref(spasm*
A)
165 spasm_lu *LU = spasm_LU(
A, SPASM_IDENTITY_PERMUTATION, 1);
166 spasm *U = spasm_transpose(LU->L, 1);
167 spasm_make_pivots_unitary(U, SPASM_IDENTITY_PERMUTATION, U->n);
172static spasm* sp_Mult_v(spasm*
A,
int *
v)
175 spasm *AA=spasm_submatrix(
A,0,
A->n,0,
A->m,1);
182static void* sp_Init(blackbox* )
186 spasm_triplet *
T = spasm_triplet_alloc(0, 0, 1,
currRing->cf->ch, 1);
187 spasm*
A=spasm_compress(
T);
188 spasm_triplet_free(
T);
193 WerrorS(
"ring with Z/p coeffs required");
197static void sp_destroy(blackbox* ,
void *d)
199 if (d!=
NULL) spasm_csr_free((spasm*)d);
202static char* sp_String(blackbox* ,
void *d)
206 sprintf(
buf,
"spasm matrix %dx%d",
A->n,
A->m);
209static void* sp_Copy(blackbox* ,
void *d)
214 spasm*
B=spasm_submatrix(
A,0,
A->n,0,
A->m,1);
223 if (d!=
NULL) spasm_csr_free((spasm*)d);
230 l->data = (
void*)
NULL;
263 if ((u!=
NULL) && (u->
Typ()==SPASM_CMD))
274 if ((u!=
NULL) && (u->
Typ()==SPASM_CMD))
285 if ((u!=
NULL) && (u->
Typ()==SPASM_CMD))
296 if ((u!=
NULL) && (u->
Typ()==SPASM_CMD))
299 res->data=(
void*)sp_rref((spasm*)u->
Data());
309 res->data=(
void*)spasm_transpose((spasm*)arg->
Data(),SPASM_WITH_NUMERICAL_VALUES);
314 spasm*
A=(spasm*)arg->
Data();
316 res->data=(
void*)(
long)
A->m;
321 spasm*
A=(spasm*)arg->
Data();
323 res->data=(
void*)(
long)
A->n;
335 res->data=(
char*)get_spasm_entry((spasm*)a1->
Data(),(int)(
long)a2->
Data(),
345 blackbox *
b=(blackbox*)
omAlloc0(
sizeof(blackbox));
346 b->blackbox_destroy=sp_destroy;
347 b->blackbox_String=sp_String;
348 b->blackbox_Init=sp_Init;
349 b->blackbox_Copy=sp_Copy;
350 b->blackbox_Assign=sp_Assign;
351 b->blackbox_Op1=sp_Op1;
352 b->blackbox_Op3=sp_Op3;
354 p->iiAddCproc(
"spasm.so",
"spasm_kernel",
FALSE,kernel);
355 p->iiAddCproc(
"spasm.so",
"spasm_rref",
FALSE,rref);
356 p->iiAddCproc(
"spasm.so",
"to_smatrix",
FALSE,to_smatrix);
357 p->iiAddCproc(
"spasm.so",
"to_matrix",
FALSE,to_matrix);
363 PrintS(
"no spasm support\n");
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
BOOLEAN blackboxDefaultOp3(int, leftv, leftv, leftv, leftv)
default procedure blackboxDefaultOp3, to be called as "default:" branch
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Class used for (list of) interpreter objects.
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
matrix mpNew(int r, int c)
create a r x c zero-matrix
#define MATELEM(mat, i, j)
1-based access to matrix
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
static poly p_Add_q(poly p, poly q, const ring r)
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void PrintS(const char *s)
static BOOLEAN rField_is_Zp(const ring r)
int status int void * buf
ideal idInit(int idsize, int rank)
initialise an ideal / module
int SI_MOD_INIT() sispasm(SModulFunctions *psModulFunctions)