Skip to content

Commit 5331823

Browse files
committed
Change onehot to oneelement
1 parent e9f1be2 commit 5331823

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Project.toml

Lines changed: 1 addition & 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 <[email protected]> and contributors"]
4-
version = "0.1.13"
4+
version = "0.1.14"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/abstractitensor.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ function ITensor(parent::AbstractArray)
9191
return ITensor(parent, ())
9292
end
9393

94+
# TODO:
95+
# 1. Generalize this to arbitrary dimensions.
96+
# 2. Define a basic non-ITensor version in `SparseArraysBase.jl`,
97+
# and this constructor can wrap that one. It could construct
98+
# a `OneElement` sparse object like `FillArrays.OneElement`
99+
# (https://juliaarrays.github.io/FillArrays.jl/stable/#FillArrays.OneElement).
100+
# 3. Define `oneelement(value, index::Tuple{Vargarg{Int}}, axes::Tuple{Vararg{Index}})`,
101+
# where the pair version calls out to that one.
102+
function oneelement(elt::Type{<:Number}, iv::Pair{<:Index,<:Int})
103+
a = ITensor(first(iv))
104+
a[last(iv)] = one(elt)
105+
return a
106+
end
107+
# TODO: The non-ITensor version should default to `Float64`,
108+
# like `FillArrays.OneElement`.
109+
# TODO: Make the element type `UnspecifiedOne`.
110+
oneelement(iv::Pair{<:Index,<:Int}) = oneelement(Bool, iv)
111+
94112
using Accessors: @set
95113
setdenamed(a::ITensor, denamed) = (@set a.parent = denamed)
96114
setdenamed!(a::ITensor, denamed) = (a.parent = denamed)

src/quirks.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
# TODO: Define this properly.
2+
# TODO: Rename this to `dual`.
23
dag(i::Index) = i
34
# TODO: Define this properly.
5+
# TODO: Rename this to `dual`.
46
dag(a::ITensor) = a
5-
# TODO: Deprecate.
7+
8+
# TODO: Deprecate, just use `Int(length(i))` or
9+
# `unname(length(i))` directly.
610
# Conversion to `Int` is used in case the output is named.
711
dim(i::Index) = Int(length(i))
812
# TODO: Deprecate.
913
# Conversion to `Int` is used in case the output is named.
14+
# TODO: Deprecate, just use `Int(length(i))` or
15+
# `unname(length(i))` directly.
1016
dim(a::AbstractITensor) = Int(length(a))
17+
1118
# TODO: Define this properly.
12-
hasqns(i::Index) = false
19+
# TODO: Maybe rename to `isgraded(i::Index) = isgraded(dename(i))`.
20+
hasqns(::Index) = false
1321
# TODO: Define this properly.
14-
hasqns(i::AbstractITensor) = false
22+
# TODO: Maybe rename to `isgraded(a) = all(isgraded, axes(a))`.
23+
hasqns(::AbstractITensor) = false
1524

1625
# This seems to be needed to get broadcasting working.
1726
# TODO: Investigate this and see if we can get rid of it.
1827
Base.Broadcast.extrude(a::AbstractITensor) = a
1928

20-
# TODO: Generalize this.
21-
# Maybe define it as `oneelement`, and base it on
22-
# `FillArrays.OneElement` (https://juliaarrays.github.io/FillArrays.jl/stable/#FillArrays.OneElement).
23-
function onehot(elt::Type{<:Number}, iv::Pair{<:Index,<:Int})
24-
a = ITensor(first(iv))
25-
a[last(iv)] = one(elt)
26-
return a
27-
end
28-
onehot(iv::Pair{<:Index,<:Int}) = onehot(Bool, iv)
29-
3029
# TODO: This is just a stand-in for truncated SVD
3130
# that only makes use of `maxdim`, just to get some
3231
# functionality running in `ITensorMPS.jl`.

0 commit comments

Comments
 (0)