public static float MaxAbs(ReadOnlySpan <float> src) { Contracts.AssertNonEmpty(src); unsafe { fixed(float *psrc = &MemoryMarshal.GetReference(src)) return(Thunk.MaxAbsU(psrc, src.Length)); } }
public static void ScaleMaxNorm(float maxNorm, int kernCount, int kernSize, float[] mat) { Contracts.AssertNonEmpty(mat); unsafe { fixed(float *pmat = &mat[0]) Thunk.ScaleMaxNormCU(maxNorm, kernCount, kernSize, pmat); } }
public static float SumAbs(float mean, ReadOnlySpan <float> src) { Contracts.AssertNonEmpty(src); unsafe { fixed(float *psrc = &MemoryMarshal.GetReference(src)) return(mean == 0 ? Thunk.SumAbsU(psrc, src.Length) : Thunk.SumAbsDiffU(mean, psrc, src.Length)); } }
// dst[i] = a * (dst[i] + b) public static void ScaleAdd(float a, float b, Span <float> dst) { Contracts.AssertNonEmpty(dst); unsafe { fixed(float *pdst = &MemoryMarshal.GetReference(dst)) Thunk.ScaleAddU(a, b, pdst, dst.Length); } }
public static float Sum(AlignedArray src) { Contracts.Assert(Compat(src)); unsafe { fixed(float *psrc = &src.Items[0]) return(Thunk.SumX(Ptr(src, psrc), src.Size)); } }
public static void Scale(float a, AlignedArray dst) { Contracts.Assert(Compat(dst)); unsafe { fixed(float *pdst = &dst.Items[0]) Thunk.ScaleX(a, Ptr(dst, pdst), dst.Size); } }
public static float MaxAbs(float[] src, int count) { Contracts.AssertNonEmpty(src); Contracts.Assert(0 < count && count <= src.Length); unsafe { fixed(float *psrc = &src[0]) return(Thunk.MaxAbsU(psrc, count)); } }
public static void Scale(float a, float[] dst, int count) { Contracts.AssertNonEmpty(dst); Contracts.Assert(0 < count && count <= dst.Length); unsafe { fixed(float *pd = &dst[0]) Thunk.Scale(a, pd, count); } }
public static void ApplyBoundedRectifiedLinearDerivative(AlignedArray value, AlignedArray grad) { Contracts.Assert(Compat(value)); Contracts.Assert(Compat(grad)); Contracts.Assert(value.Size == grad.Size); unsafe { fixed(float *pvalue = &value.Items[0]) fixed(float *pgrad = &grad.Items[0]) Thunk.ApplyBoundedRectifiedLinearDerivativeX(Ptr(value, pvalue), Ptr(grad, pgrad), grad.Size); } }
public static void Add(AlignedArray src, AlignedArray dst) { Contracts.Assert(Compat(src)); Contracts.Assert(Compat(dst)); Contracts.Assert(src.Size == dst.Size); unsafe { fixed(float *psrc = &src.Items[0]) fixed(float *pdst = &dst.Items[0]) Thunk.AddX(Ptr(src, psrc), Ptr(dst, pdst), dst.Size); } }
public static void Add(ReadOnlySpan <float> src, Span <float> dst, int count) { Contracts.AssertNonEmpty(src); Contracts.Assert(0 < count && count <= src.Length); Contracts.AssertNonEmpty(dst); Contracts.Assert(count <= dst.Length); unsafe { fixed(float *ps = &MemoryMarshal.GetReference(src)) fixed(float *pd = &MemoryMarshal.GetReference(dst)) Thunk.AddU(ps, pd, count); } }
public static void ApplyTanh(AlignedArray src, AlignedArray dst, int c) { Contracts.Assert(Compat(src)); Contracts.Assert(Compat(dst)); Contracts.Assert(src.Size == dst.Size); Contracts.Assert(0 < c && c <= dst.Size); unsafe { fixed(float *psrc = &src.Items[0]) fixed(float *pdst = &dst.Items[0]) Thunk.ApplyTanhX(Ptr(src, psrc), Ptr(dst, pdst), c); } }
public static float L2DistSquared(ReadOnlySpan <float> a, ReadOnlySpan <float> b, int count) { Contracts.AssertNonEmpty(a); Contracts.AssertNonEmpty(b); Contracts.Assert(0 < count && count <= a.Length); Contracts.Assert(count <= b.Length); unsafe { fixed(float *pa = &MemoryMarshal.GetReference(a)) fixed(float *pb = &MemoryMarshal.GetReference(b)) return(Thunk.Dist2(pa, pb, count)); } }
public static void Add(float[] src, float[] dst, int count) { Contracts.AssertNonEmpty(src); Contracts.Assert(0 < count && count <= src.Length); Contracts.AssertNonEmpty(dst); Contracts.Assert(count <= dst.Length); unsafe { fixed(float *ps = &src[0]) fixed(float *pd = &dst[0]) Thunk.AddU(ps, pd, count); } }
public static float DotProductDense(ReadOnlySpan <float> a, ReadOnlySpan <float> b, int count) { Contracts.AssertNonEmpty(a); Contracts.AssertNonEmpty(b); Contracts.Assert(0 < count); Contracts.Assert(a.Length >= count); Contracts.Assert(b.Length >= count); unsafe { fixed(float *pa = &MemoryMarshal.GetReference(a)) fixed(float *pb = &MemoryMarshal.GetReference(b)) return(Thunk.DotU(pa, pb, count)); } }
public static void MulElementWise(ReadOnlySpan <float> src1, ReadOnlySpan <float> src2, Span <float> dst, int count) { Contracts.AssertNonEmpty(src1); Contracts.Assert(0 < count && count <= src1.Length); Contracts.AssertNonEmpty(src2); Contracts.Assert(0 < count && count <= src2.Length); Contracts.AssertNonEmpty(dst); unsafe { fixed(float *ps1 = &MemoryMarshal.GetReference(src1)) fixed(float *ps2 = &MemoryMarshal.GetReference(src2)) fixed(float *pd = &MemoryMarshal.GetReference(dst)) Thunk.MulElementWiseU(ps1, ps2, pd, count); } }
public static void ApplyAbsDerivative(AlignedArray input, AlignedArray output, AlignedArray grad, bool drop) { Contracts.Assert(Compat(input)); Contracts.Assert(Compat(output)); Contracts.Assert(Compat(grad)); Contracts.Assert(output.Size == input.Size); Contracts.Assert(output.Size == grad.Size); unsafe { fixed(float *px = &input.Items[0]) fixed(float *py = &output.Items[0]) fixed(float *pg = &grad.Items[0]) Thunk.ApplyAbsDerivativeX(Ptr(input, px), Ptr(output, py), Ptr(grad, pg), grad.Size, drop); } }
public static void AddScale(float a, AlignedArray src, AlignedArray dst, float momentum, AlignedArray delta) { Contracts.Assert(Compat(src)); Contracts.Assert(Compat(dst)); Contracts.Assert(Compat(delta)); Contracts.Assert(src.Size == dst.Size); Contracts.Assert(src.Size == delta.Size); unsafe { fixed(float *psrc = &src.Items[0]) fixed(float *pdst = &dst.Items[0]) fixed(float *pdel = &delta.Items[0]) Thunk.AddScaleMomX(a, Ptr(src, psrc), Ptr(dst, pdst), momentum, Ptr(delta, pdel), dst.Size); } }
// dst = a * src public static void Scale(float a, ReadOnlySpan <float> src, Span <float> dst, int count) { Contracts.AssertNonEmpty(src); Contracts.Assert(0 < count && count <= src.Length); Contracts.AssertNonEmpty(dst); Contracts.Assert(count <= dst.Length); unsafe { fixed(float *psrc = &MemoryMarshal.GetReference(src)) fixed(float *pdst = &MemoryMarshal.GetReference(dst)) { Thunk.ScaleSrcU(a, psrc, pdst, count); } } }
public static void AddScaleCopy(float a, ReadOnlySpan <float> src, ReadOnlySpan <float> dst, Span <float> res, int count) { Contracts.AssertNonEmpty(dst); Contracts.Assert(0 < count && count <= dst.Length); Contracts.AssertNonEmpty(src); Contracts.Assert(count <= src.Length); Contracts.AssertNonEmpty(res); Contracts.Assert(count <= res.Length); unsafe { fixed(float *pdst = &MemoryMarshal.GetReference(dst)) fixed(float *psrc = &MemoryMarshal.GetReference(src)) fixed(float *pres = &MemoryMarshal.GetReference(res)) Thunk.AddScaleCopyU(a, psrc, pdst, pres, count); } }
public static void AddScale(float a, ReadOnlySpan <float> src, ReadOnlySpan <int> indices, Span <float> dst, int count) { Contracts.AssertNonEmpty(src); Contracts.Assert(0 < count && count <= src.Length); Contracts.AssertNonEmpty(indices); Contracts.Assert(count <= indices.Length); Contracts.AssertNonEmpty(dst); Contracts.Assert(count < dst.Length); unsafe { fixed(float *psrc = &MemoryMarshal.GetReference(src)) fixed(int *pi = &MemoryMarshal.GetReference(indices)) fixed(float *pdst = &MemoryMarshal.GetReference(dst)) Thunk.AddScaleSU(a, psrc, pi, pdst, count); } }
public static void AddXYTran(float a, AlignedArray x, AlignedArray y, AlignedArray mat, int crow, float decay) { Contracts.Assert(Compat(x)); Contracts.Assert(Compat(y)); Contracts.Assert(Compat(mat)); Contracts.Assert(0 < crow && crow <= x.Size); Contracts.Assert(x.Size * y.Size == mat.Size); Contracts.Assert(decay >= 0); unsafe { fixed(float *px = &x.Items[0]) fixed(float *py = &y.Items[0]) fixed(float *pmat = &mat.Items[0]) Thunk.AddXYTranX(a, Ptr(x, px), Ptr(y, py), Ptr(mat, pmat), crow, y.Size, decay); } }
public static float DotProductSparse(float[] a, float[] b, int[] indices, int count) { Contracts.AssertNonEmpty(a); Contracts.AssertNonEmpty(b); Contracts.Assert(0 < count); Contracts.Assert(count < a.Length); Contracts.Assert(count <= b.Length); Contracts.Assert(count <= indices.Length); unsafe { fixed(float *pa = &a[0]) fixed(float *pb = &b[0]) fixed(int *pi = &indices[0]) return(Thunk.DotSU(pa, pb, pi, count)); } }
public static float DotProductSparse(ReadOnlySpan <float> a, ReadOnlySpan <float> b, ReadOnlySpan <int> indices, int count) { Contracts.AssertNonEmpty(a); Contracts.AssertNonEmpty(b); Contracts.Assert(0 < count); Contracts.Assert(count < a.Length); Contracts.Assert(count <= b.Length); Contracts.Assert(count <= indices.Length); unsafe { fixed(float *pa = &MemoryMarshal.GetReference(a)) fixed(float *pb = &MemoryMarshal.GetReference(b)) fixed(int *pi = &MemoryMarshal.GetReference(indices)) return(Thunk.DotSU(pa, pb, pi, count)); } }
public static void ScaleAdadelta(float[] mat, float[] accGrads, float[] accUpdates, float decay, float cond, float[] grads) { Contracts.AssertNonEmpty(mat); Contracts.AssertNonEmpty(accGrads); Contracts.AssertNonEmpty(accUpdates); Contracts.Assert(mat.Length == accGrads.Length); Contracts.Assert(mat.Length == accUpdates.Length); Contracts.Assert(mat.Length <= grads.Length); unsafe { fixed(float *pm = &mat[0]) fixed(float *pag = &accGrads[0]) fixed(float *pau = &accUpdates[0]) fixed(float *pg = &grads[0]) Thunk.ScaleAdadeltaX(pm, pag, pau, decay, cond, pg, mat.Length); } }
public static void ScaleMaxNorm(float maxNorm, int[] starts, int[] indices, float[] mat) { Contracts.AssertNonEmpty(starts); int crow = starts.Length - 1; Contracts.Assert(starts[0] == 0); Contracts.AssertValue(indices); Contracts.Assert(starts[crow] == indices.Length); Contracts.AssertNonEmpty(mat); unsafe { fixed(int *pstarts = &starts[0]) fixed(float *pmat = &mat[0]) Thunk.ScaleMaxNormRU(maxNorm, pstarts, pmat, crow); } }
public static void SdcaL1UpdateDense(float primalUpdate, int count, ReadOnlySpan <float> src, float threshold, Span <float> v, Span <float> w) { Contracts.AssertNonEmpty(src); Contracts.Assert(count <= src.Length); Contracts.AssertNonEmpty(v); Contracts.Assert(count <= v.Length); Contracts.AssertNonEmpty(w); Contracts.Assert(count <= w.Length); Contracts.Assert(count > 0); unsafe { fixed(float *psrc = &MemoryMarshal.GetReference(src)) fixed(float *pd1 = &MemoryMarshal.GetReference(v)) fixed(float *pd2 = &MemoryMarshal.GetReference(w)) Thunk.SdcaL1UpdateU(primalUpdate, psrc, threshold, pd1, pd2, count); } }
public static void AddXYTran(float a, AlignedArray x, AlignedArray y, AlignedArray mat, float momentum, AlignedArray delta, int crow) { Contracts.Assert(Compat(x)); Contracts.Assert(Compat(y)); Contracts.Assert(Compat(mat)); Contracts.Assert(Compat(delta)); Contracts.Assert(0 < crow && crow <= x.Size); Contracts.Assert(x.Size * y.Size == mat.Size); Contracts.Assert(mat.Size == delta.Size); unsafe { fixed(float *px = &x.Items[0]) fixed(float *py = &y.Items[0]) fixed(float *pmat = &mat.Items[0]) fixed(float *pdel = &delta.Items[0]) Thunk.AddXYTranMomX(a, Ptr(x, px), Ptr(y, py), Ptr(mat, pmat), momentum, Ptr(delta, pdel), crow, y.Size); } }
public static void ZeroMatrixItems(AlignedArray dst, int ccol, int cfltRow, int[] indices) { Contracts.Assert(0 < ccol && ccol <= cfltRow); unsafe { fixed(float *pdst = &dst.Items[0]) fixed(int *pi = &indices[0]) { if (ccol == cfltRow) { Thunk.ZeroItemsU(Ptr(dst, pdst), dst.Size, pi, indices.Length); } else { Thunk.ZeroMatrixItemsCore(Ptr(dst, pdst), dst.Size, ccol, cfltRow, pi, indices.Length); } } } }
public static void AddScale(AlignedArray src, AlignedArray dst, AlignedArray accGrads, AlignedArray accUpdates, float decay, float cond) { Contracts.Assert(Compat(src)); Contracts.Assert(Compat(dst)); Contracts.Assert(Compat(accGrads)); Contracts.Assert(Compat(accUpdates)); Contracts.Assert(src.Size == dst.Size); Contracts.Assert(src.Size == accGrads.Size); Contracts.Assert(src.Size == accUpdates.Size); unsafe { fixed(float *psrc = &src.Items[0]) fixed(float *pdst = &dst.Items[0]) fixed(float *pag = &accGrads.Items[0]) fixed(float *pau = &accUpdates.Items[0]) Thunk.AddScaleGradX(Ptr(src, psrc), Ptr(dst, pdst), Ptr(accGrads, pag), Ptr(accUpdates, pau), decay, cond, dst.Size); } }