Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MeanFi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quantum Tinkerer
MeanFi
Commits
f4945090
Commit
f4945090
authored
Apr 2, 2024
by
Johanna Zijderveld
Browse files
Options
Downloads
Patches
Plain Diff
more optimal flattening
parent
2c754354
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!4
Interface refactoring
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
codes/params/matrixShaping.py
+13
-11
13 additions, 11 deletions
codes/params/matrixShaping.py
with
13 additions
and
11 deletions
codes/params/matrixShaping.py
+
13
−
11
View file @
f4945090
import
numpy
as
np
def
hop_dict_to_flat
(
hop_dict
):
"""
Convert a hermitian tight-binding dictionary to flat complex matrix.
...
...
@@ -14,11 +15,12 @@ def hop_dict_to_flat(hop_dict):
flat : complex 1d numpy array
Flattened tight-binding dictionary
"""
N
=
len
(
hop_dict
.
keys
())
//
2
+
1
sorted_vals
=
np
.
array
(
list
(
hop_dict
.
values
()))[
np
.
lexsort
(
np
.
array
(
list
(
hop_dict
)).
T
)
np
.
lexsort
(
np
.
array
(
list
(
hop_dict
.
keys
()
)).
T
)
]
flat
=
sorted_vals
[...,
*
np
.
triu_indices
(
sorted_vals
.
shape
[
-
1
])
].
flatten
()
return
flat
return
sorted_vals
[:
N
].
flatten
()
def
flat_to_hop_dict
(
flat
,
shape
,
hop_dict_keys
):
"""
...
...
@@ -40,17 +42,16 @@ def flat_to_hop_dict(flat, shape, hop_dict_keys):
tight-binding dictionary
"""
matrix
=
np
.
zeros
(
shape
,
dtype
=
complex
)
matrix
[...,
*
np
.
triu_indices
(
shape
[
-
1
])]
=
flat
.
reshape
(
*
shape
[:
-
2
],
-
1
)
indices
=
np
.
arange
(
shape
[
-
1
])
diagonal
=
matrix
[...,
indices
,
indices
]
matrix
+=
np
.
moveaxis
(
matrix
[
-
1
::
-
1
],
-
1
,
-
2
).
conj
()
matrix
[...,
indices
,
indices
]
-=
diagonal
N
=
len
(
hop_dict_keys
)
//
2
+
1
matrix
[:
N
]
=
flat
.
reshape
(
N
,
*
shape
[
1
:])
matrix
[
N
:]
=
np
.
moveaxis
(
matrix
[
-
(
N
+
1
)
::
-
1
],
-
1
,
-
2
).
conj
()
hop_dict_keys
=
np
.
array
(
list
(
hop_dict_keys
))
sorted_keys
=
hop_dict_keys
[
np
.
lexsort
(
hop_dict_keys
.
T
)]
hop_dict
=
dict
(
zip
(
map
(
tuple
,
sorted_keys
),
matrix
))
return
hop_dict
def
complex_to_real
(
z
):
"""
Split real and imaginary parts of a complex array.
...
...
@@ -61,6 +62,7 @@ def complex_to_real(z):
"""
return
np
.
concatenate
((
np
.
real
(
z
),
np
.
imag
(
z
)))
def
real_to_complex
(
z
):
"""
Undo `complex_to_real`.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment