diff --git a/CHANGES b/CHANGES index df9231d..d2ad846 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,16 @@ viktor Changelog Here you can see the full list of changes between each viktor release. +Version 0.1.1 +------------- + +Technical release, released on October 22th, 2015 + +- Updated to Kotlin 1.0.0-beta. +- Renamed '_' to '_I' because the latter isn't a valid identifier as + of Kotlin M14. This is a temporary solution. I hope we'll find + a more human-readable workaround eventually. + Version 0.1.0 ------------- diff --git a/README.md b/README.md index 2f27a27..3c95fc7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Kotlin. Here're some of the higlights: ```kotlin val m = StridedMatrix(4, 3) m[0] = StridedVector.full(3, 42.0) // row-view. - m[_, 0] // column-view. + m[_I, 0] // column-view. m[0] = 42.0 // broadcasting. m + m // arithmetic operations. ``` diff --git a/build.gradle b/build.gradle index 041efca..56462c4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '0.14.+' + ext.kotlin_version = '1.0.0-beta-+' repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index 766f931..d58cf44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ groupId=org.jetbrains.bio -version=0.1.0 +version=0.1.1 diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/MoreMath.kt b/src/main/kotlin/org/jetbrains/bio/viktor/MoreMath.kt index 6324b58..fea6c1f 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/MoreMath.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/MoreMath.kt @@ -9,7 +9,7 @@ import org.apache.commons.math3.util.FastMath * * assuming a >= b. */ -fun Double.logAddExp(b: Double): Double { +infix fun Double.logAddExp(b: Double): Double { val a = this return when { a.isInfinite() && a < 0 -> b diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMagic.kt b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMagic.kt index 92885ee..cf55c01 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMagic.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMagic.kt @@ -1,4 +1,4 @@ package org.jetbrains.bio.viktor /** A special object used to denote *all indices*. */ -public object _ {} \ No newline at end of file +public object _I {} \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix2.kt b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix2.kt index fc0ca09..68ed150 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix2.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix2.kt @@ -27,7 +27,7 @@ open class StridedMatrix2(val rowsNumber: Int, * of memory. This allows to use SIMD operations, e.g. when * computing the sum of elements. */ - protected inline val isDense: Boolean get() { + protected val isDense: Boolean get() { return rowStride == columnsNumber && columnStride == 1 } @@ -80,18 +80,18 @@ open class StridedMatrix2(val rowsNumber: Int, /** * A less-verbose alias to [.columnView]. * - * Use in conjunction with [_], e.g. `m[_, i]`. + * Use in conjunction with [_I], e.g. `m[_I, i]`. */ - operator fun get(any: _, c: Int) = columnView(c) + operator fun get(any: _I, c: Int) = columnView(c) - operator fun set(any: _, c: Int, other: StridedVector) = other.copyTo(columnView(c)) + operator fun set(any: _I, c: Int, other: StridedVector) = other.copyTo(columnView(c)) - operator fun set(any: _, c: Int, init: Double) = columnView(c).fill(init) + operator fun set(any: _I, c: Int, init: Double) = columnView(c).fill(init) - operator fun set(row: Int, any: _, init: Double) = columnView(row).fill(init) + operator fun set(row: Int, any: _I, init: Double) = columnView(row).fill(init) /** A useful shortcut for transposed matrix. */ - inline val T: StridedMatrix2 get() = transpose() + val T: StridedMatrix2 get() = transpose() fun transpose() = StridedMatrix2(columnsNumber, rowsNumber, offset, data, columnStride, rowStride) diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix3.kt b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix3.kt index 296ead4..a207fea 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix3.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/StridedMatrix3.kt @@ -27,7 +27,7 @@ open class StridedMatrix3(val depth: Int, * of memory. This allows to use SIMD operations, e.g. when * computing the sum of elements. */ - protected inline val isDense: Boolean get() { + protected val isDense: Boolean get() { return depthStride == rowsNumber * columnsNumber && rowStride == columnsNumber && columnStride == 1 @@ -72,7 +72,7 @@ open class StridedMatrix3(val depth: Int, require(depthStride == other.depthStride && rowStride == other.rowStride && columnStride == other.columnStride) - System.arraycopy(data, 0, other.data, 0, data.size()) + System.arraycopy(data, 0, other.data, 0, data.size) } fun flatten(): StridedVector { diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/StridedVector.kt b/src/main/kotlin/org/jetbrains/bio/viktor/StridedVector.kt index 3cf4fcb..d0d84df 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/StridedVector.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/StridedVector.kt @@ -10,7 +10,7 @@ import java.util.* /** * Wrap a given array of elements. The array will not be copied. */ -fun DoubleArray.asStrided() = StridedVector.create(this, 0, size(), 1) +fun DoubleArray.asStrided() = StridedVector.create(this, 0, size, 1) /** * Strided floating point containers. @@ -40,9 +40,9 @@ open class StridedVector(protected val data: DoubleArray, * Create a vector with given elements. */ @JvmStatic fun of(first: Double, vararg rest: Double): StridedVector { - val data = DoubleArray(rest.size() + 1) + val data = DoubleArray(rest.size + 1) data[0] = first - System.arraycopy(rest, 0, data, 1, rest.size()) + System.arraycopy(rest, 0, data, 1, rest.size) return data.asStrided() } @@ -65,11 +65,11 @@ open class StridedVector(protected val data: DoubleArray, * TODO: remove this once we get rid of all Java usages. */ @JvmStatic fun wrap(data: DoubleArray): StridedVector { - return create(data, 0, data.size(), 1) + return create(data, 0, data.size, 1) } fun create(data: DoubleArray, offset: Int, size: Int, stride: Int): StridedVector { - require(offset + size <= data.size()) { "not enough data" } + require(offset + size <= data.size) { "not enough data" } return if (stride == 1) { DenseVector.create(data, offset, size) } else { @@ -78,7 +78,7 @@ open class StridedVector(protected val data: DoubleArray, } } - inline val indices: IntRange get() = 0..size() - 1 + val indices: IntRange get() = 0..size() - 1 operator fun get(pos: Int): Double { try { @@ -108,9 +108,9 @@ open class StridedVector(protected val data: DoubleArray, return StridedVector(data, offset + from, to - from, stride) } - operator fun set(any: _, init: Double): Unit = fill(init) + operator fun set(any: _I, init: Double): Unit = fill(init) - operator fun set(any: _, other: StridedVector): Unit = other.copyTo(this) + operator fun set(any: _I, other: StridedVector): Unit = other.copyTo(this) open fun fill(init: Double) { for (pos in 0..size - 1) { @@ -127,7 +127,7 @@ open class StridedVector(protected val data: DoubleArray, } /** A useful shortcut for column-vector. */ - inline val T: StridedMatrix2 get() = transpose() + val T: StridedMatrix2 get() = transpose() fun transpose() = reshape(size, 1) @@ -163,7 +163,7 @@ open class StridedVector(protected val data: DoubleArray, } fun reorder(indices: IntArray) { - require(size == indices.size()) + require(size == indices.size) val copy = indices.clone() for (pos in 0..size - 1) { val value = unsafeGet(pos) @@ -189,7 +189,7 @@ open class StridedVector(protected val data: DoubleArray, } fun dot(other: ShortArray): Double { - require(other.size() == size) { "non-conformable arrays" } + require(other.size == size) { "non-conformable arrays" } var acc = 0.0 for (pos in 0..size - 1) { acc += unsafeGet(pos) * other[pos].toDouble() @@ -199,7 +199,7 @@ open class StridedVector(protected val data: DoubleArray, } fun dot(other: IntArray): Double { - require(other.size() == size) { "non-conformable arrays" } + require(other.size == size) { "non-conformable arrays" } var acc = 0.0 for (pos in 0..size - 1) { acc += unsafeGet(pos) * other[pos].toDouble() @@ -208,8 +208,8 @@ open class StridedVector(protected val data: DoubleArray, return acc } - open fun dot(other: DoubleArray): Double { - require(other.size() == size) { "non-conformable arrays" } + open infix fun dot(other: DoubleArray): Double { + require(other.size == size) { "non-conformable arrays" } var acc = 0.0 for (pos in 0..size - 1) { acc += unsafeGet(pos) * other[pos] @@ -508,16 +508,16 @@ class LargeDenseVector(data: DoubleArray, offset: Int, size: Int) : override fun max() = Core.Max_V64f_S64f(data, offset, size) override fun dot(other: DoubleArray): Double { - require(other.size() == size) { "non-conformable arrays" } + require(other.size == size) { "non-conformable arrays" } return Core.DotProduct_V64fV64f_S64f(data, offset, other, 0, size) } override fun expInPlace() { - info.yeppp.Math.Exp_V64f_V64f(data, 0, data, 0, data.size()) + info.yeppp.Math.Exp_V64f_V64f(data, 0, data, 0, data.size) } override fun logInPlace() { - info.yeppp.Math.Log_V64f_V64f(data, 0, data, 0, data.size()) + info.yeppp.Math.Log_V64f_V64f(data, 0, data, 0, data.size) } override fun logRescale() = SIMDMath.logRescale(data, offset, size) diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/StridedVectorTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/StridedVectorTests.kt index ee943f3..2667b41 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/StridedVectorTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/StridedVectorTests.kt @@ -82,7 +82,7 @@ class StridedVectorTest { copy.sort() for ((i, j) in indices.withIndex()) { - assertEquals(copy[copy.size() - 1 - i], v[j]) + assertEquals(copy[copy.size - 1 - i], v[j]) } } @@ -97,7 +97,7 @@ class StridedVectorTest { Double.NaN, 0.0, Double.NaN, 4.0, Double.NaN, 2.0), - offset = 2, size = values.size(), stride = 2) + offset = 2, size = values.size, stride = 2) v.reorder(indices) assertArrayEquals(doubleArrayOf(-1.0, 0.0, 2.0, 2.0, 4.0, 42.0), v.toArray(), Precision.EPSILON)