Skip to content

Commit fde025f

Browse files
authored
Split y coordinate computation in paduapoints (#226)
* split y coordinate computation in paduapoints * Add inbounds and tests * Bump version to v0.15.7
1 parent 490ce9a commit fde025f

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FastTransforms"
22
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
3-
version = "0.15.6"
3+
version = "0.15.7"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/PaduaTransform.jl

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,46 @@ function paduapoints(::Type{T}, n::Integer) where T
209209
MM=Matrix{T}(undef,N,2)
210210
m=0
211211
delta=0
212-
NN=fld(n+2,2)
213-
@inbounds for k=n:-1:0
214-
if isodd(n)>0
215-
delta=mod(k,2)
212+
NN=div(n,2)+1
213+
# x coordinates
214+
for k=n:-1:0
215+
if isodd(n)
216+
delta = Int(isodd(k))
216217
end
218+
x = -cospi(T(k)/n)
217219
@inbounds for j=NN+delta:-1:1
218220
m+=1
219-
MM[m,1]=sinpi(T(k)/n-T(0.5))
220-
if isodd(n-k)>0
221-
MM[m,2]=sinpi((2j-one(T))/(n+1)-T(0.5))
221+
MM[m,1]=x
222+
end
223+
end
224+
# y coordinates
225+
# populate the first two sets, and copy the rest
226+
m=0
227+
for k=n:-1:n-1
228+
if isodd(n)
229+
delta = Int(isodd(k))
230+
end
231+
for j=NN+delta:-1:1
232+
m+=1
233+
@inbounds if isodd(n-k)
234+
MM[m,2]=-cospi((2j-one(T))/(n+1))
222235
else
223-
MM[m,2]=sinpi(T(2j-2)/(n+1)-T(0.5))
236+
MM[m,2]=-cospi(T(2j-2)/(n+1))
224237
end
225238
end
226239
end
240+
m += 1
241+
# number of y coordinates between k=n and k=n-2
242+
Ny_shift = 2NN+isodd(n)
243+
for k in n-2:-1:0
244+
if isodd(n)
245+
delta = Int(isodd(k))
246+
end
247+
for j in range(m, length=NN+delta)
248+
@inbounds MM[j,2] = MM[j-Ny_shift,2]
249+
end
250+
m += NN+delta
251+
end
227252
return MM
228253
end
229254

test/paduatests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ using FastTransforms, Test
5353
g_l=paduaeval(g_xy,x,y,l,Val{false})
5454
@test f_xy(x,y) f_m
5555
@test g_xy(x,y) g_l
56+
57+
# odd n
58+
m=135
59+
l=85
60+
f_m=paduaeval(f_xy,x,y,m,Val{true})
61+
g_l=paduaeval(g_xy,x,y,l,Val{true})
62+
@test f_xy(x,y) f_m
63+
@test g_xy(x,y) g_l
64+
65+
f_m=paduaeval(f_xy,x,y,m,Val{false})
66+
g_l=paduaeval(g_xy,x,y,l,Val{false})
67+
@test f_xy(x,y) f_m
68+
@test g_xy(x,y) g_l
5669
end

0 commit comments

Comments
 (0)