Ejemplo n.º 1
0
        /// <summary>Creates a copy of the matrix.</summary>
        public FMatrix Clone()
        {
            FMatrix X = new FMatrix(rows, columns);

            //fixed (double* ptrX = X.data, ptrThis = data)
            //{
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    X.data[j + (columns * i)] = data[j + (columns * i)];
                    //(*(ptrX + j + (columns * i))) = (*(ptrThis + j + (columns * i)));
                }
            }
            //}
            return(X);
        }
Ejemplo n.º 2
0
        /// <summary>Returns the transposed matrix.</summary>
        public FMatrix Transpose()
        {
            FMatrix X = new FMatrix(columns, rows);

            //fixed (double* ptrX = X.data, ptrThis = data)
            //{
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    X.data[i + (rows * j)] = data[j + (columns * i)];
                    //		(*(ptrX + j + (columns * i))) = (*(ptrThis + i + (columns * j)));
                }
            }
            //}

            return(X);
        }
Ejemplo n.º 3
0
        /// <summary>Matrix-scalar multiplication.</summary>
        public static FMatrix Multiply(FMatrix left, double right)
        {
            int rows    = left.rows;
            int columns = left.columns;

            FMatrix X = new FMatrix(rows, columns);

            //fixed (double* ptrX = X.data, ptrL = left.data)
            //{
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    X.data[j + (columns * i)] = left.data[j + (columns * i)] * right;
                    //(*(ptrX + j + (columns * i))) = ((*(ptrL + j + (columns * i))) * right);
                }
            }
            //}
            return(X);
        }
Ejemplo n.º 4
0
        /// <summary>Returns a sub matrix extracted from the current matrix.</summary>
        /// <param name="startRow">Start row index</param>
        /// <param name="endRow">End row index</param>
        /// <param name="startColumn">Start column index</param>
        /// <param name="endColumn">End column index</param>
        public FMatrix Submatrix(int startRow, int endRow, int startColumn, int endColumn)
        {
            if ((startRow > endRow) || (startColumn > endColumn) || (startRow < 0) || (startRow >= this.rows) || (endRow < 0) || (endRow >= this.rows) || (startColumn < 0) || (startColumn >= this.columns) || (endColumn < 0) || (endColumn >= this.columns))
            {
                throw new ArgumentException("Argument out of range.");
            }

            FMatrix X = new FMatrix(endRow - startRow + 1, endColumn - startColumn + 1);

            //fixed (double* ptrX = X.data, ptrThis = data)
            //{

            for (int i = startRow; i <= endRow; i++)
            {
                for (int j = startColumn; j <= endColumn; j++)
                {
                    X.data[j + (X.columns * i)] = data[j + (columns * i)];
                    //(*(ptrX + j + (columns * i))) = (*(ptrThis + j + (columns * i)));
                }
            }
            //}

            return(X);
        }
Ejemplo n.º 5
0
        /// <summary>Returns the transposed matrix.</summary>
        public FMatrix Transpose()
        {
            FMatrix X = new FMatrix(columns, rows);
            //fixed (double* ptrX = X.data, ptrThis = data)
            //{
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < columns; j++)
                    {
                        X.data[i + (rows * j)] = data[j + (columns * i)];
                //		(*(ptrX + j + (columns * i))) = (*(ptrThis + i + (columns * j)));
                    }
                }
            //}

            return X;
        }
Ejemplo n.º 6
0
        /// <summary>Returns a sub matrix extracted from the current matrix.</summary>
        /// <param name="startRow">Start row index</param>
        /// <param name="endRow">End row index</param>
        /// <param name="startColumn">Start column index</param>
        /// <param name="endColumn">End column index</param>
        public FMatrix Submatrix(int startRow, int endRow, int startColumn, int endColumn)
        {
            if ((startRow > endRow) || (startColumn > endColumn) || (startRow < 0) || (startRow >= this.rows) || (endRow < 0) || (endRow >= this.rows) || (startColumn < 0) || (startColumn >= this.columns) || (endColumn < 0) || (endColumn >= this.columns))
            {
                throw new ArgumentException("Argument out of range.");
            }

            FMatrix X = new FMatrix(endRow - startRow + 1, endColumn - startColumn + 1);
            //fixed (double* ptrX = X.data, ptrThis = data)
            //{

                for (int i = startRow; i <= endRow; i++)
                {
                    for (int j = startColumn; j <= endColumn; j++)
                    {
                        X.data[j + (X.columns * i)] = data[j + (columns * i)];
                        //(*(ptrX + j + (columns * i))) = (*(ptrThis + j + (columns * i)));
                    }
                }
            //}

            return X;
        }
