Пример #1
0
 /// <summary>
 ///   Stores a row vector into the given row position of the matrix.
 /// </summary>
 public static T[][] SetRow <T>(this T[][] m, int index, T value)
 {
     index = Matrix.index(index, m.Rows());
     for (int i = 0; i < m[index].Length; i++)
     {
         m[index][i] = value;
     }
     return(m);
 }
Пример #2
0
 /// <summary>
 ///   Stores a column vector into the given column position of the matrix.
 /// </summary>
 public static T[,] SetColumn <T>(this T[,] m, int index, T[] column)
 {
     index = Matrix.index(index, m.Columns());
     for (int i = 0; i < column.Length; i++)
     {
         m[i, index] = column[i];
     }
     return(m);
 }
Пример #3
0
 /// <summary>
 ///   Stores a row vector into the given row position of the matrix.
 /// </summary>
 public static T[][] SetRow <T>(this T[][] m, int index, T[] row)
 {
     index = Matrix.index(index, m.Rows());
     for (int i = 0; i < row.Length; i++)
     {
         m[index][i] = row[i];
     }
     return(m);
 }
Пример #4
0
        /// <summary>
        ///   Stores a column vector into the given column position of the matrix.
        /// </summary>
        public static T[][] SetColumn <T>(this T[][] m, int index, T value)
        {
            index = Matrix.index(index, m.Columns());
            for (int i = 0; i < m.Length; i++)
            {
                m[i][index] = value;
            }

            return(m);
        }
Пример #5
0
        /// <summary>
        ///   Gets a row vector from a matrix.
        /// </summary>
        ///
        public static T[] GetRow <T>(this T[][] m, int index, T[] result = null)
        {
            index = Matrix.index(index, m.Rows());

            if (result == null)
            {
                return((T[])m[index].Clone());
            }
            else
            {
                m[index].CopyTo(result, 0);
                return(result);
            }
        }
Пример #6
0
        /// <summary>
        ///   Gets a column vector from a matrix.
        /// </summary>
        ///
        public static T[] GetColumn <T>(this T[,] m, int index, T[] result = null)
        {
            if (result == null)
            {
                result = new T[m.Rows()];
            }

            index = Matrix.index(index, m.Columns());
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = m[i, index];
            }

            return(result);
        }
Пример #7
0
        /// <summary>
        ///   Returns a value extracted from the current vector.
        /// </summary>
        ///
        public static T Get <T>(this T[] source, int index)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (index >= source.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            index = Matrix.index(index, source.Length);

            return(source[index]);
        }
Пример #8
0
        /// <summary>
        ///   Sets a subvector to the given value.
        /// </summary>
        ///
        /// <param name="destination">The vector to return the subvector from.</param>
        /// <param name="value">The matrix of values to which matrix elements will be set.</param>
        /// <param name="index">The index of the element to be set.</param>
        ///
        public static void Set <T>(this T[] destination, T value, int index)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("source");
            }

            if (index >= destination.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            index = Matrix.index(index, destination.Length);

            destination[index] = value;
        }
Пример #9
0
        private static void set <T>(this
                                    T[,] dst, int[] dstRowIndices, int[] dstColumnIndices,
                                    T[,] src, int[] srcRowIndices, int[] srcColumnIndices)
        {
            if (src == null)
            {
                throw new ArgumentNullException("source");
            }

            if (dst == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (srcRowIndices == null)
            {
                srcRowIndices = Accord.Math.Vector.Range(0, src.Rows());
            }

            if (srcColumnIndices == null)
            {
                srcColumnIndices = Accord.Math.Vector.Range(0, src.Columns());
            }

            if (dstRowIndices == null)
            {
                dstRowIndices = Accord.Math.Vector.Range(0, dst.Rows());
            }
            if (dstColumnIndices == null)
            {
                dstColumnIndices = Accord.Math.Vector.Range(0, dst.Columns());
            }

            for (int i = 0; i < srcRowIndices.Length; i++)
            {
                int si = Matrix.index(srcRowIndices[i], src.Rows());
                int di = Matrix.index(srcRowIndices[i], dst.Rows());

                for (int j = 0; j < srcColumnIndices.Length; j++)
                {
                    int sj = Matrix.index(srcColumnIndices[j], src.Columns());
                    int dj = Matrix.index(dstColumnIndices[j], dst.Columns());
                    dst[di, dj] = src[si, sj];
                }
            }
        }
Пример #10
0
        /// <summary>
        ///   Sets a region of a matrix to the given values.
        /// </summary>
        ///
        /// <param name="destination">The matrix where elements will be set.</param>
        /// <param name="value">The matrix of values to which matrix elements will be set.</param>
        /// <param name="indices">Array of indices.</param>
        ///
        public static void Set <T>(this T[] destination, T value, int[] indices)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("source");
            }

            if (indices == null)
            {
                throw new ArgumentNullException("Indices");
            }

            for (int i = 0; i < indices.Length; i++)
            {
                destination[Matrix.index(indices[i], destination.Length)] = value;
            }
        }
Пример #11
0
        /// <summary>
        ///   Gets a column vector from a matrix.
        /// </summary>
        ///
        public static T[,] GetPlane <T>(this T[,,] m, int index, T[,] result = null)
        {
            int rows  = m.Rows();
            int cols  = m.Columns();
            int depth = m.Depth();

            if (result == null)
            {
                result = new T[rows, cols];
            }

            index = Matrix.index(index, depth);
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    result[i, j] = m[i, j, index];
                }
            }

            return(result);
        }