[Jprogramming] Floating from
Marshall Lochbaum
mlochbaum at raleighcharterhs.org
Wed Jan 26 09:34:25 HKT 2011
The bilinear resampling is a separable problem. All you have to do is
resample along each axis in succession. So:
(0&|:)@:(ffrom~ f)^:(#@$)
with f giving you the correct set of indices for that axis (in your example,
(0.9*i.n)"_), will give you the correct answer quickly.
6!:2 '(0&|:)@:(ffrom~ (0.9*i.n)"_)^:(#@$) i.n,n=.100'
0.0080147
6!:2 '(0&|:)@:(ffrom~ (0.9*i.n)"_)^:(#@$) i.n,n=.200'
0.0207797
Marshall
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Ben Gorte - LR
Sent: Monday, January 24, 2011 12:42 PM
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: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] 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: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] 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: programming-bounces at jsoftware.com 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
More information about the Programming
mailing list