コード例 #1
0
        public static float MaxAbs(ReadOnlySpan <float> src)
        {
            Contracts.AssertNonEmpty(src);

            unsafe
            {
                fixed(float *psrc = &MemoryMarshal.GetReference(src))
                return(Thunk.MaxAbsU(psrc, src.Length));
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        // 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);
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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));
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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));
            }
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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));
            }
        }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        // 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);
                }
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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));
            }
        }
コード例 #24
0
        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));
            }
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
        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);
                    }
                }
            }
        }
コード例 #30
0
        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);
            }
        }