use of water.Value in project h2o-3 by h2oai.
the class SharedTreeMojoWriter method writeModelData.
@Override
protected void writeModelData() throws IOException {
assert model._output._treeKeys.length == model._output._ntrees;
int nclasses = model._output.nclasses();
int ntreesPerClass = model.binomialOpt() && nclasses == 2 ? 1 : nclasses;
writekv("n_trees", model._output._ntrees);
writekv("n_trees_per_class", ntreesPerClass);
for (int i = 0; i < model._output._ntrees; i++) {
for (int j = 0; j < ntreesPerClass; j++) {
Key<CompressedTree> key = model._output._treeKeys[i][j];
Value ctVal = key != null ? DKV.get(key) : null;
if (ctVal == null)
//throw new H2OKeyNotFoundArgumentException("CompressedTree " + key + " not found");
continue;
CompressedTree ct = ctVal.get();
assert ct._nclass == nclasses;
// assume ct._seed is useless and need not be persisted
writeblob(String.format("trees/t%02d_%03d.bin", j, i), ct._bits);
if (model._output._treeKeysAux != null) {
key = model._output._treeKeysAux[i][j];
ctVal = key != null ? DKV.get(key) : null;
if (ctVal != null) {
ct = ctVal.get();
assert ct._nclass == -1;
writeblob(String.format("trees/t%02d_%03d_aux.bin", j, i), ct._bits);
}
}
}
}
}
use of water.Value in project h2o-3 by h2oai.
the class ByteVec method openStream.
/**
* Open a stream view over the underlying data
*/
public InputStream openStream(final Key job_key) {
InputStream is = new InputStream() {
final long[] sz = new long[1];
private int _cidx, _pidx, _sz;
private C1NChunk _c0;
@Override
public int available() {
if (_c0 == null || _sz >= _c0._len) {
sz[0] += _c0 != null ? _c0._len : 0;
if (_cidx >= nChunks())
return 0;
_c0 = chunkForChunkIdx(_cidx++);
_sz = C1NChunk._OFF;
if (job_key != null)
Job.update(_c0._len, job_key);
}
return _c0._len - _sz;
}
@Override
public void close() {
_cidx = nChunks();
_c0 = null;
_sz = 0;
}
@Override
public int read() throws IOException {
return available() == 0 ? -1 : 0xFF & _c0._mem[_sz++];
}
@Override
public int read(byte[] b, int off, int len) {
if (b == null) {
// Back-channel read of cidx
if (_cidx > _pidx) {
// Remove prev chunk from memory
Value v = Value.STORE_get(chunkKey(_pidx++));
if (v != null && v.isPersisted()) {
// Eagerly toss from memory
v.freePOJO();
v.freeMem();
}
// Else not found, or not on disk somewhere
}
return _cidx;
}
int sz = available();
if (sz == 0)
return -1;
len = Math.min(len, sz);
System.arraycopy(_c0._mem, _sz, b, off, len);
_sz += len;
return len;
}
};
try {
is.available();
} catch (IOException e) {
throw new RuntimeException(e);
}
return is;
}
use of water.Value in project h2o-2 by h2oai.
the class SpeeDRFProgressPage method toHTML.
@Override
public boolean toHTML(StringBuilder sb) {
Job jjob = Job.findJob(job_key);
if (jjob == null)
return true;
Value v = DKV.get(jjob.dest());
if (v != null) {
SpeeDRFModel m = v.get();
m.generateHTML("SpeeDRF", sb);
} else
sb.append("<b>No model yet.</b>");
return true;
}
use of water.Value in project h2o-2 by h2oai.
the class PCAProgressPage method toHTML.
@Override
public boolean toHTML(StringBuilder sb) {
Job jjob = Job.findJob(job_key);
if (jjob == null)
return true;
Value v = DKV.get(jjob.dest());
if (v != null) {
PCAModel m = v.get();
m.generateHTML("PCA Model", sb);
} else
sb.append("<b>No model yet.</b>");
return true;
}
use of water.Value in project h2o-2 by h2oai.
the class PutValue method serve.
@Override
public Response serve() {
JsonObject response = new JsonObject();
Key k = Key.make(_key.value()._kb, (byte) (int) _rf.value());
Value v = new Value(k, _value.value().getBytes());
UKV.put(k, v);
response.addProperty(KEY, k.toString());
response.addProperty(REPLICATION_FACTOR, k.desired());
response.addProperty(VALUE_SIZE, v._max);
return Response.done(response);
}
Aggregations