Skip to content
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

Fix np.float and np.float32 to float. #1257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions pytorch_forecasting/data/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _set_parameters(
if isinstance(y_center, torch.Tensor):
eps = torch.finfo(y_center.dtype).eps
else:
eps = np.finfo(np.float).eps
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 or 64 bits? Why not y_center.dtype?

eps = np.finfo(float).eps
if self.method == "identity":
if isinstance(y_center, torch.Tensor):
self.center_ = torch.zeros(y_center.size()[:-1])
Expand Down Expand Up @@ -785,7 +785,7 @@ def fit(self, y: pd.Series, X: pd.DataFrame):
self
"""
y = self.preprocess(y)
eps = np.finfo(np.float).eps
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 or 64 bits? We cannot use y.dtype because it is possible to have different type for y and X.

eps = np.finfo(float).eps
if len(self.groups) == 0:
assert not self.scale_by_group, "No groups are defined, i.e. `scale_by_group=[]`"
if self.method == "standard":
Expand Down
4 changes: 2 additions & 2 deletions pytorch_forecasting/data/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,12 +1721,12 @@ def _collate_fn(
scale = torch.stack([batch[0]["target_scale"][idx] for batch in batches])
else:
scale = torch.from_numpy(
np.array([batch[0]["target_scale"][idx] for batch in batches], dtype=np.float32),
np.array([batch[0]["target_scale"][idx] for batch in batches], dtype=float),
)
target_scale.append(scale)
else: # convert to tensor
target_scale = torch.from_numpy(
np.array([batch[0]["target_scale"] for batch in batches], dtype=np.float32),
np.array([batch[0]["target_scale"] for batch in batches], dtype=float),
)

# target and weight
Expand Down
2 changes: 1 addition & 1 deletion pytorch_forecasting/models/nbeats/sub_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def linspace(backcast_length: int, forecast_length: int, centered: bool = False)
norm = backcast_length + forecast_length
start = 0
stop = backcast_length + forecast_length - 1
lin_space = np.linspace(start / norm, stop / norm, backcast_length + forecast_length, dtype=np.float32)
lin_space = np.linspace(start / norm, stop / norm, backcast_length + forecast_length, dtype=float)
b_ls = lin_space[:backcast_length]
f_ls = lin_space[backcast_length:]
return b_ls, f_ls
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ def test_TorchNormalizer_dtype_consistency():
assert TorchNormalizer()(dict(prediction=parameters, target_scale=target_scale)).dtype == torch.float32
assert TorchNormalizer().transform(parameters, target_scale=target_scale).dtype == torch.float32

y = np.array([1, 2, 3], dtype=np.float32)
y = np.array([1, 2, 3], dtype=float)
assert TorchNormalizer(method="identity").fit(y).get_parameters().dtype == torch.float32