Fix GSL matrix context

This commit is contained in:
Iaroslav Postovalov 2020-12-02 10:12:33 +07:00
parent 0e8f6e29ee
commit f46826f2b1
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7

View File

@ -19,10 +19,9 @@ internal inline fun <T : Any, H : CStructVar> GslMatrix<T, H>.fill(initializer:
internal inline fun <T : Any, H : CStructVar> GslVector<T, H>.fill(initializer: (Int) -> T): GslVector<T, H> = internal inline fun <T : Any, H : CStructVar> GslVector<T, H>.fill(initializer: (Int) -> T): GslVector<T, H> =
apply { (0 until size).forEach { index -> this[index] = initializer(index) } } apply { (0 until size).forEach { index -> this[index] = initializer(index) } }
public abstract class GslMatrixContext< public abstract class GslMatrixContext<T : Any, H1 : CStructVar, H2 : CStructVar> internal constructor(
T : Any, internal val scope: DeferScope
H1 : CStructVar, ) : MatrixContext<T, GslMatrix<T, H1>> {
H2 : CStructVar> internal constructor(internal val scope: DeferScope) : MatrixContext<T> {
init { init {
ensureHasGslErrorHandler() ensureHasGslErrorHandler()
} }
@ -46,7 +45,10 @@ public abstract class GslMatrixContext<
public class GslRealMatrixContext(scope: DeferScope) : GslMatrixContext<Double, gsl_matrix, gsl_vector>(scope) { public class GslRealMatrixContext(scope: DeferScope) : GslMatrixContext<Double, gsl_matrix, gsl_vector>(scope) {
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Double, gsl_matrix> = override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Double, gsl_matrix> =
GslRealMatrix(nativeHandle = requireNotNull(gsl_matrix_alloc(rows.toULong(), columns.toULong())), scope = scope) GslRealMatrix(
nativeHandle = requireNotNull(gsl_matrix_alloc(rows.toULong(), columns.toULong())),
scope = scope
)
override fun produceDirtyVector(size: Int): GslVector<Double, gsl_vector> = override fun produceDirtyVector(size: Int): GslVector<Double, gsl_vector> =
GslRealVector(nativeHandle = requireNotNull(gsl_vector_alloc(size.toULong())), scope = scope) GslRealVector(nativeHandle = requireNotNull(gsl_vector_alloc(size.toULong())), scope = scope)
@ -131,7 +133,8 @@ public class GslFloatMatrixContext(scope: DeferScope) :
public class GslComplexMatrixContext(scope: DeferScope) : public class GslComplexMatrixContext(scope: DeferScope) :
GslMatrixContext<Complex, gsl_matrix_complex, gsl_vector_complex>(scope) { GslMatrixContext<Complex, gsl_matrix_complex, gsl_vector_complex>(scope) {
override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Complex, gsl_matrix_complex> = GslComplexMatrix( override fun produceDirtyMatrix(rows: Int, columns: Int): GslMatrix<Complex, gsl_matrix_complex> =
GslComplexMatrix(
nativeHandle = requireNotNull(gsl_matrix_complex_alloc(rows.toULong(), columns.toULong())), nativeHandle = requireNotNull(gsl_matrix_complex_alloc(rows.toULong(), columns.toULong())),
scope = scope scope = scope
) )