-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check shapes in arithmetic operations
fixes #59
- Loading branch information
1 parent
e05ec25
commit 91b9aa3
Showing
4 changed files
with
64 additions
and
11 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
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
48 changes: 48 additions & 0 deletions
48
multik-api/src/test/kotlin/org/jetbrains/kotlinx/multik/ndarray/data/InternalsTest.kt
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,48 @@ | ||
package org.jetbrains.kotlinx.multik.ndarray.data | ||
|
||
import org.jetbrains.kotlinx.multik.api.empty | ||
import org.jetbrains.kotlinx.multik.api.mk | ||
import org.jetbrains.kotlinx.multik.api.zeros | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
import kotlin.test.fail | ||
|
||
class InternalsTest { | ||
|
||
@Test | ||
fun `require equal shape throws exception for unequal shape`() { | ||
val left = mk.zeros<Double>(0, 1, 2, 3) | ||
val right = mk.zeros<Double>(0, 1, 2, 4) | ||
expectUnEqualShape(left, right) | ||
} | ||
|
||
@Test | ||
fun `require equal shape throws exception for different no of dim`() { | ||
val left = mk.zeros<Double>(0, 1, 2, 3) | ||
val right = mk.zeros<Double>(0, 1, 2) | ||
expectUnEqualShape(left, right) | ||
} | ||
|
||
@Test | ||
fun `require equal shape succeeds for arrays with equal shapes`() { | ||
val left = mk.zeros<Double>(0, 1, 2, 3) | ||
val right = mk.zeros<Double>(0, 1, 2, 3) | ||
requireEqualShape(left.shape, right.shape) | ||
} | ||
|
||
@Test | ||
fun `require equal shape succeeds empty arrays`() { | ||
val left = mk.zeros<Double>(0) | ||
val right = mk.zeros<Double>(0) | ||
assertTrue(left.isEmpty()) | ||
assertTrue(right.isEmpty()) | ||
requireEqualShape(left.shape, right.shape) | ||
} | ||
|
||
private fun expectUnEqualShape(left: NDArray<Double, *>, right: NDArray<Double, *>) { | ||
try { | ||
requireEqualShape(left.shape, right.shape) | ||
fail("Exception expected") | ||
} catch (e: IllegalArgumentException) { } | ||
} | ||
} |