AliasSampler_2D_t Derived Type

type, public :: AliasSampler_2D_t


Contents

Source Code


Components

Type Visibility Attributes Name Initial
type(AliasSampler_3D_t), private :: alias_sampler

Type-Bound Procedures

procedure, public, :: shared_alloc => setupSamplerArray_2D

  • private subroutine setupSamplerArray_2D(this, dims, entrySize, name)

    Setup an array of samplers using a single shared resource (split into parts associated with one of them each). This only does the allocation. @param[in] nEntries number of samplers to initialise @param[in] entrySize number of values per sampler

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t) :: this
    integer, intent(in) :: dims(2)
    integer, intent(in) :: entrySize
    character(len=*), intent(in) :: name

procedure, public, :: setup_entry => setupEntry_2D

  • private subroutine setupEntry_2D(this, i, j, rank_with_info, arr)

    Initialise one sampler of an array @param[in] iEntry index of the entry to initialize @param[in] arr data to be loaded by that entry

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(inout) :: this
    integer, intent(in) :: i
    integer, intent(in) :: j
    integer, intent(in) :: rank_with_info
    real(kind=dp), intent(in) :: arr(:)

procedure, public, :: finalize => samplerArrayDestructor_2D

procedure, public, :: sample => aSample_2D

  • private subroutine aSample_2D(this, i, j, tgt, prob)

    Draw a random element from 1:size(this%probs) with the probabilities listed in prob

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i

    The index of the sampler.

    integer, intent(in) :: j

    The index of the sampler.

    integer, intent(out) :: tgt

    The sampled value tgt.

    real(kind=dp), intent(out) :: prob

    The probability of sampling tgt.

generic, public, :: constrained_sample => constrained_sample_2D_nI, constrained_sample_2D_fast

  • private subroutine constrained_sample_2D_nI(this, i, j, contain, renorm, pos, tgt, prob)

    Draw a random element from 1:size(this%probs) with the probabilities listed in prob while adherring to constraints

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i

    The index of the sampler.

    integer, intent(in) :: j

    The index of the sampler.

    integer, intent(in) :: contain(:)

    The constraint in nI format.

    real(kind=dp), intent(in) :: renorm

    The renormalization. (i.e. sum(this%get_prob(… contain…))

    integer, intent(out) :: pos

    The sampled value tgt and its position pos in `contain.

    integer, intent(out) :: tgt

    The sampled value tgt and its position pos in `contain.

    real(kind=dp), intent(out) :: prob

    The probability of sampling tgt from contain

  • private subroutine constrained_sample_2D_fast(this, i, j, contain, contain_ilut, renormalization, pos, tgt, prob)

    Draw a random element from 1:size(this%probs) with the probabilities listed in prob while adherring to constraints

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i

    The index of the sampler.

    integer, intent(in) :: j

    The index of the sampler.

    integer, intent(in) :: contain(:)

    The constraint in nI format.

    integer(kind=n_int), intent(in) :: contain_ilut(0:)

    The constraint in ilut (bitmask) format

    real(kind=dp), intent(in) :: renormalization

    The renormalization. (i.e. sum(this%get_prob(… contain…))

    integer, intent(out) :: pos

    The sampled value tgt and its position pos in `contain.

    integer, intent(out) :: tgt

    The sampled value tgt and its position pos in `contain.

    real(kind=dp), intent(out) :: prob

    The probability of sampling tgt from contain

procedure, private :: constrained_sample_2D_fast

  • private subroutine constrained_sample_2D_fast(this, i, j, contain, contain_ilut, renormalization, pos, tgt, prob)

    Draw a random element from 1:size(this%probs) with the probabilities listed in prob while adherring to constraints

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i

    The index of the sampler.

    integer, intent(in) :: j

    The index of the sampler.

    integer, intent(in) :: contain(:)

    The constraint in nI format.

    integer(kind=n_int), intent(in) :: contain_ilut(0:)

    The constraint in ilut (bitmask) format

    real(kind=dp), intent(in) :: renormalization

    The renormalization. (i.e. sum(this%get_prob(… contain…))

    integer, intent(out) :: pos

    The sampled value tgt and its position pos in `contain.

    integer, intent(out) :: tgt

    The sampled value tgt and its position pos in `contain.

    real(kind=dp), intent(out) :: prob

    The probability of sampling tgt from contain

procedure, private :: constrained_sample_2D_nI

  • private subroutine constrained_sample_2D_nI(this, i, j, contain, renorm, pos, tgt, prob)

    Draw a random element from 1:size(this%probs) with the probabilities listed in prob while adherring to constraints

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i

    The index of the sampler.

    integer, intent(in) :: j

    The index of the sampler.

    integer, intent(in) :: contain(:)

    The constraint in nI format.

    real(kind=dp), intent(in) :: renorm

    The renormalization. (i.e. sum(this%get_prob(… contain…))

    integer, intent(out) :: pos

    The sampled value tgt and its position pos in `contain.

    integer, intent(out) :: tgt

    The sampled value tgt and its position pos in `contain.

    real(kind=dp), intent(out) :: prob

    The probability of sampling tgt from contain

procedure, public, :: get_prob => aGetProb_2D

  • private elemental function aGetProb_2D(this, i, j, tgt) result(prob)

    Returns the probability to draw tgt from the sampler with index iEntry @param[in] iEntry index of the sampler to use @param[in] tgt the number for which we request the probability of sampling @return prob the probability of drawing tgt with the sample routine

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(in) :: j
    integer, intent(in) :: tgt

    Return Value real(kind=dp)

procedure, public, :: constrained_getProb => constrained_get_prob_2D

  • private pure function constrained_get_prob_2D(this, i, j, contain, renorm, tgt) result(prob)

    Returns the probability to draw tgt from the sampler with index iEntry @param[in] i Index of the sampler to use @param[in] j Index of the sampler to use @param[in] constraint pick only elements from constraint @param[in] tgt the number for which we request the probability of sampling @return prob the probability of drawing tgt with the sample routine from constraint

    Arguments

    Type IntentOptional Attributes Name
    class(AliasSampler_2D_t), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(in) :: j
    integer, intent(in) :: contain(:)
    real(kind=dp), intent(in) :: renorm
    integer, intent(in) :: tgt

    Return Value real(kind=dp)

Source Code

    type AliasSampler_2D_t
        private
        type(AliasSampler_3D_t) :: alias_sampler
    contains
        ! constructor
        procedure :: shared_alloc => setupSamplerArray_2D
        procedure :: setup_entry => setupEntry_2D
        ! destructor
        procedure :: finalize => samplerArrayDestructor_2D
        ! get a random element and the generation probability from one of the samplers
        procedure :: sample => aSample_2D
        generic :: constrained_sample => constrained_sample_2D_nI, constrained_sample_2D_fast
        procedure, private :: constrained_sample_2D_nI, constrained_sample_2D_fast
        procedure :: get_prob => aGetProb_2D
        procedure :: constrained_getProb => constrained_get_prob_2D
    end type AliasSampler_2D_t