From dde1db7b0afa27162988fcb1b3543afe6187a4d6 Mon Sep 17 00:00:00 2001 From: Andrei Kislitsyn Date: Fri, 7 May 2021 23:05:37 +0300 Subject: [PATCH] fixes --- .../kmath/tensors/core/tensorCasts.kt | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorCasts.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorCasts.kt index 921bcf97e..4e43ed1e1 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorCasts.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorCasts.kt @@ -9,17 +9,17 @@ import space.kscience.kmath.tensors.api.Tensor import space.kscience.kmath.tensors.core.internal.tensor /** - * Casts [Tensor] to [DoubleTensor] + * Casts [Tensor] iof [Double] to [DoubleTensor] */ public fun Tensor.toDoubleTensor(): DoubleTensor = this.tensor /** - * Casts [Tensor] to [IntTensor] + * Casts [Tensor] iof [Int] to [IntTensor] */ public fun Tensor.toIntTensor(): IntTensor = this.tensor /** - * @return [DoubleArray] of tensor elements + * Returns [DoubleArray] of tensor elements */ public fun DoubleTensor.toDoubleArray(): DoubleArray { return DoubleArray(numElements) { i -> @@ -28,42 +28,10 @@ public fun DoubleTensor.toDoubleArray(): DoubleArray { } /** - * @return [IntArray] of tensor elements + * Returns [IntArray] of tensor elements */ public fun IntTensor.toIntArray(): IntArray { return IntArray(numElements) { i -> mutableBuffer[bufferStart + i] } } - -/** - * Casts [Array] to [DoubleTensor] - */ -public fun Array.toDoubleTensor(): DoubleTensor { - val n = size - check(n > 0) { "An empty array cannot be casted to tensor" } - val m = first().size - check(m > 0) { "Inner arrays must have at least 1 argument" } - check(all { size == m }) { "Inner arrays must be the same size" } - - val shape = intArrayOf(n, m) - val buffer = this.flatMap { arr -> arr.map { it } }.toDoubleArray() - - return DoubleTensor(shape, buffer, 0) -} - -/** - * Casts [Array] to [IntTensor] - */ -public fun Array.toIntTensor(): IntTensor { - val n = size - check(n > 0) { "An empty array cannot be casted to tensor" } - val m = first().size - check(m > 0) { "Inner arrays must have at least 1 argument" } - check(all { size == m }) { "Inner arrays must be the same size" } - - val shape = intArrayOf(n, m) - val buffer = this.flatMap { arr -> arr.map { it } }.toIntArray() - - return IntTensor(shape, buffer, 0) -}