Example #1
0
 public static RCVector <L> DoAt <L> (RCClosure closure, RCVector <L> left, RCVector <decimal> right)
 {
     L[] result = new L[right.Count];
     for (int i = 0; i < right.Count; ++i)
     {
         if (right[i] < 0)
         {
             int j = (int)(left.Count + right[i]);
             if (j < 0 || j >= left.Count)
             {
                 throw RCException.Range(closure, (long)right[i], left.Count);
             }
             result[i] = left[j];
         }
         else
         {
             int j = (int)right[i];
             if (j < 0 || j >= left.Count)
             {
                 throw RCException.Range(closure, (long)right[i], left.Count);
             }
             result[i] = left[j];
         }
     }
     return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> (result)));
 }
Example #2
0
        protected virtual void DoEach <T> (RCRunner runner,
                                           RCClosure closure,
                                           RCBlock left,
                                           RCVector <T> right)
        {
            if (right.Count == 0)
            {
                runner.Yield(closure, RCBlock.Empty);
                return;
            }
            int i = closure.Index - 2;

            if (i < right.Count)
            {
                RCBlock result = new RCBlock("I", ":", new RCLong(i));
                result = new RCBlock(result,
                                     "R",
                                     ":",
                                     RCVectorBase.FromArray(new RCArray <T> (right[i])));
                left.Eval(runner,
                          new RCClosure(closure, closure.Bot, left, closure.Left, result, 0));
            }
            else
            {
                runner.Yield(closure, closure.Parent.Result);
            }
        }
Example #3
0
 protected RCValue ReorderColumn <T> (RCLong rank, RCVector <T> column) where T : IComparable <T>
 {
     return(RCVectorBase.FromArray(
                VectorMath.MonadicOp <long, T> (rank.Data,
                                                delegate(long r)
     {
         return column[(int)r];
     })));
 }
Example #4
0
        public static RCVector <L> DoWhere <L> (RCVector <L> left, RCVector <bool> right)
        {
            RCArray <L> result = new RCArray <L> ();

            for (int i = 0; i < right.Count; ++i)
            {
                if (right[i])
                {
                    result.Write(left[i]);
                }
            }
            return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> (result)));
        }
Example #5
0
 public static RCVector <L> DoAt <L> (RCClosure closure, RCVector <L> left, RCVector <byte> right)
 {
     L[] result = new L[right.Count];
     for (int i = 0; i < right.Count; ++i)
     {
         int j = right[i];
         if (j < 0 || j >= left.Count)
         {
             throw RCException.Range(closure, right[i], left.Count);
         }
         result[i] = left[j];
     }
     return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> (result)));
 }
Example #6
0
        public static RCValue InvokeSequential(RCClosure closure, string name, RCVectorBase right)
        {
            RCActivator.OverloadKey key = new RCActivator.OverloadKey(name,
                                                                      typeof(object),
                                                                      null,
                                                                      right.ScalarType);
            Overload overload;

            if (!_overloads.TryGetValue(key, out overload))
            {
                throw RCException.Overload(closure, name, right);
            }
            object array = overload.Invoke(right.Array);

            return(RCVectorBase.FromArray(array));
        }
Example #7
0
 public static RCVector <L> DoRange <L> (RCVector <long> left, RCVector <L> right)
 {
     if (left.Count == 0)
     {
         return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> ()));
     }
     else if (left.Count == 1)
     {
         RCArray <L> result = new RCArray <L> ();
         for (int i = (int)left[0]; i < right.Count; ++i)
         {
             result.Write(right[i]);
         }
         return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> (result)));
     }
     else if (left.Count % 2 == 0)
     {
         RCArray <L> result = new RCArray <L> ();
         int         pair   = 0;
         while (pair < left.Count / 2)
         {
             int i = (int)left[2 * pair];
             int j = (int)left[2 * pair + 1];
             while (i <= j)
             {
                 result.Write(right[i]);
                 ++i;
             }
             ++pair;
         }
         return((RCVector <L>)RCVectorBase.FromArray(new RCArray <L> (result)));
     }
     else
     {
         throw new Exception("count of left argument must be 1 or an even number.");
     }
 }