cddb07a176
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
36 lines
867 B
Python
36 lines
867 B
Python
import datetime
|
|
import typing
|
|
import uuid
|
|
|
|
import numpy as np
|
|
|
|
|
|
def get_timestamp() -> int:
|
|
return int(datetime.datetime.now(datetime.timezone.utc).timestamp())
|
|
|
|
|
|
def get_iso_timestamp() -> str:
|
|
return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
|
|
|
|
def get_datetime_from_iso_timestamp(iso_timestamp: str) -> datetime.datetime:
|
|
return datetime.datetime.fromisoformat(iso_timestamp)
|
|
|
|
|
|
SEED_MAX = np.iinfo(np.uint32).max
|
|
|
|
|
|
def get_random_seed() -> int:
|
|
rng = np.random.default_rng(seed=None)
|
|
return int(rng.integers(0, SEED_MAX))
|
|
|
|
|
|
def uuid_string() -> str:
|
|
res = uuid.uuid4()
|
|
return str(res)
|
|
|
|
|
|
def is_optional(value: typing.Any) -> bool:
|
|
"""Checks if a value is typed as Optional. Note that Optional is sugar for Union[x, None]."""
|
|
return typing.get_origin(value) is typing.Union and type(None) in typing.get_args(value)
|