Package net.fec.openrq.util.linearalgebra.matrix

Examples of net.fec.openrq.util.linearalgebra.matrix.ByteMatrix


    @Test
    public void testMultiply_5_0x0_InRangeOf_5_to_5() {

        ByteVector a = factory().createVector(new byte[] {0, 1, 0, 2, 1});
        ByteMatrix b = factory().createMatrix(new byte[][] {});
        ByteVector c = factory().createVector(new byte[] {});

        assertEquals(c, a.multiply(b, 5, 5));
    }
View Full Code Here


    @Test
    public void testMultiply_2_2x4() {

        ByteVector a = factory().createVector(new byte[] {1, 2});

        ByteMatrix b = factory().createMatrix(new byte[][] {
                                                            {0, 5, 0, 6},
                                                            {1, 0, 8, 0}
        });

        ByteVector c = factory().createVector(new byte[] {2, 5, 16, 6});
View Full Code Here

    @Test
    public void testMultiply_3_3x1() {

        ByteVector a = factory().createVector(new byte[] {0, 2, 0});

        ByteMatrix b = factory().createMatrix(new byte[][] {
                                                            {0},
                                                            {3},
                                                            {0},
        });
View Full Code Here

    @Test
    public void testMultiply_5_0x0_InRangeOf_0_to_0() {

        ByteVector a = factory().createVector(new byte[] {0, 1, 0, 2, 1});
        ByteMatrix b = factory().createMatrix(new byte[][] {});
        ByteVector c = factory().createVector(new byte[] {});

        assertEquals(c, a.multiply(b, 0, 0));
    }
View Full Code Here

    @Test
    public void testCreateDiagonalMatrix_3x3() {

        byte diagonal[] = new byte[] {1, 2, 3};
        ByteMatrix a = factory().createDiagonalMatrix(diagonal);

        assertEquals(3, a.rows());
        assertEquals(3, a.columns());

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == j) {
                    assertEquals(diagonal[i], a.get(i, j));
                }
                else {
                    assertEquals(0, a.get(i, j));
                }
            }
        }
    }
View Full Code Here

    public void testLargeMatrix() {

        int i = 1000000;
        int j = 2000000;

        ByteMatrix a = factory().createMatrix(i, j);

        assertEquals(i, a.rows());
        assertEquals(j, a.columns());

        for (int x = 0; x < i; x += 100000) {
            for (int y = 0; y < j; y += 500000) {
                a.set(x, y, aTimesB((byte)x, (byte)y));
            }
        }

        for (int x = 0; x < i; x += 100000) {
            for (int y = 0; y < j; y += 500000) {
                assertEquals(a.get(x, y), aTimesB((byte)x, (byte)y));
            }
        }
    }
View Full Code Here

        int j = 65536;

        // Integer 65536 * 65536 overflows to 0
        assertEquals(0, i * j);

        ByteMatrix a = factory().createMatrix(i, j);

        assertEquals(i, a.rows());
        assertEquals(j, a.columns());

        a.set(0, 0, (byte)42);
        assertEquals(a.get(0, 0), 42);

        a.set(i - 1, j - 1, (byte)7);
        assertEquals(a.get(i - 1, j - 1), 7);

        // Since values and Indices array sizes are align'd with CCSMatrix and
        // CRSMatrix.MINIMUM_SIZE (=32), we need to set more than 32 values.
        for (int row = 0; row < 32; row++) {
            a.set(row, 1, (byte)3);
        }
    }
View Full Code Here

        int j = 7340;

        // Test overflow
        assertTrue(i * j < 0);

        ByteMatrix a = factory().createMatrix(i, j);

        assertEquals(i, a.rows());
        assertEquals(j, a.columns());

        for (int row = 0; row < 32; row++) {
            a.set(row, 1, (byte)3);
        }
    }
View Full Code Here

    @Test
    public void testIdentityMatrixSource() {

        for (Factory factory : FACTORIES) {
            ByteMatrix a = factory.createMatrix(new IdentityMatrixSource(5));

            assertEquals(5, a.rows());
            assertEquals(5, a.columns());

            for (int i = 0; i < a.rows(); i++) {
                for (int j = 0; j < a.columns(); j++) {
                    if (i == j) {
                        assertEquals(a.get(i, j), 1);
                    }
                    else {
                        assertEquals(a.get(i, j), 0);
                    }
                }
            }
        }
    }
View Full Code Here

    public abstract Factory factory();

    @Test
    public void testCreateMatrix() {

        ByteMatrix a = factory().createMatrix();
        ByteMatrix b = factory().createMatrix(5, 5);
        ByteMatrix c = factory().createRandomMatrix(5, 5);
        ByteMatrix d = factory().createSquareMatrix(5);

        assertEquals(0, a.rows());
        assertEquals(0, a.columns());
        assertEquals(5, b.columns());
        assertEquals(5, b.rows());
        assertEquals(5, c.rows());
        assertEquals(5, c.columns());
        assertEquals(5, d.rows());
        assertEquals(5, d.columns());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++)
            {
                assertEquals(0, b.get(i, j));
                assertEquals(0, d.get(i, j));
            }
        }
    }
View Full Code Here

TOP

Related Classes of net.fec.openrq.util.linearalgebra.matrix.ByteMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.