Skip to content

Commit 22234cc

Browse files
authored
Fix variable order in partial derivatives (#207)
1 parent 6fb10b9 commit 22234cc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MultivariateOrthogonalPolynomials"
22
uuid = "4f6956fd-4f93-5457-9149-7bfc4b2ce06d"
3-
version = "0.9.1"
3+
version = "0.9.2"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/rect.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function jacobimatrix(::Val{2}, P::RectPolynomial)
5353
KronTrav(Y, Eye{eltype(Y)}(∞))
5454
end
5555
function diff(P::KronPolynomial{N}, order::NTuple{N,Int}; dims...) where N
56-
diffs = diff.(P.args, order)
57-
RectPolynomial(basis.(diffs)...) * KronTrav(coefficients.(diffs)...)
56+
diffs = map(diff, P.args, order)
57+
RectPolynomial(map(basis, diffs)...) * KronTrav(reverse(map(coefficients, diffs))...)
5858
end
5959

6060

@@ -164,7 +164,7 @@ end
164164

165165
## sum
166166

167-
function Base._sum(P::RectPolynomial, dims)
167+
function Base._sum(P::RectPolynomial, dims::Int)
168168
@assert dims == 1
169169
KronTrav(sum.(P.args; dims=1)...)
170170
end

test/test_rect.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ using Base: oneto
155155
@test sum(f) 10.546408460894801 # empirical
156156
end
157157

158+
@testset "diff" begin
159+
P = RectPolynomial(Legendre(),Legendre())
160+
f = expand(P, splat((x,y) -> 1))
161+
@test diff(f,(1,0))[SVector(0.1,0.2)] == diff(f,(0,1))[SVector(0.1,0.2)] == 0.0
162+
f = expand(P, splat((x,y) -> x))
163+
@test diff(f,(1,0))[SVector(0.1,0.2)] == 1.0
164+
@test diff(f,(0,1))[SVector(0.1,0.2)] == 0.0
165+
f = expand(P, splat((x,y) -> cos(x*exp(y))))
166+
@test diff(f,(1,0))[SVector(0.1,0.2)] -sin(0.1*exp(0.2))*exp(0.2)
167+
@test diff(f,(0,1))[SVector(0.1,0.2)] -0.1*sin(0.1*exp(0.2))*exp(0.2)
168+
@test diff(f,(2,0))[SVector(0.1,0.2)] -cos(0.1*exp(0.2))*exp(0.4)
169+
@test diff(f,(1,1))[SVector(0.1,0.2)] -sin(0.1*exp(0.2))*exp(0.2) - 0.1*cos(0.1*exp(0.2))*exp(0.4)
170+
@test diff(f,(0,2))[SVector(0.1,0.2)] -0.1*sin(0.1*exp(0.2))*exp(0.2) - 0.1^2*cos(0.1*exp(0.2))*exp(0.4)
171+
end
172+
158173
@testset "KronTrav bug" begin
159174
W = Weighted(Ultraspherical(3/2))
160175
= diff(W)'diff(W)

0 commit comments

Comments
 (0)