[Numpy-discussion] array, asarray as contiguous and friends

Tim Hochberg tim.hochberg at cox.net
Fri Mar 24 08:49:01 EST 2006


Alexander Belopolsky wrote:

>On 3/24/06, Tim Hochberg <tim.hochberg at cox.net> wrote:
>  
>
>>....                                                        For
>>    
>>
>example (and just for
>  
>
>>example, I make no great claims for either this name or interface):
>>    a = array_from_data(a_buffer_object, dtype, dims, strides)
>>
>>    
>>
>
>This looks very similar to the current ndarray "new" constructor:
>  
>
It sure does.

> |  ndarray.__new__(subtype, shape=, dtype=int_, buffer=None,
> |                  offset=0, strides=None, fortran=False)
> |
> |   There are two modes of creating an array using __new__:
> |   1) If buffer is None, then only shape, dtype, and fortran
> |      are used
> |   2) If buffer is an object exporting the buffer interface, then
> |      all keywords are interpreted.
> |   The dtype parameter can be any object that can be interpreted
> |      as a numpy.dtype object.
>
>(see pydoc numpy.ndarray)
>
>I would not mind to leave array() unchanged and move discussion to
>streamlining ndarray.__new__ .  For example, some time ago I suggested
>that strides should be interpreted even if buffer=None.
>  
>
That does look like a good place to hang any arbitrary strides creating 
stuff. I'm of the opinion that arguments should *never* be ignored, so 
I'm all for interpreting strides even when buffer is None. I'd also 
contend that offset should either be respected (by overallocating) or 
since that's probably useless, raising a ValueError when it's nonzero.

Regards,

Tim







More information about the NumPy-Discussion mailing list