Workaround for JS reflection for dimenstions
This commit is contained in:
parent
169801060b
commit
2d71452341
@ -19,13 +19,11 @@ interface Dimension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified D : Dimension> dim(): UInt {
|
|
||||||
return D::class.objectInstance?.dim ?: error("Dimension object must be a singleton")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expect inline fun <reified D : Dimension> Dimension.Companion.dim(): UInt
|
||||||
|
|
||||||
object D1 : Dimension {
|
object D1 : Dimension {
|
||||||
override val dim: UInt = 1u
|
override val dim: UInt = 1u
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ interface DPoint<T, D : Dimension> : Point<T> {
|
|||||||
/**
|
/**
|
||||||
* Dimension-safe point wrapper
|
* Dimension-safe point wrapper
|
||||||
*/
|
*/
|
||||||
inline class DPointWrapper<T, D : Dimension>(val point: Point<T>) : DPoint<T, D> {
|
inline class DPointWrapper<T, D : Dimension>(val point: Point<T>) :
|
||||||
|
DPoint<T, D> {
|
||||||
override val size: Int get() = point.size
|
override val size: Int get() = point.size
|
||||||
|
|
||||||
override fun get(index: Int): T = point[index]
|
override fun get(index: Int): T = point[index]
|
||||||
@ -94,7 +95,12 @@ inline class DMatrixContext<T : Any, Ri : Ring<T>>(val context: GenericMatrixCon
|
|||||||
|
|
||||||
inline fun <reified D : Dimension> point(noinline initializer: (Int) -> T): DPoint<T, D> {
|
inline fun <reified D : Dimension> point(noinline initializer: (Int) -> T): DPoint<T, D> {
|
||||||
val size = Dimension.dim<D>()
|
val size = Dimension.dim<D>()
|
||||||
return DPoint.coerceUnsafe(context.point(size.toInt(), initializer))
|
return DPoint.coerceUnsafe(
|
||||||
|
context.point(
|
||||||
|
size.toInt(),
|
||||||
|
initializer
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline infix fun <reified R1 : Dimension, reified C1 : Dimension, reified C2 : Dimension> DMatrix<T, R1, C1>.dot(
|
inline infix fun <reified R1 : Dimension, reified C1 : Dimension, reified C2 : Dimension> DMatrix<T, R1, C1>.dot(
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package scientifik.kmath.dimensions
|
||||||
|
|
||||||
|
actual inline fun <reified D : Dimension> Dimension.Companion.dim(): UInt {
|
||||||
|
TODO("KClass::objectInstance does not work")
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package scientifik.kmath.dimensions
|
||||||
|
|
||||||
|
actual inline fun <reified D : Dimension> Dimension.Companion.dim(): UInt =
|
||||||
|
D::class.objectInstance?.dim ?: error("Dimension object must be a singleton")
|
Loading…
Reference in New Issue
Block a user