-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add direct from ground truth (#32)
* feat: add direct from ground truth * guard import * add example * update * add explanation
- Loading branch information
1 parent
36dabb9
commit ed70c3a
Showing
5 changed files
with
247 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any, Literal | ||
|
||
from microsim.schema._base_model import SimBaseModel | ||
from microsim.schema.backend import NumpyAPI | ||
|
||
if TYPE_CHECKING: | ||
from microsim._data_array import DataArray | ||
|
||
|
||
class FixedArrayTruth(SimBaseModel): | ||
type: Literal["fixed-array"] = "fixed-array" | ||
array: Any | ||
|
||
def render(self, space: DataArray, xp: NumpyAPI | None = None) -> DataArray: | ||
if space.shape != self.array.shape: | ||
raise ValueError( | ||
"This GroundTruth may only be used with simulation space of shape: " | ||
f"{self.array.shape}. Got: {space.shape}" | ||
) | ||
|
||
xp = xp or NumpyAPI() | ||
return space + xp.asarray(self.array).astype(space.dtype) |
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
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