Пример #1
0
 public static RDouble expandXVector(DoubleImpl xarg, int xsize, int count) {
     int nsize = xsize * count;
     double[] x = xarg.getContent();
     double[] res = new double[nsize];
     int offset = 0;
     for (int rep = 0; rep < count; rep++) {
         System.arraycopy(x, 0, res, offset, xsize);
         offset += xsize;
     }
     return RDouble.RDoubleFactory.getFor(res);
 }
Пример #2
0
    public static RDouble expandYVector(DoubleImpl yarg, int ysize, int count) {
        int size = ysize;
        int nsize = size * count;
        double[] y = yarg.getContent();

        double[] res = new double[nsize];
        int offset = 0;
        for (int elem = 0; elem < size; elem++) {
            double v = y[elem];
            Arrays.fill(res, offset, offset + count, v);
            offset += count;
        }
        return RDouble.RDoubleFactory.getFor(res);
    }
Пример #3
0
    @Override public RNode create(ASTNode call, RSymbol[] names, RNode[] exprs) {
        final ArgumentInfo ia = check(call, names, exprs);
        final int posText = ia.position("text");
        final int posLast = ia.position("last");
        final int posFirst = ia.position("first");
        final RDouble defaultLast = RDouble.RDoubleFactory.getScalar(1000000); // FIXME slow, but perhaps the default is not used, anyway
        return new Builtin(call, names, exprs) {
            @Override public RAny doBuiltIn(Frame frame, RAny[] args) {
                RString text = args[posText].asString();
                warn.naIntroduced = false;
                RDouble first = args[posFirst].asDouble(warn);
                RDouble last;
                last = posLast != -1 ? args[posLast].asDouble(warn) : defaultLast;

                RString res = substring(text, first, last, ast);
                if (warn.naIntroduced) {
                    RContext.warning(ast, RError.NA_INTRODUCED_COERCION);
                }
                return res;
            }
        };
    }