Пример #1
0
        /// <summary>
        /// Computes the product of square metrices X = AB
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="X">The target matrix</param>
        /// <param name="N">The number of columns in B and C</param>
        public static ref Matrix256 <N, double> gemm <N>(Matrix256 <N, double> A, Matrix256 <N, double> B, ref Matrix256 <N, double> X)
            where N : unmanaged, ITypeNat
        {
            var n  = nat32i <N>();
            var ld = n;

            CBLAS.cblas_dgemm(RowMajor, NoTranspose, NoTranspose, n, n, n, 1, ref head(A), ld, ref head(B), ld, 0, ref head(X), ld);
            return(ref X);
        }
Пример #2
0
        /// <summary>
        /// Computes the product of square metrices X = AB
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="X">The target matrix</param>
        /// <param name="N">The number of columns in B and C</param>
        public static ref BlockMatrix <N, double> gemm <N>(BlockMatrix <N, double> A, BlockMatrix <N, double> B, ref BlockMatrix <N, double> X)
            where N : ITypeNat, new()
        {
            var n  = nati <N>();
            var ld = n;

            CBLAS.cblas_dgemm(RowMajor, NoTranspose, NoTranspose, n, n, n, 1, ref head(A), ld, ref head(B), ld, 0, ref head(X), ld);
            return(ref X);
        }
Пример #3
0
Файл: gemv.cs Проект: 0xCM/z0
        /// <summary>
        /// Computes the matrix-vector product y = A*x;
        /// </summary>
        /// <param name="A">A source matrix of dimension MxN</param>
        /// <param name="x">A source vector of length N</param>
        /// <param name="y">A target vector of length M</param>
        /// <typeparam name="M">The row dimension type of A</typeparam>
        /// <typeparam name="N">The column dimension type of A</typeparam>
        public static ref Block256 <M, float> gemv <M, N>(Matrix256 <M, N, float> A, Block256 <N, float> x, ref Block256 <M, float> y)
            where M : unmanaged, ITypeNat
            where N : unmanaged, ITypeNat
        {
            var m   = nat32i <M>();
            var n   = nat32i <N>();
            var lda = n;

            CBLAS.cblas_sgemv(RowMajor, NoTranspose, m, n, alpha: 1f, ref head(A), lda, ref head(x), incX: 1, beta: 0, ref head(y), incY: 1);
            return(ref y);
        }
Пример #4
0
        /// <summary>
        /// Computes the matrix-vector product y = A*x;
        /// </summary>
        /// <param name="A">A source matrix of dimension MxN</param>
        /// <param name="x">A source vector of length N</param>
        /// <param name="y">A target vector of length M</param>
        /// <typeparam name="M">The row dimension type of A</typeparam>
        /// <typeparam name="N">The column dimension type of A</typeparam>
        public static ref BlockVector <M, float> gemv <M, N>(BlockMatrix <M, N, float> A, BlockVector <N, float> x, ref BlockVector <M, float> y)
            where M : ITypeNat, new()
            where N : ITypeNat, new()
        {
            var m   = nati <M>();
            var n   = nati <N>();
            var lda = n;

            CBLAS.cblas_sgemv(RowMajor, NoTranspose, m, n, alpha: 1f, ref head(A), lda, ref head(x), incX: 1, beta: 0, ref head(y), incY: 1);
            return(ref y);
        }
Пример #5
0
        /// <summary>
        /// Populates a target matrix with the product of the operands
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="M">The number of rows in A and C</param>
        /// <param name="N">The number of columns in B and C</param>
        /// <param name="K">The number of columns in A and rows in B</param>
        public static ref BlockMatrix <M, N, double> gemm <M, K, N>(BlockMatrix <M, K, double> A, BlockMatrix <K, N, double> B, ref BlockMatrix <M, N, double> X)
            where M : ITypeNat, new()
            where K : ITypeNat, new()
            where N : ITypeNat, new()
        {
            var m   = nati <M>();
            var k   = nati <K>();
            var n   = nati <N>();
            var lda = k;
            var ldb = n;
            var ldx = n;

            CBLAS.cblas_dgemm(RowMajor, NoTranspose, NoTranspose, m, n, k, 1d, ref head(A), lda, ref head(B), ldb, 0, ref head(X), ldx);
            return(ref X);
        }
