From 53b604886afcaa112e3220591e7674aaabaf8eff Mon Sep 17 00:00:00 2001 From: dievsky Date: Fri, 8 Oct 2021 16:43:21 +0200 Subject: [PATCH] Deprecated size, added length Also changed internal usages. See #37 --- .../org/jetbrains/bio/viktor/F64Array.kt | 28 +++++--- .../jetbrains/bio/viktor/F64DenseFlatArray.kt | 70 +++++++++---------- .../org/jetbrains/bio/viktor/F64FlatArray.kt | 62 ++++++++-------- .../kotlin/org/jetbrains/bio/viktor/Random.kt | 14 ++-- .../org/jetbrains/bio/viktor/Searching.kt | 2 +- .../org/jetbrains/bio/viktor/Sorting.kt | 8 +-- .../jetbrains/bio/viktor/BalancedSumTests.kt | 8 +-- .../bio/viktor/F64ArrayCreationTest.kt | 2 +- .../bio/viktor/F64ArrayGetSetTests.kt | 14 ++-- .../jetbrains/bio/viktor/F64ArrayOpsTests.kt | 4 +- .../bio/viktor/F64ArraySlicingTest.kt | 10 +-- .../org/jetbrains/bio/viktor/RandomTests.kt | 4 +- .../org/jetbrains/bio/viktor/SortingTests.kt | 2 +- 13 files changed, 117 insertions(+), 111 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/F64Array.kt b/src/main/kotlin/org/jetbrains/bio/viktor/F64Array.kt index 2a3dbc3..0684c97 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/F64Array.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/F64Array.kt @@ -69,7 +69,13 @@ open class F64Array protected constructor( val nDim: Int = shape.size /** Number of elements along the first axis. */ - val size: Int = shape[0] + val length: Int = shape[0] + + @Deprecated( + "This property will change semantics in 2.0.0, see https://github.com/JetBrains-Research/viktor/issues/37", + ReplaceWith("length") + ) + val size: Int get() = length /** * Returns `true` if this array can be flattened using [flatten]. @@ -549,7 +555,7 @@ open class F64Array protected constructor( open fun sd(): Double { val s = sum() val s2 = dot(this) - return sqrt((s2 - s * s / size) / (size - 1)) + return sqrt((s2 - s * s / length) / (length - 1)) } /** @@ -941,7 +947,7 @@ open class F64Array protected constructor( * * Copying method. Not implemented for flat arrays. */ - open fun toGenericArray(): Array<*> = Array(size) { view(it).toArray() } + open fun toGenericArray(): Array<*> = Array(length) { view(it).toArray() } /** * Converts this vector to a [DoubleArray]. @@ -961,7 +967,7 @@ open class F64Array protected constructor( ): String { val sb = StringBuilder() sb.append('[') - if (maxDisplay < size) { + if (maxDisplay < length) { for (r in 0 until maxDisplay / 2) { sb.append(V[r].toString(maxDisplay, format)).append(", ") } @@ -969,16 +975,16 @@ open class F64Array protected constructor( sb.append("..., ") val leftover = maxDisplay - maxDisplay / 2 - for (r in size - leftover until size) { + for (r in length - leftover until length) { sb.append(V[r].toString(maxDisplay, format)) - if (r < size - 1) { + if (r < length - 1) { sb.append(", ") } } } else { - for (r in 0 until size) { + for (r in 0 until length) { sb.append(V[r].toString(maxDisplay, format)) - if (r < size - 1) { + if (r < length - 1) { sb.append(", ") } } @@ -994,10 +1000,10 @@ open class F64Array protected constructor( this === other -> true other !is F64Array -> false !shape.contentEquals(other.shape) -> false - else -> (0 until size).all { view(it) == other.view(it) } + else -> (0 until length).all { view(it) == other.view(it) } } - override fun hashCode(): Int = (0 until size).fold(1) { acc, r -> + override fun hashCode(): Int = (0 until length).fold(1) { acc, r -> 31 * acc + view(r).hashCode() } @@ -1100,7 +1106,7 @@ open class F64Array protected constructor( val result = invoke(*shape) var offset = 0 for (a in arrayOf(first, *rest)) { - if (a.size > 0) { + if (a.length > 0) { a.copyTo(result.slice(offset, offset + a.shape[axis], axis = axis)) offset += a.shape[axis] } diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/F64DenseFlatArray.kt b/src/main/kotlin/org/jetbrains/bio/viktor/F64DenseFlatArray.kt index 3d51ff1..dfdacbb 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/F64DenseFlatArray.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/F64DenseFlatArray.kt @@ -12,29 +12,29 @@ internal sealed class F64DenseFlatArray( size: Int ) : F64FlatArray(data, offset, 1, size) { - override fun fill(init: Double) = data.fill(init, offset, offset + size) + override fun fill(init: Double) = data.fill(init, offset, offset + length) override fun copy(): F64FlatArray { - val copyData = DoubleArray(size) - System.arraycopy(data, offset, copyData, 0, size) - return create(copyData, 0, size) + val copyData = DoubleArray(length) + System.arraycopy(data, offset, copyData, 0, length) + return create(copyData, 0, length) } override fun copyTo(other: F64Array) { if (other is F64DenseFlatArray) { checkShape(other) - System.arraycopy(data, offset, other.data, other.offset, size) + System.arraycopy(data, offset, other.data, other.offset, length) } else { super.copyTo(other) } } - override fun clone(): F64DenseFlatArray = create(data.clone(), offset, size) + override fun clone(): F64DenseFlatArray = create(data.clone(), offset, length) private inline fun denseTransformInPlace(op: (Double) -> Double) { val dst = data var dstOffset = offset - val dstEnd = dstOffset + size + val dstEnd = dstOffset + length while (dstOffset < dstEnd) { dst[dstOffset] = op.invoke(dst[dstOffset]) dstOffset++ @@ -42,10 +42,10 @@ internal sealed class F64DenseFlatArray( } private inline fun denseTransform(op: (Double) -> Double): F64FlatArray { - val dst = DoubleArray(size) + val dst = DoubleArray(length) val src = data var srcOffset = offset - val length = size + val length = length if (srcOffset == 0) { for (i in 0 until length) { dst[i] = op.invoke(src[i]) @@ -56,7 +56,7 @@ internal sealed class F64DenseFlatArray( srcOffset++ } } - return create(dst, 0, size) + return create(dst, 0, this.length) } private inline fun denseEBEInPlace(other: F64DenseFlatArray, op: (Double, Double) -> Double) { @@ -64,7 +64,7 @@ internal sealed class F64DenseFlatArray( val src = other.data var dstOffset = offset var srcOffset = other.offset - val length = size + val length = length if (dstOffset == 0 && srcOffset == 0) { for (i in 0 until length) { dst[i] = op.invoke(dst[i], src[i]) @@ -93,12 +93,12 @@ internal sealed class F64DenseFlatArray( } private inline fun denseEBE(other: F64DenseFlatArray, op: (Double, Double) -> Double): F64DenseFlatArray { - val dst = DoubleArray(size) + val dst = DoubleArray(length) val src1 = data val src2 = other.data var src1Offset = offset var src2Offset = other.offset - val length = size + val length = length if (src1Offset == 0 && src2Offset == 0) { for (i in 0 until length) { dst[i] = op.invoke(src1[i], src2[i]) @@ -110,7 +110,7 @@ internal sealed class F64DenseFlatArray( src2Offset++ } } - return create(dst, 0, size) + return create(dst, 0, this.length) } private inline fun ebe( @@ -132,7 +132,7 @@ internal sealed class F64DenseFlatArray( var res = initial val dst = data var dstOffset = offset - val dstEnd = dstOffset + size + val dstEnd = dstOffset + length while (dstOffset < dstEnd) { res = op.invoke(res, dst[dstOffset]) dstOffset++ @@ -143,7 +143,7 @@ internal sealed class F64DenseFlatArray( override fun reduce(op: (Double, Double) -> Double): Double { val dst = data var dstOffset = offset - val dstEnd = dstOffset + size + val dstEnd = dstOffset + length var res = dst[dstOffset] dstOffset++ while (dstOffset < dstEnd) { @@ -187,7 +187,7 @@ internal sealed class F64DenseFlatArray( override fun div(other: F64Array) = ebe(other, { a, b -> a / b }, { super.div(it) }) - override fun toDoubleArray() = data.copyOfRange(offset, offset + size) + override fun toDoubleArray() = data.copyOfRange(offset, offset + length) companion object { /** @@ -229,22 +229,22 @@ internal class F64LargeDenseArray( size: Int ) : F64DenseFlatArray(data, offset, size) { - override fun sd() = NativeSpeedups.unsafeSD(data, offset, size) + override fun sd() = NativeSpeedups.unsafeSD(data, offset, length) - override fun sum() = NativeSpeedups.unsafeSum(data, offset, size) + override fun sum() = NativeSpeedups.unsafeSum(data, offset, length) override fun cumSum() { - if (!NativeSpeedups.unsafeCumSum(data, offset, size)) super.cumSum() + if (!NativeSpeedups.unsafeCumSum(data, offset, length)) super.cumSum() } - override fun min() = NativeSpeedups.unsafeMin(data, offset, size) + override fun min() = NativeSpeedups.unsafeMin(data, offset, length) - override fun max() = NativeSpeedups.unsafeMax(data, offset, size) + override fun max() = NativeSpeedups.unsafeMax(data, offset, length) override fun dot(other: F64Array): Double { return if (other is F64LargeDenseArray) { checkShape(other) - NativeSpeedups.unsafeDot(data, offset, other.data, other.offset, size) + NativeSpeedups.unsafeDot(data, offset, other.data, other.offset, length) } else { super.dot(other) } @@ -254,43 +254,43 @@ internal class F64LargeDenseArray( nativeOp: (DoubleArray, Int, DoubleArray, Int, Int) -> Boolean, superOp: F64FlatArray.() -> F64FlatArray ): F64FlatArray { - val dst = DoubleArray(size) - if (nativeOp(dst, 0, data, offset, size)) { - return create(dst, 0, size) + val dst = DoubleArray(length) + if (nativeOp(dst, 0, data, offset, length)) { + return create(dst, 0, length) } return superOp() } override fun expInPlace() { - if (!NativeSpeedups.unsafeExp(data, offset, data, offset, size)) super.expInPlace() + if (!NativeSpeedups.unsafeExp(data, offset, data, offset, length)) super.expInPlace() } override fun exp() = nativeTransform(NativeSpeedups::unsafeExp) { super.exp() } override fun expm1InPlace() { - if (!NativeSpeedups.unsafeExpm1(data, offset, data, offset, size)) super.expm1InPlace() + if (!NativeSpeedups.unsafeExpm1(data, offset, data, offset, length)) super.expm1InPlace() } override fun expm1() = nativeTransform(NativeSpeedups::unsafeExpm1) { super.expm1() } override fun logInPlace() { - if (!NativeSpeedups.unsafeLog(data, offset, data, offset, size)) super.logInPlace() + if (!NativeSpeedups.unsafeLog(data, offset, data, offset, length)) super.logInPlace() } override fun log() = nativeTransform(NativeSpeedups::unsafeLog) { super.log() } override fun log1pInPlace(){ - if (!NativeSpeedups.unsafeLog1p(data, offset, data, offset, size)) super.log1pInPlace() + if (!NativeSpeedups.unsafeLog1p(data, offset, data, offset, length)) super.log1pInPlace() } override fun log1p() = nativeTransform(NativeSpeedups::unsafeLog1p) { super.log1p() } - override fun logSumExp() = NativeSpeedups.unsafeLogSumExp(data, offset, size) + override fun logSumExp() = NativeSpeedups.unsafeLogSumExp(data, offset, length) override fun logAddExpAssign(other: F64Array) { if (other is F64LargeDenseArray) { checkShape(other) - if (NativeSpeedups.unsafeLogAddExp(data, offset, data, offset, other.data, other.offset, size)) return + if (NativeSpeedups.unsafeLogAddExp(data, offset, data, offset, other.data, other.offset, length)) return } super.logAddExpAssign(other) } @@ -298,9 +298,9 @@ internal class F64LargeDenseArray( override fun logAddExp(other: F64Array): F64FlatArray { if (other is F64LargeDenseArray) { checkShape(other) - val res = DoubleArray(size) - if (NativeSpeedups.unsafeLogAddExp(res, 0, data, offset, other.data, other.offset, size)) { - return create(res, 0, size) + val res = DoubleArray(length) + if (NativeSpeedups.unsafeLogAddExp(res, 0, data, offset, other.data, other.offset, length)) { + return create(res, 0, length) } } return super.logAddExp(other) diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/F64FlatArray.kt b/src/main/kotlin/org/jetbrains/bio/viktor/F64FlatArray.kt index 1a995f6..aa85966 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/F64FlatArray.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/F64FlatArray.kt @@ -22,19 +22,19 @@ open class F64FlatArray protected constructor( internal open val unsafeSet: (Int, Double) -> Unit = { i, v -> data[i * stride + offset] = v } override operator fun get(pos: Int): Double { - checkIndex("pos", pos, size) + checkIndex("pos", pos, length) return unsafeGet(pos) } override operator fun set(pos: Int, value: Double) { - checkIndex("pos", pos, size) + checkIndex("pos", pos, length) unsafeSet(pos, value) } override fun flatten() = this override fun contains(other: Double): Boolean { - for (pos in 0 until size) { + for (pos in 0 until length) { if (unsafeGet(pos) == other) { return true } @@ -49,15 +49,15 @@ open class F64FlatArray protected constructor( override fun copyTo(other: F64Array) { val o = checkShape(other) - for (pos in 0 until size) { + for (pos in 0 until length) { o.unsafeSet(pos, unsafeGet(pos)) } } - override fun copy(): F64FlatArray = F64DenseFlatArray.create(toDoubleArray(), 0, size) + override fun copy(): F64FlatArray = F64DenseFlatArray.create(toDoubleArray(), 0, length) override fun fill(init: Double) { - for (pos in 0 until size) { + for (pos in 0 until length) { unsafeSet(pos, init) } } @@ -88,7 +88,7 @@ open class F64FlatArray protected constructor( */ private inline fun balancedSum(getter: (Int) -> Double): Double { var accUnaligned = 0.0 - var remaining = size + var remaining = length while (remaining % 4 > 0) { remaining-- accUnaligned += getter(remaining) @@ -122,7 +122,7 @@ open class F64FlatArray protected constructor( override fun cumSum() { val acc = KahanSum() - for (pos in 0 until size) { + for (pos in 0 until length) { acc += unsafeGet(pos) unsafeSet(pos, acc.result()) } @@ -133,7 +133,7 @@ open class F64FlatArray protected constructor( override fun argMin(): Int { var minValue = Double.POSITIVE_INFINITY var res = 0 - for (pos in 0 until size) { + for (pos in 0 until length) { val value = unsafeGet(pos) if (value <= minValue) { minValue = value @@ -148,7 +148,7 @@ open class F64FlatArray protected constructor( override fun argMax(): Int { var maxValue = Double.NEGATIVE_INFINITY var res = 0 - for (pos in 0 until size) { + for (pos in 0 until length) { val value = unsafeGet(pos) if (value >= maxValue) { maxValue = value @@ -159,14 +159,14 @@ open class F64FlatArray protected constructor( } private inline fun flatTransformInPlace(op: (Double) -> Double) { - for (pos in 0 until size) { + for (pos in 0 until length) { unsafeSet(pos, op.invoke(unsafeGet(pos))) } } private inline fun flatTransform(op: (Double) -> Double): F64FlatArray { - val res = DoubleArray(size) - for (pos in 0 until size) { + val res = DoubleArray(length) + for (pos in 0 until length) { res[pos] = op.invoke(unsafeGet(pos)) } return create(res) @@ -174,18 +174,18 @@ open class F64FlatArray protected constructor( private inline fun flatEBEInPlace(other: F64Array, op: (Double, Double) -> Double) { val o = checkShape(other) - for (pos in 0 until size) { + for (pos in 0 until length) { unsafeSet(pos, op.invoke(unsafeGet(pos), o.unsafeGet(pos))) } } private inline fun flatEBE(other: F64Array, op: (Double, Double) -> Double): F64FlatArray { val o = checkShape(other) - val res = DoubleArray(size) - for (pos in 0 until size) { + val res = DoubleArray(length) + for (pos in 0 until length) { res[pos] = op.invoke(unsafeGet(pos), o.unsafeGet(pos)) } - return F64DenseFlatArray.create(res, 0, size) + return F64DenseFlatArray.create(res, 0, length) } override fun transformInPlace(op: (Double) -> Double) = flatTransformInPlace(op) @@ -194,7 +194,7 @@ open class F64FlatArray protected constructor( override fun fold(initial: T, op: (T, Double) -> T): T { var res = initial - for (pos in 0 until size) { + for (pos in 0 until length) { res = op(res, unsafeGet(pos)) } return res @@ -202,7 +202,7 @@ open class F64FlatArray protected constructor( override fun reduce(op: (Double, Double) -> Double): Double { var res = unsafeGet(0) - for (pos in 1 until size) { + for (pos in 1 until length) { res = op(res, unsafeGet(pos)) } return res @@ -228,7 +228,7 @@ open class F64FlatArray protected constructor( override fun logSumExp(): Double { val offset = max() val acc = KahanSum() - for (pos in 0 until size) { + for (pos in 0 until length) { acc += FastMath.exp(unsafeGet(pos) - offset) } return ln(acc.result()) + offset @@ -265,7 +265,7 @@ open class F64FlatArray protected constructor( override fun reshape(vararg shape: Int): F64Array { shape.forEach { require(it > 0) { "shape must be positive but was $it" } } - check(shape.product() == size) { "total size of the new array must be unchanged" } + check(shape.product() == length) { "total size of the new array must be unchanged" } return when { this.shape.contentEquals(shape) -> this else -> { @@ -279,7 +279,7 @@ open class F64FlatArray protected constructor( } } - override fun asSequence(): Sequence = (0 until size).asSequence().map { unsafeGet(it) } + override fun asSequence(): Sequence = (0 until length).asSequence().map { unsafeGet(it) } override fun clone(): F64FlatArray = F64FlatArray(data.clone(), offset, strides[0], shape[0]) @@ -287,7 +287,7 @@ open class F64FlatArray protected constructor( override fun toGenericArray() = unsupported() - override fun toDoubleArray() = DoubleArray(size) { unsafeGet(it) } + override fun toDoubleArray() = DoubleArray(length) { unsafeGet(it) } /** * A version of [DecimalFormat.format] which doesn't produce ? @@ -304,7 +304,7 @@ open class F64FlatArray protected constructor( val sb = StringBuilder() sb.append('[') - if (maxDisplay < size) { + if (maxDisplay < length) { for (pos in 0 until maxDisplay / 2) { sb.append(format.safeFormat(this[pos])).append(", ") } @@ -312,16 +312,16 @@ open class F64FlatArray protected constructor( sb.append("..., ") val leftover = maxDisplay - maxDisplay / 2 - for (pos in size - leftover until size) { + for (pos in length - leftover until length) { sb.append(format.safeFormat(this[pos])) - if (pos < size - 1) { + if (pos < length - 1) { sb.append(", ") } } } else { - for (pos in 0 until size) { + for (pos in 0 until length) { sb.append(format.safeFormat(this[pos])) - if (pos < size - 1) { + if (pos < length - 1) { sb.append(", ") } } @@ -334,13 +334,13 @@ open class F64FlatArray protected constructor( override fun equals(other: Any?) = when { this === other -> true other !is F64FlatArray -> false // an instance of F64Array can't be flat - size != other.size -> false - else -> (0 until size).all { + length != other.length -> false + else -> (0 until length).all { Precision.equals(unsafeGet(it), other.unsafeGet(it)) } } - override fun hashCode() = (0 until size).fold(1) { acc, pos -> + override fun hashCode() = (0 until length).fold(1) { acc, pos -> // XXX calling #hashCode results in boxing, see KT-7571. 31 * acc + java.lang.Double.hashCode(unsafeGet(pos)) } diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/Random.kt b/src/main/kotlin/org/jetbrains/bio/viktor/Random.kt index 92dd651..4c9f648 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/Random.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/Random.kt @@ -59,17 +59,17 @@ fun F64Array.quantile( ): Double { check(this is F64FlatArray) { "expected a 1-D array" } - val pos = (size + 1) * q + val pos = (length + 1) * q val d = pos - floor(pos) return when { pos < 1 -> min() - pos >= size -> max() + pos >= length -> max() else -> { val lo = QuickSelect.select( - this, 0, size - 1, pos.toInt() - 1, randomGenerator + this, 0, length - 1, pos.toInt() - 1, randomGenerator ) val hi = QuickSelect.select( - this, 0, size - 1, pos.toInt(), randomGenerator + this, 0, length - 1, pos.toInt(), randomGenerator ) return lo + d * (hi - lo) } @@ -86,12 +86,12 @@ fun F64Array.quantile( fun F64Array.shuffle(randomGenerator: RandomGenerator = DEFAULT_RANDOM) { check(this is F64FlatArray) { "expected a 1-D array" } - if (size <= 1) { + if (length <= 1) { return } - for (i in 0..size - 2) { - val j = randomGenerator.nextInt(size - i) + for (i in 0..length - 2) { + val j = randomGenerator.nextInt(length - i) swap(i, i + j) } } diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/Searching.kt b/src/main/kotlin/org/jetbrains/bio/viktor/Searching.kt index b6003e6..2b62c28 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/Searching.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/Searching.kt @@ -10,7 +10,7 @@ package org.jetbrains.bio.viktor */ fun F64Array.searchSorted(target: Double): Int { var lo = 0 - var hi = size + var hi = length while (lo < hi) { val mid = (lo + hi) ushr 1 when { diff --git a/src/main/kotlin/org/jetbrains/bio/viktor/Sorting.kt b/src/main/kotlin/org/jetbrains/bio/viktor/Sorting.kt index d113a0f..1e39871 100644 --- a/src/main/kotlin/org/jetbrains/bio/viktor/Sorting.kt +++ b/src/main/kotlin/org/jetbrains/bio/viktor/Sorting.kt @@ -20,9 +20,9 @@ fun F64Array.sort(reverse: Boolean = false) = reorder(argSort(reverse)) fun F64Array.argSort(reverse: Boolean = false): IntArray { check(this is F64FlatArray) { "expected a 1-D array" } val comparator = Comparator(IndexedDoubleValue::compareTo) - val indexedValues = Array(size) { IndexedDoubleValue(it, unsafeGet(it)) } + val indexedValues = Array(length) { IndexedDoubleValue(it, unsafeGet(it)) } indexedValues.sortWith(if (reverse) comparator.reversed() else comparator) - return IntArray(size) { indexedValues[it].index } + return IntArray(length) { indexedValues[it].index } } /** A version of [IndexedValue] specialized to [Double]. */ @@ -81,8 +81,8 @@ internal inline fun reorderInternal( */ fun F64Array.partition(p: Int) { check(this is F64FlatArray) { "expected a 1-D array" } - require(p in 0 until size) { "p must be in [0, $size)" } - partition(p, 0, size - 1) + require(p in 0 until length) { "p must be in [0, $length)" } + partition(p, 0, length - 1) } /** diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/BalancedSumTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/BalancedSumTests.kt index 3ddaa5a..a75783f 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/BalancedSumTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/BalancedSumTests.kt @@ -13,7 +13,7 @@ class BalancedSumTest(private val size: Int) { val v = Random().doubles(size.toLong()).toArray().asF64Array() val expected = KahanSum() - for (i in 0 until v.size) { + for (i in 0 until v.length) { expected.feed(v[i]) } @@ -34,7 +34,7 @@ class BalancedDotTest(private val size: Int) { val w = r.doubles(size.toLong()).toArray().asF64Array() val expected = KahanSum() - for (i in 0 until v.size) { + for (i in 0 until v.length) { expected.feed(v[i] * w[i]) } @@ -47,7 +47,7 @@ class BalancedDotTest(private val size: Int) { val w = r.ints(-1000, 1000).limit(size.toLong()).toArray() val expected = KahanSum() - for (i in 0 until v.size) { + for (i in 0 until v.length) { expected.feed(v[i] * w[i]) } @@ -63,7 +63,7 @@ class BalancedDotTest(private val size: Int) { w[i] = (r.nextInt(2000) - 1000).toShort() } val expected = KahanSum() - for (i in 0 until v.size) { + for (i in 0 until v.length) { expected.feed(v[i] * w[i]) } diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayCreationTest.kt b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayCreationTest.kt index 886061b..75a3362 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayCreationTest.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayCreationTest.kt @@ -97,7 +97,7 @@ class F64ArrayCreationTest { @Test fun full() { val v = F64Array.full(2, 42.0) - assertEquals(2, v.size) + assertEquals(2, v.length) assertEquals(F64Array.of(42.0, 42.0), v) } diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayGetSetTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayGetSetTests.kt index 46e3c99..156262b 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayGetSetTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayGetSetTests.kt @@ -21,23 +21,23 @@ class F64FlatArrayGetSetTest( private val v = F64FlatArray.create(values, offset, stride, size) @Test fun get() { - for (i in 0 until v.size) { + for (i in 0 until v.length) { assertEquals(values[offset + i * stride], v[i], Precision.EPSILON) } } @Test(expected = IndexOutOfBoundsException::class) fun getOutOfBounds() { - v[v.size] + v[v.length] } @Test fun set() { - for (i in 0 until v.size) { + for (i in 0 until v.length) { val copy = v.copy() copy[i] = 42.0 assertEquals(42.0, copy[i], Precision.EPSILON) // Ensure all other elements are unchanged. - for (j in 0 until v.size) { + for (j in 0 until v.length) { if (j == i) { continue } @@ -48,18 +48,18 @@ class F64FlatArrayGetSetTest( } @Test(expected = IndexOutOfBoundsException::class) fun setOutOfBounds() { - v[v.size] = 42.0 + v[v.length] = 42.0 } @Test fun setMagicScalar() { val copy = v.copy() copy.V[_I] = 42.0 - assertEquals(F64Array.full(copy.size, 42.0), copy) + assertEquals(F64Array.full(copy.length, 42.0), copy) } @Test fun setMagicVector() { - val other = F64Array.full(v.size, 42.0) + val other = F64Array.full(v.length, 42.0) val copy = v.copy() copy.V[_I] = other diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayOpsTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayOpsTests.kt index fe628b7..e599723 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayOpsTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArrayOpsTests.kt @@ -270,7 +270,7 @@ class F64FlatArrayOperationTest(private val v: F64FlatArray) { @Test fun cumSum() { val actual = v.clone().apply { cumSum() } val acc = KahanSum() - for (i in 0 until v.size) { + for (i in 0 until v.length) { acc.feed(v[i]) assertEquals(acc.result(), actual[i], DELTA) } @@ -278,7 +278,7 @@ class F64FlatArrayOperationTest(private val v: F64FlatArray) { @Test fun dot() { val random = Random() - val other = DoubleArray(v.size) { random.nextDouble() }.asF64Array() + val other = DoubleArray(v.length) { random.nextDouble() }.asF64Array() val voActual = v.checkConstant(other, F64Array::dot) val ovActual = other.checkConstant(v, F64Array::dot) val voExpected = v.asSequence().zip(other.asSequence()).map { (a, b) -> a * b }.sum() diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArraySlicingTest.kt b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArraySlicingTest.kt index 9e01b15..5dc0930 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/F64ArraySlicingTest.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/F64ArraySlicingTest.kt @@ -10,7 +10,7 @@ class F64FlatArraySlicingTest { @Test fun slice() { val v = F64Array.of(1.0, 2.0, 3.0) val slice = v.slice(1, 2) - assertEquals(1, slice.size) + assertEquals(1, slice.length) assertEquals(F64Array.of(2.0), slice) slice[0] = 42.0 @@ -50,22 +50,22 @@ class F64FlatArraySlicingTest { val v = F64Array.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0) v.slice(step = 2).let { - assertEquals(3, it.size) + assertEquals(3, it.length) assertEquals(F64Array.of(1.0, 3.0, 5.0), it) } v.slice(1, step = 2).let { - assertEquals(3, it.size) + assertEquals(3, it.length) assertEquals(F64Array.of(2.0, 4.0, 6.0), it) } v.slice(1, step = 3).let { - assertEquals(2, it.size) + assertEquals(2, it.length) assertEquals(F64Array.of(2.0, 5.0), it) } v.slice(1, step = 4).let { - assertEquals(2, it.size) + assertEquals(2, it.length) assertEquals(F64Array.of(2.0, 6.0), it) } } diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/RandomTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/RandomTests.kt index 0afd717..1f3bc50 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/RandomTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/RandomTests.kt @@ -13,8 +13,8 @@ import java.util.* class QuickSelectTest { @Test fun quantileRandom() { val values = Random().doubles(1024).toArray().asF64Array() - for (i in 0 until values.size) { - val q = (i.toDouble() + 1) / values.size + for (i in 0 until values.length) { + val q = (i.toDouble() + 1) / values.length assertEquals(StatUtils.percentile(values.data, q * 100), values.quantile(q), Precision.EPSILON) } diff --git a/src/test/kotlin/org/jetbrains/bio/viktor/SortingTests.kt b/src/test/kotlin/org/jetbrains/bio/viktor/SortingTests.kt index 478cd2d..2e7b358 100644 --- a/src/test/kotlin/org/jetbrains/bio/viktor/SortingTests.kt +++ b/src/test/kotlin/org/jetbrains/bio/viktor/SortingTests.kt @@ -17,7 +17,7 @@ class SortingTests { @Test fun partitionInternal() { val values = F64Array.of(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) - val length = values.size + val length = values.length for (p in 0 until length) { values.shuffle() val pivot = values[p]