Exemplo n.º 1
0
 public static SparseIntArray histogram(int[] vector, int W) {
   final SparseIntArray hist = new SparseIntArray(W);
   for (int i : vector) {
     hist.inc(i);
   }
   return hist;
 }
Exemplo n.º 2
0
 public static SparseIntArray fromBinary(InputStream stream, int W) throws IOException {
   final DataInputStream dis = new DataInputStream(stream);
   final SparseIntArray arr = new SparseIntArray(W);
   while (dis.available() > 0) {
     try {
       arr.inc(dis.readInt());
     } catch (EOFException x) {
       break;
     }
   }
   return arr;
 }
Exemplo n.º 3
0
 public static SparseIntArray fromFrequencyString(String string, int n)
     throws VectorFormatException {
   final String[] entries = string.split("\\s+");
   final SparseIntArray array = new SparseIntArray(n);
   for (String entry : entries) {
     try {
       array.inc(Integer.parseInt(entry));
     } catch (NumberFormatException x) {
       throw new VectorFormatException(x);
     }
   }
   return array;
 }