each  (&.>) is supported by special code.

Henry Rich

On 1/7/2018 5:44 PM, Jimmy Gauvin wrote:
I was playing with alternative ways to get to the result:

hw=: 3 : '; _2 -/\ each (-2^i.1+2^.#y) +/\ each < y'

hw3=: 3 : '_2 -/\ ; (-2^i.1+2^.#y) +/\ each < y'


and I noticed that hw is faster even though it has an extra each.

Shouldn't hw3 be faster with less boxing and unboxing ?



As usual Raul' Haar is faster and consumes less memory.



On Sun, Jan 7, 2018 at 4:07 PM, 'Mike Day' via Programming <
[email protected]> wrote:

Not at all familiar with this,  but I played with the Matrices H2n in the
wiki
article,  and found they reproduce these results,  subject to reordering.

So, fwiw, here are a few verbs:
(I assume the argument size is a power (> 0) of 2; no checking!)

kp =:  *&$ ($,) 0 2 1 3 |: */   NB. Kronecker product from J Wiki

H2n =: 3 : 0    NB. H2n as defined in Wiki
n =. y
h =. 1 1,:1 _1
n2=. 2
for_i. i. <: 2 <.@^. n do.
    h =. (h kp ,:1 1) , (=i. n2) kp ,: 1 _1
    n2=. +:n2
end.
h
)

H2na =: 3 : 0  NB. H2n reordered to match Raul's Haar verb
i  =. i. n =. y
I  =. ''
while. 1 < n =. -: n do.NB. build map from Wiki H2n to required order
    i =. (-n) <\ i
    I =. I, ;{: i
    i =. ;}:  i
end.
(I,  |. i) { H2n y
)

applyHaar =: H2na@# +/ . * ]  NB. do matrix product

    Haar 3 2 3 2 2 2 1 1   NB. Raul's verb
1 1 0 0 0 2 4 16
    applyHaar 3 2 3 2 2 2 1 1  NB. verb using H2n matrix
1 1 0 0 0 2 4 16

Might help a bit!

Mike



On 07/01/2018 17:41, Raul Miller wrote:

https://en.wikipedia.org/wiki/Haar_wavelet

https://pbs.twimg.com/media/DS7mmaLWAAE6-US.jpg

     Haar=: _2&(-/\ , Haar^:(1<#)@(+/\))
     Haar 3 2 3 2 2 2 1 1
1 1 0 0 0 2 4 16

Like the fast fourier transform, this is only defined on arguments
whose length is a power of 2 (which might be enforced by requiring an
array whose dimensions are all 2 and then raveling it).

Unlike the FFT, however, the Haar transform is not self inverting.
Still, since every non-lossey transform deserves an inverse transform:

     iHaar=: -:@(+/,@,.-~/)@(,:$:^:(1<#))/@($~ 2,-:@#)
     iHaar 1 1 0 0 0 2 4 16
3 2 3 2 2 2 1 1

As an aside, though: I found the wikipedia article nearly useless for
this implementation - I used the example contained in the image to
write this code and only briefly skimmed the wikipedia text for rough
agreement. (And since I've encountered plenty of errors in wikipedia
in the past, that's all I'm inclined to do with that page at the
moment.) Still, if someone with more familiarity with wavelets than I
could tell me if I've screwed up royally (and, if so, how and where),
please let me know.

Thanks,


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


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

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


---
This email has been checked for viruses by AVG.
http://www.avg.com

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

Reply via email to