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
14 changes: 1 addition & 13 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
name = "ITensorBase"
uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.4.4"
version = "0.4.5"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MapBroadcast = "ebd9b9da-f48d-417c-9660-449667d60261"
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
UnallocatedArrays = "43c9e47c-e622-40fb-bf18-a09fc8c466b6"
UnspecifiedTypes = "42b3faec-625b-4613-8ddc-352bf9672b8d"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"

[compat]
Accessors = "0.1.39"
ConstructionBase = "1.6.0"
FillArrays = "1.13"
LinearAlgebra = "1.10"
MapBroadcast = "0.1.5"
NamedDimsArrays = "0.13"
Random = "1.10"
TensorAlgebra = "0.3, 0.4, 0.5, 0.6"
UnallocatedArrays = "0.1.1"
UnspecifiedTypes = "0.1.1"
VectorInterface = "0.5"
julia = "1.10"

[workspace]
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ q, r = qr(a, (i,))
@test q * r ≈ a
````

Automatic allocation

````julia
a = ITensor(i, j)
a[j[1], i[2]] = 1 + 2im
eltype(a) == Complex{Int}
@test a[i[2], j[1]] == 1 + 2im
````

---

*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
Expand Down
6 changes: 0 additions & 6 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,3 @@ d = a + a′
@test a ≈ aligndims(a, (j, i))
q, r = qr(a, (i,))
@test q * r ≈ a

# Automatic allocation
a = ITensor(i, j)
a[j[1], i[2]] = 1 + 2im
eltype(a) == Complex{Int}
@test a[i[2], j[1]] == 1 + 2im
67 changes: 1 addition & 66 deletions src/abstractitensor.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using MapBroadcast: Mapped
using NamedDimsArrays: NamedDimsArrays, AbstractNamedDimsArray, NamedDimsArray, denamed,
dimnames, inds, mapinds

Expand All @@ -8,52 +7,7 @@ NamedDimsArrays.nameddimsconstructor(::Type{<:IndexName}) = ITensor

Base.ndims(::Type{<:AbstractITensor}) = Any

using FillArrays: Zeros
using UnallocatedArrays: UnallocatedZeros, allocate
using UnspecifiedTypes: UnspecifiedZero

# TODO: Make this more general, maybe with traits `is_unallocated`
# and `is_eltype_unspecified`.
function specify_eltype(a::Zeros{UnspecifiedZero}, elt::Type)
return Zeros{elt}(axes(a))
end
specify_eltype(a::AbstractArray, elt::Type) = a

# TODO: Use `adapt` to reach down into the storage.
function specify_eltype!(a::AbstractITensor, elt::Type)
setdenamed!(a, specify_eltype(denamed(a), elt))
return a
end

# Assume it is allocated.
allocate!(a::AbstractArray) = a

# TODO: Use `adapt` to reach down into the storage.
function allocate!(a::AbstractITensor)
setdenamed!(a, allocate(denamed(a)))
return a
end

unallocatable(a::AbstractITensor) = NamedDimsArray(a)

function setindex_allocatable!(a::AbstractArray, value, I...)
allocate!(specify_eltype!(a, typeof(value)))
# TODO: Maybe use `@interface interface(a) a[I...] = value`?
unallocatable(a)[I...] = value
return a
end

# TODO: Combine these by using `Base.to_indices`.
function Base.setindex!(a::AbstractITensor, value, I::Int...)
setindex_allocatable!(a, value, I...)
return a
end
function Base.setindex!(a::AbstractITensor, value, I::AbstractNamedInteger...)
setindex_allocatable!(a, value, I...)
return a
end

mutable struct ITensor <: AbstractITensor
struct ITensor <: AbstractITensor
parent::AbstractArray
inds
function ITensor(parent::AbstractArray, dims)
Expand All @@ -72,22 +26,3 @@ end
function ITensor(parent::AbstractArray)
return ITensor(parent, ())
end

using Accessors: @set
setdenamed(a::ITensor, denamed) = (@set a.parent = denamed)
setdenamed!(a::ITensor, denamed) = (a.parent = denamed)

function ITensor(elt::Type, I1::Index, I_rest::Index...)
I = (I1, I_rest...)
# TODO: Use `FillArrays.Zeros`.
return ITensor(zeros(elt, length.(denamed.(I))...), I)
end

function ITensor(I1::Index, I_rest::Index...)
I = (I1, I_rest...)
return ITensor(Zeros{UnspecifiedZero}(length.(denamed.(I))...), I)
end

function ITensor()
return ITensor(Zeros{UnspecifiedZero}(), ())
end
Loading