Skip to content

Commit

Permalink
πŸ”€ Merge pull request #18 from robertdj/tensor
Browse files Browse the repository at this point in the history
πŸ”€ Fix tensorgrid
  • Loading branch information
robertdj authored Jul 12, 2023
2 parents f6254a1 + 68209c0 commit 82a5988
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseGrids"
uuid = "bafbe729-afc6-5148-bb4f-226bf3d46895"
authors = ["Robert DJ <[email protected]>"]
version = "2.0.1"
version = "2.0.2"

[deps]
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
Expand Down
2 changes: 1 addition & 1 deletion src/grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function tensorgrid(N::Vector, W::Vector, D::Integer)
WW = repeat([W], outer=[D; 1])

tensorN = combvec(NN[:])
tensorW = vec(prod(combvec(WW[:]), 1))
tensorW = map(prod, combvec(WW[:]))

return tensorN, tensorW
end
Expand Down
10 changes: 7 additions & 3 deletions test/quadtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ end

@testset "Quadrature rule $generator" for generator in [gausshermite, kpn]
N, W = sparsegrid(dim, order, generator)
Ntensor, Wtensor = tensorgrid(dim, order, generator)

# Maximum degree for which the generator gives correct results
generator == kpn ? max_degree = dim * order : max_degree = 2 * order - 1

@testset "Gaussian moments $powers" for powers in even_powers
I = gaussmoment(powers)
Q = gaussquad(powers, N, W)
sparse_quadrature = gaussquad(powers, N, W)

# Expected test result depends on the total degree
if sum(powers) <= max_degree
@test I β‰ˆ Q
@test I β‰ˆ sparse_quadrature
else
@test abs(I - Q) > 1e-3
@test abs(I - sparse_quadrature) > 1e-3
end

tensor_quadrature = gaussquad(powers, Ntensor, Wtensor)
@test I β‰ˆ tensor_quadrature
end
end
end

0 comments on commit 82a5988

Please sign in to comment.