Skip to content

Commit a2185f6

Browse files
committed
move Hermitian wrapper to instantiation, not at callers
1 parent 8a35356 commit a2185f6

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

ext/SymmetricTightBindingOptimExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function fg!(
2020
end
2121

2222
for (Es_r, k) in zip(eachrow(Em_r), ks)
23-
H = Hermitian(ptbm(k))
23+
H = ptbm(k)
2424
Es, us = eigen!(H) # no Bloch phases, deliberately
2525

2626
# MSE loss (possibly with lasso penalty)

src/spectrum.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ function spectrum_single_k(
8787
) where {D, S, F}
8888
length(k) == D ||
8989
error(lazy"dimension mismatch of momentum ($(length(k))) & model ($D)")
90-
_H = ptbm(k)
91-
H = S == HERMITIAN ? Hermitian(_H) : _H
90+
H = ptbm(k)
9291
es = eigvals!(H)
9392
return _apply_transform(es, transform)
9493
end

src/types.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,24 +417,24 @@ hermiticity(::ParameterizedTightBindingModel{D, S}) where {D, S} = S
417417
orbital_positions(ptbm::ParameterizedTightBindingModel) = ptbm.tbm.positions
418418
Crystalline.CompositeBandRep(ptbm::ParameterizedTightBindingModel) = ptbm.tbm.cbr
419419

420-
function (ptbm::ParameterizedTightBindingModel{D})(
420+
function (ptbm::ParameterizedTightBindingModel{D, S})(
421421
k::ReciprocalPointLike{D},
422422
scratch::Matrix{ComplexF64} = ptbm.scratch,
423-
) where {D}
423+
) where {D, S}
424424
if length(k) D
425425
error("momentum `k` must be a $D-dimensional vector to match the model dimension")
426426
end
427427
tbm = ptbm.tbm
428428
size(scratch) (tbm.N, tbm.N) && _throw_scratch_size_mismatch(scratch, tbm.N)
429429

430-
H = scratch # grab & reset scratch space for evaluating Hamiltonian matrix
431-
fill!(H, 0.0)
430+
_H = scratch # grab & reset scratch space for evaluating Hamiltonian matrix
431+
fill!(_H, 0.0)
432432

433433
# evaluate each block of the Hamiltonian terms, multiply by coefficients, & store in `H`
434434
for (tbt, c) in zip(tbm.terms, ptbm.cs)
435-
evaluate_tight_binding_term!(tbt, k, c, H) # modifies `H` in-place
435+
evaluate_tight_binding_term!(tbt, k, c, _H) # modifies `H` in-place
436436
end
437-
437+
H = S == HERMITIAN ? Hermitian(_H) : _H # return Hermitian wrapper if S == HERMITIAN
438438
return H
439439
end
440440

@@ -500,8 +500,7 @@ function solve(
500500
eigen_kws...,
501501
) where {D, S}
502502
length(k) == D || error("dimension mismatch")
503-
_H = ptbm(k)
504-
H = S == HERMITIAN ? Hermitian(_H) : _H
503+
H = ptbm(k)
505504
es, vs = eigen!(H; eigen_kws...)
506505
if bloch_phase === Val(true)
507506
Θₖ = reciprocal_translation_phase(orbital_positions(ptbm), k)

test/spectrum.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ using LinearAlgebra
1818
@test issorted(es) # eigenvalues sorted
1919

2020
# compare against direct eigvals
21-
H = Hermitian(ptbm(k))
21+
H = ptbm(k)
22+
@test H isa Hermitian
2223
@test es eigvals(H)
2324
end
2425

0 commit comments

Comments
 (0)