Skip to content

Commit

Permalink
Change the SAA vectors in the EM demo to being stored as a BitArray,
Browse files Browse the repository at this point in the history
reducing 450MiB of serialized data to 5MiB.
  • Loading branch information
cgeoga committed Jan 4, 2023
1 parent 64b90ac commit 391edf4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion paperscripts/EM/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end

function extract_saa(j)
_saa = deserialize("./data/saa.jls") # v1.7 serialization!
_saa[:,:,j]
booltosgn.(_saa[:,:,j])
end

# Wrapping in a function just to be obviously sure that there is no global scope
Expand Down
9 changes: 4 additions & 5 deletions paperscripts/EM/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ function simulate(init_seed, n, true_parms, nsamp)
(pts=points, data=data)
end

# TODO (cg 2023/01/04 10:25): What I should have done here is saved this as a
# BitArray and then converted on the fly to random signs. That would have turned
# 400 MiB of disk to 4 MiB of disk. But at this point I am not interested to
# play with this code.
# Note that this comes out as a BitArray now to save space. Since all we need is
# the sign (each entry is +1 or -1), we can do that with one bit. And so using a
# BitArray instead of storing them as floats turns 450 MiB into 5 MiB.
function generate_saa(init_seed, n, m, l)
rng = StableRNG(init_seed)
rand(rng, (-1.0, 1.0), n, m, l)
BitArray(sgntobool.(rand(rng, (-1.0, 1.0), n, m, l)))
end

if !isinteractive()
Expand Down
5 changes: 5 additions & 0 deletions paperscripts/EM/shared.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ if !isinteractive()
end
end

# Just two little trick functions to work with the SAA vectors that have been
# stored in a BitArray. Your computers allocator will thank me.
sgntobool(x) = x > zero(x)
booltosgn(x) = x ? 1.0 : -1.0

function kernel_nonugget(x, y, p)
(sg2, rho, nu, nug2) = p
scaledist = norm(x-y)/rho
Expand Down

0 comments on commit 391edf4

Please sign in to comment.