feat: Implement flexible ArrayLike input handling for arrays, lists, and tuples #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances the flexibility and usability of osipi functions by implementing support for array-like inputs. Users can now pass Python lists and tuples, in addition to np.ndarrays, for parameters representing array data.
Background:
During the review of PR #63 (which focused on fixing initial type annotations using
NDArray
), @plaresmedima and @ltorres6 suggested improving usability by accepting more general array-like types (like lists and tuples), aligning better with standard NumPy practice. This PR fulfills that follow-up action.How it Works:
For Array-Like Inputs (
t
,ca
,R1
,S
, etc.):NDArray
tonumpy.typing.ArrayLike
.np.asarray()
on these inputs upon entry. This converts lists, tuples, or existing arrays into NumPy ndarrays..astype(np.float64)
).For Scalar Inputs (
k
,TR
,a
,Ktrans
,ve
,r1
, etc.):np.floating
type hints.np.asarray()
is not called on scalars. They are used directly.Consistency Achieved:
ArrayLike
+np.asarray
) for all parameters designed to accept array data.Testing:
tests/test_array_like_inputs.py
) has been added to verify:np.ndarray
,list
, andtuple
inputs.float32
andfloat64
dtypes.TypeError
orValueError
is raised for invalid inputs (e.g., strings, incorrect dimensions).pytest
and passed successfully before submission.