Ejemplo n.º 1
0
        /// <summary>
        ///     For axes-formed linq, operator, calculates the partial array shape.
        /// </summary>
        /// <param name="sourceShape"></param>
        /// <param name="axes"></param>
        /// <param name="flattenIndex"></param>
        /// <returns></returns>
        internal static IndexOrRange[] CalculatePartialShape(
            IndexArray sourceShape,
            ReadOnlySpan <int> axes,
            int flattenIndex)
        {
            var len                   = sourceShape.Length;
            var newShape              = CalculateAxesFormedShape(sourceShape, axes);
            var indicesOnThis         = NdArrayImpl.ToShapedIndices(newShape, flattenIndex);
            var indexOrRangesOnSource = new IndexOrRange[len];

            for (int i = 0, j = 0; i < len; ++i)
            {
                if (!axes.Contains(i))
                {
                    indexOrRangesOnSource[i] = new Index(indicesOnThis[j], false);
                    ++j;
                }
                else
                {
                    indexOrRangesOnSource[i] = Range.Whole;
                }
            }

            return(indexOrRangesOnSource);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     [Pure] Gets enumerable object of this.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <NdArray <T> > AsEnumerable(int axis)
        {
            var index = Enumerable
                        .Range(0, Rank)
                        .Select(_ => (IndexOrRange)Range.Whole)
                        .ToArray();

            for (var i = 0; i < Shape[axis]; ++i)
            {
                index[axis] = new IndexOrRange(i);
                yield return(this[index]);
            }
        }