File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -14,4 +14,30 @@ tensor(states::Vector{T}) where T<:StateVector = reduce(tensor, states)
1414
1515Gives the tensor product of `a` `N` times.
1616"""
17- tensor_pow (a, N) = Base. power_by_squaring (a, N; mul= ⊗ )
17+ tensor_pow (a, N) = tensor_pow_by_squaring (a, N)
18+
19+ # Copied from Base.power_by_squaring as `mul` keyword dosn't work without implementing `*`
20+ function tensor_pow_by_squaring (x, p:: Integer )
21+ if p == 1
22+ return x
23+ elseif p == 2
24+ return tensor (x, x)
25+ elseif p < 1
26+ throw (DomainError (" Cannot take tensor_pow to power less than one" ))
27+ end
28+ t = trailing_zeros (p) + 1
29+ p >>= t
30+ while (t -= 1 ) > 0
31+ x = tensor (x, x)
32+ end
33+ y = x
34+ while p > 0
35+ t = trailing_zeros (p) + 1
36+ p >>= t
37+ while (t -= 1 ) >= 0
38+ x = tensor (x, x)
39+ end
40+ y = tensor (y, x)
41+ end
42+ return y
43+ end
You can’t perform that action at this time.
0 commit comments