Exemple #1
0
 public static RDouble stripKeepNames(RDouble v) {
   Names names = v.names();
   if (v.size() == 1 && names == null) {
     return new ScalarDoubleImpl(v.getDouble(0));
   }
   return new DoubleImpl(v, null, names, null);
 }
Exemple #2
0
 public static boolean hasNAorNaN(RDouble d) {
   int size = d.size();
   for (int i = 0; i < size; i++) {
     if (isNAorNaN(d.getDouble(i))) {
       return true;
     }
   }
   return false;
 }
Exemple #3
0
 public static RInt double2int(
     RDouble value, ConversionStatus warn) { // eager to keep error semantics eager
   int size = value.size();
   int[] content = new int[size];
   for (int i = 0; i < size; i++) {
     double d = value.getDouble(i);
     content[i] = Convert.double2int(d, warn);
   }
   return RInt.RIntFactory.getFor(content, value.dimensions(), value.names());
 }
Exemple #4
0
 public static RRaw doubleToRaw(
     RDouble value, ConversionStatus warn) { // eager to keep error semantics eager
   int size = value.size();
   byte[] content = new byte[size];
   for (int i = 0; i < size; i++) {
     double dval = value.getDouble(i);
     content[i] = Convert.double2raw(dval, warn);
   }
   return RRaw.RRawFactory.getFor(content, value.dimensions(), value.names());
 }
Exemple #5
0
    @Override
    public double getDouble(int i) {
      assert Utils.check(i < size, "bounds check");
      assert Utils.check(i >= 0, "bounds check");

      if (i < excludeIndex) {
        return orig.getDouble(i);
      } else {
        return orig.getDouble(i + 1);
      }
    }
Exemple #6
0
 public static RDouble exclude(int excludeIndex, RDouble orig) {
   Names names = orig.names();
   if (names == null) {
     return new RDoubleExclusion(excludeIndex, orig);
   }
   int size = orig.size();
   int nsize = size - 1;
   double[] content = new double[nsize];
   for (int i = 0; i < excludeIndex; i++) {
     content[i] = orig.getDouble(i);
   }
   for (int i = excludeIndex; i < nsize; i++) {
     content[i] = orig.getDouble(i + 1);
   }
   return RDoubleFactory.getFor(content, null, names.exclude(excludeIndex));
 }
Exemple #7
0
    public static double[] copyAsDoubleArray(RDouble d) {
      int size = d.size();
      if (size == 1) {
        return new double[] {d.getDouble(0)};
      } else {
        double[] res = new double[size];

        if (d instanceof DoubleImpl) {
          System.arraycopy(((DoubleImpl) d).getContent(), 0, res, 0, size);
        } else {
          for (int i = 0; i < size; i++) {
            res[i] = d.getDouble(i);
          }
        }
        return res;
      }
    }
Exemple #8
0
 @Override
 public double getDouble(int i) {
   int j = index.getInt(i);
   assert Utils.check(j > 0);
   if (j > vsize) {
     return RDouble.NA;
   } else {
     return value.getDouble(j - 1);
   }
 }
Exemple #9
0
 public static RDouble convertNAandNaNtoZero(RDouble d) {
   if (d instanceof ScalarDoubleImpl) {
     ScalarDoubleImpl sd = (ScalarDoubleImpl) d;
     if (sd.isNAorNaN()) {
       return BOXED_ZERO;
     } else {
       return sd;
     }
   } else {
     RDouble res = d.materialize();
     double[] content = res.getContent();
     for (int i = 0; i < content.length; i++) {
       if (isNAorNaN(content[i])) {
         content[i] = 0;
       }
     }
     return res;
   }
 }
    public static RString substring(RString text, RDouble first, RDouble last, ASTNode ast) {
        int textSize = text.size();
        int firstSize = first.size();
        int lastSize = last.size();
        int textIndex = 0;
        int firstIndex = 0;
        int lastIndex = 0;
        if (textSize == 0) { return RString.EMPTY; }
        if (firstSize == 0) { throw RError.getInvalidArgument(ast, "first"); }// not exactly R-warning        
        if (lastSize == 0) { throw RError.getInvalidArgument(ast, "last"); } // not exactly R-warning        

        int n = Math.max(textSize, Math.max(firstSize, lastSize));

        String[] content = new String[n];
        for (int i = 0; i < n; i++) {
            double nfirst = first.getDouble(firstIndex++);
            if (firstIndex == firstSize) {
                firstIndex = 0;
            }
            double nlast = last.getDouble(lastIndex++);
            if (lastIndex == lastSize) {
                lastIndex = 0;
            }
            String str = text.getString(textIndex++);
            if (textIndex == textSize) {
                textIndex = 0;
            }
            if (!RDouble.RDoubleUtils.isNAorNaN(nfirst) && !RDouble.RDoubleUtils.isNAorNaN(nlast) && str != RString.NA) {
                int stp = (int) nlast;
                int len = str.length();
                if (stp > len) {
                    stp = len;
                }
                content[i] = str.substring(((int) nfirst) - 1, stp);
            } else {
                content[i] = RString.NA;
            }
        }
        return RString.RStringFactory.getFor(content);
    }
Exemple #11
0
 @Override
 public void ref() {
   orig.ref();
 }
Exemple #12
0
 public static RDouble strip(RDouble v) {
   if (v.size() == 1) {
     return new ScalarDoubleImpl(v.getDouble(0));
   }
   return new DoubleImpl(v, true);
 }
Exemple #13
0
 public static RDouble copy(RDouble d) {
   if (d.size() == 1 && d.dimensions() == null && d.names() == null && d.attributes() == null) {
     return new ScalarDoubleImpl(d.getDouble(0));
   }
   return new DoubleImpl(d, false);
 }
Exemple #14
0
 @Override
 public void ref() {
   value.ref();
   index.ref();
 }
Exemple #15
0
 @Override
 public boolean dependsOn(RAny v) {
   return value.dependsOn(v) || index.dependsOn(v);
 }
Exemple #16
0
 @Override
 public boolean isSharedReal() {
   return value.isShared() || index.isShared();
 }
Exemple #17
0
 public RDoubleExclusion(int excludeIndex, RDouble orig) {
   this.orig = orig;
   this.excludeIndex = excludeIndex;
   this.size = orig.size() - 1;
 }
Exemple #18
0
 public RDoubleSubset(RDouble value, RInt index) {
   this.value = value;
   this.index = index;
   this.isize = index.size();
   this.vsize = value.size();
 }
Exemple #19
0
 @Override
 public boolean dependsOn(RAny value) {
   return orig.dependsOn(value);
 }
Exemple #20
0
 @Override
 public boolean isSharedReal() {
   return orig.isShared();
 }