コード例 #1
0
        public Mat(VecCollection collection)
        {
            if (collection == null || collection.Count < 1)
                throw new ArgumentNullException("Collection cannot be null or empty.");

            Size = new MatSize(collection);

            Collection = collection;
        }
コード例 #2
0
        public Mat(int rowCount, int colCount)
        {
            var collection = new VecCollection(colCount);
            for (int i = 0; i < rowCount; i++)
            {
                collection.Add(new Vec(colCount));
            }

            Size = new MatSize(collection);

            Collection = collection;
        }
コード例 #3
0
        public void TestMatCreation()
        {
            // Create 3 x 6 matrix.
            VecCollection collection1 = new VecCollection(6, new Vec[]
            {
                new Vec(6),
                new Vec(6),
                new Vec(6),
            });
            var matArray = new Mat[]
            {
                new Mat(4), // Create 4x4 matrix.
                new Mat(collection1), // Create 3x6 matrix.
                new Mat(2,3) // Create 2x3 matrix.
            };

            Assert.AreEqual(new MatSize(4, 4), matArray[0].Size);
            Assert.AreEqual(new MatSize(3, 6), matArray[1].Size);
            Assert.AreEqual(new MatSize(2, 3), matArray[2].Size);

            matArray[0][0][0] = 5;

            Assert.AreEqual(5, matArray[0][0][0]);
        }
コード例 #4
0
        /// <summary>
        /// Before: ----------- After:<para/>
        /// |1 - 2 - 3 - 4 | ----- |1 - 5 - 9 - 13|<para/>
        /// |5 - 6 - 7 - 8 | ----- |2 - 6 - 10- 14|<para/>
        /// |9 - 10- 11- 12| ---- |3 - 7 - 11- 15|<para/>
        /// |13- 14- 15- 16| ---- |4 - 8 - 12- 16|<para/>
        /// </summary>
        /// <returns></returns>
        public Mat SwapColumnsAndRows()
        {
            var newVecCol = new VecCollection(Size.RowCount,
                new Vec[]
                {
                    new Vec(Size.ColumnCount),
                    new Vec(Size.ColumnCount),
                    new Vec(Size.ColumnCount),
                    new Vec(Size.ColumnCount),
                });

            for (int i = 0; i < Size.RowCount; i++)
            {
                for (int j = 0; j < Size.ColumnCount; j++)
                {
                    newVecCol[j][i] = Collection[i][j];
                }
            }

            return new Mat(newVecCol);
        }
コード例 #5
0
        public static Mat operator -(Mat m1, Mat m2)
        {
            if (m1.Size != m2.Size)
                throw new OverflowException("Can't increment 2 different sized matrices.");

            var resCollection = new VecCollection(m1.Size.ColumnCount);
            for (int i = 0; i < m1.Size.RowCount; i++)
            {
                var vec = new Vec(m1.Size.ColumnCount);
                for (int j = 0; j < m1.Size.ColumnCount; j++)
                {
                    vec[j] = m1[i][j] +- m2[i][j];
                }
                resCollection.Add(vec);
            }

            return new Mat(resCollection);
        }
コード例 #6
0
 public MatSize(VecCollection mat)
 {
     RowCount = mat.Count;
     ColumnCount = mat.LengthVec;
 }