Skip to content

[inferno-ml] Make asTensor* and asArray* functions polymorphic - #187

Open
ngua wants to merge 8 commits into
mainfrom
rory-iml-more-prelude-refactor
Open

[inferno-ml] Make asTensor* and asArray* functions polymorphic#187
ngua wants to merge 8 commits into
mainfrom
rory-iml-more-prelude-refactor

Conversation

@ngua

@ngua ngua commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Currently we only allow double values to be converted back and forth between tensors, which I don't think is ideal since we've already introduced the scalar typeclass to represent scalar values that can be used with tensors.

So this makes asArray1 and asTensor1 (and their nested equivalents) polymorphic for any scalar value.

Examples:

asTensor*
let is : array of int = 1..5 in
ML.asTensor1 ML.#float is

// Tensor Float [5] [ 1.0000   ,  2.0000   ,  3.0000   ,  4.0000   ,  5.0000   ]
let bs = [[ #true, #true ], [ #false, #false ]] in
ML.asTensor2 ML.#bool bs

// Tensor Bool [2,2] [[ 1,  1], [ 0,  0]]
asArray*
let t = ML.ones ML.#int [3, 3] in
ML.asArray2 t

// [[1,1,1],[1,1,1],[1,1,1]]
let t = ML.ones ML.#bool [3, 2, 1] in
ML.asArray3 t

// [[[#true],[#true]],[[#true],[#true]],[[#true],[#true]]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants