From d8c4b84ddc9f4920f40b2f9903db339b67aeec52 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Fri, 9 Jul 2021 08:14:27 +0100 Subject: [PATCH] relying to Java library path to load JNoa --- kmath-noa/build.gradle.kts | 9 ++++- .../java/space/kscience/kmath/noa/JNoa.java | 11 +++--- .../space/kscience/kmath/noa/algebras.kt | 36 +++++++++---------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/kmath-noa/build.gradle.kts b/kmath-noa/build.gradle.kts index 57b9fe6d0..984c0e2f5 100644 --- a/kmath-noa/build.gradle.kts +++ b/kmath-noa/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { val home: String = System.getProperty("user.home") val javaHome: String = System.getProperty("java.home") -val thirdPartyDir = "$home/.konan/third-party/kmath-noa-${project.property("version")}" +val thirdPartyDir = "$home/.konan/third-party/noa-v0.0.1" val cppBuildDir = "$thirdPartyDir/cpp-build" val jNoaDir = "$thirdPartyDir/jnoa/noa-kmath" @@ -182,6 +182,13 @@ val buildCpp by tasks.registering { //tasks["compileJava"].dependsOn(buildCpp) +tasks { + withType{ + systemProperty("java.library.path", + "$home/devspace/noa/cmake-build-release/kmath") + } +} + readme { maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE } diff --git a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java index 55566d753..3724d45f4 100644 --- a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java +++ b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java @@ -8,15 +8,12 @@ package space.kscience.kmath.noa; class JNoa { static { - String jNoaPath = System.getProperty("user.home") + - "/devspace/noa/cmake-build-release/kmath/libjnoa.so"; - //"/.konan/third-party/kmath-noa-0.3.0-dev-14/cpp-build/kmath/libjnoa.so"; - try { - System.load(jNoaPath); + System.loadLibrary("jnoa"); } catch (UnsatisfiedLinkError e) { - System.err.println("Failed to load native NOA library from:\n" + - jNoaPath + "\n" + e); + System.err.println( + "Failed to load the native library NOA:\n" + + " Set JAVA_LIBRARY_PATH to the location of libjnoa.so"); System.exit(1); } } diff --git a/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/algebras.kt b/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/algebras.kt index 039024861..ef228d96a 100644 --- a/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/algebras.kt +++ b/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/algebras.kt @@ -387,28 +387,28 @@ public class NoaFloatAlgebra(scope: NoaScope) : wrap(JNoa.plusFloat(this, other.tensor.tensorHandle)) override fun Tensor.plus(value: Float): NoaFloatTensor = - wrap(space.kscience.kmath.noa.JNoa.plusFloat(value, tensor.tensorHandle)) + wrap(JNoa.plusFloat(value, tensor.tensorHandle)) override fun Tensor.plusAssign(value: Float): Unit = - space.kscience.kmath.noa.JNoa.plusFloatAssign(value, tensor.tensorHandle) + JNoa.plusFloatAssign(value, tensor.tensorHandle) override operator fun Float.minus(other: Tensor): NoaFloatTensor = wrap(JNoa.plusFloat(-this, other.tensor.tensorHandle)) override fun Tensor.minus(value: Float): NoaFloatTensor = - wrap(space.kscience.kmath.noa.JNoa.plusFloat(-value, tensor.tensorHandle)) + wrap(JNoa.plusFloat(-value, tensor.tensorHandle)) override fun Tensor.minusAssign(value: Float): Unit = - space.kscience.kmath.noa.JNoa.plusFloatAssign(-value, tensor.tensorHandle) + JNoa.plusFloatAssign(-value, tensor.tensorHandle) override operator fun Float.times(other: Tensor): NoaFloatTensor = wrap(JNoa.timesFloat(this, other.tensor.tensorHandle)) override fun Tensor.times(value: Float): NoaFloatTensor = - wrap(space.kscience.kmath.noa.JNoa.timesFloat(value, tensor.tensorHandle)) + wrap(JNoa.timesFloat(value, tensor.tensorHandle)) override fun Tensor.timesAssign(value: Float): Unit = - space.kscience.kmath.noa.JNoa.timesFloatAssign(value, tensor.tensorHandle) + JNoa.timesFloatAssign(value, tensor.tensorHandle) override fun Float.div(other: Tensor): NoaFloatTensor = other * (1 / this) @@ -456,28 +456,28 @@ public class NoaLongAlgebra(scope: NoaScope) : wrap(JNoa.plusLong(this, other.tensor.tensorHandle)) override fun Tensor.plus(value: Long): NoaLongTensor = - wrap(space.kscience.kmath.noa.JNoa.plusLong(value, tensor.tensorHandle)) + wrap(JNoa.plusLong(value, tensor.tensorHandle)) override fun Tensor.plusAssign(value: Long): Unit = - space.kscience.kmath.noa.JNoa.plusLongAssign(value, tensor.tensorHandle) + JNoa.plusLongAssign(value, tensor.tensorHandle) override operator fun Long.minus(other: Tensor): NoaLongTensor = wrap(JNoa.plusLong(-this, other.tensor.tensorHandle)) override fun Tensor.minus(value: Long): NoaLongTensor = - wrap(space.kscience.kmath.noa.JNoa.plusLong(-value, tensor.tensorHandle)) + wrap(JNoa.plusLong(-value, tensor.tensorHandle)) override fun Tensor.minusAssign(value: Long): Unit = - space.kscience.kmath.noa.JNoa.plusLongAssign(-value, tensor.tensorHandle) + JNoa.plusLongAssign(-value, tensor.tensorHandle) override operator fun Long.times(other: Tensor): NoaLongTensor = wrap(JNoa.timesLong(this, other.tensor.tensorHandle)) override fun Tensor.times(value: Long): NoaLongTensor = - wrap(space.kscience.kmath.noa.JNoa.timesLong(value, tensor.tensorHandle)) + wrap(JNoa.timesLong(value, tensor.tensorHandle)) override fun Tensor.timesAssign(value: Long): Unit = - space.kscience.kmath.noa.JNoa.timesLongAssign(value, tensor.tensorHandle) + JNoa.timesLongAssign(value, tensor.tensorHandle) public fun full(value: Long, shape: IntArray, device: Device): NoaLongTensor = wrap(JNoa.fullLong(value, shape, device.toInt())) @@ -516,28 +516,28 @@ public class NoaIntAlgebra(scope: NoaScope) : wrap(JNoa.plusInt(this, other.tensor.tensorHandle)) override fun Tensor.plus(value: Int): NoaIntTensor = - wrap(space.kscience.kmath.noa.JNoa.plusInt(value, tensor.tensorHandle)) + wrap(JNoa.plusInt(value, tensor.tensorHandle)) override fun Tensor.plusAssign(value: Int): Unit = - space.kscience.kmath.noa.JNoa.plusIntAssign(value, tensor.tensorHandle) + JNoa.plusIntAssign(value, tensor.tensorHandle) override operator fun Int.minus(other: Tensor): NoaIntTensor = wrap(JNoa.plusInt(-this, other.tensor.tensorHandle)) override fun Tensor.minus(value: Int): NoaIntTensor = - wrap(space.kscience.kmath.noa.JNoa.plusInt(-value, tensor.tensorHandle)) + wrap(JNoa.plusInt(-value, tensor.tensorHandle)) override fun Tensor.minusAssign(value: Int): Unit = - space.kscience.kmath.noa.JNoa.plusIntAssign(-value, tensor.tensorHandle) + JNoa.plusIntAssign(-value, tensor.tensorHandle) override operator fun Int.times(other: Tensor): NoaIntTensor = wrap(JNoa.timesInt(this, other.tensor.tensorHandle)) override fun Tensor.times(value: Int): NoaIntTensor = - wrap(space.kscience.kmath.noa.JNoa.timesInt(value, tensor.tensorHandle)) + wrap(JNoa.timesInt(value, tensor.tensorHandle)) override fun Tensor.timesAssign(value: Int): Unit = - space.kscience.kmath.noa.JNoa.timesIntAssign(value, tensor.tensorHandle) + JNoa.timesIntAssign(value, tensor.tensorHandle) public fun full(value: Int, shape: IntArray, device: Device): NoaIntTensor = wrap(JNoa.fullInt(value, shape, device.toInt()))