-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathfunctions.jl
More file actions
77 lines (66 loc) · 3.35 KB
/
functions.jl
File metadata and controls
77 lines (66 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# methods/simple.jl
#
# Method-based access to planar operations using simple definitions.
# ------------------------------------------------------------------------------------------
function planarcopy(A, pA::Index2Tuple, conjA::Symbol, α::Number=One(), backend::Backend...)
TC = TO.promote_add(scalartype(A), scalartype(α))
C = tensoralloc_add(TC, pA, A, conjA)
return planaradd!(C, A, pA, conjA, α, Zero(), backend...)
end
# ------------------------------------------------------------------------------------------
function planartrace(A, pA::Index2Tuple, qA::Index2Tuple, conjA::Symbol, α::Number=One(),
backend::Backend...)
TC = TO.promote_contract(scalartype(A), scalartype(α))
C = tensoralloc_add(TC, pA, A, conjA)
return planartrace!(C, A, pA, qA, conjA, α, Zero(), backend...)
end
# ------------------------------------------------------------------------------------------
"""
planarcontract(A, IA, [conjA], B, IB, [conjB], [IC], [α=1])
planarcontract(A, pA::Index2Tuple, conjA, B, pB::Index2Tuple, conjB, pAB::Index2Tuple, α=1, [backend]) # expert mode
Contract indices of tensor `A` with corresponding indices in tensor `B` by assigning
them identical labels in the iterables `IA` and `IB`. The indices of the resulting
tensor correspond to the indices that only appear in either `IA` or `IB` and can be
ordered by specifying the optional argument `IC`. The default is to have all open
indices of `A` followed by all open indices of `B`. Note that inner contractions of an array
should be handled first with `tensortrace`, so that every label can appear only once in `IA`
or `IB` seperately, and once (for an open index) or twice (for a contracted index) in the
union of `IA` and `IB`.
Optionally, the symbols `conjA` and `conjB` can be used to specify that the input tensors
should be conjugated.
See also [`tensorcontract`](@ref).
"""
function planarcontract end
function planarcontract(A, IA::TensorLabels, conjA::Symbol, B, IB::TensorLabels,
conjB::Symbol, IC::TensorLabels,
α::Number=One())
ia = canonicalize_labels(A, IA)
ib = canonicalize_labels(B, IB)
ic = canonicalize_labels(IC)
pA, pB, pAB = planarcontract_indices(ia, ib, ic)
return planarcontract(A, pA, conjA, B, pB, conjB, pAB, α)
end
# default `IC`
function planarcontract(A, IA::TensorLabels, conjA::Symbol, B, IB::TensorLabels,
conjB::Symbol, α::Number=One())
ia = canonicalize_labels(A, IA)
ib = canonicalize_labels(B, IB)
pA, pB, pAB = planarcontract_indices(ia, ib)
return planarcontract(A, pA, conjA, B, pB, conjB, pAB, α)
end
# default `conjA` and `conjB`
function planarcontract(A, IA, B, IB, IC, α::Number=One())
return planarcontract(A, IA, :N, B, IB, :N, IC, α)
end
function planarcontract(A, IA, B, IB, α::Number=One())
return planarcontract(A, IA, :N, B, IB, :N, α)
end
# expert mode
function planarcontract(A, pA::Index2Tuple, conjA::Symbol,
B, pB::Index2Tuple, conjB::Symbol,
pAB::Index2Tuple, α::Number=One(),
backend::Backend...)
TC = TO.promote_contract(scalartype(A), scalartype(B), scalartype(α))
C = TO.tensoralloc_contract(TC, pAB, A, pA, conjA, B, pB, conjB)
return planarcontract!(C, A, pA, conjA, B, pB, conjB, pAB, α, Zero(), backend...)
end