Skip to content

A lightweight library to calculate tensors in Kotlin, which has similar APIs to TensorFlow's

License

Notifications You must be signed in to change notification settings

ddenton/tensor-kotlin

 
 

Repository files navigation

TensorKotlin

TensorKotlin is a lightweight library to calculate tensors, which has similar APIs to TensorFlow's. TensorKotlin is useful to simulate calculating tensors in Kotlin using models trained by TensorFlow.

val a = Tensor(Shape(2, 3), floatArrayOf(1, 2, 3, 4, 5, 6)) // [[1, 2, 3], [4, 5, 6]]
val b = Tensor(Shape(2, 3), floatArrayOf(7, 8, 9, 10, 11, 12)) // [[7, 8, 9], 10, 11, 12]]

val x = a[1, 2] // 6.0f
val sub = a[0..1, 1..2] // [[2, 3], [5, 6]]

val sum = a + b // [[8, 10, 12], [14, 16, 18]]
val mul = a * b // [[7, 16, 27], [40, 55, 72]]

val c = Tensor(Shape(3, 1), floatArrayOf(7, 8, 9)) // [[7], [8], [9]]
val matmul = a.matmul(c) // [[50], [122]]

val zeros = Tensor(Shape(2, 3, 4))
val ones = Tensor(Shape(2, 3, 4), 1.0f)

License

The MIT License

About

A lightweight library to calculate tensors in Kotlin, which has similar APIs to TensorFlow's

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%