Ejemplo n.º 7
0
        /// <summary>Creates a copy of the matrix.</summary>
        public FMatrix Clone()
        {
            FMatrix X = new FMatrix(rows, columns);

            //fixed (double* ptrX = X.data, ptrThis = data)
            //{
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    X.data[j + (columns * i)] = data[j + (columns * i)];
                    //(*(ptrX + j + (columns * i))) = (*(ptrThis + j + (columns * i)));
                }
            }
            //}
            return X;
        }
Ejemplo n.º 8
0
        /// <summary>Matrix subtraction.</summary>
        public static FMatrix Subtract(FMatrix left, FMatrix right)
        {
            int rows = left.rows;
            int columns = left.columns;

            if ((rows != right.rows) || (columns != right.columns))
            {
                throw new ArgumentException("Matrix dimension do not match.");
            }

            FMatrix X = new FMatrix(rows, columns);
            //fixed (double* ptrX = X.data, ptrL = left.data, ptrR = right.data)
            //{
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < columns; j++)
                    {
                        X.data[j + (columns * i)] = left.data[j + (columns * i)] - right.data[j + (columns * i)];
                        //(*(ptrX + j + (columns * i))) = (*(ptrL + j + (columns * i))) - (*(ptrR + j + (columns * i)));
                    }
                }
            //}
            return X;
        }
Ejemplo n.º 9
0
        /// <summary>Unary minus.</summary>
        public static FMatrix Negate(FMatrix value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            int rows = value.rows;
            int columns = value.columns;
            FMatrix X = new FMatrix(rows, columns);
            //fixed (double* ptrX = X.data, ptrThis = value.data)
            //{
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < columns; j++)
                    {
                        X.data[j + (columns * i)] = -value.data[j + (columns * i)];
                        //(*(ptrX + j + (columns * i))) = -(*(ptrThis + j + (columns * i)));
                    }
                //}
            }

            return X;
        }
Ejemplo n.º 10
0
        /// <summary>Matrix-matrix multiplication.</summary>
        public static FMatrix Multiply(FMatrix left, FMatrix right)
        {
            if (right.rows != left.columns)
            {
                throw new ArgumentException("Matrix dimensions are not valid.");
            }

            int rows = left.rows;
            int columns = right.columns;
            int size = left.columns;
            FMatrix X = new FMatrix(rows, columns);

            //fixed (double* ptrX = X.data, ptrL = left.data, ptrR = right.data)
            //{
                for (int rl = 0; rl < left.rows; rl++)
                {
                    for (int cr = 0; cr < right.columns; cr++)
                    {
                        double sum = 0;

                        for (int rr = 0; rr < right.rows; rr++)
                        {
                            //sum += (*(ptrL + rr + (columns * rl))) * (*(ptrR + cr + (columns * rr)));
                            sum += left.data[rr + (left.columns * rl)] * right.data[cr + (right.columns * rr)];
                        }
                        X.data[cr + (X.columns * rl)] = sum;
                        //(*(ptrX + cr + (columns * rl))) = sum;
                    }
                //}
            }

            //-----------------------------------------------------

            return X;
        }
Ejemplo n.º 11
0
        /// <summary>Matrix-scalar multiplication.</summary>
        public static FMatrix Multiply(FMatrix left, double right)
        {
            int rows = left.rows;
            int columns = left.columns;

            FMatrix X = new FMatrix(rows, columns);
            //fixed (double* ptrX = X.data, ptrL = left.data)
            //{
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < columns; j++)
                    {
                        X.data[j + (columns * i)] = left.data[j + (columns * i)] * right;
                        //(*(ptrX + j + (columns * i))) = ((*(ptrL + j + (columns * i))) * right);
                    }
                }
            //}
            return X;
        }