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); }
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); }
public override void Dispose() { if (Pointer != IntPtr.Zero) { VSL.vslSSDeleteTask(ref Pointer); } }
public void Dispose() { if (Pointer != IntPtr.Zero) { VSL.vslDeleteStream(ref Pointer); } }
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>(); } }
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>(); } }
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])); } }
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>(); } }
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();
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();
public static void poisson(MklRng stream, double alpha, Span <int> dst) => VSL.viRngPoisson(0, stream.Source, dst.Length, ref first(dst), alpha).ThrowOnError();
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();
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);
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();
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);
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();
public static void chi2(MklRng stream, int dof, Span <double> dst) => VSL.vdRngChiSquare(0, stream.Source, dst.Length, ref first(dst), dof).ThrowOnError();
public static void bernoulli(MklRng stream, double p, Span <int> dst) => VSL.viRngBernoulli(0, stream.Source, dst.Length, ref first(dst), p).ThrowOnError();
public static void geometric(MklRng stream, double p, Span <int> dst) => VSL.viRngGeometric(0, stream.Source, dst.Length, ref first(dst), p).ThrowOnError();
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();
internal static Brng Brng(this VslStream stream) => VSL.vslGetStreamStateBrng(stream);
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();
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();
public static void bits(MklRng stream, Span <uint> dst) => VSL.viRngUniformBits32(0, stream.Source, dst.Length, ref head(dst)).ThrowOnError();
public static void bits(MklRng stream, Span <ulong> dst) => VSL.viRngUniformBits64(0, stream.Source, dst.Length, ref first(dst)).ThrowOnError();
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();
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();
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();
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();
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();