Search in sources :

Example 11 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyMult.

@Test
void polyMult() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    DogArray_I16 inputA = createArbitraryPolynomial(alg.max_value);
    var inputB = new DogArray_I16();
    inputB.resize(2);
    inputB.set(1, 0x03);
    // make sure the order doesn't matter
    var output0 = new DogArray_I16();
    alg.polyMult(inputA, inputB, output0);
    var output1 = new DogArray_I16();
    alg.polyMult(inputB, inputA, output1);
    assertEquals(4, output0.size);
    assertEqualsG(output0, output1);
    // check the value against a manual solution
    DogArray_I16 expected = new DogArray_I16();
    expected.resize(4);
    expected.set(1, alg.multiply(0x121, 0x03));
    expected.set(2, alg.multiply(0x54, 0x03));
    expected.set(3, alg.multiply(0xFFF, 0x03));
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 12 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyScale.

@Test
void polyScale() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    DogArray_I16 input = createArbitraryPolynomial(alg.max_value);
    int scale = 0x45;
    var output = new DogArray_I16();
    alg.polyScale(input.copy(), scale, output);
    assertEquals(input.size, output.size);
    for (int i = 0; i < input.size; i++) {
        int expected = alg.multiply(input.data[i] & 0xFFFF, scale);
        assertEquals(expected, output.data[i] & 0xFFFF);
    }
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 13 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyAdd.

@Test
void polyAdd() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    DogArray_I16 inputA = createArbitraryPolynomial(alg.max_value);
    // Create an arbitrary polynomial: 0xA0*x^3 + 0x45
    var inputB = new DogArray_I16(4);
    inputB.resize(4);
    inputB.set(0, 0xA0);
    inputB.set(3, 0x45);
    // make sure the order doesn't matter
    var output0 = new DogArray_I16();
    alg.polyAdd(inputA, inputB, output0);
    var output1 = new DogArray_I16();
    alg.polyAdd(inputB, inputA, output1);
    assertEquals(4, output0.size);
    assertEqualsG(output0, output1);
    // compare to hand computed solution
    assertEquals(0xA0, output0.data[0] & 0xFFFF);
    assertEquals(0x121, output0.data[1] & 0xFFFF);
    assertEquals(0x54, output0.data[2] & 0xFFFF);
    assertEquals(0xFFF ^ 0x45, output0.data[3] & 0xFFFF);
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 14 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps_U16 method polyEvalContinue.

@Test
void polyEvalContinue() {
    var alg = new GaliosFieldTableOps_U16(12, primitive12);
    DogArray_I16 polyA = new DogArray_I16();
    randomPoly(polyA, 30);
    int x = 0x09;
    int expected = alg.polyEval(polyA, x);
    var polyB = new DogArray_I16(10);
    polyB.resize(10);
    System.arraycopy(polyA.data, 20, polyB.data, 0, 10);
    polyA.size = 20;
    int found = alg.polyEval(polyA, x);
    found = alg.polyEvalContinue(found, polyB, x);
    assertEquals(expected, found);
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) Test(org.junit.jupiter.api.Test)

Example 15 with DogArray_I16

use of org.ddogleg.struct.DogArray_I16 in project BoofCV by lessthanoptimal.

the class TestReedSolomonCodes_U16 method findErrorLocatorPolynomialBM_compareToDirect.

/**
 * Compares the results from BM against an error locator polynomial computed directly given the known
 * error locations
 */
@Test
void findErrorLocatorPolynomialBM_compareToDirect() {
    DogArray_I16 found = new DogArray_I16();
    DogArray_I16 expected = new DogArray_I16();
    for (int generatorBase = 0; generatorBase < 2; generatorBase++) {
        var alg = new ReedSolomonCodes_U16(12, primitive12, generatorBase);
        for (int trial = 0; trial < 30; trial++) {
            int N = 50;
            DogArray_I16 message = randomMessage(0xFFF, N);
            var ecc = new DogArray_I16();
            int nsyn = 10;
            DogArray_I16 syndromes = DogArray_I16.zeros(nsyn);
            alg.generator(nsyn);
            alg.computeECC(message, ecc);
            int where = rand.nextInt(N);
            message.data[where] ^= (short) 0x12;
            alg.computeSyndromes(message, ecc, syndromes);
            var whereList = new DogArray_I32(1);
            whereList.add(where);
            alg.findErrorLocatorPolynomialBM(syndromes, found);
            alg.findErrorLocatorPolynomial(N + ecc.size, whereList, expected);
            assertEquals(expected.size, found.size);
            for (int j = 0; j < found.size; j++) {
                assertEquals(expected.get(j), found.get(j));
            }
        }
    }
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_I16 (org.ddogleg.struct.DogArray_I16)17 Test (org.junit.jupiter.api.Test)13 DogArray_I32 (org.ddogleg.struct.DogArray_I32)3