As part of one of the demos for CXX there is an =
example=20
defines an Array object. Here is a portion of the

header file in the Include directory. This is only a =
demo. I=20
did not have the time to do a complete wrap on Numerical's API. A better =
version=20
of this class would be welcome.

class Array: public=20
Sequence

{

public:

virtual bool accepts = (PyObject=20 *pyob) const {

return pyob = && PyArray_Check (pyob);

= }

=20

explicit Array (PyObject *pyob): Sequence(pyob)=20 {

=20 validate();

}

=

=20 Array(const Object& other): Sequence(*other)=20 {

=20 validate();

}

=

=20 Array& operator=3D (const Object& rhs)=20 {

return (*this =3D=20 *rhs);

}

=

=20 Array& operator=3D (PyObject* rhsp)=20 {

if(ptr() =3D=3D rhsp) = return=20 *this;

=20 set(rhsp);

return=20 *this;

}

=

=20 explicit Array (int n=3D0, PyArray_TYPES t =3D=20 PyArray_DOUBLE)

:=20 Sequence(FromAPI(PyArray_FromDims(1, &n, t)))=20 {

=20 validate();

}

{

public:

virtual bool accepts = (PyObject=20 *pyob) const {

return pyob = && PyArray_Check (pyob);

= }

=20

explicit Array (PyObject *pyob): Sequence(pyob)=20 {

=20 validate();

}

=

=20 Array(const Object& other): Sequence(*other)=20 {

=20 validate();

}

=

=20 Array& operator=3D (const Object& rhs)=20 {

return (*this =3D=20 *rhs);

}

=

=20 Array& operator=3D (PyObject* rhsp)=20 {

if(ptr() =3D=3D rhsp) = return=20 *this;

=20 set(rhsp);

return=20 *this;

}

=

=20 explicit Array (int n=3D0, PyArray_TYPES t =3D=20 PyArray_DOUBLE)

:=20 Sequence(FromAPI(PyArray_FromDims(1, &n, t)))=20 {

=20 validate();

}

Array clone() const=20
{

PyObject *p =3D=20 PyArray_CopyFromObject(ptr(), species(), rank(),=20 rank());

return=20 Array(p);

}

PyObject *p =3D=20 PyArray_CopyFromObject(ptr(), species(), rank(),=20 rank());

return=20 Array(p);

}

int species() const=20
{

return = PyArray_ObjectType(ptr(),=20 0);

}

return = PyArray_ObjectType(ptr(),=20 0);

}

int rank() const=20
{

return ((PyArrayObject*) = ptr())->nd;

}

return ((PyArrayObject*) = ptr())->nd;

}

int dimension(int i) const=20
{

if (1 <=3D i = && i <=3D=20 rank()) = {

=20 return ((PyArrayObject*)=20 ptr())->dimensions[i-1];

= } else=20 {

= return=20 1;

}

= }

if (1 <=3D i = && i <=3D=20 rank()) = {

=20 return ((PyArrayObject*)=20 ptr())->dimensions[i-1];

= } else=20 {

= return=20 1;

}

= }

int is_contiguous() const=20
{

return = PyArray_ISCONTIGUOUS=20 ((PyArrayObject*) ptr());

}

return = PyArray_ISCONTIGUOUS=20 ((PyArrayObject*) ptr());

}

char* to_C() const=20
{

return ((PyArrayObject*) = ptr())->data;

}

return ((PyArrayObject*) = ptr())->data;

}

Array as_contiguous()=20
{

if (is_contiguous()) = return=20 Array(ptr());

return=20 Array((PyObject*)PyArray_ContiguousFromObject(ptr(), species(), 1,=20 0));

} =20

};

------=_NextPart_000_0007_01BEAC26.8E732C80--
From HYoon@exchange.ml.com Tue Jun 1 20:25:53 1999
From: HYoon@exchange.ml.com (Yoon, Hoon (CICG - NY Program Trading))
Date: Tue, 1 Jun 1999 15:25:53 -0400
Subject: [Matrix-SIG] RE: CXX and Numeric
Message-ID: if (is_contiguous()) = return=20 Array(ptr());

return=20 Array((PyObject*)PyArray_ContiguousFromObject(ptr(), species(), 1,=20 0));

} =20

};