Aha! your version from Yesterday (without loops) is really the fastest
one!
It remains my favorite ffrom.

      ffrom=:4 :0 "0 _
 x=.,>x
 range=. { (<.,>.)&.> x
 mult=. *// (,.~-.) (-<.) x
 mult +/^:(#x)@:* range{y
 )
 
    6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.100'
0.223896
    6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.200'
0.893405
 
Ben  

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ben Gorte - LR
Sent: maandag 24 januari 2011 18:42
To: Programming forum
Subject: Re: [Jprogramming] Floating from

If it is about speed (not beauty), then it seems yours is not very fast
when selecting a lot of elements at once, as in bilinear image
resampling.

The example:

   ((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.5
   0  0.9  1.8  2.7  3.6
 4.5  5.4  6.3  7.2  8.1
   9  9.9 10.8 11.7 12.6
13.5 14.4 15.3 16.2 17.1
  18 18.9 19.8 20.7 21.6

This is your fastest version:

   6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.100'
0.405595
   6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.200'
6.26634

About mine I may say:

 6!:2 '((<"1)0.9*,"0/~i.n) bgffrom i.n,n=.100'
0.27029
   6!:2 '((<"1)0.9*,"0/~i.n) bgffrom i.n,n=.200'
1.07775

(pure luck, I admit)

Ben



 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Marshall
Lochbaum
Sent: maandag 24 januari 2011 14:06
To: 'Programming forum'
Subject: Re: [Jprogramming] Floating from

If you want one that works exactly like the others, replace }. in the
code with |.  . This is a much more elegant way to do it, but it
requires moving the whole array around and more time and space (it is
about three times slower).

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ben Gorte - LR
Sent: Monday, January 24, 2011 2:14 AM
To: Programming forum
Subject: Re: [Jprogramming] Floating from

Impressed again.
I suppose I should start using that one in my application,

However you were changing the specs.
Your previous one is the real ffrom.

Ben


-----Original Message-----
From: [email protected] on behalf of Marshall Lochbaum
Sent: Mon 1/24/2011 1:18 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Floating from
 
I have a better version!
This one, despite an ugly for loop, uses more J array power and
outperforms my previous attempt by an order of magnitude in time and
space.

   ffrom=:4 :0"0 _
x=.,>x
a=.(2"0 x) {. (<.x) }. y
mult=. (,.~-.) (-<.) x
for_m. mult do.
  a=. m +/@:* a
end.
a
)
   6!:2 '(<?20$0) ffrom i.20#2'
0.0627697
   7!:2 '(<?20$0) ffrom i.20#2'
75506048

Note that this one, because of its use of head, substitutes 0 for any
value that is out of range. It also doesn't work for negative indices.

Marshall

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to