Esempio n. 1
0
        /// <summary>
        /// Computes the transpose of the current matrix.
        /// </summary>
        /// <returns>A matrix that is the transpose of the input matrix.</returns>
        public unsafe MatrixF Transpose()
        {
            var    result  = new MatrixF(this.NumCols, this.NumRows);
            float *pResult = result.Data;
            float *pThis   = this.Data;

            for (int y = 0; y < this.NumRows; y++)
            {
                for (int x = 0; x < this.NumCols; x++)
                {
                    pResult[x * this.NumRows + y] = pThis[y * this.NumCols + x];
                }
            }
            return(result);
        }
Esempio n. 2
0
 public unsafe static MatrixF ReadFromMat(string path)
 {
     using (var reader = new BinaryReader(File.Open(path, FileMode.Open))) {
         if (new string(reader.ReadChars(6)) != "single")
         {
             throw new IOException("The input matrix is not single-precision.");
         }
         var    result  = new MatrixF(reader.ReadInt32(), reader.ReadInt32());
         float *pResult = result.Data;
         for (int i = 0; i < result.TotalSize; i++)
         {
             pResult[i] = reader.ReadSingle();
         }
         return(result);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Computes the product of the current matrix and another matrix.
        /// </summary>
        /// <param name="mat">A matrix by which to multiply the current matrix.</param>
        /// <returns>A matrix that is the product of the input matrix and the other matrix.</returns>
        public unsafe MatrixF Dot(MatrixF mat)
        {
            var    result  = new MatrixF(this.NumRows, mat.NumCols);
            float *pResult = result.Data;
            float *pThis   = this.Data;
            float *pMat    = mat.Data;

            for (int y = 0; y < this.NumRows; y++)
            {
                int i = y * this.NumCols;
                for (int x = 0; x < mat.NumCols; x++)
                {
                    int   j   = x;
                    float sum = 0f;
                    for (int z = 0; z < this.NumCols; z++, j += mat.NumCols)
                    {
                        sum += pThis[i + z] * pMat[j];
                    }
                    pResult[y * mat.NumCols + x] = sum;
                }
            }
            return(result);
        }