forked from pytorch/botorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add constrained synthetic test functions (pytorch#1832)
Summary: Pull Request resolved: pytorch#1832 Adds the following engineering-problem test functions: - PressureVesselDesign - WeldedBeam - SpeedReducer - TensionCompressionString Reviewed By: SebastianAment Differential Revision: D45821102 fbshipit-source-id: 9dfda0cb48d218588e3528e32c249fe131b56d70
- Loading branch information
1 parent
087901c
commit 300b8bf
Showing
2 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional, Tuple | ||
|
||
import torch | ||
|
||
from torch import Tensor | ||
|
||
|
||
def round_nearest( | ||
X: Tensor, increment: float, bounds: Optional[Tuple[float, float]] | ||
) -> Tensor: | ||
X_round = torch.round(X / increment) * increment | ||
if bounds is not None: | ||
X_round = torch.where(X_round < bounds[0], X_round + increment, X_round) | ||
X_round = torch.where(X_round > bounds[1], X_round - increment, X_round) | ||
return X_round |