Exemple #1
0
        Tuple <IIndex <a>, VectorConstruction> IIndexBuilder.GetAddressRange <a>(Tuple <IIndex <a>, VectorConstruction> _arg11, RangeRestriction <long> range)
        {
            Tuple <IIndex <a>, VectorConstruction> tuple = _arg11;
            VectorConstruction vectorConstruction1       = tuple.Item2;
            IIndex <a>         index1  = tuple.Item1;
            IIndexBuilder      builder = (IIndexBuilder)this;
            FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > fsharpChoice = range.AsAbsolute(index1.KeyCount);

            if (fsharpChoice is FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice1Of2)
            {
                FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice1Of2 choice1Of2 = (FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice1Of2)fsharpChoice;
                long num1 = choice1Of2.get_Item().Item1;
                if (choice1Of2.get_Item().Item2 < num1)
                {
                    long num2 = choice1Of2.get_Item().Item1;
                    long num3 = choice1Of2.get_Item().Item2;
                    return(new Tuple <IIndex <a>, VectorConstruction>((IIndex <a>) new LinearIndex <a>(ReadOnlyCollection.empty <a>(), builder, FSharpOption <bool> .Some(true)), VectorConstruction.NewEmpty(0L)));
                }
            }
            if (!(fsharpChoice is FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice2Of2))
            {
                FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice1Of2 choice1Of2 = (FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice1Of2)fsharpChoice;
                long startAddress         = choice1Of2.get_Item().Item1;
                long endAddress           = choice1Of2.get_Item().Item2;
                VectorConstruction range1 = VectorConstruction.NewGetRange(vectorConstruction1, RangeRestriction <long> .NewFixed(startAddress, endAddress));
                return(new Tuple <IIndex <a>, VectorConstruction>((IIndex <a>) new LinearRangeIndex <a>(index1, startAddress, endAddress), range1));
            }
            IRangeRestriction <long> indices = ((FSharpChoice <Tuple <long, long>, IRangeRestriction <long> > .Choice2Of2)fsharpChoice).get_Item();
            IEnumerable <a>          @as     = (IEnumerable <a>) new LinearIndex.newKeys <a>(index1, indices, new long(), (IEnumerator <long>)null, 0, default(a));
            IIndex <a> index2 = builder.Create <a>(@as, (FSharpOption <bool>)null);

            LinearIndex.relocations relocations59218 = new LinearIndex.relocations();
            long   lo  = 0;
            long   hi  = index2.KeyCount - 1L;
            object obj = lo > hi ? (object)new LinearIndex.relocations(lo, hi, 1L, (Func <long, Func <long, bool> >) new LinearIndex.relocations()) : (object)new LinearIndex.relocations(lo, hi, 1L, (Func <long, Func <long, bool> >) new LinearIndex.relocations());
            IEnumerable <Tuple <long, long> > tuples = (IEnumerable <Tuple <long, long> >)SeqModule.Zip <long, long>((IEnumerable <M0>)SeqModule.Map <long, long>((Func <M0, M1>)relocations59218, (IEnumerable <M0>)obj), (IEnumerable <M1>)indices);
            VectorConstruction vectorConstruction2   = VectorConstruction.NewRelocate(vectorConstruction1, index2.KeyCount, tuples);

            return(new Tuple <IIndex <a>, VectorConstruction>(index2, vectorConstruction2));
        }
