larry support for numpy.dot and similar operators

7 views
Skip to first unread message

Thomas Coffee

unread,
Jan 12, 2012, 5:48:24 PM1/12/12
to labeled-array
From the documentation at

http://berkeleyanalytics.com/la/ref_flarry.html#binary-functions

it does not seem immediately obvious that

la.binaryop(numpy.dot, ...)

will not work, and indeed, upon my first look at the documentation, I
assumed that it would. Some prospective users could be saved
disappointment by making this clear.


In the longer term, I can imagine many useful scenarios for supporting
tensor contraction operators like numpy.dot, for instance, in my own
application using larrys to facilitate the process of assembling large
linear programming problems. I'm imagining a specification like the
following:

la.binaryop(func, la1, la2, ..., axes=None, ...)

where

axes=None

yields the current behavior, but

axes=[(axis_1_0, axis_2_0), (axis_1_1, axis_2_1), ...]

specifies that axis_1_K in la1 should be aligned with axis_2_K in la2
for purposes of applying func.

Then, for example, one could write

la.binaryop(numpy.dot, la1, la2, ..., axes=[(-1, -2)], ...)

When such an axes specification is given, the list form of the join
option would be interpreted to apply the method join[K] to the axis
alignment axes[K].

Is anyone aware of a reason why something like this could not be
implemented? If not, I may attempt a prototype when time permits.

Keith Goodman

unread,
Jan 12, 2012, 6:05:32 PM1/12/12
to labele...@googlegroups.com
On Thu, Jan 12, 2012 at 2:48 PM, Thomas Coffee <thomas...@gmail.com> wrote:
> From the documentation at
>
>  http://berkeleyanalytics.com/la/ref_flarry.html#binary-functions
>
> it does not seem immediately obvious that
>
>  la.binaryop(numpy.dot, ...)
>
> will not work, and indeed, upon my first look at the documentation, I
> assumed that it would. Some prospective users could be saved
> disappointment by making this clear.

binaryop aligns the data in the two larrys according to the join
method you specify. And then it applies the binary function that you
supply.

Can you give a simple example of what is not working?

Here's an example of use.

Make two larrys:

I[15] lar1 = la.rand(2,2)
I[16] lar2 = la.rand(2,2)

Here's what numpy gives:

I[17] np.dot(lar1.x, lar2.x)
O[17]
array([[ 0.6679216 , 0.423808 ],
[ 0.75695756, 0.67014283]])

la gives the same answer:

I[18] la.binaryop(np.dot, lar1, lar2)
O[18]
label_0
0
1
label_1
0
1
x
array([[ 0.6679216 , 0.423808 ],
[ 0.75695756, 0.67014283]])

Reply all
Reply to author
Forward
0 new messages