Search in sources :

Example 6 with TAbstractVector

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));
}
Also used : TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) Test(org.junit.Test)

Example 7 with TAbstractVector

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));
}
Also used : TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) Test(org.junit.Test)

Example 8 with TAbstractVector

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));
}
Also used : TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) Test(org.junit.Test)

Example 9 with TAbstractVector

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));
}
Also used : Random(java.util.Random) TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) Test(org.junit.Test)

Aggregations

TAbstractVector (com.tencent.angel.ml.math.TAbstractVector)9 Test (org.junit.Test)9 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)2 Random (java.util.Random)2 MathsTest (com.tencent.angel.ml.utils.MathsTest)1