Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a custom type for the random field #43

Merged
merged 1 commit into from
May 15, 2020
Merged

Define a custom type for the random field #43

merged 1 commit into from
May 15, 2020

Conversation

giordano
Copy link
Member

@giordano giordano commented May 14, 2020

Define a custom type for the random field

With this change we also take advantage of a new change introduced in
GaussianRandomFields v2.1.1 that allows us to reduce memory allocations when
sampling. For example, with current master:

julia> using BenchmarkTools, TDAC

julia> x = 1.:200.;

julia> y = 1.:200.;

julia> grf = @btime TDAC.init_gaussian_random_field_generator(1.0,1.0,1.0,$x,$y,0);
  18.287 ms (121 allocations: 5.50 MiB)

julia> f = zeros(40000);

julia> rnn = rand(160000);

julia> @btime TDAC.sample_gaussian_random_field!($f, $grf, $rnn);
  1.461 ms (10 allocations: 2.75 MiB)

With this change:

julia> using BenchmarkTools, TDAC

julia> x = 1.:200.;

julia> y = 1.:200.;

julia> grf = @btime TDAC.init_gaussian_random_field_generator(1.0,1.0,1.0,$x,$y,0,$true);
  18.102 ms (126 allocations: 8.25 MiB)

julia> f = zeros(40000);

julia> rnn = randn(size(grf.grf.data[1]));

julia> @btime TDAC.sample_gaussian_random_field!($f, $grf, $rnn);
  1.366 ms (3 allocations: 128 bytes)

The speed-up is modest, the major benefit is from having much less memory
allocations every time we do the sampling. The memory allocations have been
moved to the initialisation, which is however a one-off.

@giordano giordano requested a review from tkoskela May 14, 2020 15:53
@giordano giordano force-pushed the mg/noise branch 2 times, most recently from 449593f to 4b2df3f Compare May 14, 2020 16:21
src/noise.jl Outdated Show resolved Hide resolved
src/params.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
With this change we also take advantage of a new change introduced in
GaussianRandomFields v2.1.1 that allows us to reduce memory allocations when
sampling.  For example, with current master:

```julia
julia> using BenchmarkTools, TDAC

julia> x = 1.:200.;

julia> y = 1.:200.;

julia> grf = @Btime TDAC.init_gaussian_random_field_generator(1.0,1.0,1.0,$x,$y,0);
  18.287 ms (121 allocations: 5.50 MiB)

julia> f = zeros(40000);

julia> rnn = rand(160000);

julia> @Btime TDAC.sample_gaussian_random_field!($f, $grf, $rnn);
  1.461 ms (10 allocations: 2.75 MiB)
```

With this change:

```julia
julia> using BenchmarkTools, TDAC

julia> x = 1.:200.;

julia> y = 1.:200.;

julia> grf = @Btime TDAC.init_gaussian_random_field_generator(1.0,1.0,1.0,$x,$y,0,$true);
  18.102 ms (126 allocations: 8.25 MiB)

julia> f = zeros(40000);

julia> rnn = randn(size(grf.grf.data[1]));

julia> @Btime TDAC.sample_gaussian_random_field!($f, $grf, $rnn);
  1.366 ms (3 allocations: 128 bytes)
```

The speed-up is modest, the major benefit is from having much less memory
allocations every time we do the sampling.  The memory allocations have been
moved to the initialisation, which is however a one-off.
@giordano giordano merged commit 60529c0 into master May 15, 2020
@giordano giordano deleted the mg/noise branch May 15, 2020 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants