Skip to content

Commit 4cdf95c

Browse files
authored
Implement more missing functionality (#15)
1 parent 354c56d commit 4cdf95c

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorBase"
22
uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
33
authors = ["ITensor developers <support@itensor.org> and contributors"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -12,6 +12,7 @@ MapBroadcast = "ebd9b9da-f48d-417c-9660-449667d60261"
1212
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
1313
UnallocatedArrays = "43c9e47c-e622-40fb-bf18-a09fc8c466b6"
1414
UnspecifiedTypes = "42b3faec-625b-4613-8ddc-352bf9672b8d"
15+
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
1516

1617
[compat]
1718
Accessors = "0.1.39"
@@ -22,4 +23,5 @@ MapBroadcast = "0.1.5"
2223
NamedDimsArrays = "0.3.0"
2324
UnallocatedArrays = "0.1.1"
2425
UnspecifiedTypes = "0.1.1"
26+
VectorInterface = "0.5.0"
2527
julia = "1.10"

src/ITensorBase.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ addtags(n::IndexName, ts) = settags(n, tags(n) ∪ tagset(ts))
5454

5555
setprime(n::IndexName, plev) = @set n.plev = plev
5656
prime(n::IndexName) = setprime(n, plev(n) + 1)
57+
noprime(n::IndexName) = setprime(n, 0)
5758

5859
function Base.show(io::IO, i::IndexName)
5960
idstr = "id=$(id(i) % 1000)"
@@ -97,6 +98,7 @@ plev(i::Index) = plev(name(i))
9798
addtags(i::Index, tags) = setname(i, addtags(name(i), tags))
9899
prime(i::Index) = setname(i, prime(name(i)))
99100
Base.adjoint(i::Index) = prime(i)
101+
noprime(i::Index) = setname(i, noprime(name(i)))
100102

101103
# Interface
102104
# TODO: Overload `Base.parent` instead.
@@ -253,6 +255,10 @@ end
253255
# TODO: Use `replaceinds`/`mapinds`, based on
254256
# `replacenameddimsindices`/`mapnameddimsindices`.
255257
prime(a::AbstractITensor) = setinds(a, prime.(inds(a)))
258+
noprime(a::AbstractITensor) = setinds(a, noprime.(inds(a)))
259+
260+
using VectorInterface: VectorInterface, scalartype
261+
VectorInterface.scalartype(a::AbstractITensor) = scalartype(unallocatable(a))
256262

257263
include("quirks.jl")
258264

src/quirks.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# TODO: Define this properly.
22
dag(i::Index) = i
3+
# TODO: Define this properly.
4+
dag(a::ITensor) = a
35
# TODO: Deprecate.
46
dim(i::Index) = dename(length(i))
7+
# TODO: Deprecate.
8+
dim(a::AbstractITensor) = unname(length(a))
59
# TODO: Define this properly.
610
hasqns(i::Index) = false
11+
# TODO: Define this properly.
12+
hasqns(i::AbstractITensor) = false
713
# TODO: Deprecate.
814
itensor(parent::AbstractArray, nameddimsindices) = ITensor(parent, nameddimsindices)
915
function itensor(parent::AbstractArray, i1::Index, i_rest::Index...)
1016
return ITensor(parent, (i1, i_rest...))
1117
end
18+
# TODO: Deprecate.
19+
order(a::AbstractArray) = ndims(a)
1220

1321
# This seems to be needed to get broadcasting working.
1422
# TODO: Investigate this and see if we can get rid of it.
@@ -23,9 +31,24 @@ function onehot(iv::Pair{<:Index,<:Int})
2331
return a
2432
end
2533

26-
using LinearAlgebra: svd
34+
using LinearAlgebra: qr, svd
2735
# TODO: Define this in `MatrixAlgebra.jl`/`TensorAlgebra.jl`.
28-
function factorize(a::AbstractITensor, args...; kwargs...)
29-
U, S, V = svd(a, args...; kwargs...)
30-
return U, S * V
36+
function factorize(a::AbstractITensor, args...; maxdim=nothing, cutoff=nothing, kwargs...)
37+
if isnothing(maxdim) && isnothing(cutoff)
38+
Q, R = qr(a, args...)
39+
return Q, R
40+
else
41+
error("Truncation in `factorize` not implemented yet.")
42+
U, S, V = svd(a, args...; kwargs...)
43+
return U, S * V
44+
end
3145
end
46+
47+
# TODO: Used in `ITensorMPS.jl`, decide where or if to define it.
48+
# Ideally this would just be a zero-dimensional `ITensor` wrapping
49+
# a special type, like `Zeros{UnspecifiedZero()}()`.
50+
struct OneITensor <: AbstractITensor end
51+
Base.size(::OneITensor) = ()
52+
Base.:*(::OneITensor, ::OneITensor) = OneITensor()
53+
Base.:*(::OneITensor, a::ITensor) = a
54+
Base.:*(a::ITensor, ::OneITensor) = a

0 commit comments

Comments
 (0)