Пример #6
0
        /// <summary>
        /// Populates a target matrix with the product of the operands
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="M">The number of rows in A and C</param>
        /// <param name="N">The number of columns in B and C</param>
        /// <param name="K">The number of columns in A and rows in B</param>
        public static ref Matrix256 <M, N, double> gemm <M, K, N>(Matrix256 <M, K, double> A, Matrix256 <K, N, double> B, ref Matrix256 <M, N, double> X)
            where M : unmanaged, ITypeNat
            where K : unmanaged, ITypeNat
            where N : unmanaged, ITypeNat
        {
            var m   = nat32i <M>();
            var k   = nat32i <K>();
            var n   = nat32i <N>();
            var lda = k;
            var ldb = n;
            var ldx = n;

            CBLAS.cblas_dgemm(RowMajor, NoTranspose, NoTranspose, m, n, k, 1d, ref head(A), lda, ref head(B), ldb, 0, ref head(X), ldx);
            return(ref X);
        }
Пример #7
0
        /// <summary>
        /// Allocates a target matrix and populates it with the product of the operands
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="M">The number of rows in A and C</param>
        /// <param name="N">The number of columns in B and C</param>
        /// <param name="K">The number of columns in A and rows in B</param>
        public static Matrix256 <M, N, float> gemm <M, K, N>(Matrix256 <M, K, float> A, Matrix256 <K, N, float> B)
            where M : unmanaged, ITypeNat
            where K : unmanaged, ITypeNat
            where N : unmanaged, ITypeNat
        {
            var m   = nat32i <M>();
            var k   = nat32i <K>();
            var n   = nat32i <N>();
            var lda = k;
            var ldb = n;
            var ldx = n;
            var X   = Matrix.blockalloc <M, N, float>();

            CBLAS.cblas_sgemm(RowMajor, NoTranspose, NoTranspose, m, n, k, 1.0f, ref head(A), lda, ref head(B), ldb, 0, ref head(X), ldx);
            return(X);
        }
Пример #8
0
        /// <summary>
        /// Allocates a target matrix and populates it with the product of the operands
        /// </summary>
        /// <param name="A">The left matrix</param>
        /// <param name="B">The right matrix</param>
        /// <param name="M">The number of rows in A and C</param>
        /// <param name="N">The number of columns in B and C</param>
        /// <param name="K">The number of columns in A and rows in B</param>
        public static BlockMatrix <M, N, float> gemm <M, K, N>(BlockMatrix <M, K, float> A, BlockMatrix <K, N, float> B)
            where M : ITypeNat, new()
            where K : ITypeNat, new()
            where N : ITypeNat, new()
        {
            var m   = nati <M>();
            var k   = nati <K>();
            var n   = nati <N>();
            var lda = k;
            var ldb = n;
            var ldx = n;
            var X   = BlockMatrix.Alloc <M, N, float>();

            CBLAS.cblas_sgemm(RowMajor, NoTranspose, NoTranspose, m, n, k, 1.0f, ref head(A), lda, ref head(B), ldb, 0, ref head(X), ldx);
            return(X);
        }
Пример #9
0
        public static void sasum()
        {
            var silent = true;

            (var method, var msg) = intro(silent);
            var n    = 10;
            var incx = 1;
            var x    = floats(1.0, -2.0, 3.0, 4.0, -5.0, 6.0, -7.0, 8.0, -9.0, 10.0);

            input(x.FormatVector());

            var sw     = stopwatch();
            var result = CBLAS.cblas_sasum(n, ref x[0], incx);
            var time   = snapshot(sw);

            msg += output(result, silent);
            msg += eol();
            msg += conclude(time, silent);
        }
Пример #10
0
Файл: All.cs Проект: 0xCM/z0
        public static void sasum()
        {
            var silent = true;

            (var method, var msg) = intro(silent);
            var          n    = 10;
            var          incx = 1;
            Span <float> x    = new float[] { 1.0f, -2.0f, 3.0f, 4.0f, -5.0f, 6.0f, -7.0f, 8.0f, -9.0f, 10.0f };

            input(x.FormatVector());

            var sw     = Time.stopwatch();
            var result = CBLAS.cblas_sasum(n, ref x[0], incx);
            var ss     = snap(sw);

            msg += output(result, silent);
            msg += Eol;
            msg += conclude(ss, silent);
        }
Пример #11
0
Файл: All.cs Проект: 0xCM/z0
        public static void saxpy()
        {
            (var method, var msg) = intro();
            var          n     = 5;
            var          incx  = 1;
            var          incy  = 1;
            var          alpha = .5f;
            Span <float> x     = new float[] { 1, 2, 3, 4, 5 };
            Span <float> y     = new float[] { .5f, .5f, .5f, .5f, .5f };

            input($"alpha={alpha}, x = {x.FormatVector()}, y = {y.FormatVector()}");

            var sw = Time.stopwatch();

            CBLAS.cblas_saxpy(n, alpha, ref x[0], incx, ref y[0], incy);
            var ss = snap(sw);

            output(y.FormatVector());
            conclude(ss);
        }
