| 560 | | |
| | 560 | |
| | 561 | ## __array_priority__ and __array_wrap__ are required to override |
| | 562 | ## the default behavior of numpy. If a numpy array and a Variable |
| | 563 | ## are in a binary operation and numpy is first, then numpy will, |
| | 564 | ## by default, try and do everything it can to get a a raw numpy |
| | 565 | ## array out of Variable. __array_wrap__ seems to have been |
| | 566 | ## introduced into masked array to fix this issue. __array_wrap__ is |
| | 567 | ## called after the operation is done so it could hurt efficiency badly. |
| | 568 | ## Something else needs to be done to stop the initial evaluation. |
| | 569 | |
| | 570 | __array_priority__ = 100.0 |
| | 571 | |
| | 572 | def __array_wrap__(self, arr, context=None): |
| | 573 | """ |
| | 574 | Required to prevent numpy not calling the reverse binary operations. |
| | 575 | Both the following tests are examples ufuncs. |
| | 576 | |
| | 577 | >>> print type(numerix.array([1.0, 2.0]) * PhysicalField([1.0, 2.0], 'm')) |
| | 578 | <class 'fipy.tools.dimensions.physicalField.PhysicalField'> |
| | 579 | |
| | 580 | >>> from scipy.special import gamma as Gamma |
| | 581 | >>> print type(Gamma(PhysicalField([1.0, 2.0]))) |
| | 582 | <type 'numpy.ndarray'> |
| | 583 | |
| | 584 | """ |
| | 585 | if context is not None and len(context[1])==2: |
| | 586 | return NotImplemented |
| | 587 | else: |
| | 588 | return arr |
| | 589 | |