Skip to content

Commit a0eed42

Browse files
Merge pull request #189 from rohanbabbar04/numpy2.4-fix
Fixes to support numpy>=2.4
2 parents b6df40a + f13c237 commit a0eed42

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ channels:
55
dependencies:
66
- python >= 3.8.0
77
- pip
8-
- numpy>=1.15.0,<=2.3.5
8+
- numpy>=1.15.0
99
- scipy>=1.8.0
1010
- mpi4py
1111
- pylops

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ channels:
44
- conda-forge
55
dependencies:
66
- python>=3.8.0
7-
- numpy>=1.15.0,<=2.3.5
7+
- numpy>=1.15.0
88
- scipy>=1.8.0
99
- pylops>=2.0
1010
- matplotlib

pylops_mpi/basicoperators/BlockDiag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ def __init__(self, ops: Sequence[MPILinearOperator], base_comm: MPI.Comm = MPI.C
170170
dtype: Optional[DTypeLike] = None):
171171
self.ops = ops
172172
dtype = _get_dtype(self.ops) if dtype is None else np.dtype(dtype)
173-
shape = (int(np.sum(op.shape[0] for op in ops)),
174-
int(np.sum(op.shape[1] for op in ops)))
173+
shape = (int(sum(op.shape[0] for op in ops)),
174+
int(sum(op.shape[1] for op in ops)))
175175
super().__init__(shape=shape, dtype=dtype, base_comm=base_comm)
176176

177177
def _matvec(self, x: StackedDistributedArray) -> StackedDistributedArray:

pylops_mpi/basicoperators/VStack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(self, ops: Sequence[MPILinearOperator],
183183
self.ops = ops
184184
if len(set(op.shape[1] for op in ops)) > 1:
185185
raise ValueError("Operators have different number of columns")
186-
shape = (int(np.sum(op.shape[0] for op in ops)), ops[0].shape[1])
186+
shape = (int(sum(op.shape[0] for op in ops)), ops[0].shape[1])
187187
dtype = _get_dtype(self.ops) if dtype is None else np.dtype(dtype)
188188
super().__init__(shape=shape, dtype=dtype, base_comm=base_comm)
189189

pylops_mpi/optimization/cls_basic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def setup(
9292
self.r = self.y - self.Op.matvec(x)
9393
self.rank = x.rank
9494
self.c = self.r.copy()
95-
self.kold = float(np.abs(self.r.dot(self.r.conj())))
95+
self.kold = float(np.abs(self.r.dot(self.r.conj())).item())
9696

9797
# create variables to track the residual norm and iterations
9898
self.cost: List = []
@@ -127,10 +127,10 @@ def step(self, x: Union[DistributedArray, StackedDistributedArray],
127127
"""
128128
Opc = self.Op.matvec(self.c)
129129
cOpc = np.abs(self.c.dot(Opc.conj()))
130-
a = float(self.kold / cOpc)
130+
a = float((self.kold / cOpc).item())
131131
x += a * self.c
132132
self.r -= a * Opc
133-
k = float(np.abs(self.r.dot(self.r.conj())))
133+
k = float(np.abs(self.r.dot(self.r.conj())).item())
134134
b = float(k / self.kold)
135135
self.c = self.r + b * self.c
136136
self.kold = k
@@ -349,13 +349,13 @@ def setup(self,
349349
self.rank = x.rank
350350
self.c = r.copy()
351351
self.q = self.Op.matvec(self.c)
352-
self.kold = float(np.abs(r.dot(r.conj())))
352+
self.kold = float(np.abs(r.dot(r.conj())).item())
353353

354354
# create variables to track the residual norm and iterations
355355
self.cost = []
356356
self.cost1 = []
357-
self.cost.append(float(self.s.norm()))
358-
self.cost1.append(np.sqrt(float(self.cost[0] ** 2 + damp * np.abs(x.dot(x.conj())))))
357+
self.cost.append(float(self.s.norm().item()))
358+
self.cost1.append(np.sqrt(float(self.cost[0] ** 2 + damp * np.abs(x.dot(x.conj())).item())))
359359
self.iiter = 0
360360

361361
# print setup
@@ -386,19 +386,19 @@ def step(self, x: Union[DistributedArray, StackedDistributedArray],
386386
387387
"""
388388

389-
a = float(np.abs(self.kold / (self.q.dot(self.q.conj()) + self.damp * self.c.dot(self.c.conj()))))
389+
a = float(np.abs(self.kold / (self.q.dot(self.q.conj()) + self.damp * self.c.dot(self.c.conj()))).item())
390390
x += a * self.c
391391
self.s -= a * self.q
392392
damped_x = self.damp * x
393393
r = self.Op.rmatvec(self.s) - damped_x
394-
k = float(np.abs(r.dot(r.conj())))
394+
k = float(np.abs(r.dot(r.conj())).item())
395395
b = float(k / self.kold)
396396
self.c = r + b * self.c
397397
self.q = self.Op.matvec(self.c)
398398
self.kold = k
399399
self.iiter += 1
400-
self.cost.append(float(self.s.norm()))
401-
self.cost1.append(np.sqrt(float(self.cost[self.iiter] ** 2 + self.damp * np.abs(x.dot(x.conj())))))
400+
self.cost.append(float(self.s.norm().item()))
401+
self.cost1.append(np.sqrt(float(self.cost[self.iiter] ** 2 + self.damp * np.abs(x.dot(x.conj())).item())))
402402
if show and self.rank == 0:
403403
self._print_step(x)
404404
return x

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Topic :: Scientific/Engineering :: Mathematics",
3030
]
3131
dependencies = [
32-
"numpy>=1.15.0,<=2.3.5",
32+
"numpy>=1.15.0",
3333
"scipy >= 1.4.0",
3434
"pylops >= 2.0",
3535
"mpi4py",

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy>=1.15.0,<=2.3.5
1+
numpy>=1.15.0
22
scipy>=1.8.0
33
pylops
44
mpi4py

0 commit comments

Comments
 (0)