KMP library for tensors #300

Merged
grinisrit merged 215 commits from feature/tensor-algebra into dev 2021-05-08 09:48:04 +03:00
2 changed files with 9 additions and 3 deletions
Showing only changes of commit 1e7cf39150 - Show all commits

View File

@ -71,8 +71,8 @@ internal inline fun format(value: Double, digits: Int = 4): String {
val lead = value / ten.pow(order) val lead = value / ten.pow(order)
val leadDisplay = round(lead*ten.pow(digits)) / ten.pow(digits) val leadDisplay = round(lead*ten.pow(digits)) / ten.pow(digits)
val orderDisplay = if(order >= 0) "+$order" else "$order" val orderDisplay = if(order == 0) "" else if(order > 0) "E+$order" else "E$order"
val valueDisplay = "${leadDisplay}E$orderDisplay" val valueDisplay = "${leadDisplay}$orderDisplay"
val res = if(value < 0.0) valueDisplay else " $valueDisplay" val res = if(value < 0.0) valueDisplay else " $valueDisplay"
val fLength = digits + 6 val fLength = digits + 6
val endSpace = " ".repeat(fLength - res.length) val endSpace = " ".repeat(fLength - res.length)
@ -83,7 +83,7 @@ internal inline fun DoubleTensor.toPrettyString(): String = buildString {
var offset = 0 var offset = 0
val shape = this@toPrettyString.shape val shape = this@toPrettyString.shape
val linearStructure = this@toPrettyString.linearStructure val linearStructure = this@toPrettyString.linearStructure
var vectorSize = shape.last() val vectorSize = shape.last()
val initString = "DoubleTensor(\n" val initString = "DoubleTensor(\n"
append(initString) append(initString)
var charOffset = 3 var charOffset = 3

View File

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