Exemple #2
0
        Tuple <IIndex <TNewKey>, IVector <R> > IIndexBuilder.Aggregate <K, TNewKey, R>(IIndex <K> index, Aggregation <K> aggregation, VectorConstruction vector, Func <Tuple <DataSegmentKind, Tuple <IIndex <K>, VectorConstruction> >, Tuple <TNewKey, R> > selector)
        {
            if (!index.IsOrdered)
            {
                throw new InvalidOperationException("Floating window aggregation and chunking is only supported on ordered indices. Consider sorting the series before calling the operation.");
            }
            IIndexBuilder   indexBuilder1 = (IIndexBuilder)this;
            Aggregation <K> aggregation1  = aggregation;
            IEnumerable <Tuple <DataSegmentKind, long, long> > tuples1;

            switch (aggregation1.get_Tag())
            {
            case 0:
                Aggregation <K> .WindowSize windowSize = (Aggregation <K> .WindowSize)aggregation1;
                tuples1 = Seq.windowRangesWithBounds((long)windowSize.item1, windowSize.item2, index.KeyCount);
                break;

            case 2:
                tuples1 = (IEnumerable <Tuple <DataSegmentKind, long, long> >)SeqModule.Map <Tuple <long, long>, Tuple <DataSegmentKind, long, long> >((Func <M0, M1>) new LinearIndex.locations(), (IEnumerable <M0>)Seq.windowRangesWhile <K>(((Aggregation <K> .WindowWhile)aggregation1).item, (IEnumerable <K>)index.Keys));
                break;

            case 3:
                tuples1 = (IEnumerable <Tuple <DataSegmentKind, long, long> >)SeqModule.Map <Tuple <long, long>, Tuple <DataSegmentKind, long, long> >((Func <M0, M1>) new LinearIndex.locations(), (IEnumerable <M0>)Seq.chunkRangesWhile <K>(((Aggregation <K> .ChunkWhile)aggregation1).item, (IEnumerable <K>)index.Keys));
                break;

            default:
                Aggregation <K> .ChunkSize chunkSize = (Aggregation <K> .ChunkSize)aggregation1;
                tuples1 = Seq.chunkRangesWithBounds((long)chunkSize.item1, chunkSize.item2, index.KeyCount);
                break;
            }
            IEnumerable <Tuple <DataSegmentKind, long, long> > tuples2 = tuples1;
            IEnumerable <Tuple <DataSegmentKind, Tuple <IIndex <K>, VectorConstruction> > > tuples3 = (IEnumerable <Tuple <DataSegmentKind, Tuple <IIndex <K>, VectorConstruction> > >)SeqModule.Map <Tuple <DataSegmentKind, long, long>, Tuple <DataSegmentKind, Tuple <IIndex <K>, VectorConstruction> > >((Func <M0, M1>) new LinearIndex.vectorConstructions <K>(index, vector), (IEnumerable <M0>)tuples2);

            Tuple <TNewKey, R>[] tupleArray1         = (Tuple <TNewKey, R>[])ArrayModule.OfSeq <Tuple <TNewKey, R> >((IEnumerable <M0>)SeqModule.Map <Tuple <DataSegmentKind, Tuple <IIndex <K>, VectorConstruction> >, Tuple <TNewKey, R> >((Func <M0, M1>)selector, (IEnumerable <M0>)tuples3));
            IIndexBuilder        indexBuilder2       = indexBuilder1;
            Func <Tuple <TNewKey, R>, TNewKey> Func1 = (Func <Tuple <TNewKey, R>, TNewKey>) new LinearIndex.newIndex <TNewKey, R>();

            Tuple <TNewKey, R>[] tupleArray2 = tupleArray1;
            if ((object)tupleArray2 == null)
            {
                throw new ArgumentNullException("array");
            }
            TNewKey[]     array         = new TNewKey[tupleArray2.Length];
            IIndexBuilder indexBuilder3 = indexBuilder2;

            for (int index1 = 0; index1 < array.Length; ++index1)
            {
                array[index1] = Func1.Invoke(tupleArray2[index1]);
            }
            IIndex <TNewKey>             index2         = indexBuilder3.Create <TNewKey>(System.Array.AsReadOnly <TNewKey>(array), (FSharpOption <bool>)null);
            IVectorBuilder               vectorBuilder1 = this.vectorBuilder;
            Func <Tuple <TNewKey, R>, R> Func2          = (Func <Tuple <TNewKey, R>, R>) new LinearIndex.vect <TNewKey, R>();

            Tuple <TNewKey, R>[] tupleArray3 = tupleArray1;
            if ((object)tupleArray3 == null)
            {
                throw new ArgumentNullException("array");
            }
            R[]            optionalValueArray = new R[tupleArray3.Length];
            IVectorBuilder vectorBuilder2     = vectorBuilder1;

            for (int index1 = 0; index1 < optionalValueArray.Length; ++index1)
            {
                optionalValueArray[index1] = Func2.Invoke(tupleArray3[index1]);
            }
            IVector <R> missing = vectorBuilder2.CreateMissing <R>(optionalValueArray);

            return(new Tuple <IIndex <TNewKey>, IVector <R> >(index2, missing));
        }
