Beispiel #1
0
        public static Array CreateArray <T>(this RegularArrayLongInfo arrayInfo, ICollection <T> coll)
        {
            if (arrayInfo == null)
            {
                throw new ArgumentNullException("arrayInfo");
            }
            if (coll == null)
            {
                throw new ArgumentNullException("coll");
            }
            if (coll.Count != arrayInfo.Length)
            {
                throw new ArgumentException("Invalid collection length", "coll");
            }

            var indices = new long[arrayInfo.Rank];
            var array   = arrayInfo.CreateArray <T>();

            coll.ForEach((t, i) =>
            {
                arrayInfo.CalcDimIndices(i, indices);
                arrayInfo.SetValue(array, t, indices);
            });
            return(array);
        }
Beispiel #2
0
        public static long TransformFlatIndex(this RegularArrayLongInfo arrayInfo, long flatIndex, params LongRange[] ranges)
        {
            arrayInfo.ValidateRanges(ranges);
            long[] dimIndices       = new long[arrayInfo.Rank];
            RegularArrayLongInfo ai = new RegularArrayLongInfo(ranges.Select(r => new ArrayLongDimension(r.Count, r.Index)).ToArray());

            ai.CalcDimIndices(flatIndex, dimIndices);
            return(arrayInfo.CalcFlatIndex(dimIndices));
        }