relying to Java library path to load JNoa

This commit is contained in:
Roland Grinis 2021-07-09 08:14:27 +01:00
parent 80879d3736
commit d8c4b84ddc
3 changed files with 30 additions and 26 deletions

View File

@ -20,7 +20,7 @@ dependencies {
val home: String = System.getProperty("user.home") val home: String = System.getProperty("user.home")
val javaHome: String = System.getProperty("java.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 cppBuildDir = "$thirdPartyDir/cpp-build"
val jNoaDir = "$thirdPartyDir/jnoa/noa-kmath" val jNoaDir = "$thirdPartyDir/jnoa/noa-kmath"
@ -182,6 +182,13 @@ val buildCpp by tasks.registering {
//tasks["compileJava"].dependsOn(buildCpp) //tasks["compileJava"].dependsOn(buildCpp)
tasks {
withType<Test>{
systemProperty("java.library.path",
"$home/devspace/noa/cmake-build-release/kmath")
}
}
readme { readme {
maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE
} }

View File

@ -8,15 +8,12 @@ package space.kscience.kmath.noa;
class JNoa { class JNoa {
static { 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 { try {
System.load(jNoaPath); System.loadLibrary("jnoa");
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
System.err.println("Failed to load native NOA library from:\n" + System.err.println(
jNoaPath + "\n" + e); "Failed to load the native library NOA:\n" +
" Set JAVA_LIBRARY_PATH to the location of libjnoa.so");
System.exit(1); System.exit(1);
} }
} }

View File

@ -387,28 +387,28 @@ public class NoaFloatAlgebra(scope: NoaScope) :
wrap(JNoa.plusFloat(this, other.tensor.tensorHandle)) wrap(JNoa.plusFloat(this, other.tensor.tensorHandle))
override fun Tensor<Float>.plus(value: Float): NoaFloatTensor = override fun Tensor<Float>.plus(value: Float): NoaFloatTensor =
wrap(space.kscience.kmath.noa.JNoa.plusFloat(value, tensor.tensorHandle)) wrap(JNoa.plusFloat(value, tensor.tensorHandle))
override fun Tensor<Float>.plusAssign(value: Float): Unit = override fun Tensor<Float>.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<Float>): NoaFloatTensor = override operator fun Float.minus(other: Tensor<Float>): NoaFloatTensor =
wrap(JNoa.plusFloat(-this, other.tensor.tensorHandle)) wrap(JNoa.plusFloat(-this, other.tensor.tensorHandle))
override fun Tensor<Float>.minus(value: Float): NoaFloatTensor = override fun Tensor<Float>.minus(value: Float): NoaFloatTensor =
wrap(space.kscience.kmath.noa.JNoa.plusFloat(-value, tensor.tensorHandle)) wrap(JNoa.plusFloat(-value, tensor.tensorHandle))
override fun Tensor<Float>.minusAssign(value: Float): Unit = override fun Tensor<Float>.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<Float>): NoaFloatTensor = override operator fun Float.times(other: Tensor<Float>): NoaFloatTensor =
wrap(JNoa.timesFloat(this, other.tensor.tensorHandle)) wrap(JNoa.timesFloat(this, other.tensor.tensorHandle))
override fun Tensor<Float>.times(value: Float): NoaFloatTensor = override fun Tensor<Float>.times(value: Float): NoaFloatTensor =
wrap(space.kscience.kmath.noa.JNoa.timesFloat(value, tensor.tensorHandle)) wrap(JNoa.timesFloat(value, tensor.tensorHandle))
override fun Tensor<Float>.timesAssign(value: Float): Unit = override fun Tensor<Float>.timesAssign(value: Float): Unit =
space.kscience.kmath.noa.JNoa.timesFloatAssign(value, tensor.tensorHandle) JNoa.timesFloatAssign(value, tensor.tensorHandle)
override fun Float.div(other: Tensor<Float>): NoaFloatTensor = override fun Float.div(other: Tensor<Float>): NoaFloatTensor =
other * (1 / this) other * (1 / this)
@ -456,28 +456,28 @@ public class NoaLongAlgebra(scope: NoaScope) :
wrap(JNoa.plusLong(this, other.tensor.tensorHandle)) wrap(JNoa.plusLong(this, other.tensor.tensorHandle))
override fun Tensor<Long>.plus(value: Long): NoaLongTensor = override fun Tensor<Long>.plus(value: Long): NoaLongTensor =
wrap(space.kscience.kmath.noa.JNoa.plusLong(value, tensor.tensorHandle)) wrap(JNoa.plusLong(value, tensor.tensorHandle))
override fun Tensor<Long>.plusAssign(value: Long): Unit = override fun Tensor<Long>.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<Long>): NoaLongTensor = override operator fun Long.minus(other: Tensor<Long>): NoaLongTensor =
wrap(JNoa.plusLong(-this, other.tensor.tensorHandle)) wrap(JNoa.plusLong(-this, other.tensor.tensorHandle))
override fun Tensor<Long>.minus(value: Long): NoaLongTensor = override fun Tensor<Long>.minus(value: Long): NoaLongTensor =
wrap(space.kscience.kmath.noa.JNoa.plusLong(-value, tensor.tensorHandle)) wrap(JNoa.plusLong(-value, tensor.tensorHandle))
override fun Tensor<Long>.minusAssign(value: Long): Unit = override fun Tensor<Long>.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<Long>): NoaLongTensor = override operator fun Long.times(other: Tensor<Long>): NoaLongTensor =
wrap(JNoa.timesLong(this, other.tensor.tensorHandle)) wrap(JNoa.timesLong(this, other.tensor.tensorHandle))
override fun Tensor<Long>.times(value: Long): NoaLongTensor = override fun Tensor<Long>.times(value: Long): NoaLongTensor =
wrap(space.kscience.kmath.noa.JNoa.timesLong(value, tensor.tensorHandle)) wrap(JNoa.timesLong(value, tensor.tensorHandle))
override fun Tensor<Long>.timesAssign(value: Long): Unit = override fun Tensor<Long>.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 = public fun full(value: Long, shape: IntArray, device: Device): NoaLongTensor =
wrap(JNoa.fullLong(value, shape, device.toInt())) wrap(JNoa.fullLong(value, shape, device.toInt()))
@ -516,28 +516,28 @@ public class NoaIntAlgebra(scope: NoaScope) :
wrap(JNoa.plusInt(this, other.tensor.tensorHandle)) wrap(JNoa.plusInt(this, other.tensor.tensorHandle))
override fun Tensor<Int>.plus(value: Int): NoaIntTensor = override fun Tensor<Int>.plus(value: Int): NoaIntTensor =
wrap(space.kscience.kmath.noa.JNoa.plusInt(value, tensor.tensorHandle)) wrap(JNoa.plusInt(value, tensor.tensorHandle))
override fun Tensor<Int>.plusAssign(value: Int): Unit = override fun Tensor<Int>.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<Int>): NoaIntTensor = override operator fun Int.minus(other: Tensor<Int>): NoaIntTensor =
wrap(JNoa.plusInt(-this, other.tensor.tensorHandle)) wrap(JNoa.plusInt(-this, other.tensor.tensorHandle))
override fun Tensor<Int>.minus(value: Int): NoaIntTensor = override fun Tensor<Int>.minus(value: Int): NoaIntTensor =
wrap(space.kscience.kmath.noa.JNoa.plusInt(-value, tensor.tensorHandle)) wrap(JNoa.plusInt(-value, tensor.tensorHandle))
override fun Tensor<Int>.minusAssign(value: Int): Unit = override fun Tensor<Int>.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<Int>): NoaIntTensor = override operator fun Int.times(other: Tensor<Int>): NoaIntTensor =
wrap(JNoa.timesInt(this, other.tensor.tensorHandle)) wrap(JNoa.timesInt(this, other.tensor.tensorHandle))
override fun Tensor<Int>.times(value: Int): NoaIntTensor = override fun Tensor<Int>.times(value: Int): NoaIntTensor =
wrap(space.kscience.kmath.noa.JNoa.timesInt(value, tensor.tensorHandle)) wrap(JNoa.timesInt(value, tensor.tensorHandle))
override fun Tensor<Int>.timesAssign(value: Int): Unit = override fun Tensor<Int>.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 = public fun full(value: Int, shape: IntArray, device: Device): NoaIntTensor =
wrap(JNoa.fullInt(value, shape, device.toInt())) wrap(JNoa.fullInt(value, shape, device.toInt()))