Skip to content

Enable ProbNum Import with NumPy 2.0 (Tested via linpde-gp) #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
"# %load -s function_evaluation quadopt_example/observation_operators\n",
"def function_evaluation(\n",
" fun: Callable[[FloatLike], FloatLike], action: FloatLike\n",
") -> np.float_:\n",
") -> np.float64:\n",
" \"\"\"Observe a (noisy) function evaluation of the quadratic objective.\n",
"\n",
" Parameters\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def function_evaluation(
fun: Callable[[FloatLike], FloatLike], action: FloatLike
) -> np.float_:
) -> np.float64:
"""Observe a (noisy) function evaluation of the quadratic objective.

Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
" return np.roll(v, 1)\n",
"\n",
"n = 5\n",
"P_op = LambdaLinearOperator(shape=(n, n), dtype=np.float_, matmul=mv)\n",
"P_op = LambdaLinearOperator(shape=(n, n), dtype=np.float64, matmul=mv)\n",
"x = np.arange(0., n, 1)\n",
"\n",
"P_op"
Expand Down Expand Up @@ -512,7 +512,7 @@
"def mv(v):\n",
" return v[:n-1]\n",
"\n",
"Pr = LambdaLinearOperator(shape=(n-1, n), dtype=np.float_, matmul=mv)\n",
"Pr = LambdaLinearOperator(shape=(n-1, n), dtype=np.float64, matmul=mv)\n",
"\n",
"# Apply the operator to the 3D normal random variable\n",
"rv_projected = Pr @ rv"
Expand Down
6 changes: 2 additions & 4 deletions src/probnum/linops/_arithmetic_fallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def __init__(self, *summands: LinearOperator):

super().__init__(
shape=summands[0].shape,
dtype=np.find_common_type(
[summand.dtype for summand in self._summands], []
),
dtype=functools.reduce(np.result_type, [summand.dtype for summand in self._summands]),
matmul=lambda x: functools.reduce(
operator.add, (summand @ x for summand in self._summands)
),
Expand Down Expand Up @@ -192,7 +190,7 @@ def __init__(self, *factors: LinearOperator):

super().__init__(
shape=(self._factors[0].shape[0], self._factors[-1].shape[1]),
dtype=np.find_common_type([factor.dtype for factor in self._factors], []),
dtype=functools.reduce(np.result_type, [factor.dtype for factor in self._factors]),
matmul=lambda x: functools.reduce(
lambda vec, op: op @ vec, reversed(self._factors), x
),
Expand Down
2 changes: 1 addition & 1 deletion src/probnum/linops/_linear_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ class LambdaLinearOperator( # pylint: disable=too-many-instance-attributes
... def mv(v):
... return np.array([2 * v[0] - v[1], 3 * v[1]])

>>> A = LambdaLinearOperator(shape=(2, 2), dtype=np.float_, matmul=mv)
>>> A = LambdaLinearOperator(shape=(2, 2), dtype=np.float64, matmul=mv)
>>> A
<LambdaLinearOperator with shape=(2, 2) and dtype=float64>

Expand Down
2 changes: 1 addition & 1 deletion src/probnum/randprocs/_gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
super().__init__(
input_shape=mean.input_shape,
output_shape=mean.output_shape,
dtype=np.dtype(np.float_),
dtype=np.dtype(np.float64),
mean=mean,
cov=cov,
)
Expand Down
2 changes: 1 addition & 1 deletion src/probnum/randprocs/markov/_markov.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
super().__init__(
input_shape=input_shape,
output_shape=output_shape,
dtype=np.dtype(np.float_),
dtype=np.dtype(np.float64),
mean=functions.LambdaFunction(
lambda x: self.__call__(args=x).mean,
input_shape=input_shape,
Expand Down
6 changes: 3 additions & 3 deletions src/probnum/randvars/_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
self._support = support

support_floating = self._support.astype(
np.promote_types(self._support.dtype, np.float_)
np.promote_types(self._support.dtype, np.float64)
)

if config.matrix_free:
Expand Down Expand Up @@ -95,8 +95,8 @@ def __init__(
parameters={"support": self._support},
sample=self._sample,
in_support=lambda x: np.all(x == self._support),
pmf=lambda x: np.float_(1.0 if np.all(x == self._support) else 0.0),
cdf=lambda x: np.float_(1.0 if np.all(x >= self._support) else 0.0),
pmf=lambda x: np.float64(1.0 if np.all(x == self._support) else 0.0),
cdf=lambda x: np.float64(1.0 if np.all(x >= self._support) else 0.0),
mode=lambda: self._support,
median=lambda: support_floating,
mean=lambda: support_floating,
Expand Down
24 changes: 12 additions & 12 deletions src/probnum/randvars/_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,25 @@ def _univariate_sample(
def _univariate_in_support(x: ValueType) -> bool:
return np.isfinite(x)

def _univariate_pdf(self, x: ValueType) -> np.float_:
def _univariate_pdf(self, x: ValueType) -> np.float64:
return scipy.stats.norm.pdf(x, loc=self.mean, scale=self.std)

def _univariate_logpdf(self, x: ValueType) -> np.float_:
def _univariate_logpdf(self, x: ValueType) -> np.float64:
return scipy.stats.norm.logpdf(x, loc=self.mean, scale=self.std)

def _univariate_cdf(self, x: ValueType) -> np.float_:
def _univariate_cdf(self, x: ValueType) -> np.float64:
return scipy.stats.norm.cdf(x, loc=self.mean, scale=self.std)

def _univariate_logcdf(self, x: ValueType) -> np.float_:
def _univariate_logcdf(self, x: ValueType) -> np.float64:
return scipy.stats.norm.logcdf(x, loc=self.mean, scale=self.std)

def _univariate_quantile(self, p: FloatLike) -> np.floating:
return scipy.stats.norm.ppf(p, loc=self.mean, scale=self.std)

def _univariate_entropy(self: ValueType) -> np.float_:
def _univariate_entropy(self: ValueType) -> np.float64:
return _utils.as_numpy_scalar(
scipy.stats.norm.entropy(loc=self.mean, scale=self.std),
dtype=np.float_,
dtype=np.float64,
)

# Multi- and matrixvariate Gaussians
Expand Down Expand Up @@ -500,28 +500,28 @@ def _arg_todense(x: Union[np.ndarray, linops.LinearOperator]) -> np.ndarray:
def _dense_in_support(x: ValueType) -> bool:
return np.all(np.isfinite(Normal._arg_todense(x)))

def _dense_pdf(self, x: ValueType) -> np.float_:
def _dense_pdf(self, x: ValueType) -> np.float64:
return scipy.stats.multivariate_normal.pdf(
Normal._arg_todense(x).reshape(x.shape[: -self.ndim] + (-1,)),
mean=self.dense_mean.ravel(),
cov=self.dense_cov,
)

def _dense_logpdf(self, x: ValueType) -> np.float_:
def _dense_logpdf(self, x: ValueType) -> np.float64:
return scipy.stats.multivariate_normal.logpdf(
Normal._arg_todense(x).reshape(x.shape[: -self.ndim] + (-1,)),
mean=self.dense_mean.ravel(),
cov=self.dense_cov,
)

def _dense_cdf(self, x: ValueType) -> np.float_:
def _dense_cdf(self, x: ValueType) -> np.float64:
return scipy.stats.multivariate_normal.cdf(
Normal._arg_todense(x).reshape(x.shape[: -self.ndim] + (-1,)),
mean=self.dense_mean.ravel(),
cov=self.dense_cov,
)

def _dense_logcdf(self, x: ValueType) -> np.float_:
def _dense_logcdf(self, x: ValueType) -> np.float64:
return scipy.stats.multivariate_normal.logcdf(
Normal._arg_todense(x).reshape(x.shape[: -self.ndim] + (-1,)),
mean=self.dense_mean.ravel(),
Expand All @@ -531,13 +531,13 @@ def _dense_logcdf(self, x: ValueType) -> np.float_:
def _dense_var(self) -> np.ndarray:
return np.diag(self.dense_cov).reshape(self.shape)

def _dense_entropy(self) -> np.float_:
def _dense_entropy(self) -> np.float64:
return _utils.as_numpy_scalar(
scipy.stats.multivariate_normal.entropy(
mean=self.dense_mean.ravel(),
cov=self.dense_cov,
),
dtype=np.float_,
dtype=np.float64,
)

# Matrixvariate Gaussian with Kronecker covariance
Expand Down
Loading
Loading