Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add conversion from tensor to/from org.tribuo.math.la.Matrix #406

Open
behrica opened this issue Apr 27, 2024 · 1 comment
Open

add conversion from tensor to/from org.tribuo.math.la.Matrix #406

behrica opened this issue Apr 27, 2024 · 1 comment

Comments

@behrica
Copy link
Contributor

behrica commented Apr 27, 2024

Either by implementing interface org.tribuo.math.la.Matrix based on a tensor,
or creating DenseMarix from a tech.v3.tensor

As we have tribuo interop in here anyway, it might make sense

@behrica
Copy link
Contributor Author

behrica commented Apr 27, 2024

Something like this works:


(def t (tech.v3.tensor/new-tensor [4 5]))

(import '[org.tribuo.math.la DenseMatrix])
(def jvm (tech.v3.tensor/->jvm t {:base-storage :java-array :datatype :double}))
(DenseMatrix/createDenseMatrix (into-array jvm))
#object[org.tribuo.math.la.DenseMatrix 0x49d26eba "DenseMatrix(dim1=4,dim2=5,values=\n\trow 0 [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000];\n\trow 1 [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000];\n\trow 2 [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000];\n\trow 3 [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000];\n)"]

Maybe there is a faster way, and it would only work for 2D tensors of type double

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

No branches or pull requests

1 participant