示例#1
0
        public static IEnumerable <T> Serialize <T>(this IMultiIndexable <T> nddata, IEnumerable <int[]> indexOrder)
        {
            int rank = nddata.Sizes.Size;

            if (rank == 0)
            {
                yield return(nddata.GetElement());
            }
            else
            {
                var dsindex = new DimSpec[rank];
                foreach (var index in indexOrder)
                {
                    if (index == null)
                    {
                        throw new ArgumentException("index enumeration returned null index");
                    }
                    if (index.Length != dsindex.Length)
                    {
                        throw new ArgumentException("index enumeration returned index of wrong rank");
                    }
                    for (int i = 0; i < index.Length; i++)
                    {
                        dsindex[i] = index[i];
                    }
                    yield return(nddata[dsindex].GetElement());
                }
            }
        }
示例#2
0
        private static int GetIndex(DimSpec ds)
        {
            switch (ds.Kind)
            {
            case DimSpec.EKind.Index: return((int)ds);

            case DimSpec.EKind.Range: return(((Range)ds).FirstBound);

            default: throw new NotImplementedException();
            }
        }
示例#3
0
        public override T ElementAt(params int[] indices)
        {
            Contract.Requires <ArgumentNullException>(indices != null, "indices");
            Contract.Requires <ArgumentException>(indices.Length == Rank, "Length of indices must equal the rank.");

            DimSpec[] translatedIndices = new DimSpec[Rank];
            for (int i = 0; i < indices.Length; i++)
            {
                translatedIndices[_newDimensions[i]] = indices[i];
            }
            return(_source[translatedIndices].GetElement());
        }