Exemple #3
0
        Tuple <IIndex <TNewKey>, IVector <R> > IIndexBuilder.Resample <K, TNewKey, R>(IIndexBuilder chunkBuilder, IIndex <K> index, IEnumerable <K> keys, Deedle.Direction dir, VectorConstruction vector, Func <Tuple <K, Tuple <IIndex <K>, VectorConstruction> >, Tuple <TNewKey, R> > selector)
        {
            if (!index.IsOrdered)
            {
                throw new InvalidOperationException("Resampling is only supported on ordered indices");
            }
            IIndexBuilder    indexBuilder = (IIndexBuilder)this;
            IEnumerable <M1> m1s;

            if (dir == Deedle.Direction.Forward)
            {
                IEnumerable <Tuple <K, long> > tuples = (IEnumerable <Tuple <K, long> >)SeqModule.Map <K, Tuple <K, long> >((Func <M0, M1>) new LinearIndex.keyLocations <K>(index), keys);
                m1s = SeqModule.MapIndexed <Tuple <Tuple <K, long>, Tuple <K, long> >, Tuple <K, Tuple <long, long> > >((Func <int, Func <M0, M1> >) new LinearIndex.locations <K>(index), (IEnumerable <M0>)SeqModule.Pairwise <Tuple <K, long> >(SeqModule.Append <Tuple <K, long> >((IEnumerable <M0>)tuples, (IEnumerable <M0>)FSharpList <Tuple <K, long> > .Cons(new Tuple <K, long>(default(K), Addressing.LinearAddress.invalid), FSharpList <Tuple <K, long> > .get_Empty()))));
            }
            else
            {
                int keyLen = SeqModule.Length <K>(keys);
                IEnumerable <Tuple <K, long> > tuples = (IEnumerable <Tuple <K, long> >)SeqModule.Map <K, Tuple <K, long> >((Func <M0, M1>) new LinearIndex.keyLocations <K>(index), keys);
                m1s = SeqModule.MapIndexed <Tuple <Tuple <K, long>, Tuple <K, long> >, Tuple <K, Tuple <long, long> > >((Func <int, Func <M0, M1> >) new LinearIndex.locations <K>(index, keyLen), (IEnumerable <M0>)SeqModule.Pairwise <Tuple <K, long> >(SeqModule.Append <Tuple <K, long> >((IEnumerable <M0>)FSharpList <Tuple <K, long> > .Cons(new Tuple <K, long>(default(K), Addressing.LinearAddress.invalid), FSharpList <Tuple <K, long> > .get_Empty()), (IEnumerable <M0>)tuples)));
            }
            Tuple <K, Tuple <long, long> >[] tupleArray1 = (Tuple <K, Tuple <long, long> >[])ArrayModule.OfSeq <Tuple <K, Tuple <long, long> > >((IEnumerable <M0>)m1s);
            Func <Tuple <K, Tuple <long, long> >, Tuple <K, Tuple <IIndex <K>, VectorConstruction> > > Func1 = (Func <Tuple <K, Tuple <long, long> >, Tuple <K, Tuple <IIndex <K>, VectorConstruction> > >) new LinearIndex.vectorConstructions <K>(chunkBuilder, index);

            Tuple <K, Tuple <long, long> >[] tupleArray2 = tupleArray1;
            if ((object)tupleArray2 == null)
            {
                throw new ArgumentNullException("array");
            }
            Tuple <K, Tuple <IIndex <K>, VectorConstruction> >[] tupleArray3 = new Tuple <K, Tuple <IIndex <K>, VectorConstruction> > [tupleArray2.Length];
            for (int index1 = 0; index1 < tupleArray3.Length; ++index1)
            {
                tupleArray3[index1] = Func1.Invoke(tupleArray2[index1]);
            }
            Tuple <K, Tuple <IIndex <K>, VectorConstruction> >[] tupleArray4 = tupleArray3;
            Func <Tuple <K, Tuple <IIndex <K>, VectorConstruction> >, Tuple <TNewKey, R> > Func2 = selector;

            Tuple <K, Tuple <IIndex <K>, VectorConstruction> >[] tupleArray5 = tupleArray4;
            if ((object)tupleArray5 == null)
            {
                throw new ArgumentNullException("array");
            }
            Tuple <TNewKey, R>[] tupleArray6 = new Tuple <TNewKey, R> [tupleArray5.Length];
            for (int index1 = 0; index1 < tupleArray6.Length; ++index1)
            {
                tupleArray6[index1] = Func2.Invoke(tupleArray5[index1]);
            }
            Tuple <TNewKey, R>[]         tupleArray7    = tupleArray6;
            IIndex <TNewKey>             index2         = indexBuilder.Create <TNewKey>(SeqModule.Map <Tuple <TNewKey, R>, TNewKey>((Func <M0, M1>) new LinearIndex.newIndex <TNewKey, R>(), (IEnumerable <M0>)tupleArray7), (FSharpOption <bool>)null);
            IVectorBuilder               vectorBuilder1 = this.vectorBuilder;
            Func <Tuple <TNewKey, R>, R> Func3          = (Func <Tuple <TNewKey, R>, R>) new LinearIndex.vect <TNewKey, R>();

            Tuple <TNewKey, R>[] tupleArray8 = tupleArray7;
            if ((object)tupleArray8 == null)
            {
                throw new ArgumentNullException("array");
            }
            R[]            optionalValueArray = new R[tupleArray8.Length];
            IVectorBuilder vectorBuilder2     = vectorBuilder1;

            for (int index1 = 0; index1 < optionalValueArray.Length; ++index1)
            {
                optionalValueArray[index1] = Func3.Invoke(tupleArray8[index1]);
            }
            IVector <R> missing = vectorBuilder2.CreateMissing <R>(optionalValueArray);

            return(new Tuple <IIndex <TNewKey>, IVector <R> >(index2, missing));
        }
