TCore β€” NumPy in Roblox

TCore is a comprehensive library filled with various tensor manipulation functions, complete with element-wise operations, broadcasting, and shape manipulation.

TCore at its core uses buffers to store the tensor data, which ensures that it consumes less memory than a table.

:envelope_with_arrow: Installation

TCore is currently only available on Wally:

tcore = "artzified/tcore@1.8.1"

Or you could check out the github repository:

:black_nib: Example Usage

local TCore = require(...)

-- matrices
local t1 = TCore.randNum({100, 100})
local t2 = TCore.randNum({100, 100})

local result = TCore.matMul(t1, t2)
TCore.print(result)

:memo: List of Supported Functions

  • readElement
  • writeElement
  • create
  • zeros
  • ones
  • randInt
  • randNum
  • add
  • subtract
  • multiply
  • divide
  • scale
  • sum
  • matMul
  • reshape
  • flatten
  • mean
  • variance
  • std
  • minMaxNormalize
  • zScoreNormalize
  • argmax
  • print
  • transpose
  • toFlatArray
  • toNestedTable
  • elementWiseOperation
  • map
  • fromNestedTable
  • convertToTensorIfAppropriate

:chains: Limitations

Due to roblox’s buffer limitations, it can only store 1 GiB or 1073741824 bytes (134217728 float64 elements). In addition to that, the precision is only up to 64 bits.

:gear: Performance

Specs: Intel(R) Coreβ„’ i7-4770k CPU @ 3.50GHz, 3501Mhz

  • zeros({999, 999, 99}) β†’ 0.2-0.4s
  • randNum({999, 999, 99}) β†’ 8-9s
  • matMul(t1, t2) β†’ ~5s (699x699 dimensions)

:spiral_notepad: Notes

I made this with the sole purpose of pairing with my machine learning library, but decided to publish it. I tried to make it as performant as possible but roblox really limited the usability and scalability of it. Tried to parallelize it but the parallelism system is really funky to be worth implementing.

3 Likes