Exemplo n.º 1
0
 @Override
 public StringDatasetBase getView() {
   StringDatasetBase view = new StringDatasetBase();
   copyToView(this, view, true, true);
   view.setData();
   return view;
 }
Exemplo n.º 2
0
  @Override
  public StringDatasetBase getSlice(final SliceIterator siter) {
    StringDatasetBase result = new StringDatasetBase(siter.getShape());
    String[] rdata = result.data; // PRIM_TYPE

    for (int i = 0; siter.hasNext(); i++) rdata[i] = data[siter.index];

    result.setName(
        name
            + BLOCK_OPEN
            + Slice.createString(siter.shape, siter.start, siter.stop, siter.step)
            + BLOCK_CLOSE);
    return result;
  }
Exemplo n.º 3
0
  @Override
  public boolean equals(Object obj) {
    if (!super.equals(obj)) {
      return false;
    }

    if (getRank() == 0) // already true for zero-rank dataset
    return true;

    StringDatasetBase other = (StringDatasetBase) obj;
    IndexIterator iter = getIterator();
    IndexIterator oiter = other.getIterator();
    while (iter.hasNext() && oiter.hasNext()) {
      if (!data[iter.index].equals(other.data[oiter.index])) // OBJECT_UNEQUAL
      return false;
    }
    return true;
  }
Exemplo n.º 4
0
  /**
   * Copy a dataset
   *
   * @param dataset
   */
  public StringDatasetBase(final StringDatasetBase dataset) {
    copyToView(dataset, this, true, true);

    try {
      if (dataset.stride == null) {
        odata = data = dataset.data.clone();
      } else {
        offset = 0;
        stride = null;
        base = null;
        odata = data = createArray(size);

        IndexIterator iter = dataset.getIterator();
        for (int i = 0; iter.hasNext(); i++) {
          data[i] = dataset.data[iter.index];
        }
      }
    } catch (Throwable t) {
      logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
      throw t;
    }
  }
Exemplo n.º 5
0
  /**
   * Create a dataset from an object which could be a Java list, array (of arrays...) or Number.
   * Ragged sequences or arrays are padded with zeros.
   *
   * @param obj
   * @return dataset with contents given by input
   */
  public static StringDatasetBase createFromObject(final Object obj) {
    StringDatasetBase result = new StringDatasetBase();

    result.shape = getShapeFromObject(obj);
    result.size = calcSize(result.shape);

    try {
      result.odata = result.data = createArray(result.size);
    } catch (Throwable t) {
      logger.error("Could not create a dataset of shape {}", Arrays.toString(result.shape), t);
      throw t;
    }

    int[] pos = new int[result.shape.length];
    result.fillData(obj, 0, pos);
    return result;
  }