|
69 | 69 | # Constructors |
70 | 70 | # |
71 | 71 |
|
72 | | -# Construct by feeding `tensors` through `set_vertex_data!` one vertex |
73 | | -# at a time — this centralizes the reverse-map registration, edge |
74 | | -# inference, and hypergraph check in a single place (the `setindex!` |
75 | | -# code path). Walking `keys(tensors)` in order makes the resulting |
76 | | -# `neighbors(g, v)` / `edges(g)` iteration order deterministic in the |
77 | | -# input order. An empty `tensors` (`Dict{V, ITensor}()`, etc.) yields |
78 | | -# an empty network — there is no separate empty-arg constructor. |
| 72 | +# Empty network with no vertices. Mirrors the `Vector()` / `Dictionary()` |
| 73 | +# convention; vertex type defaults to `Any` when unspecified. |
| 74 | +function ITensorNetwork{V}() where {V} |
| 75 | + return ITensorNetwork{V}( |
| 76 | + NamedGraph{V}(), Dictionary{V, ITensor}(), Dict{Index, Set{V}}() |
| 77 | + ) |
| 78 | +end |
| 79 | +ITensorNetwork() = ITensorNetwork{Any}() |
| 80 | + |
| 81 | +# Construct by writing each tensor into a freshly empty network via |
| 82 | +# `setindex!`. The `setindex!` code path centralizes reverse-map |
| 83 | +# registration, edge inference, and the hypergraph check, and walking |
| 84 | +# `keys(tensors)` in order makes the resulting `neighbors(g, v)` / |
| 85 | +# `edges(g)` iteration order deterministic in the input order. |
79 | 86 | function ITensorNetwork{V}(tensors) where {V} |
80 | | - tn = ITensorNetwork{V}(NamedGraph{V}(), Dictionary{V, ITensor}(), Dict{Index, Set{V}}()) |
| 87 | + tn = ITensorNetwork{V}() |
81 | 88 | for v in keys(tensors) |
82 | | - set_vertex_data!(tn, tensors[v], v) |
| 89 | + tn[v] = tensors[v] |
83 | 90 | end |
84 | 91 | return tn |
85 | 92 | end |
|
0 commit comments