Exemple #1
0
        public Tensor <Type> DimShuffle(params int[] axesPerm)
        {
            // axes may contain 'x' (120). Hopefuly no tensor will ever have so many dimensions...
            var trans = Transpose <Type> .Create(this, axesPerm.Where(a => a != 'x').ToArray());

            if (axesPerm.Contains('x'))
            {
                var shape = new Dim[axesPerm.Length];
                for (int d = 0; d < axesPerm.Length; ++d)
                {
                    if (axesPerm[d] == 'x')
                    {
                        shape[d] = 1;
                    }
                    else if (axesPerm[d] < 0)
                    {
                        shape[d] = Shape[NDim + axesPerm[d]];
                    }
                    else
                    {
                        shape[d] = Shape[axesPerm[d]];
                    }
                }
                trans = trans.Reshape(shape);
            }

            return(trans);
        }