-
Notifications
You must be signed in to change notification settings - Fork 125
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
[NDTensors] NamedDimsArrays
module
#1267
Conversation
…m:ITensor/ITensors.jl into NDTensors_blocksparsearray_tensor_algebra
….jl into NDTensors_TensorAlgebra
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1267 +/- ##
===========================================
- Coverage 85.44% 54.80% -30.64%
===========================================
Files 89 88 -1
Lines 8402 8349 -53
===========================================
- Hits 7179 4576 -2603
- Misses 1223 3773 +2550 ☔ View full report in Codecov by Sentry. |
In that latest I started adding tensor algebra definitions like Here is a demonstration of some functionality: using NDTensors.NamedDimsArrays: align, dimnames, named, unname
using NDTensors.TensorAlgebra: TensorAlgebra
# Named dimensions
i = named(2, "i")
j = named(2, "j")
k = named(2, "k")
# Arrays with named dimensions
na1 = randn(i, j)
na2 = randn(j, k)
@show dimnames(na1) == ("i", "j")
# Indexing
@show na1[j => 2, i => 1] == na1[1, 2]
# Tensor contraction
na_dest = TensorAlgebra.contract(na1, na2)
@show issetequal(dimnames(na_dest), ("i", "k"))
# `unname` removes the names and returns an `Array`
@show unname(na_dest, (i, k)) ≈ unname(na1) * unname(na2)
# Permute dimensions (like `ITensors.permute`)
na1 = align(na1, (j, i))
@show na1[i => 1, j => 2] == na1[2, 1] So it is very similar to the interface of |
Interesting to see how short the code for implementing this ended up being. And I can see how it would simplify the ITensor layer on top. |
This defines a new
NamedDimsArrays
module, defining a standalone Julia array wrapper type that attaches names to dimensions.The design is some hybrid of the current ITensor Index system and Julia packages like NamedDims.jl/NamedPlus.jl, DimensionalData.jl, NamedArrays.jl, PyTorch's Named Tensors, etc.
The idea would be to replace the current
Tensor
type with aNamedDimsArray
(or some subtype ofAbstractNamedDimsArray
), which would have named dimension-aware indexing and tensor operation syntax (i.e. smart addition, contraction, and factorization like ITensors have right now). Then ITensors can be simple opaque mutable wrappers aroundNamedDimsArrays
.