Action_Recognition_2._0.FeatureExtractor2D.Reshape C# (CSharp) Method

Reshape() private method

Takes a 3D Matrix (2D Matrix array) and copies the data into a single dimension vector (double array). Can be specified to copy data row - wise or column -wise from the input Matrix using the second parameter Functions differently from the Matlab version of Reshape in that this version assumes that the input Matrix will be reshaped into a single dimension. This functionality works for our purposes.
private Reshape ( Matrix block, bool rowPacked ) : double[]
block Matrix
rowPacked bool
return double[]
        private double[] Reshape(Matrix[] block, bool rowPacked)
        {
            int xDim = block[0].getColumnDimension();       //x and y dimensions are the same for all items in the block Matrix
            int yDim = block[0].getRowDimension();
            int tDim = block.Length;
            List<double> reshapedBlock = new List<double>(xDim * yDim * tDim);  //initialized to the number of elements in the 3D matrix for optimization

            if (rowPacked)  //builds an array from row packed copy of block
            {
                foreach (var item in block)
                    reshapedBlock.AddRange(item.getRowPackedCopy());
            }
            else            //builds an array from column packed copy of block
            {
                foreach (var item in block)
                    reshapedBlock.AddRange(item.getColumnPackedCopy());
            }

            return reshapedBlock.ToArray();
        }