private void MatMulTranAnyDimensionTest(int col, int row) { float[] mat = new float[col * row]; Random rand = new Random(DefaultSeed); for (int i = 0; i < col * row; i++) { mat[i] = rand.Next(0, 10); } float[] src = new float[row]; for (int i = 0; i < row; i++) { src[i] = rand.Next(0, 10); } float[] dst = new float[col]; float[] expected = new float[col]; for (int i = 0; i < dst.Length; i++) { float dotProduct = 0; for (int j = 0; j < row; j++) { dotProduct += mat[j * dst.Length + i] * src[j]; } expected[i] = dotProduct; } CpuMathUtils.MatrixTimesSource(true, mat, src, dst, row); Assert.Equal(expected, dst, _matMulComparer); }
public void MatTimesSrcSparseTest(string mode, string matTest, string srcTest, string dstTest, Dictionary <string, string> environmentVariables) { RemoteExecutor.RemoteInvoke((arg0, arg1, arg2, arg3) => { CheckProperFlag(arg0); AlignedArray mat = _testMatrices[int.Parse(arg1)]; AlignedArray src = _testSrcVectors[int.Parse(arg2)]; AlignedArray dst = _testDstVectors[int.Parse(arg3)]; int[] idx = _testIndexArray; float[] expected = new float[dst.Size]; int limit = (int.Parse(arg2) == 0) ? 4 : 9; for (int i = 0; i < dst.Size; i++) { float dotProduct = 0; for (int j = 0; j < limit; j++) { int col = idx[j]; dotProduct += mat[i * src.Size + col] * src[col]; } expected[i] = dotProduct; } CpuMathUtils.MatrixTimesSource(mat, idx, src, 0, 0, limit, dst, dst.Size); float[] actual = new float[dst.Size]; dst.CopyTo(actual, 0, dst.Size); Assert.Equal(expected, actual, _matMulComparer); return(RemoteExecutor.SuccessExitCode); }, mode, matTest, srcTest, dstTest, new RemoteInvokeOptions(environmentVariables)); }
/// <summary> /// Matrix multiplication: /// dst = mat * src /// </summary> /// <param name="mat">The multiplier matrix</param> /// <param name="src">The source vector</param> /// <param name="dst">The destination vector</param> public static void MatTimesSrc(ICpuFullMatrix mat, ICpuVector src, ICpuVector dst) { bool colMajor = typeof(TMatrix) == typeof(CpuAlignedMatrixCol); AssertCompatible(mat, src, dst); var m = A(mat); CpuMathUtils.MatrixTimesSource(colMajor, m.Items, A(src).Items, A(dst).Items, m.RunCnt); }
public void MatMulTranTest(int matTest, int srcTest, int dstTest, float[] expected) { AlignedArray mat = _testMatrices[matTest]; AlignedArray src = _testSrcVectors[srcTest]; AlignedArray dst = _testDstVectors[dstTest]; CpuMathUtils.MatrixTimesSource(true, mat, src, dst, src.Size); float[] actual = new float[dst.Size]; dst.CopyTo(actual, 0, dst.Size); Assert.Equal(expected, actual, _matMulComparer); }
public void MatMulTest(int matTest, int srcTest, int dstTest, float[] expected) { float[] mat = _testMatrices[matTest]; float[] src = _testSrcVectors[srcTest]; float[] dst = _testDstVectors[dstTest]; CpuMathUtils.MatrixTimesSource(false, mat, src, dst, dst.Length); float[] actual = new float[dst.Length]; Array.Copy(dst, actual, dst.Length); Assert.Equal(expected, actual, _matMulComparer); }
public void MatTimesSrcSparseTest(int matTest, int srcTest, int dstTest, float[] expected) { float[] mat = _testMatrices[matTest]; float[] src = _testSrcVectors[srcTest]; float[] dst = _testDstVectors[dstTest]; int[] idx = _testIndexArray; CpuMathUtils.MatrixTimesSource(mat, idx, src, 0, 0, (srcTest == 0) ? 4 : 9, dst, dst.Length); float[] actual = new float[dst.Length]; Array.Copy(dst, actual, dst.Length); Assert.Equal(expected, actual, _matMulComparer); }
public void MatTimesSrcSparseTest(int matTest, int srcTest, int dstTest, float[] expected) { AlignedArray mat = _testMatrices[matTest]; AlignedArray src = _testSrcVectors[srcTest]; AlignedArray dst = _testDstVectors[dstTest]; int[] idx = _testIndexArray; CpuMathUtils.MatrixTimesSource(mat, idx, src, 0, 0, (srcTest == 0) ? 4 : 9, dst, dst.Size); float[] actual = new float[dst.Size]; dst.CopyTo(actual, 0, dst.Size); Assert.Equal(expected, actual, _matMulComparer); }