MCPcopy
hub / github.com/numpy/numpy / Arrayish

Class Arrayish

numpy/_core/tests/test_function_base.py:407–429  ·  view source on GitHub ↗

A generic object that supports the __array_interface__ and hence can in principle be converted to a numeric scalar, but is not otherwise recognized as numeric, but also happens to support multiplication by floats. Data should be an object

Source from the content-addressed store, hash-verified

405 # __array_interface__ and are convertible to numeric scalars
406
407 class Arrayish:
408 """
409 A generic object that supports the __array_interface__ and hence
410 can in principle be converted to a numeric scalar, but is not
411 otherwise recognized as numeric, but also happens to support
412 multiplication by floats.
413
414 Data should be an object that implements the buffer interface,
415 and contains at least 4 bytes.
416 """
417
418 def __init__(self, data):
419 self._data = data
420
421 @property
422 def __array_interface__(self):
423 return {'shape': (), 'typestr': '<i4', 'data': self._data,
424 'version': 3}
425
426 def __mul__(self, other):
427 # For the purposes of this test any multiplication is an
428 # identity operation :)
429 return self
430
431 one = Arrayish(array(1, dtype='<i4'))
432 five = Arrayish(array(5, dtype='<i4'))

Callers 1

test_array_interfaceMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_array_interfaceMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…