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

Reply via email to