[Numpy-discussion] proposing a "beware of [as]matrix()" warning
David Warde-Farley
dwf at cs.toronto.edu
Wed Apr 28 14:15:20 EDT 2010
josef.pktd at gmail.com wrote:
> On Wed, Apr 28, 2010 at 1:30 PM, David Warde-Farley <dwf at cs.toronto.edu> wrote:
>
>> On 2010-04-28, at 12:05 PM, Travis Oliphant wrote:
>>
>>
>>> a(b) is equivalent to dot(a,b)
>>>
>>> a(b)(c) would be equivalent to dot(dot(a,b),c)
>>>
>>> This seems rather reasonable.
>>>
>> Indeed, and it leads to a rather pleasant way of permuting syntax to change the order of operations, i.e. a(b(c)) vs. a(b)(c).
>>
>
> I like the explicit dot method much better, __call__ (parentheses) can
> mean anything, and reading the code will be more difficult.
> (especially when switching from matlab)
>
Yes, you have a point, though I do think it would read easier as a
method, a.dot(b.dot(c)) or a.dot(b).dot(c) rather than as a prefix/function.
(Down the line, another concern is the fact that dot() always incurs a
memory allocation for the result, which matters sometimes when you have
a huge amount of data and limited RAM. As I currently understand the
situation, it shouldn't be hard to add an optional 'out' argument or a
gaxpy primitive that maps directly onto the BLAS call; I just haven't
had time yet to investigate it further.)
David
David
More information about the NumPy-Discussion
mailing list