From 956fe9b9e6ff904938a3d120e4f85fd149ec45fd Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Sun, 11 Oct 2020 01:21:10 +0700 Subject: [PATCH] Track generated code --- .../kotlin/kscience/kmath/gsl/_Matrices.kt | 278 ++++++++++++++++++ .../kotlin/kscience/kmath/gsl/_Vectors.kt | 173 +++++++++++ 2 files changed, 451 insertions(+) create mode 100644 kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Matrices.kt create mode 100644 kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Vectors.kt diff --git a/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Matrices.kt b/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Matrices.kt new file mode 100644 index 000000000..06a9eb75e --- /dev/null +++ b/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Matrices.kt @@ -0,0 +1,278 @@ +package kscience.kmath.gsl + +import kotlinx.cinterop.* +import kscience.kmath.linear.* +import org.gnu.gsl.* + +internal class GslRealMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslRealMatrix = + GslRealMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): Double = gsl_matrix_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: Double): Unit = + gsl_matrix_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslRealMatrix { + val new = requireNotNull(gsl_matrix_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_memcpy(new, nativeHandle) + return GslRealMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslRealMatrix) return gsl_matrix_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslFloatMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslFloatMatrix = + GslFloatMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): Float = gsl_matrix_float_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: Float): Unit = + gsl_matrix_float_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslFloatMatrix { + val new = requireNotNull(gsl_matrix_float_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_float_memcpy(new, nativeHandle) + return GslFloatMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_float_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslFloatMatrix) return gsl_matrix_float_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslShortMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslShortMatrix = + GslShortMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): Short = gsl_matrix_short_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: Short): Unit = + gsl_matrix_short_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslShortMatrix { + val new = requireNotNull(gsl_matrix_short_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_short_memcpy(new, nativeHandle) + return GslShortMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_short_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslShortMatrix) return gsl_matrix_short_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslUShortMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslUShortMatrix = + GslUShortMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): UShort = gsl_matrix_ushort_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: UShort): Unit = + gsl_matrix_ushort_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslUShortMatrix { + val new = requireNotNull(gsl_matrix_ushort_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_ushort_memcpy(new, nativeHandle) + return GslUShortMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_ushort_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslUShortMatrix) return gsl_matrix_ushort_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslLongMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslLongMatrix = + GslLongMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): Long = gsl_matrix_long_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: Long): Unit = + gsl_matrix_long_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslLongMatrix { + val new = requireNotNull(gsl_matrix_long_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_long_memcpy(new, nativeHandle) + return GslLongMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_long_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslLongMatrix) return gsl_matrix_long_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslULongMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslULongMatrix = + GslULongMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): ULong = gsl_matrix_ulong_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: ULong): Unit = + gsl_matrix_ulong_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslULongMatrix { + val new = requireNotNull(gsl_matrix_ulong_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_ulong_memcpy(new, nativeHandle) + return GslULongMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_ulong_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslULongMatrix) return gsl_matrix_ulong_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslIntMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslIntMatrix = + GslIntMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): Int = gsl_matrix_int_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: Int): Unit = + gsl_matrix_int_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslIntMatrix { + val new = requireNotNull(gsl_matrix_int_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_int_memcpy(new, nativeHandle) + return GslIntMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_int_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslIntMatrix) return gsl_matrix_int_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + +internal class GslUIntMatrix( + override val nativeHandle: CPointer, + features: Set = emptySet() +) : GslMatrix() { + override val rowNum: Int + get() = nativeHandle.pointed.size1.toInt() + + override val colNum: Int + get() = nativeHandle.pointed.size2.toInt() + + override val features: Set = features + + override fun suggestFeature(vararg features: MatrixFeature): GslUIntMatrix = + GslUIntMatrix(nativeHandle, this.features + features) + + override operator fun get(i: Int, j: Int): UInt = gsl_matrix_uint_get(nativeHandle, i.toULong(), j.toULong()) + + override operator fun set(i: Int, j: Int, value: UInt): Unit = + gsl_matrix_uint_set(nativeHandle, i.toULong(), j.toULong(), value) + + override fun copy(): GslUIntMatrix { + val new = requireNotNull(gsl_matrix_uint_alloc(rowNum.toULong(), colNum.toULong())) + gsl_matrix_uint_memcpy(new, nativeHandle) + return GslUIntMatrix(new, features) + } + + override fun close(): Unit = gsl_matrix_uint_free(nativeHandle) + + override fun equals(other: Any?): Boolean { + if (other is GslUIntMatrix) return gsl_matrix_uint_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } +} + diff --git a/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Vectors.kt b/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Vectors.kt new file mode 100644 index 000000000..918fca825 --- /dev/null +++ b/kmath-gsl/src/nativeMain/kotlin/kscience/kmath/gsl/_Vectors.kt @@ -0,0 +1,173 @@ +package kscience.kmath.gsl + +import kotlinx.cinterop.* +import org.gnu.gsl.* + +internal class GslRealVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): Double = gsl_vector_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: Double): Unit = gsl_vector_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslRealVector { + val new = requireNotNull(gsl_vector_alloc(size.toULong())) + gsl_vector_memcpy(new, nativeHandle) + return GslRealVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslRealVector) return gsl_vector_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_free(nativeHandle) +} + +internal class GslFloatVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): Float = gsl_vector_float_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: Float): Unit = gsl_vector_float_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslFloatVector { + val new = requireNotNull(gsl_vector_float_alloc(size.toULong())) + gsl_vector_float_memcpy(new, nativeHandle) + return GslFloatVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslFloatVector) return gsl_vector_float_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_float_free(nativeHandle) +} + +internal class GslShortVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): Short = gsl_vector_short_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: Short): Unit = gsl_vector_short_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslShortVector { + val new = requireNotNull(gsl_vector_short_alloc(size.toULong())) + gsl_vector_short_memcpy(new, nativeHandle) + return GslShortVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslShortVector) return gsl_vector_short_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_short_free(nativeHandle) +} + +internal class GslUShortVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): UShort = gsl_vector_ushort_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: UShort): Unit = gsl_vector_ushort_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslUShortVector { + val new = requireNotNull(gsl_vector_ushort_alloc(size.toULong())) + gsl_vector_ushort_memcpy(new, nativeHandle) + return GslUShortVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslUShortVector) return gsl_vector_ushort_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_ushort_free(nativeHandle) +} + +internal class GslLongVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): Long = gsl_vector_long_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: Long): Unit = gsl_vector_long_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslLongVector { + val new = requireNotNull(gsl_vector_long_alloc(size.toULong())) + gsl_vector_long_memcpy(new, nativeHandle) + return GslLongVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslLongVector) return gsl_vector_long_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_long_free(nativeHandle) +} + +internal class GslULongVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): ULong = gsl_vector_ulong_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: ULong): Unit = gsl_vector_ulong_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslULongVector { + val new = requireNotNull(gsl_vector_ulong_alloc(size.toULong())) + gsl_vector_ulong_memcpy(new, nativeHandle) + return GslULongVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslULongVector) return gsl_vector_ulong_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_ulong_free(nativeHandle) +} + +internal class GslIntVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): Int = gsl_vector_int_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: Int): Unit = gsl_vector_int_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslIntVector { + val new = requireNotNull(gsl_vector_int_alloc(size.toULong())) + gsl_vector_int_memcpy(new, nativeHandle) + return GslIntVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslIntVector) return gsl_vector_int_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_int_free(nativeHandle) +} + +internal class GslUIntVector(override val nativeHandle: CPointer) : GslVector() { + override val size: Int + get() = nativeHandle.pointed.size.toInt() + + override fun get(index: Int): UInt = gsl_vector_uint_get(nativeHandle, index.toULong()) + override fun set(index: Int, value: UInt): Unit = gsl_vector_uint_set(nativeHandle, index.toULong(), value) + + override fun copy(): GslUIntVector { + val new = requireNotNull(gsl_vector_uint_alloc(size.toULong())) + gsl_vector_uint_memcpy(new, nativeHandle) + return GslUIntVector(new) + } + + override fun equals(other: Any?): Boolean { + if (other is GslUIntVector) return gsl_vector_uint_equal(nativeHandle, other.nativeHandle) == 1 + return super.equals(other) + } + + override fun close(): Unit = gsl_vector_uint_free(nativeHandle) +} +