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

Commits on May 14, 2020

  1. 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
    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 committed May 14, 2020
    Configuration menu
    Copy the full SHA
    90263c3 View commit details
    Browse the repository at this point in the history