Beispiel #1
0
  private static Dataset ifft1d(final Dataset a, final int n, final int axis) {
    Dataset result = null;
    Dataset dest = null;

    int[] shape;
    PositionIterator pi;
    int[] pos;
    boolean[] hit;

    switch (a.getDtype()) {
      case Dataset.FLOAT32:
      case Dataset.COMPLEX64:
        FloatFFT_1D ffft = new FloatFFT_1D(n);
        float[] fdata = null;
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexFloatDataset(shape);
        dest = new ComplexFloatDataset(new int[] {n});
        fdata = (float[]) dest.getBuffer();
        pi = a.getPositionIterator(axis);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(fdata, 0.f);
          a.copyItemsFromAxes(pos, hit, dest);
          ffft.complexInverse(fdata, true);
          result.setItemsOnAxes(pos, hit, fdata);
        }
        break;
      case Dataset.FLOAT64:
      case Dataset.COMPLEX128:
        DoubleFFT_1D dfft = new DoubleFFT_1D(n);
        double[] ddata = null;
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexDoubleDataset(shape);
        dest = new ComplexDoubleDataset(new int[] {n});
        ddata = (double[]) dest.getBuffer();
        pi = a.getPositionIterator(axis);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(ddata, 0.);
          a.copyItemsFromAxes(pos, hit, dest);
          dfft.complexInverse(ddata, true);
          result.setItemsOnAxes(pos, hit, ddata);
        }
        break;
      default:
        logger.warn("Non-float dataset not yet supported");
        break;
    }

    return result;
  }
Beispiel #2
0
 /**
  * Gives string representation of a sequence, parameterized by how to represent each position
  * (i.e., constructs a string by iterating over all positions of the sequence, concatenating the
  * specified string representation of each position). Iteration is in the natural order for a
  * sequence.
  *
  * @param s sequence to stringify
  * @param pts how to stringify each position
  * @return the string representation of s
  */
 public static String stringfor(InspectableSequence s, PositionToString pts) {
   String toReturn = "[";
   PositionIterator pp = s.positions();
   // first element should have no comma
   if (pp.hasNext()) toReturn += " " + pts.stringfor(pp.nextPosition());
   while (pp.hasNext()) {
     toReturn += ", " + pts.stringfor(pp.nextPosition());
   }
   toReturn += " ]";
   return toReturn;
 }
Beispiel #3
0
  private static Dataset fft3d(final Dataset a, final int[] s, final int[] axes) {
    Dataset result = null;
    Dataset dest = null;

    PositionIterator pi;
    int[] pos;
    boolean[] hit;

    switch (a.getDtype()) {
      case Dataset.FLOAT32:
      case Dataset.COMPLEX64:
        FloatFFT_3D ffft = new FloatFFT_3D(s[0], s[1], s[2]);

        float[] fdata = null;
        result = new ComplexFloatDataset(newShape(a.getShapeRef(), s, axes));
        dest = new ComplexFloatDataset(s);
        fdata = (float[]) dest.getBuffer();
        pi = a.getPositionIterator(axes);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(fdata, 0.f);
          a.copyItemsFromAxes(pos, hit, dest);
          ffft.complexForward(fdata);
          result.setItemsOnAxes(pos, hit, fdata);
        }
        break;
      case Dataset.FLOAT64:
      case Dataset.COMPLEX128:
        DoubleFFT_3D dfft = new DoubleFFT_3D(s[0], s[1], s[2]);

        double[] ddata = null;
        result = new ComplexDoubleDataset(newShape(a.getShapeRef(), s, axes));
        dest = new ComplexDoubleDataset(s);
        ddata = (double[]) dest.getBuffer();
        pi = a.getPositionIterator(axes);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(ddata, 0.);
          a.copyItemsFromAxes(pos, hit, dest);
          dfft.complexForward(ddata);
          result.setItemsOnAxes(pos, hit, ddata);
        }
        break;
      default:
        logger.warn("Non-float dataset not yet supported");
        break;
    }

    return result;
  }
Beispiel #4
0
 /**
  * Recursively dumps a byte representation of a subtree onto a stream. Used by stringfor( InspTree
  * ). Publicly available in case you want to stringify a subtree and really think this way is less
  * work than doing it yourself. You'll want to make sure the "spaces" static variable is
  * initialized first :)
  *
  * @param subtreeRoot root of subtree to represent
  * @param pts way to stringify each position
  * @param ostream stream on which to represent the subtree
  * @param t tree, so children(.) can be called
  * @param indentation number of spaces to indent this level
  * @param indentation_increment amount by which indentation will be increased before writing
  *     children
  */
 public static void writeNodeAndChildren(
     Position subtreeRoot,
     PositionToString pts,
     DataOutputStream ostream,
     InspectableTree t,
     int indentation,
     int indentation_increment) {
   try {
     // indent, then write the subtreeRoot
     ostream.write(spaces, 0, indentation);
     ostream.writeBytes(pts.stringfor(subtreeRoot));
     ostream.writeBytes("\n");
   } catch (java.io.IOException e) {
     System.err.println("\nAn I/O error occurred: " + e);
     return;
   }
   PositionIterator pp = t.children(subtreeRoot);
   // recur on all children
   while (pp.hasNext())
     writeNodeAndChildren(
         pp.nextPosition(),
         pts,
         ostream,
         t,
         indentation + indentation_increment,
         indentation_increment);
 }
  @Override
  public StringDatasetBase sort(Integer axis) {
    if (axis == null) {
      Arrays.sort(data);
    } else {
      axis = checkAxis(axis);

      StringDatasetBase ads = new StringDatasetBase(shape[axis]);
      PositionIterator pi = getPositionIterator(axis);
      int[] pos = pi.getPos();
      boolean[] hit = pi.getOmit();
      while (pi.hasNext()) {
        copyItemsFromAxes(pos, hit, ads);
        Arrays.sort(ads.data);
        setItemsOnAxes(pos, hit, ads.data);
      }
    }

    setDirty();
    return this;
    // throw new UnsupportedOperationException("Cannot sort dataset"); // BOOLEAN_USE
  }