@@ -17,8 +17,8 @@ module Hadamard
17
17
export fwht, ifwht, fwht_natural, ifwht_natural, fwht_natural!, ifwht_natural!, fwht_dyadic, ifwht_dyadic, hadamard, walsh
18
18
19
19
using FFTW, LinearAlgebra
20
- import FFTW: set_timelimit , dims_howmany, unsafe_execute!, cFFTWPlan, r2rFFTWPlan, PlanPtr, fftwNumber, ESTIMATE, NO_TIMELIMIT, R2HC
21
- import AbstractFFTs: normalization, complexfloat
20
+ using FFTW: @exclusive , unsafe_set_timelimit , dims_howmany, unsafe_execute!, cFFTWPlan, r2rFFTWPlan, PlanPtr, fftwNumber, ESTIMATE, NO_TIMELIMIT, R2HC
21
+ using AbstractFFTs: normalization, complexfloat
22
22
23
23
# A power-of-two dimension to be transformed is interpreted as a
24
24
# 2x2x2x....x2x2 multidimensional DFT. This function transforms
@@ -62,19 +62,20 @@ const libfftwf = isdefined(FFTW, :libfftwf) ? FFTW.libfftwf : FFTW.libfftw3f
62
62
63
63
for (Tr,Tc,fftw,lib) in ((:Float64 ,:ComplexF64 ," fftw" ,libfftw),
64
64
(:Float32 ,:ComplexF32 ," fftwf" ,libfftwf))
65
- @eval function Plan_Hadamard (X:: StridedArray{$Tc,N} , Y:: StridedArray{$Tc,N} ,
65
+ @eval @exclusive function Plan_Hadamard (X:: StridedArray{$Tc,N} , Y:: StridedArray{$Tc,N} ,
66
66
region, flags:: Unsigned , timelimit:: Real ,
67
67
bitreverse:: Bool ) where {N}
68
- set_timelimit ($ Tr, timelimit)
69
- dims, howmany = dims_howmany (X, Y, [size (X)... ], region)
68
+ unsafe_set_timelimit ($ Tr, timelimit)
69
+ R = isa (region, Tuple) ? region : copy (region)
70
+ dims, howmany = dims_howmany (X, Y, size (X), R)
70
71
dims = hadamardize (dims, bitreverse)
71
- plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib[] ),
72
+ plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib () ),
72
73
PlanPtr,
73
74
(Int32, Ptr{Int}, Int32, Ptr{Int},
74
75
Ptr{$ Tc}, Ptr{$ Tc}, Int32, UInt32),
75
76
size (dims,2 ), dims, size (howmany,2 ), howmany,
76
77
X, Y, FFTW. FORWARD, flags)
77
- set_timelimit ($ Tr, NO_TIMELIMIT)
78
+ unsafe_set_timelimit ($ Tr, NO_TIMELIMIT)
78
79
if plan == C_NULL
79
80
if $ (FFTW. fftw_provider == " mkl" )
80
81
error (" MKL is not supported — reconfigure FFTW.jl to use FFTW" )
@@ -85,21 +86,22 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:ComplexF64,"fftw",libfftw),
85
86
return cFFTWPlan {$Tc,FFTW.FORWARD,X===Y,N} (plan, flags, region, X, Y)
86
87
end
87
88
88
- @eval function Plan_Hadamard (X:: StridedArray{$Tr,N} , Y:: StridedArray{$Tr,N} ,
89
+ @eval @exclusive function Plan_Hadamard (X:: StridedArray{$Tr,N} , Y:: StridedArray{$Tr,N} ,
89
90
region, flags:: Unsigned , timelimit:: Real ,
90
91
bitreverse:: Bool ) where {N}
91
- set_timelimit ($ Tr, timelimit)
92
- dims, howmany = dims_howmany (X, Y, [size (X)... ], region)
92
+ unsafe_set_timelimit ($ Tr, timelimit)
93
+ R = isa (region, Tuple) ? region : copy (region)
94
+ dims, howmany = dims_howmany (X, Y, size (X), R)
93
95
dims = hadamardize (dims, bitreverse)
94
96
kind = Array {Int32} (undef, size (dims,2 ))
95
97
kind .= R2HC
96
- plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib[] ),
98
+ plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib () ),
97
99
PlanPtr,
98
100
(Int32, Ptr{Int}, Int32, Ptr{Int},
99
101
Ptr{$ Tr}, Ptr{$ Tr}, Ptr{Int32}, UInt32),
100
102
size (dims,2 ), dims, size (howmany,2 ), howmany,
101
103
X, Y, kind, flags)
102
- set_timelimit ($ Tr, NO_TIMELIMIT)
104
+ unsafe_set_timelimit ($ Tr, NO_TIMELIMIT)
103
105
if plan == C_NULL
104
106
if $ (FFTW. fftw_provider == " mkl" )
105
107
error (" MKL is not supported — reconfigure FFTW.jl to use FFTW" )
371
373
"""
372
374
walsh(n)
373
375
374
- Return a Walsh matrix of order `n`, which must be a power of two, in sequency ordering.
376
+ Return a Walsh matrix of order `n`, which must be a power of two, in sequency ordering.
375
377
This is related to the Hadamard matrix [`hadamard(n)`](@ref) by a bit-reversal permutation
376
378
followed by a Gray-code permutation of the rows.
377
379
@@ -390,7 +392,7 @@ function walsh(n::Int)
390
392
j = b ⊻ (b >> 1 ) # binary sequency index
391
393
j + 1 # 1-based index
392
394
end
393
- for i in 0 : n- 1 ]
395
+ for i in 0 : n- 1 ]
394
396
395
397
return hadamard (n)[j, :]
396
398
end
0 commit comments