Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ITensorBase"
uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
version = "0.9.0-DEV"
version = "0.9.0"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand Down
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ using ITensorBase
using ITensorFormatter: ITensorFormatter

# `using ITensorBase` (rather than `using ITensorBase: ITensorBase`) binds the exported
# names in `Main`. The tensor `show` qualifies the element type relative to the active
# module, so without it the doctests and `@example` blocks render `ITensorBase.ITensor`
# instead of `ITensor`.
# names in `Main`. The tensor `show` qualifies the type relative to the active module, so
# without it the doctests and `@example` blocks render `ITensorBase.NamedTensor` instead
# of `NamedTensor`.
DocMeta.setdocmeta!(ITensorBase, :DocTestSetup, :(using ITensorBase); recursive = true)

ITensorFormatter.make_index!(pkgdir(ITensorBase))
Expand Down
17 changes: 9 additions & 8 deletions docs/src/dev_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ stable user-facing API. For the stable user-facing API, see the [User Interface]

## Named array types

A concrete tensor type subtypes [`AbstractITensor`](@ref); [`ITensor`](@ref) is the built-in
dense implementation. Its `ITensor(array, dimnames)` constructor pairs an array with dimension
names directly; user code usually builds an `ITensor` by calling an array constructor on
indices or by indexing an array (see [Constructors](@ref)) rather than calling it. The
underlying named-range model has [`NamedUnitRange`](@ref) as the named-range type that a
tensor's dimensions are ([`Index`](@ref) is the flavor keyed by an index name).
A concrete tensor type subtypes [`AbstractNamedTensor`](@ref). [`NamedTensor`](@ref)
is the built-in implementation, and [`ITensor`](@ref) is the `NamedTensor` with dimension
names that are [`IndexName`](@ref)s. Its `NamedTensor(array, dimnames)` constructor pairs an array of
any kind with its dimension names directly. User code usually builds one by calling an array constructor on indices or by
indexing an array (see [Constructors](@ref)) rather than calling it. The underlying
named-range model has [`NamedUnitRange`](@ref) as the named-range type that a tensor's
dimensions are ([`Index`](@ref) is the flavor keyed by an index name).

```@docs; canonical=false
AbstractITensor
ITensor
AbstractNamedTensor
NamedTensor
NamedUnitRange
```

Expand Down
4 changes: 2 additions & 2 deletions ext/ITensorBaseAdaptExt/ITensorBaseAdaptExt.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module ITensorBaseAdaptExt

using Adapt: Adapt, adapt
using ITensorBase: AbstractITensor, dimnames, nameddims, unnamed
using ITensorBase: AbstractNamedTensor, dimnames, nameddims, unnamed

function Adapt.adapt_structure(to, a::AbstractITensor)
function Adapt.adapt_structure(to, a::AbstractNamedTensor)
return nameddims(adapt(to, unnamed(a)), dimnames(a))
end

Expand Down
18 changes: 9 additions & 9 deletions ext/ITensorBaseBlockArraysExt/ITensorBaseBlockArraysExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ITensorBaseBlockArraysExt
using ArrayLayouts: ArrayLayouts
using BlockArrays: Block, BlockRange
using ITensorBase: AbstractITensor, NamedUnitRange, getindex_named, view_nameddims
using ITensorBase: AbstractNamedTensor, NamedUnitRange, getindex_named, view_nameddims

# These methods disambiguate named-range block indexing from `BlockArrays`' generic
# `AbstractArray` block-indexing methods.
Expand All @@ -17,39 +17,39 @@ end

const BlockIndex{N} = Union{Block{N}, BlockRange{N}, AbstractVector{<:Block{N}}}

function Base.view(a::AbstractITensor, I1::Block{1}, Irest::BlockIndex{1}...)
function Base.view(a::AbstractNamedTensor, I1::Block{1}, Irest::BlockIndex{1}...)
# TODO: Use `Derive.@interface ITensorInterface() r[I]` instead.
return view_nameddims(a, I1, Irest...)
end

function Base.view(a::AbstractITensor, I::Block)
function Base.view(a::AbstractNamedTensor, I::Block)
# TODO: Use `Derive.@interface ITensorInterface() r[I]` instead.
return view_nameddims(a, Tuple(I)...)
end

function Base.view(a::AbstractITensor, I1::BlockIndex{1}, Irest::BlockIndex{1}...)
function Base.view(a::AbstractNamedTensor, I1::BlockIndex{1}, Irest::BlockIndex{1}...)
# TODO: Use `Derive.@interface ITensorInterface() r[I]` instead.
return view_nameddims(a, I1, Irest...)
end

# Fix ambiguity error.
function Base.getindex(
a::AbstractITensor, I1::BlockRange{1}, Irest::BlockRange{1}...
a::AbstractNamedTensor, I1::BlockRange{1}, Irest::BlockRange{1}...
)
return ArrayLayouts.layout_getindex(a, I1, Irest...)
end

# Fix ambiguity errors.
function Base.getindex(a::AbstractITensor, I1::Block{1}, Irest...)
function Base.getindex(a::AbstractNamedTensor, I1::Block{1}, Irest...)
return copy(view(a, I1, Irest...))
end
function Base.getindex(a::AbstractITensor, I1::AbstractVector, I2::Block{1})
function Base.getindex(a::AbstractNamedTensor, I1::AbstractVector, I2::Block{1})
return copy(view(a, I1, I2))
end
function Base.getindex(a::AbstractITensor, I1::Block{1}, I2::AbstractVector)
function Base.getindex(a::AbstractNamedTensor, I1::Block{1}, I2::AbstractVector)
return copy(view(a, I1, I2))
end
function Base.getindex(a::AbstractITensor, I::Block{N}) where {N}
function Base.getindex(a::AbstractNamedTensor, I::Block{N}) where {N}
return copy(view(a, I))
end

Expand Down
10 changes: 5 additions & 5 deletions ext/ITensorBaseMooncakeExt/ITensorBaseMooncakeExt.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module ITensorBaseMooncakeExt

using ITensorBase: AbstractITensor, NamedUnitRange, dimnames, dimnames_setdiff, inds, name,
nameperm, to_inds, uniquename
using ITensorBase: AbstractNamedTensor, NamedUnitRange, dimnames, dimnames_setdiff, inds,
name, nameperm, to_inds, uniquename
using Mooncake: Mooncake, @zero_derivative, DefaultCtx

Mooncake.tangent_type(::Type{<:NamedUnitRange}) = Mooncake.NoTangent

@zero_derivative DefaultCtx Tuple{typeof(nameperm), Any, Any, Any}
# `dimnames(::ITensor)` returns the stored names `Vector` directly, so its output
# `dimnames(::NamedTensor)` returns the stored names `Vector` directly, so its output
# aliases a field, where `@zero_derivative` is documented to be incorrect. Let
# Mooncake differentiate it through the underlying `getfield`, whose built-in rule
# preserves the aliasing (the names are non-differentiable, so the result is zero).
Expand All @@ -20,9 +20,9 @@ Mooncake.tangent_type(::Type{<:NamedUnitRange}) = Mooncake.NoTangent
@zero_derivative DefaultCtx Tuple{typeof(uniquename), Any, Any}
@zero_derivative DefaultCtx Tuple{typeof(to_inds), Any, Any}

using ITensorBase: AbstractITensor, ITensor, unnamed
using ITensorBase: AbstractNamedTensor, NamedTensor, unnamed
using Mooncake: Tangent
function Base.copyto!(dest::ITensor, src::Tangent)
function Base.copyto!(dest::NamedTensor, src::Tangent)
# TODO: Account for the `inds` of the Tangent? In other words, is the tangent data
# aligned with the `dest` data?
copyto!(unnamed(dest), src.fields.parent)
Expand Down
15 changes: 8 additions & 7 deletions src/ITensorBase.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module ITensorBase

export AbstractITensor, ITensor, Index, NamedUnitRange, aligndims, aligneddims,
apply, codomainnames, dimnames, dimnametype, domainnames, inds, named,
nameddims, noprime, operator, prime, similar_operator, state, uniquename
export AbstractNamedTensor, NamedTensor, AbstractITensor, ITensor, Index,
NamedUnitRange, aligndims, aligneddims, apply, codomainnames, dimnames,
dimnametype, domainnames, inds, named, nameddims, noprime, operator, prime,
similar_operator, state, uniquename
using Compat: @compat
@compat public @names
@compat public name, nametype, replacedimnames, setname, unnamed, unnamedtype
@compat public IndexName, name, nametype, replacedimnames, setname, unnamed, unnamedtype

# Named-array machinery (relocated from NamedDimsArrays.jl).
include("isnamed.jl")
Expand All @@ -15,12 +16,12 @@ include("named.jl")
include("abstractnamedarray.jl")
include("namedarray.jl")
include("namedunitrange.jl")
include("abstractitensor.jl")
include("abstractnamedtensor.jl")
include("broadcast.jl")
include("tensoralgebra.jl")
include("linearalgebra.jl")
include("itensor.jl")
include("itensoroperator.jl")
include("namedtensor.jl")
include("namedtensoroperator.jl")

# `IndexName` dimname flavor and the `Index` named unit range.
include("sorteddict.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/abstractnamedarray.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `Name` leads (matching `AbstractITensor{DimName}`); `UnnamedT` is the unwrapped
# `Name` leads (matching `AbstractNamedTensor{DimName}`); `UnnamedT` is the unwrapped
# element type and `N` the rank. The element type is always `Named{Name, UnnamedT}`,
# so it is hardcoded in the `AbstractArray` supertype rather than carried as a
# parameter. The wrapped-container type lives only on the concrete subtypes.
Expand Down
Loading
Loading