Skip to content

Commit 38d7f33

Browse files
authored
Auto code format
1 parent 60772d7 commit 38d7f33

6 files changed

Lines changed: 117 additions & 119 deletions

File tree

src/pyGroupedTransforms/GroupedTransform.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@ def get_matrix(self):
435435
u1 = (0,)
436436
else:
437437
u1 = s1.u
438-
F_direct = s1.mode.get_matrix(s1.bandwidths, self.X[:, u1].T, bases=s1.bases)
438+
F_direct = s1.mode.get_matrix(
439+
s1.bandwidths, self.X[:, u1].T, bases=s1.bases
440+
)
439441
for idx, s in enumerate(self.settings):
440442
if idx == 0:
441443
continue

src/pyGroupedTransforms/NFCTtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def get_transform(
127127
if bandwidths.ndim > 1 or bandwidths.dtype != "int32":
128128
return "Please use an zero or one-dimensional numpy.array with dtype 'int32' as input"
129129

130-
(M, d) = X.shape
130+
M, d = X.shape
131131

132132
if len(bandwidths) == 0:
133133
return DeferredLinearOperator(

src/pyGroupedTransforms/NFFTtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def get_transform(
138138
if bandwidths.ndim > 1 or bandwidths.dtype != "int32":
139139
return "Please use an zero or one-dimensional numpy.array with dtype 'int32' as input"
140140

141-
(M, d) = np.shape(X)
141+
M, d = np.shape(X)
142142

143143
if len(bandwidths) == 0:
144144
return DeferredLinearOperator(
Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,126 @@
11
import numpy as np
2+
from pyNFFT3.NFMT import BASES
23

34
from pyGroupedTransforms import *
4-
from pyNFFT3.NFMT import BASES
55

66

77
def datalength(bandwidths: np.ndarray) -> int:
8-
"""Return the number of mixed-basis Fourier coefficients (zero-frequencies excluded).
8+
"""Return the number of mixed-basis Fourier coefficients (zero-frequencies excluded).
99
10-
For each dimension j the frequency range used is:
11-
exp -> {-N_j/2, ..., -1, 1, ..., N_j/2 - 1} (N_j - 1 values)
12-
cos/alg -> {1, 2, ..., N_j - 1} (N_j - 1 values)
13-
Total: prod(N - 1).
14-
"""
15-
if bandwidths.ndim != 1 or bandwidths.dtype != "int32":
16-
return "Please use an one-dimensional numpy.array with dtype 'int32' as input"
17-
if len(bandwidths) == 0:
18-
return 1
19-
return int(np.prod(bandwidths - 1))
10+
For each dimension j the frequency range used is:
11+
exp -> {-N_j/2, ..., -1, 1, ..., N_j/2 - 1} (N_j - 1 values)
12+
cos/alg -> {1, 2, ..., N_j - 1} (N_j - 1 values)
13+
Total: prod(N - 1).
14+
"""
15+
if bandwidths.ndim != 1 or bandwidths.dtype != "int32":
16+
return "Please use an one-dimensional numpy.array with dtype 'int32' as input"
17+
if len(bandwidths) == 0:
18+
return 1
19+
return int(np.prod(bandwidths - 1))
2020

2121

2222
def nfmt_index_set_without_zeros(bandwidths: np.ndarray, bases) -> np.ndarray:
23-
"""Return the (d, prod(N-1)) integer frequency matrix.
24-
25-
Mirrors Julia's GroupedTransforms.NFMTtools.nfmt_index_set_without_zeros:
26-
exp dimension j: {-N_j/2, ..., -1, 1, ..., N_j/2 - 1}
27-
cos/alg dimension j: {1, 2, ..., N_j - 1}
28-
"""
29-
d = len(bandwidths)
30-
if d == 0:
31-
return np.array([[0]], dtype=np.int64)
32-
33-
ranges = []
34-
for n, basis in zip(bandwidths, bases):
35-
if BASES[basis] > 0:
36-
# cos or alg: {1, ..., N-1}
37-
ranges.append(list(range(1, int(n))))
38-
else:
39-
# exp: {-N/2, ..., -1, 1, ..., N/2-1}
40-
half = int(n) // 2
41-
ranges.append(list(range(-half, 0)) + list(range(1, half)))
42-
43-
if d == 1:
44-
return np.array(ranges[0], dtype=np.int64).reshape(1, -1)
45-
46-
# Cartesian product; last dimension changes fastest (row-major, matching Julia)
47-
mesh = np.array(np.meshgrid(*ranges, indexing="ij"), dtype=np.int64)
48-
return mesh.reshape(d, -1)
23+
"""Return the (d, prod(N-1)) integer frequency matrix.
24+
25+
Mirrors Julia's GroupedTransforms.NFMTtools.nfmt_index_set_without_zeros:
26+
exp dimension j: {-N_j/2, ..., -1, 1, ..., N_j/2 - 1}
27+
cos/alg dimension j: {1, 2, ..., N_j - 1}
28+
"""
29+
d = len(bandwidths)
30+
if d == 0:
31+
return np.array([[0]], dtype=np.int64)
32+
33+
ranges = []
34+
for n, basis in zip(bandwidths, bases):
35+
if BASES[basis] > 0:
36+
# cos or alg: {1, ..., N-1}
37+
ranges.append(list(range(1, int(n))))
38+
else:
39+
# exp: {-N/2, ..., -1, 1, ..., N/2-1}
40+
half = int(n) // 2
41+
ranges.append(list(range(-half, 0)) + list(range(1, half)))
42+
43+
if d == 1:
44+
return np.array(ranges[0], dtype=np.int64).reshape(1, -1)
45+
46+
# Cartesian product; last dimension changes fastest (row-major, matching Julia)
47+
mesh = np.array(np.meshgrid(*ranges, indexing="ij"), dtype=np.int64)
48+
return mesh.reshape(d, -1)
4949

5050

5151
def get_matrix(bandwidths, X, bases) -> np.ndarray:
52-
"""Build the evaluation matrix F with F[m, j] = phi(x_m, k_j).
53-
54-
Mirrors Julia's GroupedTransforms.NFMTtools.get_matrix / get_phi:
55-
exp: exp(-2pi i k x)
56-
cos: sqrt(2) * cos(pi * k * x) (k != 0 guaranteed by frequency set)
57-
alg: sqrt(2) * cos(k * arccos(2x - 1))
58-
59-
X is expected in (d, M) format (columns are nodes), consistent with the
60-
convention used in GroupedTransform.get_matrix.
61-
"""
62-
if X.ndim == 1 or X.shape[0] == 1:
63-
X_eval = X.flatten().reshape(-1, 1) # (M, 1)
64-
d = 1
65-
M = X_eval.shape[0]
66-
else:
67-
d, M = X.shape
68-
X_eval = X.T # (M, d)
69-
70-
if len(bandwidths) == 0:
71-
return np.ones((M, 1), dtype=np.complex128)
72-
73-
freq = nfmt_index_set_without_zeros(
74-
np.asarray(bandwidths, dtype=np.int32), list(bases)
75-
) # (d, nf)
76-
77-
nf = freq.shape[1]
78-
F = np.ones((M, nf), dtype=np.complex128)
79-
80-
for j in range(d):
81-
n_j = freq[j] # (nf,) all nonzero by construction
82-
x_j = X_eval[:, j][:, None] # (M, 1)
83-
if BASES[bases[j]] == 1:
84-
# cos basis: sqrt(2) * cos(pi * k * x)
85-
F *= np.sqrt(2.0) * np.cos(np.pi * x_j * n_j)
86-
elif BASES[bases[j]] == 2:
87-
# alg (Chebyshev) basis: sqrt(2) * cos(k * arccos(2x - 1))
88-
F *= np.sqrt(2.0) * np.cos(n_j * np.arccos(2.0 * x_j - 1.0))
89-
else:
90-
# exp basis: exp(-2pi i k x)
91-
F *= np.exp(-2.0j * np.pi * x_j * n_j)
92-
93-
return F
52+
"""Build the evaluation matrix F with F[m, j] = phi(x_m, k_j).
53+
54+
Mirrors Julia's GroupedTransforms.NFMTtools.get_matrix / get_phi:
55+
exp: exp(-2pi i k x)
56+
cos: sqrt(2) * cos(pi * k * x) (k != 0 guaranteed by frequency set)
57+
alg: sqrt(2) * cos(k * arccos(2x - 1))
58+
59+
X is expected in (d, M) format (columns are nodes), consistent with the
60+
convention used in GroupedTransform.get_matrix.
61+
"""
62+
if X.ndim == 1 or X.shape[0] == 1:
63+
X_eval = X.flatten().reshape(-1, 1) # (M, 1)
64+
d = 1
65+
M = X_eval.shape[0]
66+
else:
67+
d, M = X.shape
68+
X_eval = X.T # (M, d)
69+
70+
if len(bandwidths) == 0:
71+
return np.ones((M, 1), dtype=np.complex128)
72+
73+
freq = nfmt_index_set_without_zeros(
74+
np.asarray(bandwidths, dtype=np.int32), list(bases)
75+
) # (d, nf)
76+
77+
nf = freq.shape[1]
78+
F = np.ones((M, nf), dtype=np.complex128)
79+
80+
for j in range(d):
81+
n_j = freq[j] # (nf,) all nonzero by construction
82+
x_j = X_eval[:, j][:, None] # (M, 1)
83+
if BASES[bases[j]] == 1:
84+
# cos basis: sqrt(2) * cos(pi * k * x)
85+
F *= np.sqrt(2.0) * np.cos(np.pi * x_j * n_j)
86+
elif BASES[bases[j]] == 2:
87+
# alg (Chebyshev) basis: sqrt(2) * cos(k * arccos(2x - 1))
88+
F *= np.sqrt(2.0) * np.cos(n_j * np.arccos(2.0 * x_j - 1.0))
89+
else:
90+
# exp basis: exp(-2pi i k x)
91+
F *= np.exp(-2.0j * np.pi * x_j * n_j)
92+
93+
return F
9494

9595

9696
def get_transform(bandwidths: np.ndarray, X: np.ndarray, bases):
97-
"""Return a DeferredLinearOperator for the mixed-basis grouped transform.
98-
99-
Uses the same matrix as get_matrix wrapped in a linear operator so that
100-
trafo and adjoint are consistent by construction.
101-
X is expected in (M, d) format (rows are nodes), consistent with the
102-
convention used in GroupedTransform.transforms.
103-
"""
104-
if bandwidths.ndim > 1 or bandwidths.dtype != "int32":
105-
return "Please use a zero or one-dimensional numpy.array with dtype 'int32' as input"
106-
107-
M = X.shape[0]
108-
109-
if len(bandwidths) == 0:
110-
return DeferredLinearOperator(
111-
dtype=np.complex128,
112-
shape=(M, 1),
113-
mfunc=lambda fhat: np.full(M, fhat[0], dtype=np.complex128),
114-
rmfunc=lambda f: np.array([np.sum(f)], dtype=np.complex128),
115-
)
116-
117-
# X is (M, d) here; get_matrix expects (d, M)
118-
mat = get_matrix(bandwidths, X.T, list(bases)) # (M, nf)
119-
N = int(np.prod(bandwidths - 1))
120-
121-
return DeferredLinearOperator(
122-
dtype=np.complex128,
123-
shape=(M, N),
124-
mfunc=lambda fhat: mat @ np.asarray(fhat, dtype=np.complex128),
125-
rmfunc=lambda f: mat.conj().T @ np.asarray(f, dtype=np.complex128),
126-
)
97+
"""Return a DeferredLinearOperator for the mixed-basis grouped transform.
98+
99+
Uses the same matrix as get_matrix wrapped in a linear operator so that
100+
trafo and adjoint are consistent by construction.
101+
X is expected in (M, d) format (rows are nodes), consistent with the
102+
convention used in GroupedTransform.transforms.
103+
"""
104+
if bandwidths.ndim > 1 or bandwidths.dtype != "int32":
105+
return "Please use a zero or one-dimensional numpy.array with dtype 'int32' as input"
106+
107+
M = X.shape[0]
108+
109+
if len(bandwidths) == 0:
110+
return DeferredLinearOperator(
111+
dtype=np.complex128,
112+
shape=(M, 1),
113+
mfunc=lambda fhat: np.full(M, fhat[0], dtype=np.complex128),
114+
rmfunc=lambda f: np.array([np.sum(f)], dtype=np.complex128),
115+
)
116+
117+
# X is (M, d) here; get_matrix expects (d, M)
118+
mat = get_matrix(bandwidths, X.T, list(bases)) # (M, nf)
119+
N = int(np.prod(bandwidths - 1))
120+
121+
return DeferredLinearOperator(
122+
dtype=np.complex128,
123+
shape=(M, N),
124+
mfunc=lambda fhat: mat @ np.asarray(fhat, dtype=np.complex128),
125+
rmfunc=lambda f: mat.conj().T @ np.asarray(f, dtype=np.complex128),
126+
)

tests/nfmt_U.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
# set up transform ###################################################
2626

27-
F = GroupedTransform(
28-
"mixed", X, U=U, N=[0, 64, 16], basis_vect=basis_vect
29-
)
27+
F = GroupedTransform("mixed", X, U=U, N=[0, 64, 16], basis_vect=basis_vect)
3028
F_direct = F.get_matrix()
3129

3230
# compute transform with NFMT ########################################

tests/nfmt_ds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
# set up transform ###################################################
2424

25-
F = GroupedTransform(
26-
"mixed", X, d=d, ds=ds, N=[64, 16, 4], basis_vect=basis_vect
27-
)
25+
F = GroupedTransform("mixed", X, d=d, ds=ds, N=[64, 16, 4], basis_vect=basis_vect)
2826
F_direct = F.get_matrix()
2927

3028
# compute transform with NFMT ########################################

0 commit comments

Comments
 (0)