Skip to content

ITensor/NamedDimsArrays.jl

Repository files navigation

NamedDimsArrays.jl

Stable Dev Build Status Coverage Code Style: Blue Aqua

Installation instructions

This package resides in the ITensor/ITensorRegistry local registry. In order to install, simply add that registry through your package manager. This step is only required once.

julia> using Pkg: Pkg

julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry")

or:

julia> Pkg.Registry.add(url="[email protected]:ITensor/ITensorRegistry.git")

if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages.

Then, the package can be added as usual through the package manager:

julia> Pkg.add("NamedDimsArrays")

Examples

using NamedDimsArrays: align, dimnames, named, unname
using TensorAlgebra: contract

# 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 = 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]

This page was generated using Literate.jl.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages