Qqwy
TypeCheck Core Team
With the recent addition of Numbers and some improvements of the documentation, Tensor now has reached version 1.0.0!
For people that do not yet know about it:
Tensor is a library that allows you to work with sparse Vectors, Matrices and higher-order Tensors, with the following nice features:
- An implementation of the Access protocol, so you can do
mymatrix[42][3]. - It supports the arithmetic functions you would expect from vectors, matrices and tensors. These are implemented using Numbers, which means that they work on any numeric type.
- What is even more, Tensor itself implements Numbers’ Numeric behaviour, which means that anything that does number arithmetic can now do (elementwise) vector/matrix/tensor arithmetic! It also means that you can nest matrices ad infinitum!
- A sparse implementation: Only elements deviating from the default element of a data structure are stored. This means that e.g. a nearly-empty 10000x10000 element matrix takes up only a neglegible amount of memory.
- While you can work with numbers, you can store anything inside: Using it as a representation of a game board (a matrix for chess, or a 3-dimensional tensor for a Rubik’s Cube), for instance, is something that is very possible.
- Functions to rotate, transpose, transform, combine, separate, map over and reduce vectors/matrices/tensors.
Here are some examples from the Readme:
Vectors
iex> vec = Vector.new([1,2,3,4,5])
#Vector-(5)[1, 2, 3, 4, 5]
iex> vec2 = Vector.new(~w{foo bar baz qux})
#Vector-(4)["foo", "bar", "baz", "qux"]
iex> vec2[2]
"baz"
iex> Vector.add(vec, 3)
#Vector-(5)[4, 5, 6, 7, 8]
iex> Vector.add(vec, vec)
#Vector-(5)[2, 4, 6, 8, 10]
Matrices
iex> mat = Matrix.new([[1,2,3],[4,5,6],[7,8,9]],3,3)
#Matrix-(3×3)
┌ ┐
│ 1, 2, 3│
│ 4, 5, 6│
│ 7, 8, 9│
└ ┘
iex> Matrix.rotate_clockwise(mat)
#Matrix-(3×3)
┌ ┐
│ 7, 4, 1│
│ 8, 5, 2│
│ 9, 6, 3│
└ ┘
iex> mat[0]
#Vector-(3)[1, 2, 3]
iex> mat[2][2]
9
iex> Matrix.diag([1,2,3])
#Matrix-(3×3)
┌ ┐
│ 1, 0, 0│
│ 0, 2, 0│
│ 0, 0, 3│
└ ┘
iex> Matrix.add(mat, 2)
#Matrix-(3×3)
┌ ┐
│ 3, 4, 5│
│ 6, 7, 8│
│ 9, 10, 11│
└ ┘
iex> Matrix.add(mat, mat)
#Matrix-(3×3)
┌ ┐
│ 2, 4, 6│
│ 8, 10, 12│
│ 14, 16, 18│
└ ┘
Tensors
iex> tensor = Tensor.new([[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]]], [3,3,2])
#Tensor(3×3×2)
1, 2
3, 4
5, 6
7, 8
9, 10
11, 12
0, 0
0, 0
0, 0
iex> tensor[1]
#Matrix-(3×2)
┌ ┐
│ 7, 8│
│ 9, 10│
│ 11, 12│
└ ┘
Trending in Announcing
WebAuthnLiveComponent WebAuthnComponents
See this post about renaming the package.
Passwordless authentication for Phoenix LiveView app...
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I released Doggo, a collection of unstyled Phoenix components.
https://github.com/woylie/doggo
Features
Unstyled Phoenix components....
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
I’ll shortly be launching Text, a nascent text analysis library.
Current functionality
In this early version (not ready for prime time) ...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
vic
Awesome!
uranther
Great work! I will have to dust off my chess program and use this library to simplify a lot of the functions.
loongmxbt
Awesome!
Forseth
This is so cool !
OvermindDL1
Very nice! Reached 1.0.0, been waiting for Numbers. ^.^
wsmoak
I’m using Tensor in one of the Advent of Code solutions and got tripped up by “height” vs. “width”.
It’s been a long time since discrete math, but a search confirms what I thought I remembered: “A matrix with m rows and n columns is said to have dimension m × n”.
But the signature for Matrix.new is
new(list_of_lists \\ [], width, height, identity \\ 0).This seems to be backwards from the usual representation-- the width is the number of columns, while the height is the number of rows.
Matrix.new(3, 2) does what I expect – 3 rows and 2 columns – so this is really just a docs issue. (I opened a PR to fix it. First one, it looks like!
)
-Wendy
Qqwy
Wow, thank you so much for your pull request!
It has been merged and added to the new 1.0.1 version of the library.
wsmoak
You’re welcome! Unfortunately I am now completely stuck on how to update an element in the matrix.
Details here: Usage of Matrix.get or get_and_update? · Issue #3 · Qqwy/elixir-tensor · GitHub
OR if you’d rather questions went elsewhere, feel free to close that and let me know where to ask!
-Wendy