Пример #12
0
        public static void saxpy()
        {
            (var method, var msg) = intro();
            var n     = 5;
            var incx  = 1;
            var incy  = 1;
            var alpha = .5f;
            var x     = floats(1, 2, 3, 4, 5);
            var y     = floats(.5, .5, .5, .5, .5);

            input($"alpha={alpha}, x = {x.FormatVector()}, y = {y.FormatVector()}");

            var sw = stopwatch();

            CBLAS.cblas_saxpy(n, alpha, ref x[0], incx, ref y[0], incy);
            var time = snapshot(sw);

            output(y.FormatVector());
            conclude(time);
        }
Пример #13
0
        public static void dzasum()
        {
            var silent = true;

            (var method, var msg) = intro(silent);

            var n    = 4;
            var incx = 1;
            var x    = ComplexF64.Load(doubles(1.2, 2.5, 3.0, 1.7, 4.0, 0.53, -5.5, -0.29));

            msg += input(x.FormatVector(), silent);

            var expect = x.Map(z => Math.Abs(z.re) + Math.Abs(z.im)).Reduce((a, b) => a + b);

            expected(expect);


            var time   = start();
            var result = CBLAS.cblas_dzasum(n, ref x[0], incx);

            output("result", result, snapshot(time));
        }
Пример #14
0
 public static void axpy <N>(float a, BlockVector <N, float> X, BlockVector <N, float> Y, ref BlockVector <N, float> Z)
     where N : ITypeNat, new()
 {
     Y.CopyTo(ref Z);
     CBLAS.cblas_saxpy(nati <N>(), a, ref head(X), 1, ref head(Z), 1);
 }
Пример #15
0
 static double asum(Span <ComplexF64> X)
 => CBLAS.cblas_dzasum(X.Length, ref X[0], 1);
Пример #16
0
 static float asum(Span <ComplexF32> X)
 => CBLAS.cblas_scasum(X.Length, ref X[0], 1);
Пример #17
0
 public static double asum(BlockVector <double> X)
 => CBLAS.cblas_dasum(X.Length, ref head(X), 1);
Пример #18
0
 static double dot(Span <double> X, Span <double> Y)
 => CBLAS.cblas_ddot(length(X, Y), ref head(X), 1, ref head(Y), 1);
Пример #19
0
 static float dot(Span <float> X, Span <float> Y)
 => CBLAS.cblas_sdot(length(X, Y), ref head(X), 1, ref head(Y), 1);
Пример #20
0
 public static void axpy(double a, BlockVector <double> X, BlockVector <double> Y, ref BlockVector <double> Z)
 {
     Y.CopyTo(ref Z);
     CBLAS.cblas_daxpy(length(X, Y), a, ref head(X), 1, ref head(Z), 1);
 }
Пример #21
0
 static float norm(Span <ComplexF32> X)
 => CBLAS.cblas_scnrm2(X.Length, ref head(X), 1);
Пример #22
0
 public static double norm(BlockVector <double> X)
 => CBLAS.cblas_dnrm2(X.Length, ref head(X), 1);
Пример #23
0
 public static float norm(BlockVector <float> X)
 => CBLAS.cblas_snrm2(X.Length, ref head(X), 1);
Пример #24
0
Файл: iamin.cs Проект: 0xCM/z0
 public static int iamin(RowVector256 <double> X)
 => (int)CBLAS.cblas_idamin(X.Length, ref head(X), 1);
Пример #25
0
Файл: iamin.cs Проект: 0xCM/z0
 public static int iamin(RowVector256 <float> X)
 => (int)CBLAS.cblas_isamin(X.Length, ref head(X), 1);
Пример #26
0
 public static void axpy(float a, BlockVector <float> X, BlockVector <float> Y, ref BlockVector <float> Z)
 {
     Y.CopyTo(ref Z);
     CBLAS.cblas_saxpy(length(X, Y), a, ref head(X), 1, ref head(Z), 1);
 }
Пример #27
0
 public static int iamin(BlockVector <float> X)
 => (int)CBLAS.cblas_isamin(X.Length, ref head(X), 1);
Пример #28
0
 static double norm(Span <ComplexF64> X)
 => CBLAS.cblas_dznrm2(X.Length, ref head(X), 1);
Пример #29
0
 public static int iamin(BlockVector <double> X)
 => (int)CBLAS.cblas_idamin(X.Length, ref head(X), 1);
Пример #30
0
Файл: scale.cs Проект: 0xCM/z0
 public static void scale(float a, RowVector256 <float> X)
 => CBLAS.cblas_sscal(X.Length, a, ref head(X), 1);