-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move export from examples to library functions
- Loading branch information
Showing
7 changed files
with
251 additions
and
19 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
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
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,89 @@ | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
import numpy as np | ||
|
||
|
||
def is_scalar(x: Any) -> bool: | ||
""" | ||
Checks whether the input is a scalar. | ||
Parameters | ||
---------- | ||
x : any | ||
Input to check. | ||
Returns | ||
------- | ||
bool | ||
``True`` if the input is a scalar, ``False`` otherwise. | ||
""" | ||
|
||
return np.isscalar(x) or (hasattr(x, 'ndim') and x.ndim == 0) | ||
|
||
|
||
def is_array(x: Any) -> bool: | ||
""" | ||
Checks whether the input is an array. | ||
Parameters | ||
---------- | ||
x : any | ||
Input to check. | ||
Returns | ||
------- | ||
bool | ||
``True`` if the input is an array, ``False`` otherwise. | ||
""" | ||
|
||
return isinstance(x, (list, tuple)) or (hasattr(x, 'ndim') and x.ndim == 1) | ||
|
||
|
||
def is_tensor(x: Any) -> bool: | ||
""" | ||
Checks whether the input is a tensor. | ||
Parameters | ||
---------- | ||
x : any | ||
Input to check. | ||
Returns | ||
------- | ||
bool | ||
``True`` if the input is a tensor, ``False`` otherwise. | ||
""" | ||
|
||
return hasattr(x, 'ndim') and x.ndim > 1 | ||
|
||
|
||
def is_dict(x: Any) -> bool: | ||
""" | ||
Checks whether the input is a dictionary. | ||
Parameters | ||
---------- | ||
x : any | ||
Input to check. | ||
Returns | ||
------- | ||
bool | ||
``True`` if the input is a dictionary, ``False`` otherwise. | ||
""" | ||
|
||
return isinstance(x, dict) | ||
|
||
|
||
def timestamp() -> str: | ||
""" | ||
Returns the current timestamp. | ||
Returns | ||
------- | ||
str | ||
Current timestamp. | ||
""" | ||
|
||
return datetime.now().strftime('%Y%m%d-%H%M%S') |
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