Ejemplo n.º 1
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));
     }
 }
Ejemplo n.º 2
0
 public void SetFrom(ArrayIndex arrayIndex)
 {
     if (arrayIndex == null)
     {
         throw new ArgumentNullException("arrayIndex");
     }
     else if (arrayIndex._arrayInfo != _arrayInfo || arrayIndex._zeroBased != _zeroBased)
     {
         throw new ArgumentException("Diffrenarray specifications", "arrayIndex");
     }
     //
     _carry     = 0;
     _flatIndex = arrayIndex._flatIndex;
     arrayIndex._dimIndices.CopyTo(_dimIndices, 0);
 }
Ejemplo n.º 3
0
        public static void GetDimIndices(this ArrayIndex arrayIndex, int[][] dimIndices)
        {
            if (arrayIndex == null)
            {
                throw new NullReferenceException("arrayIndex");
            }
            JaggedArrayInfo arrayInfo = arrayIndex.ArrayInfo as JaggedArrayInfo;

            if (arrayInfo == null)
            {
                throw new InvalidOperationException("Indexearray is nojagged");
            }
            //
            if (dimIndices == null)
            {
                throw new ArgumentNullException("dimIndices");
            }
            else if (dimIndices.Length != arrayInfo.Depths)
            {
                throw new ArgumentException(ArrayResources.Default.Strings[ArrayMessage.InvalidArrayLength], "dimIndices");
            }
            else
            {
                for (int i = 0; i < arrayInfo.Depths; i++)
                {
                    if (dimIndices[i] == null)
                    {
                        throw new ArgumentRegularArrayElementException("dimIndices", "Value is null", i);
                    }
                    else if (dimIndices[i].Length != arrayInfo.GetRank(i))
                    {
                        throw new ArgumentRegularArrayElementException("dimIndices", ArrayResources.Default.Strings[ArrayMessage.InvalidArrayLength], i);
                    }
                }
            }
            //
            for (int i = 0, j = 0; i < arrayInfo.Depths; j += arrayInfo.GetRank(i), i++)
            {
                for (int k = 0; k < arrayInfo.GetRank(i); k++)
                {
                    dimIndices[i][k] = arrayIndex.GetDimIndex(j + k);
                }
            }
        }