use new notation
This commit is contained in:
parent
493161f6d8
commit
bc992f552f
14
docs/yap.tex
14
docs/yap.tex
@ -9962,6 +9962,13 @@ Unify @var{Elems} with the list including all the elements in @var{Matrix}.
|
|||||||
Unify @var{Elem} with the element of @var{Matrix} at position
|
Unify @var{Elem} with the element of @var{Matrix} at position
|
||||||
@var{Position}.
|
@var{Position}.
|
||||||
|
|
||||||
|
@item matrix_get(+@var{Matrix}[+@var{Position}],-@var{Elem})
|
||||||
|
@findex matrix_get/2
|
||||||
|
@snindex matrix_get/2
|
||||||
|
@cnindex matrix_get/2
|
||||||
|
|
||||||
|
Unify @var{Elem} with the element @var{Matrix}[@var{Position}].
|
||||||
|
|
||||||
@item matrix_set(+@var{Matrix},+@var{Position},+@var{Elem})
|
@item matrix_set(+@var{Matrix},+@var{Position},+@var{Elem})
|
||||||
@findex matrix_set/3
|
@findex matrix_set/3
|
||||||
@snindex matrix_set/3
|
@snindex matrix_set/3
|
||||||
@ -9970,6 +9977,13 @@ Unify @var{Elem} with the element of @var{Matrix} at position
|
|||||||
Set the element of @var{Matrix} at position
|
Set the element of @var{Matrix} at position
|
||||||
@var{Position} to @var{Elem}.
|
@var{Position} to @var{Elem}.
|
||||||
|
|
||||||
|
@item matrix_set(+@var{Matrix}[+@var{Position}],+@var{Elem})
|
||||||
|
@findex matrix_set/2
|
||||||
|
@snindex matrix_set/2
|
||||||
|
@cnindex matrix_set/2
|
||||||
|
|
||||||
|
Set the element of @var{Matrix}[@var{Position}] to @var{Elem}.
|
||||||
|
|
||||||
@item matrix_set_all(+@var{Matrix},+@var{Elem})
|
@item matrix_set_all(+@var{Matrix},+@var{Elem})
|
||||||
@findex matrix_set_all/2
|
@findex matrix_set_all/2
|
||||||
@snindex matrix_set_all/2
|
@snindex matrix_set_all/2
|
||||||
|
@ -84,7 +84,10 @@ typedef enum {
|
|||||||
matrix_set_all_that_disagree/5,
|
matrix_set_all_that_disagree/5,
|
||||||
matrix_expand/3,
|
matrix_expand/3,
|
||||||
matrix_select/4,
|
matrix_select/4,
|
||||||
matrix_column/3
|
matrix_column/3,
|
||||||
|
matrix_get/2,
|
||||||
|
matrix_set/2,
|
||||||
|
op(100, fy, '[]')
|
||||||
]).
|
]).
|
||||||
|
|
||||||
:- load_foreign_files([matrix], [], init_matrix).
|
:- load_foreign_files([matrix], [], init_matrix).
|
||||||
|
@ -220,6 +220,30 @@ scan_dims(int ndims, YAP_Term tl, int dims[MAX_DIMS])
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
scan_dims_args(int ndims, YAP_Term tl, int dims[MAX_DIMS])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ndims; i++) {
|
||||||
|
YAP_Term th;
|
||||||
|
int d;
|
||||||
|
|
||||||
|
th = YAP_ArgOfTerm(2+i, tl);
|
||||||
|
if (!YAP_IsIntTerm(th)) {
|
||||||
|
/* ERROR */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
d = YAP_IntOfTerm(th);
|
||||||
|
if (d < 0) {
|
||||||
|
/* ERROR */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
dims[i] = d;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cp_int_matrix(YAP_Term tl,YAP_Term matrix)
|
cp_int_matrix(YAP_Term tl,YAP_Term matrix)
|
||||||
{
|
{
|
||||||
@ -607,6 +631,44 @@ matrix_set(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
matrix_set2(void)
|
||||||
|
{
|
||||||
|
int dims[MAX_DIMS], *mat;
|
||||||
|
YAP_Term tf, t = YAP_ARG1;
|
||||||
|
|
||||||
|
mat = (int *)YAP_BlobOfTerm(YAP_ArgOfTerm(1,t));
|
||||||
|
if (!mat) {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!scan_dims_args(mat[MAT_NDIMS], t, dims)) {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
tf = YAP_ARG2;
|
||||||
|
if (mat[MAT_TYPE] == INT_MATRIX) {
|
||||||
|
if (YAP_IsIntTerm(tf)) {
|
||||||
|
matrix_long_set(mat, dims, YAP_IntOfTerm(tf));
|
||||||
|
} else if (YAP_IsFloatTerm(tf)) {
|
||||||
|
matrix_long_set(mat, dims, YAP_FloatOfTerm(tf));
|
||||||
|
} else {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (YAP_IsIntTerm(tf)) {
|
||||||
|
matrix_float_set(mat, dims, YAP_IntOfTerm(tf));
|
||||||
|
} else if (YAP_IsFloatTerm(tf)) {
|
||||||
|
matrix_float_set(mat, dims, YAP_FloatOfTerm(tf));
|
||||||
|
} else {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
matrix_set_all(void)
|
matrix_set_all(void)
|
||||||
{
|
{
|
||||||
@ -698,6 +760,25 @@ do_matrix_access(void)
|
|||||||
return YAP_Unify(tf, YAP_ARG3);
|
return YAP_Unify(tf, YAP_ARG3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_matrix_access2(void)
|
||||||
|
{
|
||||||
|
int dims[MAX_DIMS], *mat;
|
||||||
|
YAP_Term tf, t = YAP_ARG1;
|
||||||
|
|
||||||
|
mat = (int *)YAP_BlobOfTerm(YAP_ArgOfTerm(1, t));
|
||||||
|
if (!mat) {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!scan_dims_args(mat[MAT_NDIMS], t, dims)) {
|
||||||
|
/* Error */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
tf = matrix_access(mat, dims);
|
||||||
|
return YAP_Unify(tf, YAP_ARG2);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_matrix_inc(void)
|
do_matrix_inc(void)
|
||||||
{
|
{
|
||||||
@ -2989,9 +3070,11 @@ init_matrix(void)
|
|||||||
YAP_UserCPredicate("new_floats_matrix", new_floats_matrix, 4);
|
YAP_UserCPredicate("new_floats_matrix", new_floats_matrix, 4);
|
||||||
YAP_UserCPredicate("new_floats_matrix_set", new_floats_matrix_set, 4);
|
YAP_UserCPredicate("new_floats_matrix_set", new_floats_matrix_set, 4);
|
||||||
YAP_UserCPredicate("matrix_set", matrix_set, 3);
|
YAP_UserCPredicate("matrix_set", matrix_set, 3);
|
||||||
|
YAP_UserCPredicate("matrix_set", matrix_set2, 2);
|
||||||
YAP_UserCPredicate("matrix_set_all", matrix_set_all, 2);
|
YAP_UserCPredicate("matrix_set_all", matrix_set_all, 2);
|
||||||
YAP_UserCPredicate("matrix_add", matrix_add, 3);
|
YAP_UserCPredicate("matrix_add", matrix_add, 3);
|
||||||
YAP_UserCPredicate("matrix_get", do_matrix_access, 3);
|
YAP_UserCPredicate("matrix_get", do_matrix_access, 3);
|
||||||
|
YAP_UserCPredicate("matrix_get", do_matrix_access2, 2);
|
||||||
YAP_UserCPredicate("matrix_inc", do_matrix_inc, 2);
|
YAP_UserCPredicate("matrix_inc", do_matrix_inc, 2);
|
||||||
YAP_UserCPredicate("matrix_dec", do_matrix_dec, 2);
|
YAP_UserCPredicate("matrix_dec", do_matrix_dec, 2);
|
||||||
YAP_UserCPredicate("matrix_inc", do_matrix_inc2, 3);
|
YAP_UserCPredicate("matrix_inc", do_matrix_inc2, 3);
|
||||||
|
Reference in New Issue
Block a user