예제 #1
0
파일: ReadArray.java 프로젝트: nunb/fastr
 @Override
 public Object execute(
     RArray base, Selector selectorI, Selector selectorJ, boolean drop, int exact)
     throws UnexpectedResultException {
   int[] ndim = base.dimensions();
   int m = ndim[0];
   int n = ndim[1];
   selectorI.start(m, ast);
   selectorJ.start(n, ast);
   int i = selectorI.nextIndex(ast);
   int j = selectorJ.nextIndex(ast);
   assert Utils.check(i != RInt.NA && j != RInt.NA); // ensured by subscript selectors
   int offset = j * m + i;
   if (!(base instanceof RList)) {
     return base.boxedGet(offset);
   } else {
     return ((RList) base).getRAny(offset);
   }
 }
예제 #2
0
파일: ReadArray.java 프로젝트: nunb/fastr
    public Object execute(
        RArray source, Selector selectorI, Selector selectorJ, boolean drop, int exact)
        throws UnexpectedResultException {
      assert Utils.check(subset);
      int[] ndim = source.dimensions();
      int m = ndim[0];
      int n = ndim[1];
      selectorI.start(m, ast);
      selectorJ.start(n, ast);
      int nm = selectorI.size();
      int nn = selectorJ.size();
      boolean mayHaveNA = selectorI.mayHaveNA() || selectorJ.mayHaveNA();
      int nsize = nm * nn;
      if ((nm != 1 && nn != 1) || !drop) {
        ndim = new int[] {nm, nn};
      } else {
        ndim = null;
      }
      RArray res = Utils.createArray(source, nsize, ndim, null, null); // drop attributes
      if (!mayHaveNA) {
        int resoffset = 0;
        for (int nj = 0; nj < nn; nj++) {
          int j = selectorJ.nextIndex(ast);
          int srcoffset = j * m;
          for (int ni = 0; ni < nm; ni++) {
            int i = selectorI.nextIndex(ast);
            Object value =
                source.getRef(
                    srcoffset
                        + i); // FIXME: check overflow? (the same is at many locations, whenever
                              // indexing a matrix)
            res.set(resoffset++, value);
          }
          selectorI.restart();
        }
      } else {
        for (int nj = 0; nj < nn; nj++) {
          int j = selectorJ.nextIndex(ast);
          if (j != RInt.NA) {
            selectorI.restart();
            for (int ni = 0; ni < nm; ni++) {
              int offset = nj * nm + ni;
              int i = selectorI.nextIndex(ast);
              if (i != RInt.NA) {
                Object value;
                value =
                    source.getRef(
                        j * m
                            + i); // FIXME: check overflow? (the same is at many locations, whenever
                                  // indexing a matrix)
                res.set(offset, value);
              } else {
                Utils.setNA(res, offset);
              }
            }
          } else {
            for (int ni = 0; ni < nm; ni++) {
              Utils.setNA(res, nj * nm + ni);
            }
          }
        }
      }

      return res;
    }