Skip to content

Commit

Permalink
Support arrays in math.special.try_stack()
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed May 29, 2024
1 parent c944b86 commit a3e661c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tensortrax/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
tensorTRAX: Math on (Hyper-Dual) Tensors with Trailing Axes.
"""

__version__ = "0.23.0"
__version__ = "0.24.0"
7 changes: 5 additions & 2 deletions src/tensortrax/math/special/_special_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def from_triu_2d(A):


def try_stack(arrays, fallback=None):
"Try to unpack and stack the list of tensors and return the fallback otherwise."
"""Try to unpack and stack the list of tensors/arrays and return the fallback array
otherwise."""
try:
return stack([A.x for ary in arrays for A in ary])
return stack(
[A.x if isinstance(A, Tensor) else A for ary in arrays for A in ary]
)
except ValueError:
return fallback

0 comments on commit a3e661c

Please sign in to comment.