Don't print 0 order

This commit is contained in:
Roland Grinis 2021-04-16 11:58:42 +01:00
parent baa303171e
commit 1e7cf39150
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -46,4 +46,10 @@ class TestDoubleTensor {
assertEquals(secondRow[1], secondColumn[1])
}
}
@Test
fun toStringTest() = DoubleTensorAlgebra {
val tensor = randNormal(intArrayOf(2,3))
println(tensor)
}
}