Re: [Numpy-discussion] PyArray_FromAny does not accept a generator?

2008-01-06 Thread Neal Becker
Robert Kern wrote:

 Neal Becker wrote:
 It seems that PyArray_FromAny does not accept a generator?
 
 Seems like this would be useful.
 
 It's difficult to do all the magical interpretation that PyArray_FromAny()
 does with a iterator of unknown length. In Python, we have fromiter()
 which will consume an iterator to make (only) a rank-1 array and thus
 sidestep a big chunk of the magical interpretation.
 

I have previously created a wrapper for python around boost::ublas vector.
Basically it does (in pseudocode):

vector_from_object(obj):
  if (obj is a vector):
return a copy
  elif (obj has __len__):
return vector_from_sequence
  elif (obj has __iter__):
return vector_from_iter

vector_from_iter(iter):
  copy_iter_to_new_temp_container (in this case, we use std::vector with
push_back)
  return new vector from temp container


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


[Numpy-discussion] PyArray_FromAny does not accept a generator?

2008-01-04 Thread Neal Becker
It seems that PyArray_FromAny does not accept a generator?

Seems like this would be useful.

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


Re: [Numpy-discussion] PyArray_FromAny does not accept a generator?

2008-01-04 Thread Robert Kern
Neal Becker wrote:
 It seems that PyArray_FromAny does not accept a generator?
 
 Seems like this would be useful.

It's difficult to do all the magical interpretation that PyArray_FromAny() does
with a iterator of unknown length. In Python, we have fromiter() which will
consume an iterator to make (only) a rank-1 array and thus sidestep a big chunk
of the magical interpretation.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion