diff --git a/Project.toml b/Project.toml index e85ef7e..250c673 100644 --- a/Project.toml +++ b/Project.toml @@ -1,33 +1,21 @@ name = "ITensorBase" uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7" authors = ["ITensor developers 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] diff --git a/README.md b/README.md index f89d849..3e79771 100644 --- a/README.md +++ b/README.md @@ -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).* diff --git a/examples/README.jl b/examples/README.jl index 27e2dd2..9a6e235 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -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 diff --git a/src/abstractitensor.jl b/src/abstractitensor.jl index 8757331..f19771d 100644 --- a/src/abstractitensor.jl +++ b/src/abstractitensor.jl @@ -1,4 +1,3 @@ -using MapBroadcast: Mapped using NamedDimsArrays: NamedDimsArrays, AbstractNamedDimsArray, NamedDimsArray, denamed, dimnames, inds, mapinds @@ -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) @@ -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