Esempio n. 1
0
        internal static VslStream NewStream(this BRNG brng, uint seed = 0, int index = 0)
        {
            IntPtr stream = IntPtr.Zero;

            VSL.vslNewStream(ref stream, brng + index, seed).ThrowOnError();
            return(stream);
        }
Esempio n. 2
0
        static unsafe Dataset <T> ApplyRadixSort <T>(this Dataset <T> samples, Dataset <T> dst)
            where T : unmanaged
        {
            var dim         = samples.Dim;
            var sampleCount = samples.Count;
            var iStorage    = (int)VslSSMatrixStorage.VSL_SS_MATRIX_STORAGE_ROWS;
            var mformat     = VslSSMatrixStorage.VSL_SS_MATRIX_STORAGE_ROWS;
            var taskPtr     = IntPtr.Zero;

            if (typeof(T) == typeof(float))
            {
                VSL.vslsSSNewTask(ref taskPtr, ref dim, ref sampleCount, ref mformat,
                                  ref MemoryMarshal.Cast <T, float>(samples)[0]).AutoThrow();
            }
            else if (typeof(T) == typeof(double))
            {
                VSL.vsldSSNewTask(ref taskPtr, ref dim, ref sampleCount, ref mformat,
                                  ref MemoryMarshal.Cast <T, double>(samples)[0]).AutoThrow();
            }
            else
            {
                throw unsupported <T>();
            }

            using var handle = VslSSTaskHandle.Wrap <T>(taskPtr);
            handle.Set(VSL_SS_ED_OBSERV_STORAGE, ref iStorage);
            handle.Set(VSL_SS_ED_SORTED_OBSERV, ref dst[0]);
            handle.Set(VSL_SS_ED_SORTED_OBSERV_STORAGE, ref iStorage);
            handle.Compute(VSL_SS_SORTED_OBSERV, VSL_SS_METHOD_RADIX);
            return(dst);
        }
Esempio n. 3
0
 public override void Dispose()
 {
     if (Pointer != IntPtr.Zero)
     {
         VSL.vslSSDeleteTask(ref Pointer);
     }
 }
Esempio n. 4
0
 public void Dispose()
 {
     if (Pointer != IntPtr.Zero)
     {
         VSL.vslDeleteStream(ref Pointer);
     }
 }
Esempio n. 5
0
 public static void Set <T>(this VslSSTaskHandle <T> task, VslSSTaskParameter param, ref T value, [CallerFilePath] string file = null, [CallerLineNumber] int?line = null)
     where T : unmanaged
 {
     if (typeof(T) == typeof(float))
     {
         VSL.vslsSSEditTask(task, param, ref As.float32(ref value)).AutoThrow(file, line);
     }
     else if (typeof(T) == typeof(double))
     {
         VSL.vsldSSEditTask(task, param, ref As.float64(ref value)).AutoThrow(file, line);
     }
     else
     {
         throw unsupported <T>();
     }
 }
Esempio n. 6
0
 public static void Compute <T>(this VslSSTaskHandle <T> task, VslSSComputeRoutine routine, VslSSComputeMethod method, [CallerFilePath] string file = null, [CallerLineNumber] int?line = null)
     where T : unmanaged
 {
     if (typeof(T) == typeof(float))
     {
         VSL.vslsSSCompute(task, routine, method).AutoThrow(file, line);
     }
     else if (typeof(T) == typeof(double))
     {
         VSL.vsldSSCompute(task, routine, method).AutoThrow(file, line);
     }
     else
     {
         throw unsupported <T>();
     }
 }
Esempio n. 7
0
 public unsafe override VslSSStatus Allocate()
 {
     if (Weights.Length == 0 && Indices.Length == 0)
     {
         return(VSL.vsldSSNewTask(ref Pointer, ref Dim, ref SampleCount, ref Storage, ref Samples[0]));
     }
     else if (Weights.Length != 0 && Indices.Length == 0)
     {
         return(VSL.vsldSSNewTask(ref Pointer, ref Dim, ref SampleCount, ref Storage, ref Samples[0], ref Weights[0]));
     }
     else if (Weights.Length != 0 && Indices.Length != 0)
     {
         return(VSL.vsldSSNewTask(ref Pointer, ref Dim, ref SampleCount, ref Storage, ref Samples[0], ref Weights[0], ref Indices[0]));
     }
     else
     {
         return(VSL.vsldSSNewTask(ref Pointer, ref Dim, ref SampleCount, ref Storage, ref Samples[0], null, ref Indices[0]));
     }
 }
Esempio n. 8
0
        VslSSTaskHandle(Span <T> samples, int dim)
        {
            this.Dim          = new int[] { dim };
            this.SampleCount  = new int[] { samples.Length / dim };
            this.MatrixFormat = new VslSSMatrixStorage[] { VslSSMatrixStorage.VSL_SS_MATRIX_STORAGE_ROWS };
            this.TaskPtr      = IntPtr.Zero;

            if (typeof(T) == typeof(float))
            {
                VSL.vslsSSNewTask(ref TaskPtr, ref Dim[0], ref SampleCount[0], ref MatrixFormat[0],
                                  ref MemoryMarshal.Cast <T, float>(samples)[0]).AutoThrow();
            }
            else if (typeof(T) == typeof(double))
            {
                VSL.vsldSSNewTask(ref TaskPtr, ref Dim[0], ref SampleCount[0], ref MatrixFormat[0],
                                  ref MemoryMarshal.Cast <T, double>(samples)[0]).AutoThrow();
            }
            else
            {
                throw unsupported <T>();
            }
        }
