Merge pull request #4 from Wasabi375/master

Fixed Stride for RealNDArray
This commit is contained in:
Alexander Nozik 2018-05-01 19:03:26 +03:00 committed by GitHub
commit 6e2ad178f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -12,7 +12,7 @@ private class RealNDField(shape: List<Int>) : NDField<Real>(shape, RealField) {
private val strides: List<Int> by lazy { private val strides: List<Int> by lazy {
ArrayList<Int>(shape.size).apply { ArrayList<Int>(shape.size).apply {
var current = 1 var current = 1
add(0) add(1)
shape.forEach { shape.forEach {
current *= it current *= it
add(current) add(current)

View File

@ -18,4 +18,17 @@ class RealNDFieldTest {
val product = array1*array2 val product = array1*array2
assertEquals(0.0, product[2, 2].toDouble(), 0.1) assertEquals(0.0, product[2, 2].toDouble(), 0.1)
} }
@Test
fun testGeneration() {
val array = real2DArray(3, 3) { i, j -> (i * 10 + j).toDouble() }
for(i in 0..2){
for(j in 0..2){
val expected= (i * 10 + j).toDouble()
assertEquals("Error at index [$i, $j]", expected, array[i,j].value)
}
}
}
} }