help-octave
[Top][All Lists]

 From: John W. Eaton Subject: dynamic link questions Date: Wed, 4 Nov 1998 16:00:07 -0600 (CST)

```On  4-Nov-1998, Andy Adler <address@hidden> wrote:

| I'm in the process of writing a first stab at a sparse matrix
| library for octave, based on the SuperLU sparse library.
| Many of the fuctions are working, and I'll be posting my version 0.1
| later this month.
|
| I have a function  x= spfun( a , "operation" , b )
|
| where operation can be "solve"  to get a\b
|                        "mul"    to get a*b
|                        "el_mul" to get a.*b
|                        "trans"  to get a'
|
| I want spfun to give the right answer if you call it
| with normal"full" matrices as well.
|
| I figured that a\b is a.solve(b), a*b is a*b etc.

I think a better approach would be to define a sparse matrix data type
and then create the necessary functions for performing operations on
that data type.  Then you can define functions to handle the
operators you care about for same-type and mixed-type operations.  You
can also define a default conversion operator that will allow other
operations to succeed, though that might not be a good thing to do for
sparse matrices since you could easily run out of memory converting a
sparse matrix to a full matrix.

I think the interface provided by the octave_value class in Octave
2.0.x is adequate for defining new data types, but I'm working on
improving it for 2.2 (you can see the current state of the revision in
the 2.1.x releases).

| My question is
|
| 1. How do you get a .* b
|                   a ./ b
|    from within an *oct file ?

For the Matrix and ComplexMatrix objects, these are handled by
functions in the MArray classes from which they are derived.  The
function names are `product' and `quotient':

template MArray2<T> product (const MArray2<T>& a, const MArray2<T>& b);
template MArray2<T> quotient (const MArray2<T>& a, const MArray2<T>& b);

(these lines were extracted from liboctave/MArray2.h.

| 2. How do you sort a vector?
|    The source has mx_sort and string.qsort in various places
|    but I don't seem to be able to call them.

The sort algorithm that's used by Octave's built-in sort function is
defined in sort.cc and is not currently part of the matrix classes
defined in liboctave, although it probably should be.  There are a
number of places in Octave where code is defined at the wrong `level'
of liboctave, etc.).  I'm working on cleaning some of these things up
in 2.1.x.  It would be helpful if people send in suggestions for how
things can be redesigned, or (better) provide patches for these kinds
of things

|    I'm also not sure how I'd call the DLD function sort. I
|    tried calling Fsort but that didn't seem to work.

The safe way to call built-in functions or .m files from a .oct file
is to use feval:

int nargout = ...;
octave_value_list args = ...;
octave_value_list retval = feval ("sort", args, nargout);

It will take care of finding the function definition using the same
rules that Octave's interpreter does.

jwe

```