[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Sun, 8 Feb 2004 22:29:18 +0000 (UTC) 
Subject:Re: how do I pass array parameters to external functions? 
From:Aaron Sloman 
Volume-ID: 


Jenab,

[Please try to avoid sending html messages to email lists or news
groups. Send only plain text. Many people will refuse to answer
queries posted with unnecessary html clutter. Your email or news
posting software should be able to suppress html. If necessary use
mozilla, which gives the option.]

> Hello.
>
> Can I give a matrix(two dimensional) to a external function(C
> language)as parameter?

Pop11 arrays are actually procedures (functions) which include data.

They are therefore not capable of being recognized as arrays or
matrices by any other language. See
    REF ARRAYS
    REF PROCEDURE

So if you wish to give something like an array to an external
procedure it will have to be a vector derived from the array.

Each pop11 array includes a vector containing the data. If A is a
pop11 array created by newarray or newanyarray, then arrayvector(A)
will return the arrayvector. See
    HELP ARRAYVECTOR
    REF ARRAYS

If you really know what you are doing you can pass the arrayvector
to an external procedure.

However you will have to make sure that the vector contains objects
of the right type, which probably means that you have to create the
array using newanyarray. See HELP NEWANYARRAY

There are examples in
    REF EXTERNAL,
    REF INTVEC,
    REF EXTERNAL_DATA


There are also quite a lot of examples in David Young's popvision
package. If you have downloaded bham-linux-poplog.tar.gz then
you already have popvision.tar.gz, which you can untar into
$poplocal/local/ if you have not yet done so.

Otherwise you can fetch it from here

    http://www.cs.bham.ac.uk/research/poplog/popvision.tar.gz
        (about 2.8 Mbytes including compiled code)

If you install it by untarring into #poplocal/local, then do
    uses popvision

then HELP POPVISION will give you an overview of the facilities
provided. If there is anything there that is similar to what
you want to do you can look at the code to see how it does it.
There are pop11 sources and C sources.

The pop11 programs pass data to and get results from the C programs.
which are used to perform a variety of image processing operations.

An example can be found in these two files
    popvision/lib/array_transpose.p
    popvision/lib/array_transpose.c

The procedures are described in HELP ARRAY_TRANSPOSE


HELP MLP describes a package that implements multi-layer
perceptrons, and provides pop11 procedures for running C programs
that do the training.

The relevant pop and C procedures are in
    popvision/lib/mlp.p
    popvision/lib/mlp.c


> also, can the external function return the modified matrix?

Strictly if you pass a structure, and the external function
manipulates its contents, the altered contents will be accessible
from pop11, and the external function does not need to return the
matrix.

It may be possible for an external procedure to create a new matrix but
then it will have to be returned in a pop11 datastructure which serves
as a 'wrapper'.

The external object cannot be directly stored in a pop11 structure or
assigned to a pop11 variable, or passed as argument to a pop11
procedure, for various reasons. E.g. it could confuse the garbage
collector and lead to data-corruption and a poplog crash.

> I tried to pass parameter as array(two dimensional) and pointer.But I
> was not successful.
>
> For example,I did:
>
> external declare mytag in c;
>
> void f(a)
>
> int a[2][2]; (or int (*a)[2];)
>
> {}
>
> endexternal;
>
> external load mytag;
>
> example
>
> endexternal;
>
> vars m;
>
> newarray([1 2 1 2],4)->m;

Here you will need to use newanyarray instead of newarray, and probably
use the intvec or shortvec vector class if your matrices contain
integers. (REF INTVEC)

>
> f(m); (or f(ident m);)

You will need to use arrayvector(m).

Look at the REF files to find out how to pass a vector.

Also you will need to think carefully about whether you want
poparray_by_row to be true or false, to match the storage
conventions for the external arrays.

I have never written any programs like this and cannot give any
examples. I do all my programming in Pop11.

Maybe someone else with more experience can provide more
information.

Aaron
NOTE:
There is a new, expanded, version of popvision, which I hope to find
time to install in the near future after re-packaging it slightly to
fit the conventions of the free poplog site.
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk   (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html