-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
changed np.nparray to np.typing.NDArray #4526
base: develop
Are you sure you want to change the base?
Changes from 7 commits
9a2fd3c
60ef135
b6c7170
ee16030
1126ce4
fc4041b
f80584f
7258e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
# | ||
# Private classes and functions for experiment steps | ||
# | ||
import pybamm | ||
import numpy as np | ||
from datetime import datetime | ||
from .step_termination import _read_termination | ||
import numbers | ||
|
@@ -74,7 +76,7 @@ def __init__( | |
self.input_duration = duration | ||
self.input_value = value | ||
# Check if drive cycle | ||
is_drive_cycle = isinstance(value, np.ndarray) | ||
is_drive_cycle = isinstance(value, npt.NDArray) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be changed as we are checking if |
||
is_python_function = callable(value) | ||
if is_drive_cycle: | ||
if value.ndim != 2 or value.shape[1] != 2: | ||
|
@@ -260,7 +262,7 @@ def default_duration(self, value): | |
Default duration for the step is one day (24 hours) or the duration of the | ||
drive cycle | ||
""" | ||
if isinstance(value, np.ndarray): | ||
if isinstance(value, npt.NDArray): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
t = value[:, 0] | ||
return t[-1] | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will fix the failing style check (which you can also run locally using instructions provided above). |
||
# | ||
# NumpyArray class | ||
# | ||
from __future__ import annotations | ||
import numpy as np | ||
from scipy.sparse import csr_matrix, issparse | ||
|
||
import pybamm | ||
|
@@ -38,7 +40,7 @@ class Array(pybamm.Symbol): | |
|
||
def __init__( | ||
self, | ||
entries: np.ndarray | list[float] | csr_matrix, | ||
entries: npt.NDArray | list[float] | csr_matrix, | ||
name: str | None = None, | ||
domain: DomainType = None, | ||
auxiliary_domains: AuxiliaryDomainType = None, | ||
|
@@ -144,8 +146,8 @@ def create_copy( | |
def _base_evaluate( | ||
self, | ||
t: float | None = None, | ||
y: np.ndarray | None = None, | ||
y_dot: np.ndarray | None = None, | ||
y: npt.NDArray | None = None, | ||
y_dot: npt.NDArray | None = None, | ||
inputs: dict | str | None = None, | ||
): | ||
"""See :meth:`pybamm.Symbol._base_evaluate()`.""" | ||
|
@@ -165,7 +167,7 @@ def to_json(self): | |
Method to serialise an Array object into JSON. | ||
""" | ||
|
||
if isinstance(self.entries, np.ndarray): | ||
if isinstance(self.entries, npt.NDArray): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
matrix = self.entries.tolist() | ||
elif isinstance(self.entries, csr_matrix): | ||
matrix = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
# | ||
# Binary operator classes | ||
# | ||
from __future__ import annotations | ||
import numbers | ||
|
||
import numpy as np | ||
import sympy | ||
from scipy.sparse import csr_matrix, issparse | ||
import functools | ||
|
@@ -22,13 +24,13 @@ def _preprocess_binary( | |
) -> tuple[pybamm.Symbol, pybamm.Symbol]: | ||
if isinstance(left, (float, int, np.number)): | ||
left = pybamm.Scalar(left) | ||
elif isinstance(left, np.ndarray): | ||
elif isinstance(left, npt.NDArray): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all |
||
if left.ndim > 1: | ||
raise ValueError("left must be a 1D array") | ||
left = pybamm.Vector(left) | ||
if isinstance(right, (float, int, np.number)): | ||
right = pybamm.Scalar(right) | ||
elif isinstance(right, np.ndarray): | ||
elif isinstance(right, npt.NDArray): | ||
if right.ndim > 1: | ||
raise ValueError("right must be a 1D array") | ||
right = pybamm.Vector(right) | ||
|
@@ -152,8 +154,8 @@ def _binary_new_copy(self, left: ChildSymbol, right: ChildSymbol): | |
def evaluate( | ||
self, | ||
t: float | None = None, | ||
y: np.ndarray | None = None, | ||
y_dot: np.ndarray | None = None, | ||
y: npt.NDArray | None = None, | ||
y_dot: npt.NDArray | None = None, | ||
inputs: dict | str | None = None, | ||
): | ||
"""See :meth:`pybamm.Symbol.evaluate()`.""" | ||
|
@@ -558,7 +560,7 @@ def _binary_jac(self, left_jac, right_jac): | |
def _binary_evaluate(self, left, right): | ||
"""See :meth:`pybamm.BinaryOperator._binary_evaluate()`.""" | ||
# numpy 1.25 deprecation warning: extract value from numpy arrays | ||
if isinstance(right, np.ndarray): | ||
if isinstance(right, npt.NDArray): | ||
return int(left == right.item()) | ||
else: | ||
return int(left == right) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto