Skip to content

Commit

Permalink
use references over lambdas where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Martmists <[email protected]>
  • Loading branch information
Martmists-GH committed Jul 22, 2024
1 parent 330bb29 commit 0c58871
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
104 changes: 52 additions & 52 deletions src/commonMain/kotlin/com/martmists/ndarray/simd/impl/F64ArrayImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package com.martmists.ndarray.simd.impl
import com.martmists.ndarray.simd.*

internal open class F64ArrayImpl internal constructor(
override val data: DoubleArray,
override val offset: Int,
override val strides: IntArray,
override val shape: IntArray,
override val unrollDim: Int,
override val unrollStride: Int,
override val unrollSize: Int
final override val data: DoubleArray,
final override val offset: Int,
final override val strides: IntArray,
final override val shape: IntArray,
final override val unrollDim: Int,
final override val unrollStride: Int,
final override val unrollSize: Int
) : F64Array {
override val isFlattenable = unrollDim == nDim

Expand Down Expand Up @@ -115,11 +115,11 @@ internal open class F64ArrayImpl internal constructor(
}

override fun copy(): F64Array {
return F64Array.full(*shape, init=0.0).also { this.copyTo(it) }
return F64Array.full(*shape, init=0.0).also(this::copyTo)
}

override fun copyTo(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.copyTo(b) }
commonUnrollToFlat(other, F64FlatArray::copyTo)
}

override fun flatten(): F64FlatArray {
Expand Down Expand Up @@ -176,13 +176,13 @@ internal open class F64ArrayImpl internal constructor(
return F64Array.create(data, offset, newStrides, newShape)
}

override fun sum(): Double = unrollToFlat().map { it.sum() }.sum()
override fun sum(): Double = unrollToFlat().map(F64FlatArray::sum).sum()

override fun min(): Double = unrollToFlat().map { it.min() }.minOrNull() ?: Double.POSITIVE_INFINITY
override fun min(): Double = unrollToFlat().map(F64FlatArray::min).minOrNull() ?: Double.POSITIVE_INFINITY

override fun max(): Double = unrollToFlat().map { it.max() }.maxOrNull() ?: Double.NEGATIVE_INFINITY
override fun max(): Double = unrollToFlat().map(F64FlatArray::max).maxOrNull() ?: Double.NEGATIVE_INFINITY

override fun product(): Double = unrollToFlat().map { it.product() }.reduce(Double::times)
override fun product(): Double = unrollToFlat().map(F64FlatArray::product).reduce(Double::times)

override fun coerceInPlace(min: Double, max: Double) {
unrollToFlat().forEach { it.coerceInPlace(min, max) }
Expand Down Expand Up @@ -213,35 +213,35 @@ internal open class F64ArrayImpl internal constructor(
}

override fun expInPlace() {
unrollToFlat().forEach { it.expInPlace() }
unrollToFlat().forEach(F64FlatArray::expInPlace)
}

override fun expm1InPlace() {
unrollToFlat().forEach { it.expm1InPlace() }
unrollToFlat().forEach(F64FlatArray::expm1InPlace)
}

override fun logInPlace() {
unrollToFlat().forEach { it.logInPlace() }
unrollToFlat().forEach(F64FlatArray::logInPlace)
}

override fun log1pInPlace() {
unrollToFlat().forEach { it.log1pInPlace() }
unrollToFlat().forEach(F64FlatArray::log1pInPlace)
}

override fun log2InPlace() {
unrollToFlat().forEach { it.log2InPlace() }
unrollToFlat().forEach(F64FlatArray::log2InPlace)
}

override fun log10InPlace() {
unrollToFlat().forEach { it.log10InPlace() }
unrollToFlat().forEach(F64FlatArray::log10InPlace)
}

override fun logBaseInPlace(base: Double) {
unrollToFlat().forEach { it.logBaseInPlace(base) }
}

override fun sqrtInPlace() {
unrollToFlat().forEach { it.sqrtInPlace() }
unrollToFlat().forEach(F64FlatArray::sqrtInPlace)
}

override fun powInPlace(power: Double) {
Expand All @@ -253,191 +253,191 @@ internal open class F64ArrayImpl internal constructor(
}

override fun unaryMinusInPlace() {
unrollToFlat().forEach { it.unaryMinusInPlace() }
unrollToFlat().forEach(F64FlatArray::unaryMinusInPlace)
}

override fun plusAssign(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.plusAssign(b) }
commonUnrollToFlat(other, F64FlatArray::plusAssign)
}

override fun plusAssign(other: Double) {
unrollToFlat().forEach { it.plusAssign(other) }
}

override fun minusAssign(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.minusAssign(b) }
commonUnrollToFlat(other, F64FlatArray::minusAssign)
}

override fun minusAssign(other: Double) {
unrollToFlat().forEach { it.minusAssign(other) }
}

override fun timesAssign(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.timesAssign(b) }
commonUnrollToFlat(other, F64FlatArray::timesAssign)
}

override fun timesAssign(other: Double) {
unrollToFlat().forEach { it.timesAssign(other) }
}

override fun divAssign(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.divAssign(b) }
commonUnrollToFlat(other, F64FlatArray::divAssign)
}

override fun divAssign(other: Double) {
unrollToFlat().forEach { it.divAssign(other) }
}

override fun absInPlace() {
unrollToFlat().forEach { it.absInPlace() }
unrollToFlat().forEach(F64FlatArray::absInPlace)
}

override fun ltInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.ltInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::ltInPlace)
}

override fun ltInPlace(other: Double) {
unrollToFlat().forEach { it.ltInPlace(other) }
}

override fun lteInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.lteInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::lteInPlace)
}

override fun lteInPlace(other: Double) {
unrollToFlat().forEach { it.lteInPlace(other) }
}

override fun gtInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.gtInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::gtInPlace)
}

override fun gtInPlace(other: Double) {
unrollToFlat().forEach { it.gtInPlace(other) }
}

override fun gteInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.gteInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::gteInPlace)
}

override fun gteInPlace(other: Double) {
unrollToFlat().forEach { it.gteInPlace(other) }
}

override fun eqInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.eqInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::eqInPlace)
}

override fun eqInPlace(other: Double) {
unrollToFlat().forEach { it.eqInPlace(other) }
}

override fun neqInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.neqInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::neqInPlace)
}

override fun neqInPlace(other: Double) {
unrollToFlat().forEach { it.neqInPlace(other) }
}

override fun andInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.andInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::andInPlace)
}

override fun andInPlace(other: Int) {
unrollToFlat().forEach { it.andInPlace(other) }
}

override fun orInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.orInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::orInPlace)
}

override fun orInPlace(other: Int) {
unrollToFlat().forEach { it.orInPlace(other) }
}

override fun xorInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.xorInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::xorInPlace)
}

override fun xorInPlace(other: Int) {
unrollToFlat().forEach { it.xorInPlace(other) }
}

override fun notInPlace() {
unrollToFlat().forEach { it.notInPlace() }
unrollToFlat().forEach(F64FlatArray::notInPlace)
}

override fun shlInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.shlInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::shlInPlace)
}

override fun shlInPlace(other: Int) {
unrollToFlat().forEach { it.shlInPlace(other) }
}

override fun shrInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.shrInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::shrInPlace)
}

override fun shrInPlace(other: Int) {
unrollToFlat().forEach { it.shrInPlace(other) }
}

override fun sinInPlace() {
unrollToFlat().forEach { it.sinInPlace() }
unrollToFlat().forEach(F64FlatArray::sinInPlace)
}

override fun cosInPlace() {
unrollToFlat().forEach { it.cosInPlace() }
unrollToFlat().forEach(F64FlatArray::cosInPlace)
}

override fun tanInPlace() {
unrollToFlat().forEach { it.tanInPlace() }
unrollToFlat().forEach(F64FlatArray::tanInPlace)
}

override fun asinInPlace() {
unrollToFlat().forEach { it.asinInPlace() }
unrollToFlat().forEach(F64FlatArray::asinInPlace)
}

override fun acosInPlace() {
unrollToFlat().forEach { it.acosInPlace() }
unrollToFlat().forEach(F64FlatArray::acosInPlace)
}

override fun atanInPlace() {
unrollToFlat().forEach { it.atanInPlace() }
unrollToFlat().forEach(F64FlatArray::atanInPlace)
}

override fun atan2InPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.atan2InPlace(b) }
commonUnrollToFlat(other, F64FlatArray::atan2InPlace)
}

override fun sinhInPlace() {
unrollToFlat().forEach { it.sinhInPlace() }
unrollToFlat().forEach(F64FlatArray::sinhInPlace)
}

override fun coshInPlace() {
unrollToFlat().forEach { it.coshInPlace() }
unrollToFlat().forEach(F64FlatArray::coshInPlace)
}

override fun tanhInPlace() {
unrollToFlat().forEach { it.tanhInPlace() }
unrollToFlat().forEach(F64FlatArray::tanhInPlace)
}

override fun asinhInPlace() {
unrollToFlat().forEach { it.asinhInPlace() }
unrollToFlat().forEach(F64FlatArray::asinhInPlace)
}

override fun acoshInPlace() {
unrollToFlat().forEach { it.acoshInPlace() }
unrollToFlat().forEach(F64FlatArray::acoshInPlace)
}

override fun atanhInPlace() {
unrollToFlat().forEach { it.atanhInPlace() }
unrollToFlat().forEach(F64FlatArray::atanhInPlace)
}

override fun hypotInPlace(other: F64Array) {
commonUnrollToFlat(other) { a, b -> a.hypotInPlace(b) }
commonUnrollToFlat(other, F64FlatArray::hypotInPlace)
}

override fun matmul(other: F64Array): F64Array {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ internal open class F64FlatArrayImpl internal constructor(
return res
}

override fun sum(): Double = balancedSum { unsafeGet(it) }
override fun sum(): Double = balancedSum(unsafeGet)

override fun min() = unsafeGet(argMin())

Expand Down

0 comments on commit 0c58871

Please sign in to comment.