[Numpy-discussion] Passing a Null pointer after ndarray prototype definition

2007-12-30 Thread Nicholas
I have a problem in that I have a DLL function which accepts several numpy
double arrays, but you need to pass a NULL pointer for the ones from which
you do not require results. The prototype is as follows:

T_ndDp = numpy.ctypeslib.ndpointer(dtype=float, ndim=1,
flags='C_CONTIGUOUS')
Prototype_example = CFUNCTYPE(None, c_long, T_ndDp, T_ndDp, T_ndDp)

In ctypes None is equivelent to NULL, though in order to get past the
prototype argchecks you need to cast the object to None. If for example the
pointer was to a simple double one could write something like: cast(None,
POINTER(c_double))

the problem is in casting to None for the above (T_ndDp) type

Any help would be greatly appreciated

Nicholas
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] random access iterators

2007-12-30 Thread Neal Becker
I'm looking at writing some c++ code to interoperate with numpy.  A c++
random access iterator must include a 'distance' function.  distance (i1,
i2) must return the number of times i1 has to be incremented to reach i2.

Is there a way to get this from PyArrayIterObject?

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how do I list all combinations

2007-12-30 Thread Alan G Isaac
On Wed, 26 Dec 2007, Mathew Yeates apparently wrote: 
 r1=[dog,cat] 
 r2=[1,2] 
 I want to return [[dog,1],[dog,2],[cat,1],[cat,2]] 


This is a Cartesian product.

Sage has ``cartesian_product_iterator`` for this.
Also 
URL:http://www.sagemath.org/doc/html/ref/module-sage.combinat.cartesian-product.html

Here is a Cookbook implementation.
URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302478
The generator may be adequate to your needs.

Here is a recursive implementation that does not use 
multi-dimensional indexing:

def set_product(*sets):
last_set = sets[-1]
drop_last = sets[:-1]
if drop_last:
result = set( x+(y,)
  for x in set_product(*drop_last)
  for y in last_set )
else:
result = set( (y,) for y in last_set )
return result

Sorry for a late reply.  I'm catching up on email...

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] random access iterators

2007-12-30 Thread Travis E. Oliphant
Neal Becker wrote:
 I'm looking at writing some c++ code to interoperate with numpy.  A c++
 random access iterator must include a 'distance' function.  distance (i1,
 i2) must return the number of times i1 has to be incremented to reach i2.

 Is there a way to get this from PyArrayIterObject?
   
In the general case,  not directly.  However, you may be able to figure 
something out using the coordinate array that is stored with each 
iterator. 

-Travis O.

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion