Skip to content

Commit

Permalink
Rewrite (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Dec 25, 2024
1 parent a4ab687 commit a8caa48
Show file tree
Hide file tree
Showing 43 changed files with 1,024 additions and 891 deletions.
14 changes: 7 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name = "NamedDimsArrays"
uuid = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.0"
version = "0.2.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"

[compat]
Adapt = "4.1.1"
BroadcastMapConversion = "0.1"
BroadcastMapConversion = "0.1.2"
Derive = "0.3.6"
LinearAlgebra = "1.10"
NestedPermutedDimsArrays = "0.1"
Random = "1.10"
SparseArraysBase = "0.1"
SimpleTraits = "0.9.4"
TensorAlgebra = "0.1"
TypeParameterAccessors = "0.1"
TypeParameterAccessors = "0.2"
julia = "1.10"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ julia> Pkg.add("NamedDimsArrays")
## Examples

````julia
using NamedDimsArrays: align, dimnames, named, unname
using NamedDimsArrays: aligndims, dename, dimnames, named
using TensorAlgebra: contract

# Named dimensions
Expand All @@ -53,11 +53,11 @@ na2 = randn(j, k)
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)
# `dename` removes the names and returns an `Array`
@show dename(na_dest, (i, k)) dename(na1) * dename(na2)

# Permute dimensions (like `ITensors.permute`)
na1 = align(na1, (j, i))
na1 = aligndims(na1, (j, i))
@show na1[i => 1, j => 2] == na1[2, 1]
````

Expand Down
26 changes: 26 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- `svd`, `eigen` (including tensor versions)
- `reshape`, `vec`
- `swapdimnames`
- `mapdimnames(f, a::AbstractNamedDimsArray)` (rename `replacedimnames(f, a)` to `mapdimnames(f, a)`, or have both?)
- `cat` (define `CatName` as a combination of the input names?).
- `canonize`/`flatten_array_wrappers` (https://github.com/mcabbott/NamedPlus.jl/blob/v0.0.5/src/permute.jl#L207)
- `nameddims(PermutedDimsArray(a, perm), dimnames)` -> `nameddims(a, dimnames[invperm(perm)])`
- `nameddims(transpose(a), dimnames)` -> `nameddims(a, reverse(dimnames))`
- `Transpose(nameddims(a, dimnames))` -> `nameddims(a, reverse(dimnames))`
- etc.
- `MappedName(old_name, name)`, acts like `Name(name)` but keeps track of the old name.
- `namedmap(a, ::Pair...)`: `namedmap(named(randn(2, 2, 2, 2), i, j, k, l), i => k, j => l)`
represents that the names map back and forth to each other for the sake of `transpose`,
`tr`, `eigen`, etc. Operators are generally `namedmap(named(randn(2, 2), i, i'), i => i')`.
- `prime(:i) = PrimedName(:i)`, `prime(:i, 2) = PrimedName(:i, 2)`, `prime(prime(:i)) = PrimedName(:i, 2)`,
`Name(:i)' = prime(:i)`, etc.
- `transpose`/`adjoint` based on `swapdimnames` and `MappedName(old_name, new_name)`.
- `adjoint` could make use of a lazy `ConjArray`.
- `transpose(a, dimname1 => dimname1′, dimname2 => dimname2′)` like `https://github.com/mcabbott/NamedPlus.jl`.
- Same as `replacedims(a, dimname1 => dimname1′, dimname1′ => dimname1, dimname2 => dimname2′, dimname2′ => dimname2)`.
- `transpose(f, a)` like the function form of `replace`.
- `tr` based on `MappedName(old_name, name)`.
- Slicing: `nameddims(a, "i", "j")[1:2, 1:2] = nameddims(a[1:2, 1:2], Name(named(1:2, "i")), Name(named(1:2, "j")))`, i.e.
the parent gets sliced and the new dimensions names are the named slice.
- Should `NamedDimsArray` store the named axes rather than just the dimension names?
- Should `NamedDimsArray` have special axes types so that `axes(nameddims(a, "i", "j")) == axes(nameddims(a', "j", "i"))`?
1 change: 0 additions & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58"
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
8 changes: 4 additions & 4 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ julia> Pkg.add("NamedDimsArrays")

# ## Examples

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

## Named dimensions
Expand All @@ -58,9 +58,9 @@ na2 = randn(j, k)
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)
## `dename` removes the names and returns an `Array`
@show dename(na_dest, (i, k)) dename(na1) * dename(na2)

## Permute dimensions (like `ITensors.permute`)
na1 = align(na1, (j, i))
na1 = aligndims(na1, (j, i))
@show na1[i => 1, j => 2] == na1[2, 1]
3 changes: 0 additions & 3 deletions ext/NamedDimsArraysAdaptExt/NamedDimsArraysAdaptExt.jl

This file was deleted.

6 changes: 0 additions & 6 deletions ext/NamedDimsArraysAdaptExt/adapt_structure.jl

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions ext/NamedDimsArraysSparseArraysBaseExt/densearray.jl

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions ext/NamedDimsArraysTensorAlgebraExt/contract.jl

This file was deleted.

17 changes: 0 additions & 17 deletions ext/NamedDimsArraysTensorAlgebraExt/qr.jl

This file was deleted.

26 changes: 6 additions & 20 deletions src/NamedDimsArrays.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
module NamedDimsArrays

include("traits.jl")
include("name.jl")
include("isnamed.jl")
include("randname.jl")
include("abstractnamedint.jl")
include("abstractnamedinteger.jl")
include("namedinteger.jl")
include("abstractnamedunitrange.jl")
include("abstractnameddimsarray.jl")
include("abstractnameddimsmatrix.jl")
include("abstractnameddimsvector.jl")
include("namedint.jl")
include("namedunitrange.jl")
include("abstractnameddimsarray.jl")
include("adapt.jl")
include("tensoralgebra.jl")
include("nameddimsarray.jl")
include("constructors.jl")
include("similar.jl")
include("permutedims.jl")
include("promote_shape.jl")
include("map.jl")
include("broadcast_shape.jl")
include("broadcast.jl")

# Extensions.
# TODO: Turn these into actual package extensions.
include("../ext/NamedDimsArraysAdaptExt/NamedDimsArraysAdaptExt.jl")
include("../ext/NamedDimsArraysSparseArraysBaseExt/NamedDimsArraysSparseArraysBaseExt.jl")
include("../ext/NamedDimsArraysTensorAlgebraExt/NamedDimsArraysTensorAlgebraExt.jl")

end
Loading

0 comments on commit a8caa48

Please sign in to comment.