Add owned property to all the objects
This commit is contained in:
parent
955e95690d
commit
e66f169655
@ -21,7 +21,8 @@ private fun KtPsiFactory.createMatrixClass(
|
|||||||
@Language("kotlin") val text = """internal class $className(
|
@Language("kotlin") val text = """internal class $className(
|
||||||
override val rawNativeHandle: CPointer<$structName>,
|
override val rawNativeHandle: CPointer<$structName>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<$kotlinTypeName, $structName>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<$kotlinTypeName, $structName>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ private fun KtPsiFactory.createMatrixClass(
|
|||||||
Gsl${kotlinTypeAlias}Vector(
|
Gsl${kotlinTypeAlias}Vector(
|
||||||
${fn("gsl_matrixRrow")}(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
${fn("gsl_matrixRrow")}(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<$kotlinTypeName>>
|
override val columns: Buffer<Buffer<$kotlinTypeName>>
|
||||||
@ -41,7 +43,8 @@ private fun KtPsiFactory.createMatrixClass(
|
|||||||
Gsl${kotlinTypeAlias}Vector(
|
Gsl${kotlinTypeAlias}Vector(
|
||||||
${fn("gsl_matrixRcolumn")}(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
${fn("gsl_matrixRcolumn")}(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): $kotlinTypeName =
|
override operator fun get(i: Int, j: Int): $kotlinTypeName =
|
||||||
@ -53,7 +56,7 @@ private fun KtPsiFactory.createMatrixClass(
|
|||||||
override fun copy(): $className {
|
override fun copy(): $className {
|
||||||
val new = checkNotNull(${fn("gsl_matrixRalloc")}(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(${fn("gsl_matrixRalloc")}(rowNum.toULong(), colNum.toULong()))
|
||||||
${fn("gsl_matrixRmemcpy")}(new, nativeHandle)
|
${fn("gsl_matrixRmemcpy")}(new, nativeHandle)
|
||||||
return $className(new, scope)
|
return $className(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = ${fn("gsl_matrixRfree")}(nativeHandle)
|
override fun close(): Unit = ${fn("gsl_matrixRfree")}(nativeHandle)
|
||||||
|
@ -19,21 +19,19 @@ private fun KtPsiFactory.createVectorClass(
|
|||||||
val structName = sn("gsl_vectorR", cTypeName)
|
val structName = sn("gsl_vectorR", cTypeName)
|
||||||
|
|
||||||
@Language("kotlin") val text =
|
@Language("kotlin") val text =
|
||||||
"""internal class $className(override val rawNativeHandle: CPointer<$structName>, scope: AutofreeScope) :
|
"""internal class $className(
|
||||||
GslVector<$kotlinTypeName, $structName>(scope) {
|
override val rawNativeHandle: CPointer<$structName>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<$kotlinTypeName, $structName>(scope, owned) {
|
||||||
override operator fun get(index: Int): $kotlinTypeName =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
${fn("gsl_vectorRget")}(nativeHandle, index.toULong())
|
override operator fun get(index: Int): $kotlinTypeName = ${fn("gsl_vectorRget")}(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: $kotlinTypeName): Unit = ${fn("gsl_vectorRset")}(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: $kotlinTypeName): Unit =
|
|
||||||
${fn("gsl_vectorRset")}(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): $className {
|
override fun copy(): $className {
|
||||||
val new = checkNotNull(${fn("gsl_vectorRalloc")}(size.toULong()))
|
val new = checkNotNull(${fn("gsl_vectorRalloc")}(size.toULong()))
|
||||||
${fn("gsl_vectorRmemcpy")}(new, nativeHandle)
|
${fn("gsl_vectorRmemcpy")}(new, nativeHandle)
|
||||||
return ${className}(new, scope)
|
return ${className}(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
@ -13,20 +13,21 @@ internal fun Complex.toGsl(): CValue<gsl_complex> = cValue {
|
|||||||
dat[1] = im
|
dat[1] = im
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslComplexMatrix(override val rawNativeHandle: CPointer<gsl_matrix_complex>, scope: AutofreeScope) :
|
internal class GslComplexMatrix(
|
||||||
GslMatrix<Complex, gsl_matrix_complex>(scope) {
|
override val rawNativeHandle: CPointer<gsl_matrix_complex>,
|
||||||
override val rowNum: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Complex, gsl_matrix_complex>(scope, owned) {
|
||||||
override val colNum: Int
|
override val rowNum: Int get() = nativeHandle.pointed.size1.toInt()
|
||||||
get() = nativeHandle.pointed.size2.toInt()
|
override val colNum: Int get() = nativeHandle.pointed.size2.toInt()
|
||||||
|
|
||||||
override val rows: Buffer<Buffer<Complex>>
|
override val rows: Buffer<Buffer<Complex>>
|
||||||
get() = VirtualBuffer(rowNum) { r ->
|
get() = VirtualBuffer(rowNum) { r ->
|
||||||
GslComplexVector(
|
GslComplexVector(
|
||||||
gsl_matrix_complex_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_complex_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Complex>>
|
override val columns: Buffer<Buffer<Complex>>
|
||||||
@ -34,7 +35,8 @@ internal class GslComplexMatrix(override val rawNativeHandle: CPointer<gsl_matri
|
|||||||
GslComplexVector(
|
GslComplexVector(
|
||||||
gsl_matrix_complex_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_complex_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Complex =
|
override operator fun get(i: Int, j: Int): Complex =
|
||||||
@ -46,7 +48,7 @@ internal class GslComplexMatrix(override val rawNativeHandle: CPointer<gsl_matri
|
|||||||
override fun copy(): GslComplexMatrix {
|
override fun copy(): GslComplexMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_complex_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_complex_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_complex_memcpy(new, nativeHandle)
|
gsl_matrix_complex_memcpy(new, nativeHandle)
|
||||||
return GslComplexMatrix(new, scope)
|
return GslComplexMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_complex_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_complex_free(nativeHandle)
|
||||||
@ -59,11 +61,12 @@ internal class GslComplexMatrix(override val rawNativeHandle: CPointer<gsl_matri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslComplexVector(override val rawNativeHandle: CPointer<gsl_vector_complex>, scope: AutofreeScope) :
|
internal class GslComplexVector(
|
||||||
GslVector<Complex, gsl_vector_complex>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_complex>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Complex, gsl_vector_complex>(scope, owned) {
|
||||||
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
override fun get(index: Int): Complex = gsl_vector_complex_get(nativeHandle, index.toULong()).toKMath()
|
override fun get(index: Int): Complex = gsl_vector_complex_get(nativeHandle, index.toULong()).toKMath()
|
||||||
|
|
||||||
override fun set(index: Int, value: Complex): Unit =
|
override fun set(index: Int, value: Complex): Unit =
|
||||||
@ -72,7 +75,7 @@ internal class GslComplexVector(override val rawNativeHandle: CPointer<gsl_vecto
|
|||||||
override fun copy(): GslComplexVector {
|
override fun copy(): GslComplexVector {
|
||||||
val new = checkNotNull(gsl_vector_complex_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_complex_alloc(size.toULong()))
|
||||||
gsl_vector_complex_memcpy(new, nativeHandle)
|
gsl_vector_complex_memcpy(new, nativeHandle)
|
||||||
return GslComplexVector(new, scope)
|
return GslComplexVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
@ -2,15 +2,15 @@ package kscience.kmath.gsl
|
|||||||
|
|
||||||
import kotlinx.cinterop.AutofreeScope
|
import kotlinx.cinterop.AutofreeScope
|
||||||
import kotlinx.cinterop.CStructVar
|
import kotlinx.cinterop.CStructVar
|
||||||
import kscience.kmath.structures.Matrix
|
import kscience.kmath.linear.Matrix
|
||||||
import kscience.kmath.structures.NDStructure
|
import kscience.kmath.nd.NDStructure
|
||||||
import kscience.kmath.structures.asSequence
|
import kscience.kmath.structures.asSequence
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps gsl_matrix_* objects from GSL.
|
* Wraps gsl_matrix_* objects from GSL.
|
||||||
*/
|
*/
|
||||||
public abstract class GslMatrix<T : Any, H : CStructVar> internal constructor(scope: AutofreeScope) :
|
public abstract class GslMatrix<T : Any, H : CStructVar> internal constructor(scope: AutofreeScope, owned: Boolean) :
|
||||||
GslObject<H>(scope), Matrix<T> {
|
GslObject<H>(scope, owned), Matrix<T> {
|
||||||
internal abstract operator fun set(i: Int, j: Int, value: T)
|
internal abstract operator fun set(i: Int, j: Int, value: T)
|
||||||
internal abstract fun copy(): GslMatrix<T, H>
|
internal abstract fun copy(): GslMatrix<T, H>
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import kscience.kmath.misc.UnstableKMathAPI
|
|||||||
import kscience.kmath.operations.Complex
|
import kscience.kmath.operations.Complex
|
||||||
import kscience.kmath.operations.ComplexField
|
import kscience.kmath.operations.ComplexField
|
||||||
import kscience.kmath.operations.toComplex
|
import kscience.kmath.operations.toComplex
|
||||||
import kscience.kmath.structures.Matrix
|
|
||||||
import org.gnu.gsl.*
|
import org.gnu.gsl.*
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.cast
|
import kotlin.reflect.cast
|
||||||
@ -65,17 +64,18 @@ public class GslRealMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Double, gsl_matrix> = GslRealMatrix(
|
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Double, gsl_matrix> = GslRealMatrix(
|
||||||
rawNativeHandle = checkNotNull(gsl_matrix_alloc(rows.toULong(), columns.toULong())),
|
rawNativeHandle = checkNotNull(gsl_matrix_alloc(rows.toULong(), columns.toULong())),
|
||||||
scope = scope,
|
scope = scope,
|
||||||
|
owned = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun produceDirtyVector(size: Int): GslVector<Double, gsl_vector> =
|
override fun produceDirtyVector(size: Int): GslVector<Double, gsl_vector> =
|
||||||
GslRealVector(rawNativeHandle = checkNotNull(gsl_vector_alloc(size.toULong())), scope = scope)
|
GslRealVector(rawNativeHandle = checkNotNull(gsl_vector_alloc(size.toULong())), scope = scope, owned = true)
|
||||||
|
|
||||||
public override fun Matrix<Double>.dot(other: Matrix<Double>): GslMatrix<Double, gsl_matrix> {
|
public override fun Matrix<Double>.dot(other: Matrix<Double>): GslMatrix<Double, gsl_matrix> {
|
||||||
val x = toGsl().nativeHandle
|
val x = toGsl().nativeHandle
|
||||||
val a = other.toGsl().nativeHandle
|
val a = other.toGsl().nativeHandle
|
||||||
val result = checkNotNull(gsl_matrix_calloc(a.pointed.size1, a.pointed.size2))
|
val result = checkNotNull(gsl_matrix_calloc(a.pointed.size1, a.pointed.size2))
|
||||||
gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, x, a, 1.0, result)
|
gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, x, a, 1.0, result)
|
||||||
return GslRealMatrix(result, scope = scope)
|
return GslRealMatrix(rawNativeHandle = result, scope = scope, owned = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun Matrix<Double>.dot(vector: Point<Double>): GslVector<Double, gsl_vector> {
|
public override fun Matrix<Double>.dot(vector: Point<Double>): GslVector<Double, gsl_vector> {
|
||||||
@ -83,7 +83,7 @@ public class GslRealMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
val a = vector.toGsl().nativeHandle
|
val a = vector.toGsl().nativeHandle
|
||||||
val result = checkNotNull(gsl_vector_calloc(a.pointed.size))
|
val result = checkNotNull(gsl_vector_calloc(a.pointed.size))
|
||||||
gsl_blas_dgemv(CblasNoTrans, 1.0, x, a, 1.0, result)
|
gsl_blas_dgemv(CblasNoTrans, 1.0, x, a, 1.0, result)
|
||||||
return GslRealVector(result, scope = scope)
|
return GslRealVector(rawNativeHandle = result, scope = scope, owned = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun Matrix<Double>.times(value: Double): GslMatrix<Double, gsl_matrix> {
|
public override fun Matrix<Double>.times(value: Double): GslMatrix<Double, gsl_matrix> {
|
||||||
@ -118,7 +118,12 @@ public class GslRealMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
private val lups by lazy {
|
private val lups by lazy {
|
||||||
val lu = m.toGsl().copy()
|
val lu = m.toGsl().copy()
|
||||||
val n = m.rowNum
|
val n = m.rowNum
|
||||||
val perm = GslPermutation(checkNotNull(gsl_permutation_alloc(n.toULong())), scope)
|
|
||||||
|
val perm = GslPermutation(
|
||||||
|
rawNativeHandle = checkNotNull(gsl_permutation_alloc(n.toULong())),
|
||||||
|
scope = scope,
|
||||||
|
owned = true,
|
||||||
|
)
|
||||||
|
|
||||||
val signum = memScoped {
|
val signum = memScoped {
|
||||||
val i = alloc<IntVar>()
|
val i = alloc<IntVar>()
|
||||||
@ -192,17 +197,21 @@ public class GslFloatMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Float, gsl_matrix_float> = GslFloatMatrix(
|
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Float, gsl_matrix_float> = GslFloatMatrix(
|
||||||
rawNativeHandle = checkNotNull(gsl_matrix_float_alloc(rows.toULong(), columns.toULong())),
|
rawNativeHandle = checkNotNull(gsl_matrix_float_alloc(rows.toULong(), columns.toULong())),
|
||||||
scope = scope,
|
scope = scope,
|
||||||
|
owned = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun produceDirtyVector(size: Int): GslVector<Float, gsl_vector_float> =
|
override fun produceDirtyVector(size: Int): GslVector<Float, gsl_vector_float> = GslFloatVector(
|
||||||
GslFloatVector(rawNativeHandle = checkNotNull(value = gsl_vector_float_alloc(size.toULong())), scope = scope)
|
rawNativeHandle = checkNotNull(value = gsl_vector_float_alloc(size.toULong())),
|
||||||
|
scope = scope,
|
||||||
|
owned = true,
|
||||||
|
)
|
||||||
|
|
||||||
public override fun Matrix<Float>.dot(other: Matrix<Float>): GslMatrix<Float, gsl_matrix_float> {
|
public override fun Matrix<Float>.dot(other: Matrix<Float>): GslMatrix<Float, gsl_matrix_float> {
|
||||||
val x = toGsl().nativeHandle
|
val x = toGsl().nativeHandle
|
||||||
val a = other.toGsl().nativeHandle
|
val a = other.toGsl().nativeHandle
|
||||||
val result = checkNotNull(gsl_matrix_float_calloc(a.pointed.size1, a.pointed.size2))
|
val result = checkNotNull(gsl_matrix_float_calloc(a.pointed.size1, a.pointed.size2))
|
||||||
gsl_blas_sgemm(CblasNoTrans, CblasNoTrans, 1f, x, a, 1f, result)
|
gsl_blas_sgemm(CblasNoTrans, CblasNoTrans, 1f, x, a, 1f, result)
|
||||||
return GslFloatMatrix(rawNativeHandle = result, scope = scope)
|
return GslFloatMatrix(rawNativeHandle = result, scope = scope, owned = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun Matrix<Float>.dot(vector: Point<Float>): GslVector<Float, gsl_vector_float> {
|
public override fun Matrix<Float>.dot(vector: Point<Float>): GslVector<Float, gsl_vector_float> {
|
||||||
@ -210,7 +219,7 @@ public class GslFloatMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
val a = vector.toGsl().nativeHandle
|
val a = vector.toGsl().nativeHandle
|
||||||
val result = checkNotNull(gsl_vector_float_calloc(a.pointed.size))
|
val result = checkNotNull(gsl_vector_float_calloc(a.pointed.size))
|
||||||
gsl_blas_sgemv(CblasNoTrans, 1f, x, a, 1f, result)
|
gsl_blas_sgemv(CblasNoTrans, 1f, x, a, 1f, result)
|
||||||
return GslFloatVector(rawNativeHandle = result, scope = scope)
|
return GslFloatVector(rawNativeHandle = result, scope = scope, owned = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun Matrix<Float>.times(value: Float): GslMatrix<Float, gsl_matrix_float> {
|
public override fun Matrix<Float>.times(value: Float): GslMatrix<Float, gsl_matrix_float> {
|
||||||
@ -305,7 +314,10 @@ public class GslComplexMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
private val lups by lazy {
|
private val lups by lazy {
|
||||||
val lu = m.toGsl().copy()
|
val lu = m.toGsl().copy()
|
||||||
val n = m.rowNum
|
val n = m.rowNum
|
||||||
val perm = GslPermutation(checkNotNull(gsl_permutation_alloc(n.toULong())), scope)
|
|
||||||
|
val perm = GslPermutation(rawNativeHandle = checkNotNull(gsl_permutation_alloc(n.toULong())),
|
||||||
|
scope = scope,
|
||||||
|
owned = true)
|
||||||
|
|
||||||
val signum = memScoped {
|
val signum = memScoped {
|
||||||
val i = alloc<IntVar>()
|
val i = alloc<IntVar>()
|
||||||
@ -322,7 +334,9 @@ public class GslComplexMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
val perm = produce(n, n) { _, _ -> 0.0.toComplex() }
|
val perm = produce(n, n) { _, _ -> 0.0.toComplex() }
|
||||||
|
|
||||||
for (j in 0 until lups.second.size)
|
for (j in 0 until lups.second.size)
|
||||||
gsl_matrix_complex_set_col(perm.nativeHandle, j.toULong(), one.columns[lups.second[j]].toGsl().nativeHandle)
|
gsl_matrix_complex_set_col(perm.nativeHandle,
|
||||||
|
j.toULong(),
|
||||||
|
one.columns[lups.second[j]].toGsl().nativeHandle)
|
||||||
|
|
||||||
perm
|
perm
|
||||||
}
|
}
|
||||||
@ -344,7 +358,10 @@ public class GslComplexMatrixContext(internal val scope: AutofreeScope) :
|
|||||||
) { i, j -> if (j >= i) lups.first[i, j] else 0.0.toComplex() } + UFeature
|
) { i, j -> if (j >= i) lups.first[i, j] else 0.0.toComplex() } + UFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
override val determinant by lazy { gsl_linalg_complex_LU_det(lups.first.nativeHandle, lups.third).toKMath() }
|
override val determinant by lazy {
|
||||||
|
gsl_linalg_complex_LU_det(lups.first.nativeHandle,
|
||||||
|
lups.third).toKMath()
|
||||||
|
}
|
||||||
|
|
||||||
override val inverse by lazy {
|
override val inverse by lazy {
|
||||||
val inv = lups.first.copy()
|
val inv = lups.first.copy()
|
||||||
|
@ -13,7 +13,7 @@ import kotlinx.cinterop.DeferScope
|
|||||||
*
|
*
|
||||||
* @param scope the scope where this object is declared.
|
* @param scope the scope where this object is declared.
|
||||||
*/
|
*/
|
||||||
public abstract class GslObject<H : CStructVar> internal constructor(internal val scope: AutofreeScope) {
|
public abstract class GslObject<H : CStructVar> internal constructor(internal val scope: AutofreeScope, internal val owned: Boolean) {
|
||||||
internal abstract val rawNativeHandle: CPointer<H>
|
internal abstract val rawNativeHandle: CPointer<H>
|
||||||
private var isClosed: Boolean = false
|
private var isClosed: Boolean = false
|
||||||
|
|
||||||
@ -23,13 +23,11 @@ public abstract class GslObject<H : CStructVar> internal constructor(internal va
|
|||||||
return rawNativeHandle
|
return rawNativeHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var shouldBeFreed = true
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
ensureHasGslErrorHandler()
|
ensureHasGslErrorHandler()
|
||||||
|
|
||||||
scope.defer {
|
scope.defer {
|
||||||
if (shouldBeFreed) close()
|
if (owned) close()
|
||||||
isClosed = true
|
isClosed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,11 @@ import org.gnu.gsl.gsl_permutation
|
|||||||
import org.gnu.gsl.gsl_permutation_free
|
import org.gnu.gsl.gsl_permutation_free
|
||||||
import org.gnu.gsl.gsl_permutation_get
|
import org.gnu.gsl.gsl_permutation_get
|
||||||
|
|
||||||
internal class GslPermutation(override val rawNativeHandle: CPointer<gsl_permutation>, scope: AutofreeScope) :
|
internal class GslPermutation(
|
||||||
GslObject<gsl_permutation>(scope) {
|
override val rawNativeHandle: CPointer<gsl_permutation>,
|
||||||
|
scope: AutofreeScope,
|
||||||
|
owned: Boolean,
|
||||||
|
) : GslObject<gsl_permutation>(scope, owned) {
|
||||||
val size get() = nativeHandle.pointed.size.toInt()
|
val size get() = nativeHandle.pointed.size.toInt()
|
||||||
|
|
||||||
operator fun get(i: Int) = gsl_permutation_get(nativeHandle, i.toULong()).toInt()
|
operator fun get(i: Int) = gsl_permutation_get(nativeHandle, i.toULong()).toInt()
|
||||||
|
@ -7,8 +7,8 @@ import kscience.kmath.linear.Point
|
|||||||
/**
|
/**
|
||||||
* Wraps gsl_vector_* objects from GSL.
|
* Wraps gsl_vector_* objects from GSL.
|
||||||
*/
|
*/
|
||||||
public abstract class GslVector<T, H : CStructVar> internal constructor(scope: AutofreeScope) :
|
public abstract class GslVector<T, H : CStructVar> internal constructor(scope: AutofreeScope, owned: Boolean) :
|
||||||
GslObject<H>(scope), Point<T> {
|
GslObject<H>(scope, owned), Point<T> {
|
||||||
internal abstract operator fun set(index: Int, value: T)
|
internal abstract operator fun set(index: Int, value: T)
|
||||||
internal abstract fun copy(): GslVector<T, H>
|
internal abstract fun copy(): GslVector<T, H>
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ import org.gnu.gsl.*
|
|||||||
internal class GslRealMatrix(
|
internal class GslRealMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix>,
|
override val rawNativeHandle: CPointer<gsl_matrix>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<Double, gsl_matrix>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Double, gsl_matrix>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -19,7 +20,8 @@ internal class GslRealMatrix(
|
|||||||
GslRealVector(
|
GslRealVector(
|
||||||
gsl_matrix_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Double>>
|
override val columns: Buffer<Buffer<Double>>
|
||||||
@ -27,7 +29,8 @@ internal class GslRealMatrix(
|
|||||||
GslRealVector(
|
GslRealVector(
|
||||||
gsl_matrix_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Double =
|
override operator fun get(i: Int, j: Int): Double =
|
||||||
@ -39,7 +42,7 @@ internal class GslRealMatrix(
|
|||||||
override fun copy(): GslRealMatrix {
|
override fun copy(): GslRealMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_memcpy(new, nativeHandle)
|
gsl_matrix_memcpy(new, nativeHandle)
|
||||||
return GslRealMatrix(new, scope)
|
return GslRealMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_free(nativeHandle)
|
||||||
@ -55,7 +58,8 @@ internal class GslRealMatrix(
|
|||||||
internal class GslFloatMatrix(
|
internal class GslFloatMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_float>,
|
override val rawNativeHandle: CPointer<gsl_matrix_float>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<Float, gsl_matrix_float>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Float, gsl_matrix_float>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -67,7 +71,8 @@ internal class GslFloatMatrix(
|
|||||||
GslFloatVector(
|
GslFloatVector(
|
||||||
gsl_matrix_float_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_float_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Float>>
|
override val columns: Buffer<Buffer<Float>>
|
||||||
@ -75,7 +80,8 @@ internal class GslFloatMatrix(
|
|||||||
GslFloatVector(
|
GslFloatVector(
|
||||||
gsl_matrix_float_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_float_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Float =
|
override operator fun get(i: Int, j: Int): Float =
|
||||||
@ -87,7 +93,7 @@ internal class GslFloatMatrix(
|
|||||||
override fun copy(): GslFloatMatrix {
|
override fun copy(): GslFloatMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_float_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_float_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_float_memcpy(new, nativeHandle)
|
gsl_matrix_float_memcpy(new, nativeHandle)
|
||||||
return GslFloatMatrix(new, scope)
|
return GslFloatMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_float_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_float_free(nativeHandle)
|
||||||
@ -103,7 +109,8 @@ internal class GslFloatMatrix(
|
|||||||
internal class GslShortMatrix(
|
internal class GslShortMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_short>,
|
override val rawNativeHandle: CPointer<gsl_matrix_short>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<Short, gsl_matrix_short>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Short, gsl_matrix_short>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -115,7 +122,8 @@ internal class GslShortMatrix(
|
|||||||
GslShortVector(
|
GslShortVector(
|
||||||
gsl_matrix_short_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_short_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Short>>
|
override val columns: Buffer<Buffer<Short>>
|
||||||
@ -123,7 +131,8 @@ internal class GslShortMatrix(
|
|||||||
GslShortVector(
|
GslShortVector(
|
||||||
gsl_matrix_short_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_short_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Short =
|
override operator fun get(i: Int, j: Int): Short =
|
||||||
@ -135,7 +144,7 @@ internal class GslShortMatrix(
|
|||||||
override fun copy(): GslShortMatrix {
|
override fun copy(): GslShortMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_short_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_short_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_short_memcpy(new, nativeHandle)
|
gsl_matrix_short_memcpy(new, nativeHandle)
|
||||||
return GslShortMatrix(new, scope)
|
return GslShortMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_short_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_short_free(nativeHandle)
|
||||||
@ -151,7 +160,8 @@ internal class GslShortMatrix(
|
|||||||
internal class GslUShortMatrix(
|
internal class GslUShortMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_ushort>,
|
override val rawNativeHandle: CPointer<gsl_matrix_ushort>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<UShort, gsl_matrix_ushort>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<UShort, gsl_matrix_ushort>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -163,7 +173,8 @@ internal class GslUShortMatrix(
|
|||||||
GslUShortVector(
|
GslUShortVector(
|
||||||
gsl_matrix_ushort_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_ushort_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<UShort>>
|
override val columns: Buffer<Buffer<UShort>>
|
||||||
@ -171,7 +182,8 @@ internal class GslUShortMatrix(
|
|||||||
GslUShortVector(
|
GslUShortVector(
|
||||||
gsl_matrix_ushort_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_ushort_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): UShort =
|
override operator fun get(i: Int, j: Int): UShort =
|
||||||
@ -183,7 +195,7 @@ internal class GslUShortMatrix(
|
|||||||
override fun copy(): GslUShortMatrix {
|
override fun copy(): GslUShortMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_ushort_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_ushort_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_ushort_memcpy(new, nativeHandle)
|
gsl_matrix_ushort_memcpy(new, nativeHandle)
|
||||||
return GslUShortMatrix(new, scope)
|
return GslUShortMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_ushort_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_ushort_free(nativeHandle)
|
||||||
@ -199,7 +211,8 @@ internal class GslUShortMatrix(
|
|||||||
internal class GslLongMatrix(
|
internal class GslLongMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_long>,
|
override val rawNativeHandle: CPointer<gsl_matrix_long>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<Long, gsl_matrix_long>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Long, gsl_matrix_long>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -211,7 +224,8 @@ internal class GslLongMatrix(
|
|||||||
GslLongVector(
|
GslLongVector(
|
||||||
gsl_matrix_long_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_long_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Long>>
|
override val columns: Buffer<Buffer<Long>>
|
||||||
@ -219,7 +233,8 @@ internal class GslLongMatrix(
|
|||||||
GslLongVector(
|
GslLongVector(
|
||||||
gsl_matrix_long_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_long_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Long =
|
override operator fun get(i: Int, j: Int): Long =
|
||||||
@ -231,7 +246,7 @@ internal class GslLongMatrix(
|
|||||||
override fun copy(): GslLongMatrix {
|
override fun copy(): GslLongMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_long_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_long_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_long_memcpy(new, nativeHandle)
|
gsl_matrix_long_memcpy(new, nativeHandle)
|
||||||
return GslLongMatrix(new, scope)
|
return GslLongMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_long_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_long_free(nativeHandle)
|
||||||
@ -247,7 +262,8 @@ internal class GslLongMatrix(
|
|||||||
internal class GslULongMatrix(
|
internal class GslULongMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_ulong>,
|
override val rawNativeHandle: CPointer<gsl_matrix_ulong>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<ULong, gsl_matrix_ulong>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<ULong, gsl_matrix_ulong>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -259,7 +275,8 @@ internal class GslULongMatrix(
|
|||||||
GslULongVector(
|
GslULongVector(
|
||||||
gsl_matrix_ulong_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_ulong_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<ULong>>
|
override val columns: Buffer<Buffer<ULong>>
|
||||||
@ -267,7 +284,8 @@ internal class GslULongMatrix(
|
|||||||
GslULongVector(
|
GslULongVector(
|
||||||
gsl_matrix_ulong_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_ulong_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): ULong =
|
override operator fun get(i: Int, j: Int): ULong =
|
||||||
@ -279,7 +297,7 @@ internal class GslULongMatrix(
|
|||||||
override fun copy(): GslULongMatrix {
|
override fun copy(): GslULongMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_ulong_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_ulong_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_ulong_memcpy(new, nativeHandle)
|
gsl_matrix_ulong_memcpy(new, nativeHandle)
|
||||||
return GslULongMatrix(new, scope)
|
return GslULongMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_ulong_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_ulong_free(nativeHandle)
|
||||||
@ -295,7 +313,8 @@ internal class GslULongMatrix(
|
|||||||
internal class GslIntMatrix(
|
internal class GslIntMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_int>,
|
override val rawNativeHandle: CPointer<gsl_matrix_int>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<Int, gsl_matrix_int>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<Int, gsl_matrix_int>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -307,7 +326,8 @@ internal class GslIntMatrix(
|
|||||||
GslIntVector(
|
GslIntVector(
|
||||||
gsl_matrix_int_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_int_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<Int>>
|
override val columns: Buffer<Buffer<Int>>
|
||||||
@ -315,7 +335,8 @@ internal class GslIntMatrix(
|
|||||||
GslIntVector(
|
GslIntVector(
|
||||||
gsl_matrix_int_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_int_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Int =
|
override operator fun get(i: Int, j: Int): Int =
|
||||||
@ -327,7 +348,7 @@ internal class GslIntMatrix(
|
|||||||
override fun copy(): GslIntMatrix {
|
override fun copy(): GslIntMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_int_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_int_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_int_memcpy(new, nativeHandle)
|
gsl_matrix_int_memcpy(new, nativeHandle)
|
||||||
return GslIntMatrix(new, scope)
|
return GslIntMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_int_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_int_free(nativeHandle)
|
||||||
@ -343,7 +364,8 @@ internal class GslIntMatrix(
|
|||||||
internal class GslUIntMatrix(
|
internal class GslUIntMatrix(
|
||||||
override val rawNativeHandle: CPointer<gsl_matrix_uint>,
|
override val rawNativeHandle: CPointer<gsl_matrix_uint>,
|
||||||
scope: AutofreeScope,
|
scope: AutofreeScope,
|
||||||
) : GslMatrix<UInt, gsl_matrix_uint>(scope) {
|
owned: Boolean,
|
||||||
|
) : GslMatrix<UInt, gsl_matrix_uint>(scope, owned) {
|
||||||
override val rowNum: Int
|
override val rowNum: Int
|
||||||
get() = nativeHandle.pointed.size1.toInt()
|
get() = nativeHandle.pointed.size1.toInt()
|
||||||
|
|
||||||
@ -355,7 +377,8 @@ internal class GslUIntMatrix(
|
|||||||
GslUIntVector(
|
GslUIntVector(
|
||||||
gsl_matrix_uint_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_uint_row(nativeHandle, r.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val columns: Buffer<Buffer<UInt>>
|
override val columns: Buffer<Buffer<UInt>>
|
||||||
@ -363,7 +386,8 @@ internal class GslUIntMatrix(
|
|||||||
GslUIntVector(
|
GslUIntVector(
|
||||||
gsl_matrix_uint_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
gsl_matrix_uint_column(nativeHandle, c.toULong()).placeTo(scope).pointed.vector.ptr,
|
||||||
scope,
|
scope,
|
||||||
).apply { shouldBeFreed = false }
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): UInt =
|
override operator fun get(i: Int, j: Int): UInt =
|
||||||
@ -375,7 +399,7 @@ internal class GslUIntMatrix(
|
|||||||
override fun copy(): GslUIntMatrix {
|
override fun copy(): GslUIntMatrix {
|
||||||
val new = checkNotNull(gsl_matrix_uint_alloc(rowNum.toULong(), colNum.toULong()))
|
val new = checkNotNull(gsl_matrix_uint_alloc(rowNum.toULong(), colNum.toULong()))
|
||||||
gsl_matrix_uint_memcpy(new, nativeHandle)
|
gsl_matrix_uint_memcpy(new, nativeHandle)
|
||||||
return GslUIntMatrix(new, scope)
|
return GslUIntMatrix(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close(): Unit = gsl_matrix_uint_free(nativeHandle)
|
override fun close(): Unit = gsl_matrix_uint_free(nativeHandle)
|
||||||
|
@ -3,21 +3,19 @@ package kscience.kmath.gsl
|
|||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import org.gnu.gsl.*
|
import org.gnu.gsl.*
|
||||||
|
|
||||||
internal class GslRealVector(override val rawNativeHandle: CPointer<gsl_vector>, scope: AutofreeScope) :
|
internal class GslRealVector(
|
||||||
GslVector<Double, gsl_vector>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Double, gsl_vector>(scope, owned) {
|
||||||
override operator fun get(index: Int): Double =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): Double = gsl_vector_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: Double): Unit = gsl_vector_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: Double): Unit =
|
|
||||||
gsl_vector_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslRealVector {
|
override fun copy(): GslRealVector {
|
||||||
val new = checkNotNull(gsl_vector_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_alloc(size.toULong()))
|
||||||
gsl_vector_memcpy(new, nativeHandle)
|
gsl_vector_memcpy(new, nativeHandle)
|
||||||
return GslRealVector(new, scope)
|
return GslRealVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -30,21 +28,19 @@ internal class GslRealVector(override val rawNativeHandle: CPointer<gsl_vector>,
|
|||||||
override fun close(): Unit = gsl_vector_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslFloatVector(override val rawNativeHandle: CPointer<gsl_vector_float>, scope: AutofreeScope) :
|
internal class GslFloatVector(
|
||||||
GslVector<Float, gsl_vector_float>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_float>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Float, gsl_vector_float>(scope, owned) {
|
||||||
override operator fun get(index: Int): Float =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_float_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): Float = gsl_vector_float_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: Float): Unit = gsl_vector_float_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: Float): Unit =
|
|
||||||
gsl_vector_float_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslFloatVector {
|
override fun copy(): GslFloatVector {
|
||||||
val new = checkNotNull(gsl_vector_float_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_float_alloc(size.toULong()))
|
||||||
gsl_vector_float_memcpy(new, nativeHandle)
|
gsl_vector_float_memcpy(new, nativeHandle)
|
||||||
return GslFloatVector(new, scope)
|
return GslFloatVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -57,21 +53,19 @@ internal class GslFloatVector(override val rawNativeHandle: CPointer<gsl_vector_
|
|||||||
override fun close(): Unit = gsl_vector_float_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_float_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslShortVector(override val rawNativeHandle: CPointer<gsl_vector_short>, scope: AutofreeScope) :
|
internal class GslShortVector(
|
||||||
GslVector<Short, gsl_vector_short>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_short>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Short, gsl_vector_short>(scope, owned) {
|
||||||
override operator fun get(index: Int): Short =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_short_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): Short = gsl_vector_short_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: Short): Unit = gsl_vector_short_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: Short): Unit =
|
|
||||||
gsl_vector_short_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslShortVector {
|
override fun copy(): GslShortVector {
|
||||||
val new = checkNotNull(gsl_vector_short_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_short_alloc(size.toULong()))
|
||||||
gsl_vector_short_memcpy(new, nativeHandle)
|
gsl_vector_short_memcpy(new, nativeHandle)
|
||||||
return GslShortVector(new, scope)
|
return GslShortVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -84,21 +78,19 @@ internal class GslShortVector(override val rawNativeHandle: CPointer<gsl_vector_
|
|||||||
override fun close(): Unit = gsl_vector_short_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_short_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslUShortVector(override val rawNativeHandle: CPointer<gsl_vector_ushort>, scope: AutofreeScope) :
|
internal class GslUShortVector(
|
||||||
GslVector<UShort, gsl_vector_ushort>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_ushort>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<UShort, gsl_vector_ushort>(scope, owned) {
|
||||||
override operator fun get(index: Int): UShort =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_ushort_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): UShort = gsl_vector_ushort_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: UShort): Unit = gsl_vector_ushort_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: UShort): Unit =
|
|
||||||
gsl_vector_ushort_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslUShortVector {
|
override fun copy(): GslUShortVector {
|
||||||
val new = checkNotNull(gsl_vector_ushort_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_ushort_alloc(size.toULong()))
|
||||||
gsl_vector_ushort_memcpy(new, nativeHandle)
|
gsl_vector_ushort_memcpy(new, nativeHandle)
|
||||||
return GslUShortVector(new, scope)
|
return GslUShortVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -111,21 +103,19 @@ internal class GslUShortVector(override val rawNativeHandle: CPointer<gsl_vector
|
|||||||
override fun close(): Unit = gsl_vector_ushort_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_ushort_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslLongVector(override val rawNativeHandle: CPointer<gsl_vector_long>, scope: AutofreeScope) :
|
internal class GslLongVector(
|
||||||
GslVector<Long, gsl_vector_long>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_long>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Long, gsl_vector_long>(scope, owned) {
|
||||||
override operator fun get(index: Int): Long =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_long_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): Long = gsl_vector_long_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: Long): Unit = gsl_vector_long_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: Long): Unit =
|
|
||||||
gsl_vector_long_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslLongVector {
|
override fun copy(): GslLongVector {
|
||||||
val new = checkNotNull(gsl_vector_long_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_long_alloc(size.toULong()))
|
||||||
gsl_vector_long_memcpy(new, nativeHandle)
|
gsl_vector_long_memcpy(new, nativeHandle)
|
||||||
return GslLongVector(new, scope)
|
return GslLongVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -138,21 +128,19 @@ internal class GslLongVector(override val rawNativeHandle: CPointer<gsl_vector_l
|
|||||||
override fun close(): Unit = gsl_vector_long_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_long_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslULongVector(override val rawNativeHandle: CPointer<gsl_vector_ulong>, scope: AutofreeScope) :
|
internal class GslULongVector(
|
||||||
GslVector<ULong, gsl_vector_ulong>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_ulong>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<ULong, gsl_vector_ulong>(scope, owned) {
|
||||||
override operator fun get(index: Int): ULong =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_ulong_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): ULong = gsl_vector_ulong_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: ULong): Unit = gsl_vector_ulong_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: ULong): Unit =
|
|
||||||
gsl_vector_ulong_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslULongVector {
|
override fun copy(): GslULongVector {
|
||||||
val new = checkNotNull(gsl_vector_ulong_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_ulong_alloc(size.toULong()))
|
||||||
gsl_vector_ulong_memcpy(new, nativeHandle)
|
gsl_vector_ulong_memcpy(new, nativeHandle)
|
||||||
return GslULongVector(new, scope)
|
return GslULongVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -165,21 +153,19 @@ internal class GslULongVector(override val rawNativeHandle: CPointer<gsl_vector_
|
|||||||
override fun close(): Unit = gsl_vector_ulong_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_ulong_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslIntVector(override val rawNativeHandle: CPointer<gsl_vector_int>, scope: AutofreeScope) :
|
internal class GslIntVector(
|
||||||
GslVector<Int, gsl_vector_int>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_int>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<Int, gsl_vector_int>(scope, owned) {
|
||||||
override operator fun get(index: Int): Int =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_int_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): Int = gsl_vector_int_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: Int): Unit = gsl_vector_int_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: Int): Unit =
|
|
||||||
gsl_vector_int_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslIntVector {
|
override fun copy(): GslIntVector {
|
||||||
val new = checkNotNull(gsl_vector_int_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_int_alloc(size.toULong()))
|
||||||
gsl_vector_int_memcpy(new, nativeHandle)
|
gsl_vector_int_memcpy(new, nativeHandle)
|
||||||
return GslIntVector(new, scope)
|
return GslIntVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -192,21 +178,19 @@ internal class GslIntVector(override val rawNativeHandle: CPointer<gsl_vector_in
|
|||||||
override fun close(): Unit = gsl_vector_int_free(nativeHandle)
|
override fun close(): Unit = gsl_vector_int_free(nativeHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GslUIntVector(override val rawNativeHandle: CPointer<gsl_vector_uint>, scope: AutofreeScope) :
|
internal class GslUIntVector(
|
||||||
GslVector<UInt, gsl_vector_uint>(scope) {
|
override val rawNativeHandle: CPointer<gsl_vector_uint>,
|
||||||
override val size: Int
|
scope: AutofreeScope,
|
||||||
get() = nativeHandle.pointed.size.toInt()
|
owned: Boolean,
|
||||||
|
) : GslVector<UInt, gsl_vector_uint>(scope, owned) {
|
||||||
override operator fun get(index: Int): UInt =
|
override val size: Int get() = nativeHandle.pointed.size.toInt()
|
||||||
gsl_vector_uint_get(nativeHandle, index.toULong())
|
override operator fun get(index: Int): UInt = gsl_vector_uint_get(nativeHandle, index.toULong())
|
||||||
|
override operator fun set(index: Int, value: UInt): Unit = gsl_vector_uint_set(nativeHandle, index.toULong(), value)
|
||||||
override operator fun set(index: Int, value: UInt): Unit =
|
|
||||||
gsl_vector_uint_set(nativeHandle, index.toULong(), value)
|
|
||||||
|
|
||||||
override fun copy(): GslUIntVector {
|
override fun copy(): GslUIntVector {
|
||||||
val new = checkNotNull(gsl_vector_uint_alloc(size.toULong()))
|
val new = checkNotNull(gsl_vector_uint_alloc(size.toULong()))
|
||||||
gsl_vector_uint_memcpy(new, nativeHandle)
|
gsl_vector_uint_memcpy(new, nativeHandle)
|
||||||
return GslUIntVector(new, scope)
|
return GslUIntVector(new, scope, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package kscience.kmath.gsl
|
package kscience.kmath.gsl
|
||||||
|
|
||||||
|
import kscience.kmath.linear.Matrix
|
||||||
import kscience.kmath.linear.RealMatrixContext
|
import kscience.kmath.linear.RealMatrixContext
|
||||||
import kscience.kmath.operations.invoke
|
import kscience.kmath.operations.invoke
|
||||||
import kscience.kmath.structures.Matrix
|
|
||||||
import kscience.kmath.structures.asIterable
|
import kscience.kmath.structures.asIterable
|
||||||
import kscience.kmath.structures.toList
|
import kscience.kmath.structures.toList
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package kscience.kmath.gsl
|
package kscience.kmath.gsl
|
||||||
|
|
||||||
|
import kscience.kmath.linear.Matrix
|
||||||
import kscience.kmath.linear.RealMatrixContext
|
import kscience.kmath.linear.RealMatrixContext
|
||||||
import kscience.kmath.operations.invoke
|
import kscience.kmath.operations.invoke
|
||||||
import kscience.kmath.structures.Matrix
|
|
||||||
import kscience.kmath.structures.RealBuffer
|
import kscience.kmath.structures.RealBuffer
|
||||||
import kscience.kmath.structures.asSequence
|
import kscience.kmath.structures.asSequence
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
Loading…
Reference in New Issue
Block a user