Skip to content

Commit 1df3e57

Browse files
Merge pull request #51 from SpM-lab/terasaki/apply-ascontiguousarray
Apply `np.ascontiguousarray` to input data
2 parents d469a4d + 7c9d896 commit 1df3e57

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/sparse_ir/sampling.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def evaluate(self, al, axis=0):
6363
ndarray
6464
Values at sampling points
6565
"""
66+
al = np.ascontiguousarray(al)
6667
output_dims = list(al.shape)
6768
ndim = len(output_dims)
6869
input_dims = np.asarray(al.shape, dtype=np.int32)
@@ -104,6 +105,7 @@ def fit(self, ax, axis=0):
104105
"""
105106
Fit basis coefficients from sampling point values.
106107
"""
108+
ax = np.ascontiguousarray(ax)
107109
ndim = len(ax.shape)
108110
input_dims = np.asarray(ax.shape, dtype=np.int32)
109111
output_dims = list(ax.shape)

tutorials/flex_py.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---
22
# jupyter:
33
# jupytext:
4-
# cell_metadata_filter: -all
4+
# cell_metadata_filter: cell_depth,title,-all
55
# custom_cell_magics: kql
66
# text_representation:
77
# extension: .py
@@ -19,7 +19,7 @@
1919
import scipy as sc
2020
import scipy.optimize
2121
from warnings import warn
22-
import pylibsparseir as sparse_ir
22+
import sparse_ir
2323
# %matplotlib inline
2424
import matplotlib.pyplot as plt
2525

@@ -142,8 +142,6 @@ def __init__(self, mesh, U, n, sigma_init=0, sfc_tol=1e-4,
142142
self.grit_calc()
143143
self.ckio_calc()
144144

145-
146-
#%%%%%%%%%%% Loop solving instance
147145
def solve(self):
148146
""" FLEXSolver.solve() executes FLEX loop until convergence """
149147
# check whether U < U_crit! Otherwise, U needs to be renormalized.
@@ -180,8 +178,6 @@ def loop(self):
180178
self.grit_calc()
181179
self.ckio_calc()
182180

183-
184-
#%%%%%%%%%%% U renormalization loop instance
185181
def U_renormalization(self):
186182
""" Loop for renormalizing U if Stoner enhancement U*max{chi0} >= 1. """
187183
print('WARNING: U is too large and the spin susceptibility denominator will diverge/turn unphysical!')
@@ -211,8 +207,6 @@ def U_renormalization(self):
211207
break
212208
print('Leaving U renormalization...')
213209

214-
215-
#%%%%%%%%%%% Calculation steps
216210
def gkio_calc(self, mu):
217211
""" calculate Green function G(iw,k) """
218212
self.gkio = (self.mesh.iwn_f_ - (self.mesh.ek_ - mu) - self.sigma)**(-1)
@@ -257,8 +251,6 @@ def sigma_calc(self):
257251
sigma = self.mesh.r_to_k(sigma)
258252
self.sigma = self.mesh.tau_to_wn('F', sigma)
259253

260-
261-
#%%%%%%%%%%% Setting chemical potential mu
262254
def calc_electron_density(self, mu):
263255
""" Calculate electron density from Green function """
264256
self.gkio_calc(mu)
@@ -278,6 +270,7 @@ def mu_calc(self):
278270

279271
self.mu = sc.optimize.brentq(f, np.amax(self.mesh.ek)*3, np.amin(self.mesh.ek)*3)
280272

273+
281274
# %%
282275
# initialize calculation
283276
IR_basis_set = sparse_ir.FiniteTempBasisSet(beta, wmax, eps=IR_tol)
@@ -369,7 +362,6 @@ def solve(self):
369362
if abs(self.lam-lam_old) < self.sfc_tol:
370363
break
371364

372-
#%%%%%%%%%%% Calculation steps
373365
def V_singlet_calc(self):
374366
""" Set up interaction in real space and imaginary time """
375367

@@ -389,6 +381,8 @@ def frit_calc(self):
389381
frit = self.mesh.k_to_r(self.fkio)
390382
self.frit = self.mesh.wn_to_tau('F', frit)
391383

384+
# %%%%%%%%%%% Calculation steps
385+
392386

393387
# %%
394388
gap_solver = LinearizedGapSolver(solver, maxiter=maxiter, sfc_tol=sfc_tol)
@@ -435,7 +429,7 @@ def frit_calc(self):
435429
plt.show()
436430

437431
# %%
438-
#%%%%%%%%%%%%%%% Parameter settings
432+
# %%%%%%%%%%%%%%% Parameter settings
439433
print('Initialization...')
440434
# system parameters
441435
t = 1 # hopping amplitude
@@ -468,7 +462,7 @@ def frit_calc(self):
468462
chiSmax_T = np.empty((len(T_values)))
469463

470464

471-
#%%%%%%%%%%%%%%% Calculation for different T values
465+
# %%%%%%%%%%%%%%% Calculation for different T values
472466
for T_it, T in enumerate(T_values):
473467
print("Now: T = {}".format(T))
474468
beta = 1/T
@@ -494,8 +488,7 @@ def frit_calc(self):
494488
if T == 0.03:
495489
chi_s_plt = np.real(solver.chi_spin)[mesh.iw0_b].reshape(mesh.nk1,mesh.nk2)
496490

497-
# %%
498-
#%%%%%%%%%%%%%%%% Plot results in a combined figure
491+
# %%%%%%%%%%%%%%%% Plot results in a combined figure
499492
import matplotlib.gridspec as gridspec
500493

501494
fig = plt.figure(figsize=(10,4),constrained_layout=True)

0 commit comments

Comments
 (0)