Package water.fvec

Examples of water.fvec.Vec$Writer


   * @param op Element-wise operator encoded as a String.
   * @return new DRM containing A (element-wise) B.
   */
  public static H2ODrm exec(H2ODrm drmA, final double s, final String op) {
    Frame A = drmA.frame;
    Vec keys = drmA.keys;
    int AewScalar_cols = A.numCols();

    // AewScalar is written into ncs[] with an MRTask on A, and therefore will
    // be similarly partitioned as A.
    Frame AewScalar = new MRTask() {
View Full Code Here


   * @param drmB DRM representing matrix B.
   * @return new DRM containing columns of A and B adjacent.
   */
  public static H2ODrm exec(H2ODrm drmA, H2ODrm drmB) {
    Frame fra = drmA.frame;
    Vec keysa = drmA.keys;
    Frame frb = drmB.frame;
    Vec keysb = drmB.keys;

    // If A and B are similarly partitioned, ..
    if (fra.anyVec().group() == frb.anyVec().group()) {
      // .. then, do a light weight zip()
      return zip(fra, keysa, frb, keysb);
View Full Code Here

  }

  /** Light weight zip(), no data movement */
  private static H2ODrm zip(final Frame fra, final Vec keysa, final Frame frb, final Vec keysb) {
    // Create a new Vec[] to hold the concatenated list of A and B's column vectors
    Vec vecs[] = new Vec[fra.vecs().length + frb.vecs().length];
    int d = 0;
    // fill A's column vectors
    for (Vec vfra : fra.vecs()) {
      vecs[d++] = vfra;
    }
View Full Code Here

  }

  /** Heavy weight join(), involves moving data */
  private static H2ODrm join(final Frame fra, final Vec keysa, final Frame frb, final Vec keysb) {
    // The plan is to re-organize B to be "similarly partitioned as A", and then zip()
    Vec bvecs[] = new Vec[frb.vecs().length];

    for (int i = 0; i < bvecs.length; i++) {
      // First create column Vecs which are similarly partitioned as A
      bvecs[i] = fra.anyVec().makeZero();
    }

    // Next run an MRTask on the new vectors, and fill each cell (initially 0)
    // by pulling in appropriate values from B (frb)
    new MRTask() {
      public void map(Chunk chks[]) {
        int chunkSize = chks[0].len();
        long start = chks[0].start();
        Vec vecs[] = frb.vecs();

        for (int r = 0; r < chunkSize; r++) {
          for (int c = 0; c < chks.length; c++) {
            // assert va.atStr(start+r) == vb.atStr(start+r)
            chks[c].set0(r, vecs[c].at(start + r));
View Full Code Here

   * @param exact Hint of exact number of partitions to parallelize, if not -1.
   * @return new DRM holding the same data but parallelized according to new hints.
   */
  public static H2ODrm exec(H2ODrm drmA, int min, int exact) {
    final Frame frin = drmA.frame;
    final Vec vin = drmA.keys;

    // First create a new empty Frame with the required partitioning
    Frame frout = H2OHelper.emptyFrame(frin.numRows(), frin.numCols(), min, exact);
    Vec vout = null;

    if (vin != null) {
      // If String keyed, then run an MRTask on the new frame, and also
      // creat yet another 1-column newer frame for the re-orged String keys.
      // The new String Vec will therefore be similarly partitioned as the
      // new Frame.
      //
      // vout is finally collected by calling anyVec() on outputFrame(),
      // as it is the only column in the output frame.
      vout = new MRTask() {
          public void map(Chunk chks[], NewChunk nc) {
            int chunkSize = chks[0].len();
            Vec vins[] = frin.vecs();
            long start = chks[0].start();
            ValueString vstr = new ValueString();

            for (int r = 0; r < chunkSize; r++) {
              for (int c = 0; c < chks.length; c++) {
                chks[c].set0(r, vins[c].at(start + r));
              }
              nc.addStr(vin.atStr(vstr, start + r));
            }
          }
        }.doAll(1, frout).outputFrame(null, null).anyVec();
    } else {
      // If not String keyed, then run and MRTask on the new frame, and
      // just pull in right elements from frin
      new MRTask() {
        public void map(Chunk chks[]) {
          int chunkSize = chks[0].len();
          Vec vins[] = frin.vecs();
          long start = chks[0].start();

          for (int r = 0; r < chunkSize; r++) {
            for (int c = 0; c < chks.length; c++) {
              chks[c].set0(r, vins[c].at(start + r));
View Full Code Here

    // pulling in the appropriate value from A.
    new MRTask() {
      public void map(Chunk chks[]) {
        int chunkSize = chks[0].len();
        long start = chks[0].start();
        Vec A_vecs[] = A.vecs();

        for (int c = 0; c < chks.length; c++) {
          for (int r = 0; r < chunkSize; r++) {
            chks[c].set0(r, A_vecs[(int)(start + r)].at(c));
          }
View Full Code Here

   * @param drm DRM object to create Matrix from.
   * @return created Matrix.
   */
  public static Matrix matrixFromDrm(H2ODrm drm) {
    Frame frame = drm.frame;
    Vec labels = drm.keys;
    Matrix m;

    if (isSparse(frame)) {
      m = new SparseMatrix((int)frame.numRows(), frame.numCols());
    } else {
      m = new DenseMatrix((int)frame.numRows(), frame.numCols());
    }

    int c = 0;
    // Fill matrix, column at a time.
    for (Vec v : frame.vecs()) {
      for (int r = 0; r < frame.numRows(); r++) {
        double d = 0.0;
        if (!v.isNA(r) && ((d = v.at(r)) != 0.0)) {
          m.setQuick(r, c, d);
        }
      }
      c++;
    }

    // If string keyed, set the stings as rowlabels.
    if (labels != null) {
      HashMap<String,Integer> map = new HashMap<String,Integer>();
      ValueString vstr = new ValueString();
      for (long i = 0; i < labels.length(); i++) {
        map.put(labels.atStr(vstr, i).toString(), (int)i);
      }
      m.setRowLabelBindings(map);
    }
    return m;
  }
View Full Code Here

   * @return Created H2O backed DRM.
   */
  public static H2ODrm drmFromMatrix(Matrix m, int minHint, int exactHint) {
    // First create an empty (0-filled) frame of the required dimensions
    Frame frame = emptyFrame(m.rowSize(), m.columnSize(), minHint, exactHint);
    Vec labels = null;
    Vec.Writer writers[] = new Vec.Writer[m.columnSize()];
    Futures closer = new Futures();

    // "open" vectors for writing efficiently in bulk
    for (int i = 0; i < writers.length; i++) {
      writers[i] = frame.vecs()[i].open();
    }

    for (int r = 0; r < m.rowSize(); r++) {
      for (int c = 0; c < m.columnSize(); c++) {
        writers[c].set(r, m.getQuick(r, c));
      }
    }

    for (int c = 0; c < m.columnSize(); c++) {
      writers[c].close(closer);
    }

    // If string labeled matrix, create aux Vec
    Map<String,Integer> map = m.getRowLabelBindings();
    if (map != null) {
      // label vector must be similarly partitioned like the Frame
      labels = frame.anyVec().makeZero();
      Vec.Writer writer = labels.open();
      Map<Integer,String> rmap = reverseMap(map);

      for (long r = 0; r < m.rowSize(); r++) {
        writer.set(r, rmap.get(r));
      }
View Full Code Here

   * @param drmB DRM representing matrix B
   * @return new DRM containing AB'
   */
  public static H2ODrm exec(H2ODrm drmA, H2ODrm drmB) {
    Frame A = drmA.frame;
    Vec keys = drmA.keys;
    final Frame B = drmB.frame;
    int ABt_cols = (int)B.numRows();

    // ABt is written into ncs[] with an MRTask on A, and therefore will
    // be similarly partitioned as A.
    //
    // chks.length == A.numCols() (== B.numCols())
    // ncs.length == ABt_cols (B.numRows())
    Frame ABt = new MRTask() {
        public void map(Chunk chks[], NewChunk ncs[]) {
          int chunkSize = chks[0].len();
          Vec B_vecs[] = B.vecs();

          for (int c = 0; c < ncs.length; c++) {
            for (int r = 0; r < chunkSize; r++) {
              double v = 0;
              for (int i = 0; i < chks.length; i++) {
View Full Code Here

    new MRTask() {
      public void map(Chunk chks[]) {
        int chunkSize = chks[0].len();
        long start = chks[0].start();
        long A_rows = A.numRows();
        Vec A_vecs[] = A.vecs();
        Vec B_vecs[] = B.vecs();

        for (int c = 0; c < chks.length; c++) {
          for (int r = 0; r < chunkSize; r++) {
            double v = 0;
            for (long i = 0; i < A_rows; i++) {
View Full Code Here

TOP

Related Classes of water.fvec.Vec$Writer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.