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
| 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')) |
no outgoing calls