Esempio n. 9
0
 public static void laplace(MklRng stream, double mean, double beta, Span <double> dst)
 => VSL.vdRngLaplace(0, stream.Source, dst.Length, ref first(dst), mean, beta).ThrowOnError();
Esempio n. 10
0
 public static void laplace(MklRng stream, float a, float b, Span <float> dst)
 => VSL.vsRngLaplace(0, stream.Source, dst.Length, ref first(dst), a, b).ThrowOnError();
Esempio n. 11
0
 public static void poisson(MklRng stream, double alpha, Span <int> dst)
 => VSL.viRngPoisson(0, stream.Source, dst.Length, ref first(dst), alpha).ThrowOnError();
Esempio n. 12
0
 public static void exp(MklRng stream, double dx, double beta, Span <double> dst)
 => VSL.vdRngExponential(0, stream.Source, dst.Length, ref first(dst), dx, beta).ThrowOnError();
Esempio n. 13
0
 public static void Set <T>(this VslSSTaskHandle <T> task, VslSSTaskParameter param, ref double value, [CallerFilePath] string file = null, [CallerLineNumber] int?line = null)
     where T : unmanaged
 => VSL.vsldSSEditTask(task, param, ref value).AutoThrow(file, line);
Esempio n. 14
0
 public static void uniform(MklRng stream, double min, double max, Span <double> dst)
 => VSL.vdRngUniform(0, stream.Source, dst.Length, ref first(dst), min, max).ThrowOnError();
Esempio n. 15
0
 public static void Compute(this VslSSTaskHandle <double> task, VslSSComputeRoutine routine, VslSSComputeMethod method, [CallerFilePath] string file = null, [CallerLineNumber] int?line = null)
 => VSL.vsldSSCompute(task, routine, method).AutoThrow(file, line);
Esempio n. 16
0
 public static void gaussian(MklRng stream, float mu, float sigma, Span <float> dst)
 => VSL.vsRngGaussian(VslGaussianMethod.BoxMuller1, stream.Source, dst.Length, ref first(dst), mu, sigma).ThrowOnError();
Esempio n. 17
0
 public static void chi2(MklRng stream, int dof, Span <double> dst)
 => VSL.vdRngChiSquare(0, stream.Source, dst.Length, ref first(dst), dof).ThrowOnError();
Esempio n. 18
0
 public static void bernoulli(MklRng stream, double p, Span <int> dst)
 => VSL.viRngBernoulli(0, stream.Source, dst.Length, ref first(dst), p).ThrowOnError();
Esempio n. 19
0
 public static void geometric(MklRng stream, double p, Span <int> dst)
 => VSL.viRngGeometric(0, stream.Source, dst.Length, ref first(dst), p).ThrowOnError();
Esempio n. 20
0
 public static void cauchy(MklRng stream, double a, double b, Span <double> dst)
 => VSL.vdRngCauchy(0, stream.Source, dst.Length, ref first(dst), a, b).ThrowOnError();
Esempio n. 21
0
File: mkl.x.cs Progetto: 0xCM/z0
 internal static Brng Brng(this VslStream stream)
 => VSL.vslGetStreamStateBrng(stream);
Esempio n. 22
0
 public static void uniform(MklRng stream, float min, float max, Span <float> dst)
 => VSL.vsRngUniform(0, stream.Source, dst.Length, ref first(dst), min, max).ThrowOnError();
Esempio n. 23
0
 public static void uniform(MklRng stream, Interval <double> range, Span <double> dst)
 => VSL.vdRngUniform(0, stream.Source, dst.Length, ref first(dst), range.Left, range.Right).ThrowOnError();
Esempio n. 24
0
 public static void bits(MklRng stream, Span <uint> dst)
 => VSL.viRngUniformBits32(0, stream.Source, dst.Length, ref head(dst)).ThrowOnError();
Esempio n. 25
0
 public static void bits(MklRng stream, Span <ulong> dst)
 => VSL.viRngUniformBits64(0, stream.Source, dst.Length, ref first(dst)).ThrowOnError();
Esempio n. 26
0
 public static void gamma(MklRng stream, double alpha, double dx, double beta, Span <double> dst)
 => VSL.vdRngGamma(VslGammaMethod.GNorm, stream.Source, dst.Length, ref first(dst), alpha, dx, beta).ThrowOnError();
Esempio n. 27
0
 public static void gaussian(MklRng stream, double mu, double sigma, Span <double> dst)
 => VSL.vdRngGaussian(VslGaussianMethod.BoxMuller1, stream.Source, dst.Length, ref first(dst), mu, sigma).ThrowOnError();
Esempio n. 28
0
 public static void exp(MklRng stream, float dx, float beta, Span <float> dst)
 => VSL.vsRngExponential(0, stream.Source, dst.Length, ref first(dst), dx, beta).ThrowOnError();
Esempio n. 29
0
 public static void gamma(MklRng stream, float alpha, float dx, float beta, Span <float> dst)
 => VSL.vsRngGamma(VslGammaMethod.GNorm, stream.Source, dst.Length, ref first(dst), alpha, dx, beta).ThrowOnError();
Esempio n. 30
0
 public static void uniform(MklRng stream, Interval <float> range, Span <float> dst)
 => VSL.vsRngUniform(0, stream.Source, dst.Length, ref head(dst), range.Left, range.Right).ThrowOnError();