use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.
the class LabeledUpdateIndexBaseTask method preProcess.
@Override
public void preProcess(TaskContext taskContext) {
try {
Reader<KEYIN, VALUEIN> reader = taskContext.getReader();
while (reader.nextKeyValue()) {
LabeledData out = parse(reader.getCurrentKey(), reader.getCurrentValue());
if (out != null) {
taskDataBlock.put(out);
if (updateIndexEnable) {
TAbstractVector vector = out.getX();
if (vector instanceof SparseDummyVector) {
int[] indexes = ((SparseDummyVector) vector).getIndices();
for (int i = 0; i < indexes.length; i++) {
indexSet.add(indexes[i]);
}
}
}
}
}
taskDataBlock.flush();
} catch (Exception e) {
throw new AngelException("Pre-Process Error.", e);
}
}
use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.
the class DoubleVectorTest method densePlusByDummyTest.
@Test
public void densePlusByDummyTest() {
DenseDoubleVector vector = new DenseDoubleVector(10);
vector.set(1, 1.0);
vector.set(3, 3.0);
vector.set(5, 5.0);
SparseDummyVector dummyVector = new SparseDummyVector(10);
dummyVector.set(1, 1.0);
dummyVector.set(3, 1.0);
vector.plusBy(dummyVector, 1.0);
Assert.assertEquals(2.0, vector.get(1), 0.0);
Assert.assertEquals(4.0, vector.get(3), 0.0);
Assert.assertEquals(5.0, vector.get(5), 0.0);
Assert.assertEquals(0.0, vector.get(7), 0.0);
}
use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.
the class DoubleVectorTest method plusBySparseTest.
@Test
public void plusBySparseTest() {
SparseDoubleVector vector = new SparseDoubleVector(10);
vector.set(1, 1.0);
vector.set(3, 3.0);
vector.set(5, 5.0);
SparseDummyVector dummyVector = new SparseDummyVector(10);
dummyVector.set(1, 1.0);
dummyVector.set(3, 1.0);
vector.plusBy(dummyVector, 1.0);
Assert.assertEquals(2.0, vector.get(1), 0.0);
Assert.assertEquals(4.0, vector.get(3), 0.0);
Assert.assertEquals(5.0, vector.get(5), 0.0);
}
Aggregations