/// <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);
        }
Exemple #2
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="source"></param>
 /// <param name="slices"> [source.Rank != slices.Length] </param>
 public SliceViewNdArrayImpl(NdArrayImpl <T> source, IndexOrRange[] slices)
     : base(CalculateShape(source.Shape, slices))
 {
     Guard.AssertIndices(source.Shape, slices);
     _source = source;
     _slices = new IndexOrRange[slices.Length];
     Array.Copy(slices, _slices, slices.Length);
 }
Exemple #3
0
        /// <summary>
        ///     Create new NdArray object.
        /// </summary>
        /// <param name="array"></param>
        internal NdArray(Array array)
        {
            var shape = Enumerable
                        .Range(0, array.Rank)
                        .Select(array.GetLength)
                        .ToIndexArray();
            var entity = new RawNdArrayImpl <T>(shape);

            foreach (var(value, i) in array.Cast <T>().Select((x, i) => (x, i)))
            {
                entity.Buffer.Span[i] = value;
            }
            Entity = entity;
        }
Exemple #4
0
 /// <inheritdoc />
 public void Dispose()
 {
     _Entity = null !;
 }
Exemple #5
0
 internal Enumerator(NdArray <T> owner)
 {
     _Entity   = owner.Entity;
     _Position = -1;
 }
Exemple #6
0
 /// <summary></summary>
 /// <param name="shape"></param>
 internal NdArray(IndexArray shape)
 {
     Entity = new RawNdArrayImpl <T>(shape);
 }
Exemple #7
0
 /// <summary>
 ///     Create new NdArray object with entity object.
 /// </summary>
 /// <param name="entity"></param>
 internal NdArray(NdArrayImpl <T> entity)
 {
     Entity = entity;
 }
 internal ReshapeViewNdArrayImpl(NdArrayImpl <T> source, IndexArray shape)
     : base(shape)
 {
     _source = source;
 }