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

Resolve tradebook inconsistencies #126

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

Expand Down
40 changes: 40 additions & 0 deletions architect/libs/utillib.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,43 @@ def hypercast(*arrays) -> list[np.ndarray]:
hyperarrays.append(array_broadcasted)

return hyperarrays


def orient_tensor(a, dim: int, dims: int) -> np.ndarray:
"""Orient a tensor in a given dimensionality.

Args:
a: array tensor.
dim: index of the dimension axis on which to orient the tensor.
dims: dimensionality of the tensor space.

Returns:
The oriented tensor.

"""
shape = [1] * dims
shape[dim] = -1

return np.reshape(a=a, newshape=shape)


def orient_and_broadcast(a, dim: int, shape) -> np.ndarray:
"""Orient and broadcast a tensor into a given dimensionality.

Args:
a: array tensor.
dim: index of the dimension axis on which to orient the tensor.
shape: dimensionality and size of broadcasted tensor.

Returns:
The broadcasted tensor.

"""

a_oriented = orient_tensor(a=a, dim=dim, dims=len(shape))
a_broadcasted = np.broadcast_to(array=a_oriented, shape=shape)

if isinstance(a, Quantity):
a_broadcasted *= a.unit

return a_broadcasted
Loading