Skip to content

Commit 10fef7b

Browse files
committed
feat: creates _value_or_list_like_to_tuple
1 parent dce8534 commit 10fef7b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pylops/utils/_internal.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ def _value_or_list_like_to_array(value_or_list_like, repeat=1):
2727
return out
2828

2929

30+
def _value_or_list_like_to_tuple(value_or_list_like, repeat=1):
31+
"""Convert an object which is either single value or a list-like to a tuple.
32+
33+
Parameters
34+
----------
35+
value_or_list_like
36+
Single value or list-like.
37+
repeat : `obj`:`int`
38+
Size of resulting array if value is passed. If list is passed, it is ignored.
39+
40+
Returns
41+
-------
42+
out : `obj`:`tuple`
43+
When the input is a single value, returned an array with `repeat` samples
44+
containing that value. When the input is a list-like object, converts it to a
45+
tuple.
46+
47+
"""
48+
return tuple(_value_or_list_like_to_array(value_or_list_like, repeat=repeat))
49+
50+
3051
def _raise_on_wrong_dtype(arr, dtype, name):
3152
"""Raises an error if dtype of `arr` is not a subdtype of `dtype`.
3253

0 commit comments

Comments
 (0)