From 1e7cf39150be8393acd0f24572d0a1a93ef87e15 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Fri, 16 Apr 2021 11:58:42 +0100 Subject: [PATCH] Don't print 0 order --- .../kotlin/space/kscience/kmath/tensors/core/utils.kt | 6 +++--- .../space/kscience/kmath/tensors/core/TestDoubleTensor.kt | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt index daab79016..40d40b593 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt @@ -71,8 +71,8 @@ internal inline fun format(value: Double, digits: Int = 4): String { val lead = value / ten.pow(order) val leadDisplay = round(lead*ten.pow(digits)) / ten.pow(digits) - val orderDisplay = if(order >= 0) "+$order" else "$order" - val valueDisplay = "${leadDisplay}E$orderDisplay" + val orderDisplay = if(order == 0) "" else if(order > 0) "E+$order" else "E$order" + val valueDisplay = "${leadDisplay}$orderDisplay" val res = if(value < 0.0) valueDisplay else " $valueDisplay" val fLength = digits + 6 val endSpace = " ".repeat(fLength - res.length) @@ -83,7 +83,7 @@ internal inline fun DoubleTensor.toPrettyString(): String = buildString { var offset = 0 val shape = this@toPrettyString.shape val linearStructure = this@toPrettyString.linearStructure - var vectorSize = shape.last() + val vectorSize = shape.last() val initString = "DoubleTensor(\n" append(initString) var charOffset = 3 diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt index 4f4d9bbdf..ddcf0369c 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt @@ -46,4 +46,10 @@ class TestDoubleTensor { assertEquals(secondRow[1], secondColumn[1]) } } + + @Test + fun toStringTest() = DoubleTensorAlgebra { + val tensor = randNormal(intArrayOf(2,3)) + println(tensor) + } } \ No newline at end of file