Viktor prototype with compiler bug

This commit is contained in:
Alexander Nozik 2019-12-08 17:25:36 +03:00
parent f9836a6477
commit cbac4fca33
2 changed files with 32 additions and 13 deletions

View File

@ -13,6 +13,12 @@ fun main() {
val viktorField = ViktorNDField(intArrayOf(dim, dim))
autoField.run {
var res = one
repeat(n/2) {
res += 1.0
}
}
measureAndPrint("Automatic field addition") {
autoField.run {
@ -23,6 +29,22 @@ fun main() {
}
}
viktorField.run {
var res = one
repeat(n/2) {
res += one
}
}
measureAndPrint("Viktor field addition") {
viktorField.run {
var res = one
repeat(n) {
res += one
}
}
}
measureAndPrint("Raw Viktor") {
val one = F64Array.full(init = 1.0, shape = *intArrayOf(dim, dim))
var res = one
@ -30,13 +52,4 @@ fun main() {
res = res + one
}
}
measureAndPrint("Viktor field addition") {
viktorField.run {
var res = one
repeat(n) {
res += 1.0
}
}
}
}

View File

@ -65,9 +65,15 @@ class ViktorNDField(override val shape: IntArray) : NDField<Double, RealField, V
}
}.asStructure()
override fun ViktorNDStructure.plus(b: ViktorNDStructure): ViktorNDStructure =
(f64Buffer + b.f64Buffer).asStructure()
override fun ViktorNDStructure.minus(b: ViktorNDStructure): ViktorNDStructure =
(f64Buffer - b.f64Buffer).asStructure()
override fun add(a: ViktorNDStructure, b: ViktorNDStructure): ViktorNDStructure {
return (a.f64Buffer + b.f64Buffer).asStructure()
}
// override inline fun ViktorNDStructure.plus(b: ViktorNDStructure): ViktorNDStructure {
// return (f64Buffer + b.f64Buffer).asStructure()
// }
override fun multiply(a: ViktorNDStructure, k: Number): ViktorNDStructure {
return (a.f64Buffer * k.toDouble()).asStructure()
}
}