OjAlgo module stub
This commit is contained in:
parent
c24cf90262
commit
050eaf1d8c
@ -19,6 +19,7 @@
|
|||||||
- Complex power
|
- Complex power
|
||||||
- Separate methods for UInt, Int and Number powers. NaN safety.
|
- Separate methods for UInt, Int and Number powers. NaN safety.
|
||||||
- Tensorflow prototype
|
- Tensorflow prototype
|
||||||
|
- OjAlgo support
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Exponential operations merged with hyperbolic functions
|
- Exponential operations merged with hyperbolic functions
|
||||||
|
@ -17,4 +17,4 @@ dependencies {
|
|||||||
|
|
||||||
readme {
|
readme {
|
||||||
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
|
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
|
||||||
}
|
}
|
||||||
|
15
kmath-ojalgo/build.gradle.kts
Normal file
15
kmath-ojalgo/build.gradle.kts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("ru.mipt.npm.gradle.common")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api("org.ojalgo:ojalgo:48.4.1")
|
||||||
|
api(project(":kmath-complex"))
|
||||||
|
}
|
||||||
|
|
||||||
|
readme {
|
||||||
|
description = "OjAlgo bindings"
|
||||||
|
maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE
|
||||||
|
propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md"))
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package space.kscience.kmath.ojalgo
|
||||||
|
|
||||||
|
import org.ojalgo.algebra.ScalarOperation
|
||||||
|
import space.kscience.kmath.operations.Field
|
||||||
|
import space.kscience.kmath.operations.Group
|
||||||
|
import space.kscience.kmath.operations.Ring
|
||||||
|
import space.kscience.kmath.operations.invoke
|
||||||
|
|
||||||
|
public open class OjalgoGroup<T>(override val zero: T) : Group<T>
|
||||||
|
where T : org.ojalgo.algebra.Group.Additive<T> {
|
||||||
|
public override fun add(a: T, b: T): T = a.add(b)
|
||||||
|
public override fun T.unaryMinus(): T = negate()
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class OjalgoRing<T>(zero: T, override val one: T) : OjalgoGroup<T>(zero),
|
||||||
|
Ring<T> where T : org.ojalgo.algebra.Ring<T> {
|
||||||
|
public override fun multiply(a: T, b: T): T = a.multiply(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class OjalgoField<T>(zero: T, one: T) : OjalgoRing<T>(zero, one),
|
||||||
|
Field<T> where T : org.ojalgo.algebra.Field<T>, T : ScalarOperation.Multiplication<T, *> {
|
||||||
|
public override fun divide(a: T, b: T): T = a.divide(b)
|
||||||
|
public override fun scale(a: T, value: Double): T = a.multiply(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal inline fun <T, R> Field<T>.convert(crossinline tToR: (T) -> R, crossinline rToT: (R) -> T): Field<R> =
|
||||||
|
object : Field<R> {
|
||||||
|
override val zero: R
|
||||||
|
get() = tToR(this@convert.zero)
|
||||||
|
|
||||||
|
override val one: R
|
||||||
|
get() = tToR(this@convert.one)
|
||||||
|
|
||||||
|
override fun add(a: R, b: R): R = tToR(this@convert.add(rToT(a), rToT(b)))
|
||||||
|
override fun multiply(a: R, b: R): R = tToR(this@convert.multiply(rToT(a), rToT(b)))
|
||||||
|
override fun divide(a: R, b: R): R = tToR(this@convert.divide(rToT(a), rToT(b)))
|
||||||
|
override fun R.unaryMinus(): R = tToR(this@convert { -rToT(this@unaryMinus) })
|
||||||
|
|
||||||
|
override fun scale(a: R, value: Double): R {
|
||||||
|
return tToR(this@convert.scale(rToT(a), value))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package space.kscience.kmath.ojalgo
|
||||||
|
|
||||||
|
import org.ojalgo.structure.Access1D
|
||||||
|
import org.ojalgo.structure.Access2D
|
||||||
|
import space.kscience.kmath.linear.Matrix
|
||||||
|
import space.kscience.kmath.linear.Point
|
||||||
|
|
||||||
|
public class OjalgoMatrix<T : Comparable<T>>(public val origin: Access2D<T>) : Matrix<T> {
|
||||||
|
public override val rowNum: Int
|
||||||
|
get() = Math.toIntExact(origin.countRows())
|
||||||
|
|
||||||
|
public override val colNum: Int
|
||||||
|
get() = Math.toIntExact(origin.countColumns())
|
||||||
|
|
||||||
|
public override fun get(i: Int, j: Int): T = origin[i.toLong(), j.toLong()]
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OjalgoVector<T : Comparable<T>>(public val origin: Access1D<T>) : Point<T> {
|
||||||
|
public override val size: Int
|
||||||
|
get() = origin.size()
|
||||||
|
|
||||||
|
override fun get(index: Int): T = origin[index.toLong()]
|
||||||
|
|
||||||
|
public override operator fun iterator(): Iterator<T> = object : Iterator<T> {
|
||||||
|
private var cursor: Int = 0
|
||||||
|
|
||||||
|
override fun next(): T {
|
||||||
|
cursor += 1
|
||||||
|
return this@OjalgoVector[cursor - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasNext(): Boolean = cursor < size
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package space.kscience.kmath.ojalgo
|
||||||
|
|
||||||
|
import org.ojalgo.scalar.*
|
||||||
|
import space.kscience.kmath.complex.Complex
|
||||||
|
import space.kscience.kmath.operations.Field
|
||||||
|
|
||||||
|
public val OjalgoMoneyField: Field<Scalar<Money>> = OjalgoField<Scalar<Money>>(Money.ZERO, Money.ONE)
|
||||||
|
|
||||||
|
public val OjalgoComplexField: Field<Complex> =
|
||||||
|
OjalgoField<Scalar<ComplexNumber>>(ComplexNumber.ZERO, ComplexNumber.ONE).convert(
|
||||||
|
{ Complex(it.get().real, it.get().imaginary) },
|
||||||
|
{ ComplexNumber.of(it.re, it.im) },
|
||||||
|
)
|
||||||
|
|
||||||
|
public val OjalgoRationalField: Field<Double> =
|
||||||
|
OjalgoField<Scalar<RationalNumber>>(RationalNumber.ZERO, RationalNumber.ONE).convert(
|
||||||
|
Scalar<RationalNumber>::doubleValue,
|
||||||
|
RationalNumber::valueOf,
|
||||||
|
)
|
||||||
|
|
||||||
|
public val OjalgoQuaternionField: Field<space.kscience.kmath.complex.Quaternion> =
|
||||||
|
OjalgoField<Scalar<Quaternion>>(Quaternion.ZERO, Quaternion.ONE).convert(
|
||||||
|
{ x -> space.kscience.kmath.complex.Quaternion(x.get().scalar(), x.get().i, x.get().j, x.get().k) },
|
||||||
|
{ (s, i, j, k) -> Quaternion.of(s, i, j, k) },
|
||||||
|
)
|
||||||
|
|
||||||
|
public val OjalgoPrimitiveField: Field<Double> =
|
||||||
|
OjalgoField<Scalar<Double>>(PrimitiveScalar.ZERO, PrimitiveScalar.ONE).convert(
|
||||||
|
Scalar<Double>::doubleValue,
|
||||||
|
PrimitiveScalar::valueOf,
|
||||||
|
)
|
@ -26,5 +26,6 @@ include(
|
|||||||
":kmath-symja",
|
":kmath-symja",
|
||||||
":kmath-jafama",
|
":kmath-jafama",
|
||||||
":examples",
|
":examples",
|
||||||
|
":kmath-ojalgo",
|
||||||
":benchmarks",
|
":benchmarks",
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user