コード例 #1
0
        public static Array CreateArray <T>(this RegularArrayInfo 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 int[arrayInfo.Rank];
            var array   = arrayInfo.CreateArray <T>();

            coll.ForEach((t, i) =>
            {
                arrayInfo.CalcDimIndices(i, indices);
                arrayInfo.SetValue(array, t, indices);
            });
            return(array);
        }
コード例 #2
0
        public static int TransformFlatIndex(this RegularArrayInfo arrayInfo, int flatIndex, params Range[] ranges)
        {
            arrayInfo.ValidateRanges(ranges);
            int[]            dimIndices = new int[arrayInfo.Rank];
            RegularArrayInfo ai         = new RegularArrayInfo(ranges.Select(r => new ArrayDimension(r.Count, r.Index)).ToArray());

            ai.CalcDimIndices(flatIndex, dimIndices);
            return(arrayInfo.CalcFlatIndex(dimIndices));
        }
コード例 #3
0
 public static IEnumerable <int> EnumerateFlatIndex(this RegularArrayInfo arrayInfo, params Range[] ranges)
 {
     arrayInfo.ValidateRanges(ranges);
     int[] dimIndices = new int[arrayInfo.Rank];
     for (ArrayIndex ai = new ArrayIndex(new RegularArrayInfo(ranges.Select(r => new ArrayDimension(r.Count, r.Index)).ToArray())); ai.Carry == 0; ai++)
     {
         ai.GetDimIndices(dimIndices);
         yield return(arrayInfo.CalcFlatIndex(dimIndices));
     }
 }
コード例 #4
0
 public static void ValidateRanges(this RegularArrayInfo arrayInfo, params Range[] ranges)
 {
     if (arrayInfo == null)
     {
         throw new ArgumentNullException("arrayInfo");
     }
     if (ranges == null)
     {
         throw new ArgumentNullException("ranges");
     }
     if (ranges.Length != arrayInfo.Rank)
     {
         throw new ArgumentException("Invalid array length", "ranges");
     }
     if (Enumerable.Range(0, ranges.Length)
         .Any(i => ranges[i].Index <arrayInfo.LowerBounds[i] || ranges[i].Index + ranges[i].Count> arrayInfo.LowerBounds[i] + arrayInfo.Lengths[i]))
     {
         throw new ArgumentException("Out of range dimension exists");
     }
     //return new RegularArrayInfo(ranges.Select(r => new ArrayDimension(r.Count, r.Index)).ToArray());
 }