-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a21d7ac
commit 6288165
Showing
7 changed files
with
1,249 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
349 changes: 349 additions & 0 deletions
349
src/test/java/org/flag4j/sparse_complex_tensor/ComplexSparseTensorElemBinOpsTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/test/java/org/flag4j/sparse_complex_tensor/CooCTensorGetSetTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.flag4j.sparse_complex_tensor; | ||
|
||
import org.flag4j.arrays.sparse.CooCTensor; | ||
import org.flag4j.complex_numbers.CNumber; | ||
import org.flag4j.core.Shape; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class CooCTensorGetSetTests { | ||
static CooCTensor A; | ||
static Shape aShape; | ||
static CNumber[] aEntries; | ||
static int[][] aIndices; | ||
|
||
static CooCTensor exp; | ||
static Shape expShape; | ||
static CNumber[] expEntries; | ||
static int[][] expIndices; | ||
|
||
|
||
@Test | ||
void cooTensorSetTest() { | ||
aShape = new Shape(3, 4, 5, 1); | ||
aEntries = new CNumber[]{ | ||
new CNumber(1, 2), new CNumber(0.2324, -239.1), | ||
new CNumber(5.1), new CNumber(0, 18.2)}; | ||
aIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
A = new CooCTensor(aShape, aEntries, aIndices); | ||
|
||
// --------------- Sub-case 1 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new CNumber[]{ | ||
new CNumber(1, 2), new CNumber(2.41, -23.23), | ||
new CNumber(5.1), new CNumber(0, 18.2)}; | ||
expIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooCTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(new CNumber(2.41, -23.23), 1, 2, 0, 0)); | ||
|
||
// --------------- Sub-case 2 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new CNumber[]{ | ||
new CNumber(1, 2), new CNumber(0.2324, -239.1), new CNumber(0, -9.2), | ||
new CNumber(5.1), new CNumber(0, 18.2)}; | ||
expIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {1, 2, 4, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooCTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(new CNumber(0, -9.2), 1, 2, 4, 0)); | ||
|
||
// --------------- Sub-case 3 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new CNumber[]{ | ||
new CNumber(0.001), new CNumber(1, 2), new CNumber(0.2324, -239.1), | ||
new CNumber(5.1), new CNumber(0, 18.2)}; | ||
expIndices = new int[][]{{0, 0, 0, 0}, {0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooCTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(0.001, 0, 0, 0, 0)); | ||
|
||
// --------------- Sub-case 4 --------------- | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, -1, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 0, 0, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 1, 2, 5, 0)); | ||
} | ||
|
||
|
||
@Test | ||
void cooTensorGetTest() { | ||
aShape = new Shape(3, 4, 5, 1); | ||
aEntries = new CNumber[]{ | ||
new CNumber(1, 2), new CNumber(0.2324, -239.1), | ||
new CNumber(5.1), new CNumber(0, 18.2)}; | ||
aIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
A = new CooCTensor(aShape, aEntries, aIndices); | ||
|
||
// --------------- Sub-case 1 --------------- | ||
assertEquals(new CNumber(0.2324, -239.1), A.get(1, 2, 0, 0)); | ||
|
||
// --------------- Sub-case 2 --------------- | ||
assertEquals(CNumber.ZERO, A.get(1, 2, 4, 0)); | ||
|
||
// --------------- Sub-case 3 --------------- | ||
assertEquals(CNumber.ZERO, A.get(0, 0, 0, 0)); | ||
|
||
// --------------- Sub-case 4 --------------- | ||
assertEquals(new CNumber(1, 2), A.get(0, 1, 0, 0)); | ||
|
||
// --------------- Sub-case 5 --------------- | ||
assertEquals(new CNumber(5.1), A.get(2, 3, 2, 0)); | ||
|
||
// --------------- Sub-case 6 --------------- | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(-1, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(0, 0, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(1, 2, 5, 0)); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/test/java/org/flag4j/sparse_tensor/CooTensorGetSetTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.flag4j.sparse_tensor; | ||
|
||
import org.flag4j.arrays.sparse.CooTensor; | ||
import org.flag4j.core.Shape; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class CooTensorGetSetTests { | ||
static CooTensor A; | ||
static Shape aShape; | ||
static double[] aEntries; | ||
static int[][] aIndices; | ||
|
||
static CooTensor exp; | ||
static Shape expShape; | ||
static double[] expEntries; | ||
static int[][] expIndices; | ||
|
||
static double expScalar; | ||
|
||
|
||
@Test | ||
void cooTensorSetTest() { | ||
aShape = new Shape(3, 4, 5, 1); | ||
aEntries = new double[]{1, 223.1333, -0.991233, 100.1234}; | ||
aIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
A = new CooTensor(aShape, aEntries, aIndices); | ||
|
||
// --------------- Sub-case 1 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new double[]{1, -451.2, -0.991233, 100.1234}; | ||
expIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(-451.2, 1, 2, 0, 0)); | ||
|
||
// --------------- Sub-case 2 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new double[]{1, 223.1333, 32.1, -0.991233, 100.1234}; | ||
expIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {1, 2, 4, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(32.1, 1, 2, 4, 0)); | ||
|
||
// --------------- Sub-case 3 --------------- | ||
expShape = new Shape(3, 4, 5, 1); | ||
expEntries = new double[]{0.001, 1, 223.1333, -0.991233, 100.1234}; | ||
expIndices = new int[][]{{0, 0, 0, 0}, {0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
exp = new CooTensor(expShape, expEntries, expIndices); | ||
|
||
assertEquals(exp, A.set(0.001, 0, 0, 0, 0)); | ||
|
||
// --------------- Sub-case 4 --------------- | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, -1, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 0, 0, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.set(5, 1, 2, 5, 0)); | ||
} | ||
|
||
|
||
@Test | ||
void cooTensorGetTest() { | ||
aShape = new Shape(3, 4, 5, 1); | ||
aEntries = new double[]{1, 223.1333, -0.991233, 100.1234}; | ||
aIndices = new int[][]{{0, 1, 0, 0}, {1, 2, 0, 0}, {2, 3, 2, 0}, {2, 3, 4, 1}}; | ||
A = new CooTensor(aShape, aEntries, aIndices); | ||
|
||
// --------------- Sub-case 1 --------------- | ||
assertEquals(223.1333, A.get(1, 2, 0, 0)); | ||
|
||
// --------------- Sub-case 2 --------------- | ||
assertEquals(0, A.get(1, 2, 4, 0)); | ||
|
||
// --------------- Sub-case 3 --------------- | ||
assertEquals(0, A.get(0, 0, 0, 0)); | ||
|
||
// --------------- Sub-case 4 --------------- | ||
assertEquals(1, A.get(0, 1, 0, 0)); | ||
|
||
// --------------- Sub-case 5 --------------- | ||
assertEquals(-0.991233, A.get(2, 3, 2, 0)); | ||
|
||
// --------------- Sub-case 6 --------------- | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(-1, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(0, 0, 0, 0, 0)); | ||
assertThrows(IndexOutOfBoundsException.class, () -> A.get(1, 2, 5, 0)); | ||
} | ||
} |
Oops, something went wrong.