MCPcopy Create free account
hub / github.com/numpy/numpy / test_array_interface

Method test_array_interface

numpy/core/tests/test_function_base.py:366–398  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

364 assert_equal(ls, linspace(0.0, 1.0, 1))
365
366 def test_array_interface(self):
367 # Regression test for https://github.com/numpy/numpy/pull/6659
368 # Ensure that start/stop can be objects that implement
369 # __array_interface__ and are convertible to numeric scalars
370
371 class Arrayish:
372 """
373 A generic object that supports the __array_interface__ and hence
374 can in principle be converted to a numeric scalar, but is not
375 otherwise recognized as numeric, but also happens to support
376 multiplication by floats.
377
378 Data should be an object that implements the buffer interface,
379 and contains at least 4 bytes.
380 """
381
382 def __init__(self, data):
383 self._data = data
384
385 @property
386 def __array_interface__(self):
387 return {'shape': (), 'typestr': '<i4', 'data': self._data,
388 'version': 3}
389
390 def __mul__(self, other):
391 # For the purposes of this test any multiplication is an
392 # identity operation :)
393 return self
394
395 one = Arrayish(array(1, dtype='<i4'))
396 five = Arrayish(array(5, dtype='<i4'))
397
398 assert_equal(linspace(one, five), linspace(1, 5))
399
400 def test_denormal_numbers(self):
401 # Regression test for gh-5437. Will probably fail when compiled

Callers

nothing calls this directly

Calls 4

arrayFunction · 0.90
assert_equalFunction · 0.90
linspaceFunction · 0.90
ArrayishClass · 0.85

Tested by

no test coverage detected