Vanroose | 3 May 2000 17:17
Picon

How to construct a complex matrix in a C module?

Dear Numerical Python users,

        I am new to the numerical python and extending python in C.
I am making  a module  that involves the  construction of  complex
matrices.  But first, I really want to understand how these matrices are
constructed.
 Here is an example function  that constructs  a matrix of size M and
puts on each position a complex number "x+I y".   x and y are arguments
when you call the function in python.

        My question:  Is this the right way of organising the
construction of a  complex matrix. Are there easier ways?
        Can I construct the matrix  directly in  "result->data"??

Wim Vanroose

static PyObject* matrix(PyObject *self, PyObject *args){
  double x,y;
  int size;
  int M,n,m;
  PyArrayObject *result;
  int dimensions[2];
  Py_complex *data;
  Py_complex p;
  if(!PyArg_ParseTuple(args,"idd",&M,&x,&y))
    return NULL;
  dimensions[0] = M;
  dimensions[1] = M;
  data = calloc(M*M+1,sizeof(Py_complex));
  for(n=0;n < M;n++){
(Continue reading)

Vanroose Wim | 3 May 2000 17:19
Picon

complex matrix in a C module? Program

Dear Numerical Python users,

        A small mistake when I cut and pasted the program: Here is the
program again

static PyObject* matrix(PyObject *self, PyObject *args){
  double x,y;
  int size;
  int M,n,m;
  PyArrayObject *result;
  int dimensions[2];
  Py_complex *data;
  Py_complex p;
  if(!PyArg_ParseTuple(args,"idd",&M,&x,&y))
    return NULL;
  dimensions[0] = M;
  dimensions[1] = M;
  data = calloc(M*M+1,sizeof(Py_complex));
  for(n=0;n < M;n++){
    for(m=0; m<M; m++){
      p.real=x;
      p.imag=y;
      data[n*M+m] = p;
    }
  }
  result =
(PyArrayObject*)PyArray_FromDims(2,dimensions,PyArray_CDOUBLE);
  memcpy(result->data,data,M*M*sizeof(Py_complex));
  return PyArray_Return(result);
  free(data);
(Continue reading)

Travis Oliphant | 3 May 2000 09:52
Favicon

Re: Numpy-discussion digest, Vol 1 #50 - 2 msgs

> Dear Numerical Python users,
> 
>         I am new to the numerical python and extending python in C.
> I am making  a module  that involves the  construction of  complex
> matrices.  But first, I really want to understand how these matrices are
> constructed.
>  Here is an example function  that constructs  a matrix of size M and
> puts on each position a complex number "x+I y".   x and y are arguments
> when you call the function in python.
> 
>         My question:  Is this the right way of organising the
> construction of a  complex matrix. Are there easier ways?
>         Can I construct the matrix  directly in  "result->data"??
> 

Yes, you can create the array, point a pointer to "result->data" and fill
it in.  Internally, when the array is created an equivalent malloc is
performed.

I've changed your code below to eliminate the unecessary copying.
> 
> 
> static PyObject* matrix(PyObject *self, PyObject *args){
>   double x,y;
>   int size;
>   int M,n,m;
>   PyArrayObject *result;
>   int dimensions[2];
>   Py_complex *data;
>   Py_complex p;
(Continue reading)

Vanroose Wim | 4 May 2000 11:26
Picon

Re: Numpy-discussion digest, Vol 1 #50 - 2 msgs

Dear Travis Oliphant,

        The pointer  result->data is of  type   (char *).    So I still have
to do a cast

        data = (Py_complex *)result->data;

Best Wishes
Wim Vanroose

Travis Oliphant wrote:

> Yes, you can create the array, point a pointer to "result->data" and fill
> it in.  Internally, when the array is created an equivalent malloc is
> performed.
>
> I've changed your code below to eliminate the unecessary copying.
> >
> >
> > static PyObject* matrix(PyObject *self, PyObject *args){
> >   double x,y;
> >   int size;
> >   int M,n,m;
> >   PyArrayObject *result;
> >   int dimensions[2];
> >   Py_complex *data;
> >   Py_complex p;
> >   if(!PyArg_ParseTuple(args,"idd",&M,&x,&y))
> >     return NULL;
> >   dimensions[0] = M;
(Continue reading)

Morten Kjeldgaard | 5 May 2000 18:22
Picon
Picon

Documentation?

Hi,

What's up with the NumPy documentation? It seems not to be in the CVS
tree. The old documentation is still pretty incomplete IMHO. For example,
one of the most important routines "matrixmultiply" is not documented. And
the description of "indices" makes your head explode... :-)

Also lacking is a description (examples) of how to add Ufuncs in an
extension module.

Are there any plans of distributing the manual in an editable format (TeX,
DocBook...) instead of PDF?? That would make it easier for people to
contribute.

Cheers,
/Morten

--

-- 
Morten Kjeldgaard   <mok <at> imsb.au.dk>             | Phone : +45 89 42 50 26
Institute of Molecular and Structural Biology    | Fax   : +45 86 12 31 78
Aarhus University                                | Home  : +45 86 18 81 80
Gustav Wieds Vej 10 C, DK-8000 Aarhus C, Denmark | icq   : 27224900

Pablo Bleyer Kocik | 5 May 2000 18:21
Picon
Favicon

Re: Documentation?

Morten Kjeldgaard wrote:

> Hi,
>
> What's up with the NumPy documentation? It seems not to be in the CVS
> tree. The old documentation is still pretty incomplete IMHO. For example,
> one of the most important routines "matrixmultiply" is not documented. And
> the description of "indices" makes your head explode... :-)
>
> Also lacking is a description (examples) of how to add Ufuncs in an
> extension module.
>
> Are there any plans of distributing the manual in an editable format (TeX,
> DocBook...) instead of PDF?? That would make it easier for people to
> contribute.

    And I offered myself to contribute some months ago but nobody answered.

    ... I felt so tiny...
    ... Nobody heard me...
    ... Oh, cruel world!

    ;^)

    Cheers!

--
Pablo Bleyer Kocik |
pbleyer            |"Rintrah roars & shakes his fires in the burdend air;
       <at> embedded.cl | Hungry clouds swag on the deep" — William Blake
(Continue reading)

Paul F. Dubois | 5 May 2000 18:51
Picon

RE: Documentation?

The source for the document is on the ftp site. It is in Framemaker 5.5. If
anyone wants to improve it they should simply grab it, let everyone know
they have it for edit, and return it when done.

I have no current plans to convert it to Latex. We had a long previous
discussion on this topic.

Another way to contribute is simply send me flat text to paste in for some
certain topic.

Janko Hauser | 5 May 2000 20:25
Picon

Re: Documentation?

So, here is my attempt for an additional piece of NumPy
documentation. This is not finished, but before it never gets out the
door there is a little Zope magic, so others can give instant feedback
to the level of each function. I want to make this as complete as
possible in the sense of a function reference. This should not serve
as an introduction to NumPy in general, so please have a look and give
critiques. The zwiki will be up later this day or tomorrow, I want
first to fill in some ideas and discussion topics.
One problem is the authorship and license stuff, but I will put this
into the zwiki.

Have a look at

http://lisboa.ifm.uni-kiel.de:80080/NumPy/index_html

For corrections or additions there is a small button in the beginning
of each function definition, which gives a form for notes. This system
can be extended quite a bit, but my time is constraint at the moment. 

So this is my notice to the list, that I'm doing something :-)

HTH,
__Janko

PS: Please do not yet link this, as this is all not tested. Thanks!

Pablo Bleyer Kocik | 5 May 2000 21:40
Picon
Favicon

Re: Documentation?

Janko Hauser wrote:

> So, here is my attempt for an additional piece of NumPy
> documentation. This is not finished, but before it never gets out the
> door there is a little Zope magic, so others can give instant feedback
> to the level of each function.

    Really nice... and modern ;^)

> I want to make this as complete as
> possible in the sense of a function reference. This should not serve
> as an introduction to NumPy in general, so please have a look and give
> critiques.

    I added an issue but the "Numeric" page it crashed...

=====
Zope has encountered an error while publishing this resource.

      Error Type: TypeError
      Error Value: object can't be converted to int
=====

> So this is my notice to the list, that I'm doing something :-)
>

    Congratulations.

>
> HTH,
(Continue reading)

Rob W. W. Hooft | 5 May 2000 23:10
Gravatar

Bitten

I have to admit that today I have been bitten by NumPy's copy/pointer
and 0-order array inconsistency a bit. Easy enough to fix, but
a nice catch for somebody new to NumPy:

try:

   a=Numeric.array([1,2,3])
   a[0],a[1]=a[1],a[0]
   print a

vs:

   a=Numeric.array([[1,2,3],[4,5,6],[7,8,9]])
   a[0],a[1]=a[1],a[0]
   print a

Regards,

Rob Hooft.

--

-- 
=====   rob <at> hooft.net          http://www.xs4all.nl/~hooft/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========


Gmane