示例#1
0
 /**
  * Suggests a new capacity for this ShortColumn. If the Column implementation supports capacity
  * than the suggestion may be followed. The capacity is it's potential max number of entries. If
  * numEntries > newCapacity then Column may be truncated.
  *
  * @param newCapacity the new capacity
  */
 public void setNumRows(int newCapacity) {
   /*        if (internal != null) {
       long[] newInternal = new long[newCapacity];
       if (newCapacity > internal.length)
           newCapacity = internal.length;
       System.arraycopy(internal, 0, newInternal, 0, newCapacity);
       internal = newInternal;
   }
   else
       internal = new long[newCapacity];
   */
   if (internal != null) {
     long[] newInternal = new long[newCapacity];
     boolean[] newMissing = new boolean[newCapacity];
     boolean[] newEmpty = new boolean[newCapacity];
     if (newCapacity > internal.length) newCapacity = internal.length;
     System.arraycopy(internal, 0, newInternal, 0, newCapacity);
     System.arraycopy(missing, 0, newMissing, 0, missing.length);
     System.arraycopy(empty, 0, newEmpty, 0, empty.length);
     internal = newInternal;
     this.setMissingValues(newMissing);
     empty = newEmpty;
   } else {
     internal = new long[newCapacity];
     missing = new boolean[newCapacity];
     empty = new boolean[newCapacity];
   }
 }
示例#2
0
 /**
  * Given a two d array of doubles, create a table.
  *
  * @param data
  * @return
  */
 public static ExampleTable getTable(
     double[][] data,
     String[] inputNames,
     String[] outputNames,
     int[] inputs,
     int[] outputs,
     int count) {
   Column[] cols = new Column[data.length];
   int index = 0;
   for (int i = 0; i < inputs.length; i++, index++) {
     if (data.length != count) {
       double[] tmp = new double[count];
       System.arraycopy(data[index], 0, tmp, 0, count);
       data[index] = tmp;
     }
     cols[index] = new DoubleColumn(data[index]);
     cols[index].setLabel(inputNames[i]);
   }
   for (int i = 0; i < outputs.length; i++, index++) {
     if (data.length != count) {
       double[] tmp = new double[count];
       System.arraycopy(data[index], 0, tmp, 0, count);
       data[index] = tmp;
     }
     cols[index] = new DoubleColumn(data[index]);
     cols[index].setLabel(outputNames[i]);
   }
   MutableTable mt = new MutableTableImpl(cols);
   ExampleTable et = mt.toExampleTable();
   et.setInputFeatures(inputs);
   et.setOutputFeatures(outputs);
   return et;
 }
示例#3
0
  /**
   * Inserts a new entry in the Column at position pos. All elements from pos to capacity will be
   * moved up one.
   *
   * @param newEntry a Long wrapped long as the newEntry to insert
   * @param pos the position to insert at
   */
  public void insertRow(Object newEntry, int pos) {
    if (pos > getNumRows()) {
      addRow(newEntry);
      return;
    }
    long[] newInternal = new long[internal.length + 1];
    boolean[] newMissing = new boolean[internal.length + 1];
    boolean[] newEmpty = new boolean[internal.length + 1];
    if (pos == 0) {
      System.arraycopy(internal, 0, newInternal, 1, getNumRows());
      System.arraycopy(missing, 0, newMissing, 1, getNumRows());
      System.arraycopy(empty, 0, newEmpty, 1, getNumRows());
    } else {
      System.arraycopy(internal, 0, newInternal, 0, pos);
      System.arraycopy(internal, pos, newInternal, pos + 1, internal.length - pos);
      System.arraycopy(missing, 0, newMissing, 0, pos);
      System.arraycopy(missing, pos, newMissing, pos + 1, internal.length - pos);

      System.arraycopy(empty, 0, newEmpty, 0, pos);
      System.arraycopy(empty, pos, newEmpty, pos + 1, internal.length - pos);
    }
    newInternal[pos] = ((Long) newEntry).longValue();
    internal = newInternal;
    this.setMissingValues(newMissing);
    empty = newEmpty;
  }
示例#4
0
 /**
  * Gets a subset of this Column, given a start position and length. The primitive values are
  * copied, so they have no destructive abilities as far as the Column is concerned.
  *
  * @param pos the start position for the subset
  * @param len the length of the subset
  * @return a subset of this Column
  */
 public Column getSubset(int pos, int len) {
   if ((pos + len) > internal.length) throw new ArrayIndexOutOfBoundsException();
   long[] subset = new long[len];
   boolean[] newMissing = new boolean[len];
   boolean[] newEmpty = new boolean[len];
   System.arraycopy(internal, pos, subset, 0, len);
   System.arraycopy(missing, pos, newMissing, 0, len);
   System.arraycopy(empty, pos, newEmpty, 0, len);
   LongColumn lc = new LongColumn(subset, newMissing, newEmpty, getLabel(), getComment());
   return lc;
 }
示例#5
0
 /**
  * Adds the new entry to the Column after the last non-empty position in the Column.
  *
  * @param newEntry a new entry
  */
 public void addRow(Object newEntry) {
   int last = internal.length;
   long[] newInternal = new long[internal.length + 1];
   boolean[] newMissing = new boolean[internal.length + 1];
   boolean[] newEmpty = new boolean[internal.length + 1];
   System.arraycopy(internal, 0, newInternal, 0, internal.length);
   System.arraycopy(missing, 0, newMissing, 0, missing.length);
   System.arraycopy(empty, 0, newEmpty, 0, empty.length);
   newInternal[last] = ((Long) newEntry).longValue();
   internal = newInternal;
   this.setMissingValues(newMissing);
   empty = newEmpty;
 }
示例#6
0
  /**
   * Add the specified number of blank rows.
   *
   * @param number number of rows to add.
   */
  public void addRows(int number) {
    int last = internal.length;
    long[] newInternal = new long[last + number];
    boolean[] newMissing = new boolean[last + number];
    boolean[] newEmpty = new boolean[last + number];

    System.arraycopy(internal, 0, newInternal, 0, last);
    System.arraycopy(missing, 0, newMissing, 0, missing.length);
    System.arraycopy(empty, 0, newEmpty, 0, empty.length);
    internal = newInternal;
    this.setMissingValues(newMissing);
    empty = newEmpty;
  }
示例#7
0
 /**
  * Removes an entry from the Column, at pos. All entries from pos+1 will be moved back 1 position.
  *
  * @param pos the position to remove
  * @return a Long representation of the removed long
  */
 public Object removeRow(int pos) {
   long removed = internal[pos];
   System.arraycopy(internal, pos + 1, internal, pos, internal.length - (pos + 1));
   System.arraycopy(missing, pos + 1, missing, pos, internal.length - (pos + 1));
   System.arraycopy(empty, pos + 1, empty, pos, internal.length - (pos + 1));
   boolean newMissing[] = new boolean[internal.length - 1];
   boolean newEmpty[] = new boolean[internal.length - 1];
   long newInternal[] = new long[internal.length - 1];
   System.arraycopy(internal, 0, newInternal, 0, internal.length - 1);
   System.arraycopy(missing, 0, newMissing, 0, internal.length - 1);
   System.arraycopy(empty, 0, newEmpty, 0, internal.length - 1);
   internal = newInternal;
   this.setMissingValues(newMissing);
   empty = newEmpty;
   return new Long(removed);
 }