﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2737	Handle inherited replaceable functions called in functions	Martin Sjölund	Martin Sjölund	"Inherited replaceable functions called in functions are used in the Noise library:

{{{#!mo
package Noise
  package RNG
    package SampleBased
      function RNG_MRG
        extends Noise.Utilities.Interfaces.SampleBasedRNG;
        input Integer[:] a = {1071064, 0, 0, 0, 0, 0, 2113664};
        input Integer c = 0;
        input Integer m = 2147483629;
      algorithm
        assert(size(states_in, 1) >= size(a, 1), ""State must have at least as many elements as a!"");
        states_out := states_in;
        states_out[1] := 0;
        for i in 1:size(a, 1) loop
          states_out[1] := states_out[1] + a[i] * states_in[i];
        end for;
        states_out[1] := integer(mod(states_out[1] + c, m));
        for i in 1:size(a, 1) - 1 loop
          states_out[i + 1] := states_in[i];
        end for;
        rand := abs(states_out[1] / (m - 1));
      end RNG_MRG;

      function RNG_LCG
        extends Noise.Utilities.Interfaces.SampleBasedRNG;
        input Integer a = 69069;
        input Integer c = 1;
        input Integer m = 2147483647;
      algorithm
        (rand, states_out) := RNG_MRG(instance, states_in, a = {a}, c = c, m = m);
      end RNG_LCG;
    end SampleBased;
  end RNG;

  package PDF
    function PDF_Uniform
      extends Noise.Utilities.Interfaces.PDF;
      input Real[2] interval = {0, 1};
    algorithm
      (rand, states_out) := RNG(instance = instance, states_in = states_in);
      rand := rand * (interval[2] - interval[1]) + interval[1];
    end PDF_Uniform;
  end PDF;

  package Utilities
    package Interfaces
      partial function InputOutput
        input Real instance;
        input Integer[:] states_in;
        output Real rand;
        output Integer[size(states_in, 1)] states_out;
      end InputOutput;

      partial function RNG
        extends Interfaces.InputOutput;
      end RNG;

      partial function SampleBasedRNG
        extends RNG;
      end SampleBasedRNG;

      partial function PDF
        extends Interfaces.InputOutput;
        replaceable function RNG = Noise.RNG.SampleBased.RNG_LCG constrainedby Interfaces.RNG;
      end PDF;
    end Interfaces;
  end Utilities;
end Noise;

model M
  Real r = Noise.PDF.PDF_Uniform(1.0,{1,2,3});
end M;
}}}"	defect	closed	high	1.9.1	Frontend	trunk	fixed		Per Östlund
