Skip to content

Commit daa836c

Browse files
author
James Anderson
committed
Added helper function to get maximum dimensions
1 parent 7c20ad6 commit daa836c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

nornir_shared/mathhelper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def ListMedian(items):
3131

3232

3333
def NearestPowerOfTwo(val: float | int | NDArray[np.floating] | NDArray[np.integer]) -> NDArray[np.integer]:
34+
"""Return the nearest power of two greater than or equal to val"""
3435
return np.power(2, np.ceil(np.log2(val))).astype(int, copy=False)
3536

3637

@@ -42,5 +43,15 @@ def RoundingPrecision(dtype: DTypeLike) -> int:
4243
return int(np.abs(np.log10(np.finfo(dtype).eps)))
4344

4445

46+
def max_shape(shapes: list[np.integer]) -> NDArray[np.integer]:
47+
"""A function that returns the maximum value for each shape in the array"""
48+
if len(shapes) == 0:
49+
return np.zeros(0, dtype=int)
50+
51+
shapes = np.vstack(shapes)
52+
max_shape = np.max(shapes, axis=0)
53+
return max_shape
54+
55+
4556
if __name__ == '__main__':
4657
pass

0 commit comments

Comments
 (0)