I think "char" or "int" doesn't matter, when I change "int" to/from "char", the result is the same as before.
And, when I do as you said, replace (address aptr) with aptr, strangely, the result doesn't change.
But when I test C array API with my own function below, the result is good. Here is code:
Code: Select all
int sm(int m, int n, double * p)
{
double *p_end;
p_end = p + (m * n) - 1;
for (;p <= p_end; p++)
(*p) = (* p) + 1;
return 0;
}
here is my test.lsp:
Code: Select all
(set 'LIB "scalam.so")
(import LIB "sm" "int" "int" "int" "void*")
(set 'a '(1 1 1 2 3 4 3 5 2 4 2 5 5 4 3))
(setq m 5 n 3)
(set 'ap (pack (dup "lf" (* m n)) a))
(set 'info (sm m n ap))
output is right
Code: Select all
> (unpack (dup "lf" 15) ap)
(2 2 2 3 4 5 4 6 3 5 3 6 6 5 4)
My all questions are:
1.in newLISP, list is contiguous in memory? just as array? or anything else?
2.To compute with address or not doesn't matter, I am confused.
3.When I test my own sm function with b which has negative number, there are error with the negative elements:
Code: Select all
>(set 'bp (pack (dup "lf" 10) b)
>(set 'info (sm 5 2 (address bp)))
> (unpack (dup "lf" 10) bp)
(1.844674407e+19 1.844674407e+19 13 15 15 13 17 17 19 17)
so, the reason is the negative number? and the more negative numbers, the more error
Code: Select all
> (set 'b '(-10 -3 -12 -14 -14 12 16 16 18 16))
(-10 -3 -12 -14 -14 12 16 16 18 16)
> (set 'bp (pack (dup "lf" 10) b))
"\000\000\000\000\000\000�C\000\000\000\000\000\000�C\000\000\000\000\000\000�C\000\000\000\000\000\000�C\000\000\000\000\000\000�C\000\000\000\000\000\000(@\000\000\000\000\000\0000@\000\000\000\000\000\0000@\000\000\000\000\000\0002@\000\000\000\000\000\0000@"
> (set 'info (sm 5 2 (address bp)))
0
> (unpack (dup "lf" 10) bp)
(1.844674407e+19 1.844674407e+19 1.844674407e+19 1.844674407e+19 1.844674407e+19
13 17 17 19 17)
am I clear? Sorry for my terrible English.
PS: the dgels functioin in lapacke.h
Code: Select all
lapack_int LAPACKE_dgels( int matrix_order, char trans, lapack_int m,
lapack_int n, lapack_int nrhs, double* a,
lapack_int lda, double* b, lapack_int ldb );
Code: Select all
#ifndef lapack_int
#if defined(LAPACK_ILP64)
#define lapack_int long
#else
#define lapack_int int
#endif
#endif
#define LAPACK_ROW_MAJOR 101
#define LAPACK_COL_MAJOR 102
in dgels fortran source code, I found:
Code: Select all
*> DGELS solves overdetermined or underdetermined real linear systems
*> involving an M-by-N matrix A, or its transpose, using a QR or LQ
*> factorization of A. It is assumed that A has full rank.
*>
*> The following options are provided:
*>
*> 1. If TRANS = 'N' and m >= n: find the least squares solution of
*> an overdetermined system, i.e., solve the least squares problem
*> minimize || B - A*X ||.
*>
*> 2. If TRANS = 'N' and m < n: find the minimum norm solution of
*> an underdetermined system A * X = B.
*>
*> 3. If TRANS = 'T' and m >= n: find the minimum norm solution of
*> an undetermined system A**T * X = B.
*>
*> 4. If TRANS = 'T' and m < n: find the least squares solution of
*> an overdetermined system, i.e., solve the least squares problem
*> minimize || B - A**T * X ||.
*>