use of com.tencent.angel.ml.math.vector.DenseDoubleVector 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.DenseDoubleVector in project angel by Tencent.
the class DoubleVectorTest method densePlusBySparseTest.
@Test
public void densePlusBySparseTest() {
DenseDoubleVector vector = new DenseDoubleVector(10);
vector.set(1, 1.0);
vector.set(3, 3.0);
vector.set(5, 5.0);
SparseDoubleVector sparseDoubleVector = new SparseDoubleVector(10);
sparseDoubleVector.set(1, 1.0);
sparseDoubleVector.set(3, 3.0);
sparseDoubleVector.set(7, 7.0);
vector.plusBy(sparseDoubleVector, 1.0);
Assert.assertEquals(2.0, vector.get(1), 0.0);
Assert.assertEquals(6.0, vector.get(3), 0.0);
Assert.assertEquals(5.0, vector.get(5), 0.0);
Assert.assertEquals(7.0, vector.get(7), 0.0);
}
use of com.tencent.angel.ml.math.vector.DenseDoubleVector in project angel by Tencent.
the class DenseDoubleMatrixTest method plusBy2.
@Test
public void plusBy2() throws Exception {
double[][] value = { { 1.0, 2.0 }, { 3.0, 4.0 } };
DenseDoubleMatrix mat = new DenseDoubleMatrix(2, 2, value);
DenseDoubleVector vec = new DenseDoubleVector(2, new double[] { 1.0, 1.0 });
vec.setRowId(0);
mat.plusBy(vec);
assertEquals(2.0, mat.get(0, 0));
assertEquals(3.0, mat.get(0, 1));
assertEquals(3.0, mat.get(1, 0));
}
use of com.tencent.angel.ml.math.vector.DenseDoubleVector in project angel by Tencent.
the class DenseDoubleMatrixTest method getTDoubleVector.
@Test
public void getTDoubleVector() throws Exception {
double[][] value = { { 1.0, 2.0 }, { 3.0, 4.0 } };
DenseDoubleMatrix mat = new DenseDoubleMatrix(2, 2, value);
TDoubleVector vec = (TDoubleVector) mat.getRow(0);
assertEquals(2, vec.size());
assertEquals(0, vec.getRowId());
assertEquals(1.0, vec.get(0));
assertEquals(2.0, vec.get(1));
DenseDoubleMatrix mat_1 = new DenseDoubleMatrix(2, 2, new double[2][2]);
TDoubleVector vec_1 = new DenseDoubleVector(2, new double[] { 1.0, 2.0 });
vec_1.setRowId(0);
mat_1.plusBy(vec_1);
TDoubleVector vec_2 = (TDoubleVector) mat_1.getRow(0);
assertEquals(1.0, vec_2.get(0));
assertEquals(2.0, vec_2.get(1));
}
use of com.tencent.angel.ml.math.vector.DenseDoubleVector in project angel by Tencent.
the class DenseDoubleMatrix method initVector.
/**
* init the vector by set the value
*
* @param rowIndex
* @param values
* @return
*/
private DenseDoubleVector initVector(int rowIndex, double[] values) {
DenseDoubleVector ret = new DenseDoubleVector((int) col, values);
ret.setMatrixId(matrixId);
ret.setRowId(rowIndex);
return ret;
}
Aggregations