use of com.tencent.angel.ml.math.TAbstractVector in project angel by Tencent.
the class DenseDoubleVectorTest method plusSparseDummyVector.
@Test
public void plusSparseDummyVector() throws Exception {
DenseDoubleVector vec = new DenseDoubleVector(5, new double[] { 1, 2, 3, 4, 5 });
TAbstractVector vec_1 = new SparseDummyVector(5);
((SparseDummyVector) vec_1).set(2, 1);
((SparseDummyVector) vec_1).set(4, 1);
vec.plusBy(vec_1);
assertEquals(1.0, vec.get(0));
assertEquals(2.0, vec.get(1));
assertEquals(4.0, vec.get(2));
assertEquals(4.0, vec.get(3));
assertEquals(6.0, vec.get(4));
vec.plusBy(vec_1, 5);
assertEquals(1.0, vec.get(0));
assertEquals(2.0, vec.get(1));
assertEquals(9.0, vec.get(2));
assertEquals(4.0, vec.get(3));
assertEquals(11.0, vec.get(4));
}
use of com.tencent.angel.ml.math.TAbstractVector in project angel by Tencent.
the class DenseFloatVectorTest method dotDenseDoubleVectorTest.
@Test
public void dotDenseDoubleVectorTest() throws Exception {
DenseFloatVector vec_1 = genDenseFloatVector(dim);
TAbstractVector vec_2 = genDenseDoubleVector(dim);
double dot = 0.0;
for (int i = 0; i < dim; i++) dot += vec_1.getValues()[i] * ((DenseDoubleVector) vec_2).getValues()[i];
assertEquals(dot, vec_1.dot(vec_2));
}
use of com.tencent.angel.ml.math.TAbstractVector in project angel by Tencent.
the class DenseFloatVectorTest method dotDenseFloatVectorTest.
@Test
public void dotDenseFloatVectorTest() throws Exception {
DenseFloatVector vec_1 = genDenseFloatVector(dim);
TAbstractVector vec_2 = genDenseFloatVector(dim);
double sum = 0.0f;
for (int i = 0; i < dim; i++) sum += vec_1.getValues()[i] * ((DenseFloatVector) vec_2).getValues()[i];
assertEquals(sum, vec_1.dot(vec_2));
}
use of com.tencent.angel.ml.math.TAbstractVector in project angel by Tencent.
the class DenseIntVectorTest method plusBy.
@Test
public void plusBy() throws Exception {
int dim = 1000;
Random random = new Random();
int[] values_1 = new int[dim];
for (int i = 0; i < dim; i++) values_1[i] = random.nextInt();
DenseIntVector vec_1 = new DenseIntVector(dim, values_1);
int[] values_2 = new int[dim];
for (int i = 0; i < dim; i++) values_2[i] = random.nextInt();
TAbstractVector vec_2 = new DenseIntVector(dim, values_2);
int[] oldValues = new int[dim];
for (int i = 0; i < dim; i++) oldValues[i] = vec_1.get(i);
vec_1.plusBy(vec_2);
for (int i = 0; i < dim; i++) assertEquals(oldValues[i] + values_2[i], vec_1.get(i));
for (int i = 0; i < dim; i++) oldValues[i] = vec_1.get(i);
vec_1.plusBy(vec_2, 3);
for (int i = 0; i < dim; i++) assertEquals(oldValues[i] + 3 * values_2[i], vec_1.get(i));
}
Aggregations