Simplify similarmatrix, remove optimize! #106
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #105
This PR is an alternative to #105
PR #105 has some serious problems. Internalizing the Bloch matrix into
Hamiltonian
leads to less flexibility, since its type often depends on the context (e.g. the method used to diagonalize a Hamiltonian). Needing to mutate/regenerate a Hamiltonian just to change its Bloch matrix type is inelegant and inefficient. Also, a chain of transformations of a Hamiltonian almost always led to ablochmatrix
needing to be allocated at each step. The decision to take the Julianbloch!(matrix, h, ...)
approach was ultimately good. The only problem of needing an external preallocated Bloch matrix is that thesimilarmatrix
used to construct thematrix
was sometimes not smart enough.This PR takes the good bits of #105 without internalizing
blochmatrix
. In particular we can now dosimilarmatrix(h, flatten)
to keep the matrix type ofh
but with a scalar eltype (it is still inferable sinceflatten
is a function with a unique type). Sinceflatten
is an exported function with the same meaning of flattening eltypes, this seems appropriate, without needing a new exported function. We also get rid ofoptimize!
, and simply force the output ofsimilarmatrix(h,...)
to already be optimized forh
, thus avoiding sparse element splicing when callingbloch!/bloch
.We also sneak in a change that was part of #105: changing the
type
kwarg ofhamiltonian
toorbtype
, which is more descriptive. The equivalent forlattice
is stilltype
.