This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Guile numerical work and uniform arrays


>>>>> "Jim" == Jim Blandy <jimb@red-bean.com> writes:


Jim> Do you want all of "the basic machine types" available for use in
Jim> uniform arrays?

Jim> Or do you want all of "the types corresponding to the C and
Jim> FORTRAN types" available?

Jim> That is, what do you want to specify in your Guile code ---
Jim> 64-bit IEEE float, or "whatever a C `double' is on this machine"?

Jim> Is the purpose to mesh with libraries written in C or FORTRAN, or
Jim> to have exact control over the bytes?
In my opinion, the main purpose would be "to mesh with libraries
written in C or FORTRAN". 

That is why, "the types corresponding to the C and FORTRAN types"
will be sufficient for the majority of applications. I'm not sure
about "complex" type in FORTRAN. Is its exact layout standartized for
all machines/architectures/compilers? Is it always equivalent to
struct {double re_im[2];}?

Also, I'm not sure in absolute necessity of having equivalents of
"short ints" and "long long ints" arrays, "long doubles" (if
available), from the other side, may be quite useful in many
calculations which require extended accuracy.


>> I would also find it very useful if there were a way to get guile
>> to treat a region of memory as a uniform array (and not try to GC
>> the memory block).  This would let me attach to large chunks of
>> memory allocated by other packages.

Jim> Should Guile call a hook associated with the array to free its
Jim> space?

I would propose both interfaces, like
	SCM doubles2scm(double *array, int n)
	wrap_doubles(SCM, double *array,int n)
with the first one, allocating new memory, copying there the contents
of array, and putting SCM under garbage control.
The second (presumably macros) could work with stack variables, using
"alloca" for allocation of new pair, and putting address of "array" to
its cdr. Thus, it allocates nothing, and is not under gc. There is no
need to free it, therefore. I used such construction when called guile
closures from fortran subroutine. I think, it is very useful, because,
for example, in linear algebra calculations with large matrices,
allocation space inside internal calls, and subsequent gc, is very
inefficient.

Finally, I'd like to propose to think about multi-dimensional
arrays representation. So far as I uderstood, in SLIB they are built
on the top of uniform-vectors, and may be used quite directly with
FORTRAN libraries, but not always - for example, shared arrays do not
have such representation. Also, there is no standard C procedure to
get the "uniform-array component" from the multi-dimesnsional array.
I think, all this must be standartized, otherwise we will have a lot
of hand-written solutions :).

--
Best regards,
	V.Kamyshenko.