Skip to content

Commit

Permalink
use rand instead of randn
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Mar 2, 2024
1 parent f868ff8 commit eacccef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
11 changes: 1 addition & 10 deletions test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
using WriteVTK
using StableRNGs: StableRNG

# Version of randn that is stable across different julia versions
# Ref: https://github.com/DEShawResearch/random123/blob/9545ff6413f258be2f04c1d319d99aaef7521150/include/Random123/boxmuller.hpp
function my_randn(rng::StableRNG, dims::Integer...)
# Box–Muller transform
u01 = rand(rng, UInt64, dims...) .* (2.0^-64) .+ (2.0^-65)
uneg11 = rand(rng, Int64, dims...) .* (2.0^-63) .+ (2.0^-64)
sqrt.(-2 .* log.(u01)) .* cospi.(uneg11)
end

function main()
Ni, Nj, Nk = 20, 30, 40
outfiles = String[]
Expand All @@ -23,7 +14,7 @@ function main()
# reproducibility).
rng = StableRNG(42)

data = my_randn(rng, Ni, Nj, Nk)
data = (2.0*rand(rng, Ni, Nj, Nk)) .- 1.0

# Write 2D and 3D arrays.
@time begin
Expand Down
10 changes: 5 additions & 5 deletions test/checksums.sha1
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ a96c57cd06b71ea2793883224ec08e69c401240c unstructured_3D.vtu
a96c57cd06b71ea2793883224ec08e69c401240c unstructured_3D_tuple.vtu
084079bc4289bce1005ec85fc0b6bcb079070d81 unstructured_3D_SVector.vtu
161a307d963f2ac42caabcc63257caeafec7cde0 empty_cells.vtp
8c7f1017f106338445572ebd58c3eafc773dcf22 polydata_2D.vtp
97db1cc26aa42d501af72fc2c3af50fceee9ba3a polydata_3D.vtp
03745c0983b0dc425f80fe8c3ff122d5214e208f polydata_2D.vtp
986c015027c5c6b8566c3d47266452db9f09280b polydata_3D.vtp
3a63f7fa317097dd36edaac4c1eccbfb5e135d50 bezier_tetra_quartic_solidSphereOctant.vtu
f9c4503da4de4d20b55c3964d3ec91fbbb460336 bezier_anisotropic_degree_quarterAnnulus.vtu
795a82b363436a80068f7455a8f219017b3285d7 collection.pvd
Expand All @@ -52,9 +52,9 @@ e041dbdab45b518feee8a974fd93dce15cacd60c collection_00.vtr
b20bf14b2531aaf323b891e090d0615d0e943ef6 collection_03.vtr
4719f89362994e2412f00f506c338d0077a0a35f collection_reload.pvd
6e27ec9c5fc0ee87a5144d67f4c662859b535266 collection_reload.vtr
9ae7e799a3330563c1fe165bc2ed72a1d4ba2c4a arraydata_2D.vti
df43c8ef3476cad7d9b1cd24c2e30b83c6880dbb arraydata_3D.vti
dd7e99a1163c0d30de556ea125b685ae33da8ca1 arrays.vti
8005b27b071ed50765d0d859a9e4e84a52c3963c arraydata_2D.vti
d5215c84b3c1630bedd98994963560ff14200dc5 arraydata_3D.vti
aa49366e66d8930fa639a8361d153a95baca361e arrays.vti
2626bef24152fcfe28c810ca68adf473c8fad90c simulation.pvtu
4a0be2eaf5c7ffdb60970f0396a11ef2ab3affca simulation/simulation_1.vtu
ee3ea76e543c6e3a9c1c28d80596b68c5b22d7ac higherorderdegrees.pvtu
Expand Down
15 changes: 3 additions & 12 deletions test/polydata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ using Test

const vtk_filename_noext = "polydata"

# Version of randn that is stable across different julia versions
# Ref: https://github.com/DEShawResearch/random123/blob/9545ff6413f258be2f04c1d319d99aaef7521150/include/Random123/boxmuller.hpp
function my_randn(rng::StableRNG, dims::Integer...)
# Box–Muller transform
u01 = rand(rng, UInt64, dims...) .* (2.0^-64) .+ (2.0^-65)
uneg11 = rand(rng, Int64, dims...) .* (2.0^-63) .+ (2.0^-64)
sqrt.(-2 .* log.(u01)) .* cospi.(uneg11)
end

# Write file with D-dimensional grid.
function write_vtp(Np, D)
rng = StableRNG(42)
Expand Down Expand Up @@ -55,14 +46,14 @@ function write_vtp(Np, D)
print("PolyData $(D)D...")
@time filenames = vtk_grid(fname, points, all_cells...,
compress=false, append=false, ascii=true) do vtk
vtk["my_point_data"] = my_randn(rng, 3, Np)
vtk["vector_as_tuple"] = ntuple(_ -> my_randn(rng, Np), D)
vtk["my_point_data"] = rand(rng, 3, Np) .- 0.5
vtk["vector_as_tuple"] = ntuple(_ -> rand(rng, Np) .- 0.5, D)
# NOTE: cell data is not correctly parsed by VTK when multiple kinds of
# cells are combined in the same dataset.
# This seems to be a really old VTK issue:
# - https://vtk.org/pipermail/vtkusers/2004-August/026448.html
# - https://gitlab.kitware.com/vtk/vtk/-/issues/564
vtk["my_cell_data"] = my_randn(rng, num_cells)
vtk["my_cell_data"] = rand(rng, num_cells) .- 0.5
end
end

Expand Down

0 comments on commit eacccef

Please sign in to comment.