Exemple #4
0
        public static Frame <int, int> FromArray2D <T>(T[,] array)
        {
            IIndexBuilder         instance1   = FIndexBuilderimplementation.IndexBuilder.Instance;
            int                   length1     = array.GetLength(0);
            FSharpFunc <int, int> fsharpFunc1 = (FSharpFunc <int, int>) new FrameExtensions.rowIndex();

            if (length1 < 0)
            {
                throw new ArgumentException(string.Format("{0}\n{1} = {2}", new object[3]
                {
                    (object)LanguagePrimitives.ErrorStrings.get_InputMustBeNonNegativeString(),
                    (object)"count",
                    (object)length1
                }), "count");
            }
            int[]         numArray1     = new int[length1];
            IIndexBuilder indexBuilder1 = instance1;

            for (int index = 0; index < numArray1.Length; ++index)
            {
                numArray1[index] = fsharpFunc1.Invoke(index);
            }
            IIndex <int>          rowIndex    = indexBuilder1.Create <int>((IEnumerable <int>)numArray1, FSharpOption <bool> .Some(true));
            IIndexBuilder         instance2   = FIndexBuilderimplementation.IndexBuilder.Instance;
            int                   length2     = array.GetLength(1);
            FSharpFunc <int, int> fsharpFunc2 = (FSharpFunc <int, int>) new FrameExtensions.colIndex();

            if (length2 < 0)
            {
                throw new ArgumentException(string.Format("{0}\n{1} = {2}", new object[3]
                {
                    (object)LanguagePrimitives.ErrorStrings.get_InputMustBeNonNegativeString(),
                    (object)"count",
                    (object)length2
                }), "count");
            }
            int[]         numArray2     = new int[length2];
            IIndexBuilder indexBuilder2 = instance2;

            for (int index = 0; index < numArray2.Length; ++index)
            {
                numArray2[index] = fsharpFunc2.Invoke(index);
            }
            IIndex <int> columnIndex = indexBuilder2.Create <int>((IEnumerable <int>)numArray2, FSharpOption <bool> .Some(true));

            IVector[] vectorArray = (IVector[])ArrayModule.ZeroCreate <IVector>(array.GetLength(1));
            for (int c = 0; c < vectorArray.Length; ++c)
            {
                int length3 = array.GetLength(0);
                FSharpFunc <int, T> fsharpFunc3 = (FSharpFunc <int, T>) new FrameExtensions.col <T>(array, c);
                if (length3 < 0)
                {
                    throw new ArgumentException(string.Format("{0}\n{1} = {2}", new object[3]
                    {
                        (object)LanguagePrimitives.ErrorStrings.get_InputMustBeNonNegativeString(),
                        (object)"count",
                        (object)length3
                    }), "count");
                }
                T[] objArray1 = new T[length3];
                for (int index = 0; index < objArray1.Length; ++index)
                {
                    objArray1[index] = fsharpFunc3.Invoke(index);
                }
                T[] objArray2 = objArray1;
                vectorArray[c] = (IVector)FVectorBuilderimplementation.VectorBuilder.Instance.Create <T>(objArray2);
            }
            IVector <IVector> data = FVectorBuilderimplementation.VectorBuilder.Instance.Create <IVector>(vectorArray);

            return(new Frame <int, int>(rowIndex, columnIndex, data, FIndexBuilderimplementation.IndexBuilder.Instance, FVectorBuilderimplementation.VectorBuilder.Instance));
        }