[MATRIX-SIG] FancyArray
Timothy A. Hochberg
hochberg@wwa.com
Sat, 30 Aug 1997 16:21:59 -0500 (CDT)
TH = Tim Hochberg KH = Konrad Hinsen On Sat, 30 Aug 1997, Konrad Hinsen
wrote:
[TH sez' reshaping a UserArray should return a UserArray]
To which KH replies:
> Sure. But what about more complicated situations? What
> should add(a, b) return if a and b are instances of different subclasses
> of UserArray?
Well the best rule I can come up with is, given a set of arguments that
are in a direct line of descent such as
(array->UserArray->SomeSpecializedArray), the return type should be of the
type that is lowest in the inheritance chain. Mixed array types that were
not in a direct line of descent would raise an error. For example, given
the following class structure:
array--->UserArray-+->SpecializedArray1--->SubSpecializedArray1
|
+->SpecializedArray2
take(array, SubSpecializedArray1) returns a SubSpecializedArray1
take(UserArray, SpecializedArray2) returns a SpecializedArray2
take(SpecializedArray1, SpecializedArray2) raises an error.
Implementing this, even in Python let alone C, seems like it might be
somewhat of a pain. However, it would only need to be implemented once
(say as a function called figure_out_return_type(*args)). This could then
be called by each function that needs to know the return type.
[TH sez' shadow functions would be a good thing, but KH says:]
> Which adds overhead to every function call. It would be better to
> implement a good strategy right in the C code - but first there must
> be a good strategy.
That is why I was suggesting that these functions go in UserArray at least
for the part of their lifecycle where they are written in Python. People
who are using UserArray are allready working with enough overhead that I
doubt they'd notice the difference.
Also, a good chunk of the Numeric functions are actually shadow functions
in Numeric. Should these be migrated to C?
____
/im
+------------------------------------------------+
|Tim Hochberg Research Assistant |
|hochberg <at> wwa.com University of Illinois |
| Electrical Engineering |
+------------------------------------------------+
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________