public static void MatTimesSrc(AlignedArray mat, ReadOnlySpan <int> rgposSrc, AlignedArray srcValues, int posMin, int iposMin, int iposLim, AlignedArray dst, int crun) { Contracts.Assert(Compat(mat)); Contracts.Assert(Compat(srcValues)); Contracts.Assert(Compat(dst)); Contracts.Assert(0 <= iposMin && iposMin <= iposLim && iposLim <= rgposSrc.Length); Contracts.Assert(mat.Size == dst.Size * srcValues.Size); if (iposMin >= iposLim) { dst.ZeroItems(); return; } Contracts.AssertNonEmpty(rgposSrc); unsafe { fixed(float *pdst = &dst.Items[0]) fixed(float *pmat = &mat.Items[0]) fixed(float *psrc = &srcValues.Items[0]) fixed(int *ppossrc = &rgposSrc[0]) { Contracts.Assert(0 <= crun && crun <= dst.Size); Thunk.MatMulP(Ptr(mat, pmat), ppossrc, Ptr(srcValues, psrc), posMin, iposMin, iposLim, Ptr(dst, pdst), crun, srcValues.Size); } } }
public static void MatrixTimesSource(AlignedArray matrix, ReadOnlySpan <int> rgposSrc, AlignedArray sourceValues, int posMin, int iposMin, int iposLimit, AlignedArray destination, int stride) { Contracts.AssertValue(rgposSrc); Contracts.Assert(iposMin >= 0); Contracts.Assert(iposMin <= iposLimit); Contracts.Assert(iposLimit <= rgposSrc.Length); Contracts.Assert(matrix.Size == destination.Size * sourceValues.Size); if (iposMin >= iposLimit) { destination.ZeroItems(); return; } Contracts.AssertNonEmpty(rgposSrc); Contracts.Assert(stride >= 0); if (Avx.IsSupported) { Contracts.Assert(stride <= destination.Size); AvxIntrinsics.MatMulP(matrix, rgposSrc, sourceValues, posMin, iposMin, iposLimit, destination, stride, sourceValues.Size); } else if (Sse.IsSupported) { Contracts.Assert(stride <= destination.Size); SseIntrinsics.MatMulP(matrix, rgposSrc, sourceValues, posMin, iposMin, iposLimit, destination, stride, sourceValues.Size); } else { Contracts.Assert(stride <= destination.Size); for (int i = 0; i < stride; i++) { float dotProduct = 0; for (int j = iposMin; j < iposLimit; j++) { int col = rgposSrc[j] - posMin; dotProduct += matrix[i * sourceValues.Size + col] * sourceValues[col]; } destination[i] = dotProduct; } } }
public static void MatTimesSrc(AlignedArray mat, int[] rgposSrc, AlignedArray srcValues, int posMin, int iposMin, int iposLim, AlignedArray dst, int crun) { Contracts.AssertValue(rgposSrc); Contracts.Assert(iposMin >= 0); Contracts.Assert(iposMin <= iposLim); Contracts.Assert(iposLim <= rgposSrc.Length); Contracts.Assert(mat.Size == dst.Size * srcValues.Size); if (iposMin >= iposLim) { dst.ZeroItems(); return; } Contracts.AssertNonEmpty(rgposSrc); Contracts.Assert(crun >= 0); if (Avx.IsSupported) { Contracts.Assert(crun <= dst.Size); AvxIntrinsics.MatMulP(mat, rgposSrc, srcValues, posMin, iposMin, iposLim, dst, crun, srcValues.Size); } else if (Sse.IsSupported) { Contracts.Assert(crun <= dst.Size); SseIntrinsics.MatMulP(mat, rgposSrc, srcValues, posMin, iposMin, iposLim, dst, crun, srcValues.Size); } else { Contracts.Assert(crun <= dst.Size); for (int i = 0; i < crun; i++) { float dotProduct = 0; for (int j = iposMin; j < iposLim; j++) { int col = rgposSrc[j] - posMin; dotProduct += mat[i * srcValues.Size + col] * srcValues[col]; } dst[i] = dotProduct; } } }
public static void MatTimesSrc(bool tran, bool add, AlignedArray mat, int[] rgposSrc, AlignedArray srcValues, int posMin, int iposMin, int iposLim, AlignedArray dst, int crun) { Contracts.Assert(Compat(mat)); Contracts.Assert(Compat(srcValues)); Contracts.Assert(Compat(dst)); Contracts.AssertValue(rgposSrc); Contracts.Assert(0 <= iposMin && iposMin <= iposLim && iposLim <= rgposSrc.Length); Contracts.Assert(mat.Size == dst.Size * srcValues.Size); if (iposMin >= iposLim) { if (!add) { dst.ZeroItems(); } return; } Contracts.AssertNonEmpty(rgposSrc); unsafe { fixed(float *pdst = &dst.Items[0]) fixed(float *pmat = &mat.Items[0]) fixed(float *psrc = &srcValues.Items[0]) fixed(int *ppossrc = &rgposSrc[0]) { if (!tran) { Contracts.Assert(0 <= crun && crun <= dst.Size); Thunk.MatMulPX(add, Ptr(mat, pmat), ppossrc, Ptr(srcValues, psrc), posMin, iposMin, iposLim, Ptr(dst, pdst), crun, srcValues.Size); } else { Contracts.Assert(0 <= crun && crun <= srcValues.Size); Thunk.MatMulTranPX(add, Ptr(mat, pmat), ppossrc, Ptr(srcValues, psrc), posMin, iposMin, iposLim, Ptr(dst, pdst), dst.Size); } } } }
/// <summary> /// Assign zeros to the vector elements. /// </summary> public void Zero() { _items.ZeroItems(); }