Skip to content

Commit

Permalink
Merge pull request #126 from utat-ss/resolve-inconsistencies
Browse files Browse the repository at this point in the history
Resolve tradebook inconsistencies
  • Loading branch information
abeerfatima authored Mar 5, 2024
2 parents 4d6423e + 7cd6608 commit fba416b
Show file tree
Hide file tree
Showing 8 changed files with 1,776 additions and 472 deletions.
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

0 comments on commit fba416b

Please sign in to comment.