Search in sources :

Example 1 with VectorView

use of org.apache.ignite.ml.math.primitives.vector.impl.VectorView in project ignite by apache.

the class VectorViewTest method setup.

/**
 */
@Before
public void setup() {
    parentVector = new DenseVector(MathTestConstants.STORAGE_SIZE);
    IntStream.range(0, MathTestConstants.STORAGE_SIZE).forEach(idx -> parentVector.set(idx, Math.random()));
    parentData = parentVector.getStorage().data().clone();
    testVector = new VectorView(parentVector, OFFSET, VIEW_LENGTH);
}
Also used : VectorView(org.apache.ignite.ml.math.primitives.vector.impl.VectorView) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Before(org.junit.Before)

Example 2 with VectorView

use of org.apache.ignite.ml.math.primitives.vector.impl.VectorView in project ignite by apache.

the class VectorViewTest method testWriteReadExternal.

/**
 */
@Test
public void testWriteReadExternal() throws Exception {
    assertNotNull("Unexpected null parent data", parentData);
    File f = new File(EXTERNALIZE_TEST_FILE_NAME);
    try {
        ObjectOutputStream objOutputStream = new ObjectOutputStream(new FileOutputStream(f));
        objOutputStream.writeObject(testVector);
        objOutputStream.close();
        ObjectInputStream objInputStream = new ObjectInputStream(new FileInputStream(f));
        VectorView readVector = (VectorView) objInputStream.readObject();
        objInputStream.close();
        assertTrue(MathTestConstants.VAL_NOT_EQUALS, testVector.equals(readVector));
    } catch (ClassNotFoundException | IOException e) {
        fail(e.getMessage());
    }
}
Also used : VectorView(org.apache.ignite.ml.math.primitives.vector.impl.VectorView) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

VectorView (org.apache.ignite.ml.math.primitives.vector.impl.VectorView)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)1 Before (org.junit.Before)1 Test (org.junit.Test)1