Skip to content

Commit

Permalink
Function: Fix for numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller authored and mbaudin47 committed Jun 19, 2024
1 parent 877107d commit 052dd0c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def regularFunc(X):

def regularFuncSample(X):
# Create a numpy array with the contents of X without copy
xarray = np.array(X, copy=False)
xarray = np.asarray(X)
# Get columns as vectors, there is also no copy
x0, x1, x2 = xarray.T
# Allocate a numpy array to store result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def piecewise(X):
# f = (x+0.75)**2-0.75**2
# else:
# f = 2.0-x**2
xarray = np.array(X, copy=False)
xarray = np.asarray(X)
return np.piecewise(
xarray,
[xarray < 0, xarray >= 0],
Expand Down
4 changes: 2 additions & 2 deletions python/src/Function.i
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _exec_sample_multiprocessing_func_sample(func_sample, n_cpus):
if nsim < n_cpus:
return func_sample(X)

a = np.array(X, copy=False)
a = np.asarray(X)
rs = p.map(func_sample, [a[r:r+(nsim//n_cpus), :] for r in range(0, nsim, nsim//n_cpus)])
p.close()
p.join()
Expand Down Expand Up @@ -367,7 +367,7 @@ class PythonFunction(Function):
>>> import openturns as ot
>>> import numpy as np
>>> def a_exec_sample(X):
... Xarray = np.array(X, copy=False)
... Xarray = np.asarray(X)
... Y = 3.0 * Xarray[:,0] - Xarray[:,1]
... return np.expand_dims(Y, axis=1)
>>> def a_grad(X):
Expand Down

0 comments on commit 052dd0c

Please sign in to comment.