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
| 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')) |
no outgoing calls
searching dependent graphs…