If u and v produce the same shape and same type result,
it is often more efficient to simply apply u to the entire of y
and v to the entire of y, and then pick out the values
you want using x . For example:
x=: 4 5 [EMAIL PROTECTED] 2
y=: 4 5 [EMAIL PROTECTED] 10
u=: <:
v=: *:
x{"0 1 (u y) ,"0 v y
8 64 4 49 3
_1 1 4 49 81
2 1 0 4 81
4 2 8 5 8
x [EMAIL PROTECTED]([EMAIL PROTECTED])@.["0 y
8 64 4 49 3
_1 1 4 49 81
2 1 0 4 81
4 2 8 5 8
More efficient because each primitive "sees" a bigger slab
of the argument and so is able to amortize its fixed overhead
over a larger number of atoms.
x=: 1e6 [EMAIL PROTECTED] 2
y=: 1e6 [EMAIL PROTECTED] 10
(x{"0 1 (u y) ,"0 v y) -: x [EMAIL PROTECTED]([EMAIL PROTECTED])@.["0 y
1
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
ts 'x{"0 1 (u y) ,"0 v y'
0.555266 2.09734e7
ts 'x [EMAIL PROTECTED]([EMAIL PROTECTED])@.["0 y'
3.83144 2.1259e8
----- Original Message -----
From: "L.Tomei" <[EMAIL PROTECTED]>
Date: Wednesday, March 5, 2008 5:35
Subject: [Jprogramming] application different verbs to atoms
To: [email protected]
> I have an array y, an array of booleans x (same shape of y), and
> two monadic
> verbs u and v.
> How can I apply verb u to each atom of y when corresponding
> value of x is 0,
> and verb v when corresponding value of x is 1?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm