-
Notifications
You must be signed in to change notification settings - Fork 66
DataContainer agnostic on backend
#2132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
paskino
wants to merge
26
commits into
master
Choose a base branch
from
pytorch-hackathon-datacontainer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ed84626
initial changes on datacontainer and image data
paskino c090068
torch test working
paskino dc7c6f0
updates to the pixelwise_binary
paskino 07b00cc
sapyb
paskino 1f1fbd0
fix ImageData
paskino e8b7a92
add array_api_compat to recipe
paskino 0bba4b0
fix GHA
paskino 6827b4a
Add parametrize to unittest
paskino b0b32d8
added tests adn bugfixes
paskino 4d54f3b
work in progress
paskino 5db9a1f
modified test
paskino 101175e
convert numpy ComplexWarning to Exception
paskino c53115b
add function to squeeze an array on multiple dimensions with array_ap…
paskino 8283b87
added cil array_api_ compat
paskino b695c5b
fix test_fill_dimension_AcquisitionData
paskino a6c6e56
fixed DataContainer unittests
paskino 4ed3ffb
Merge remote-tracking branch 'origin' into pytorch-hackathon-datacont…
paskino c9977e9
removed prints
paskino cbe1f3b
temporarily disable some tests if torch is not installed
paskino 1a84659
skip tests with torch but executes with numpy
paskino b4b3cda
prevent AttributeError: module 'numpy' has no attribute 'exceptions'
paskino 97fbe35
update the type of the data according to the parameter requested
paskino fdbdb3a
WIP added allclose
paskino ba6194b
WIP for TotalVariation
paskino 0129293
WIP
paskino 50c2ffa
removed pysnooper
paskino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Updates to array API compatibility layer for CIL | ||
| from array_api_compat import array_namespace | ||
|
|
||
| def expand_dims(array, axis): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| '''Expand dimensions of an array along specified axes. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| array : array-like | ||
| The input array to expand. | ||
| axis : int or tuple of int | ||
| The axis or axes along which to expand the dimensions. | ||
|
|
||
| Returns | ||
| ------- | ||
| array-like | ||
| The array with expanded dimensions. It may be a new array or the same array with expanded dimensions. | ||
|
|
||
| Raises: | ||
| -------- | ||
| IndexError If provided an invalid axis position, an IndexError should be raised. | ||
|
|
||
| Notes: | ||
| This function recursively expands the dimensions of the input array along the specified axes if a list or tuple of ints is provided. | ||
| ''' | ||
| xp = array_namespace(array) | ||
|
|
||
| if isinstance(axis, int): | ||
| return xp.expand_dims(array, axis=axis) | ||
| if len(axis) == 1: | ||
| return xp.expand_dims(array, axis=axis[0]) | ||
| axis = list(axis) | ||
| ax = axis.pop(0) | ||
| if len(axis) == 1: | ||
| axis = axis[0] | ||
| return expand_dims(xp.expand_dims(array, axis=ax), axis=axis) | ||
|
|
||
| def squeeze(array, axis=None): | ||
| '''squeezes the array, removing all singleton dimensions recursively | ||
|
|
||
| Parameters | ||
| ---------- | ||
| array : array-like | ||
| The array to squeeze | ||
| axis : int or tuple of int, optional | ||
| The axis or axes to squeeze. If None, all singleton dimensions are removed. | ||
|
|
||
| Returns | ||
| ------- | ||
| array-like | ||
| The squeezed array with all singleton dimensions removed. If the input array has no singleton dimensions, it is returned unchanged. | ||
| ''' | ||
| xp = array_namespace(array) | ||
| # find and remove singleton dimensions | ||
| if axis is None: | ||
| s = xp.nonzero(xp.asarray(array.shape) == 1)[0] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably better to do this in pure python, particularly since this function might not be in certain lazy libraries due to being data dependent: s = tuple(i for i, ax in enumerate(array.shape) if ax==1) |
||
| axis = s.tolist() | ||
| if len(axis) == 1: | ||
| axis = axis[0] | ||
| elif len(axis) == 0: | ||
| # nothing to do | ||
| return array | ||
| if isinstance(axis, int): | ||
| return xp.squeeze(array, axis=axis) | ||
| if len(axis) == 1: | ||
| return xp.squeeze(array, axis=axis[0]) | ||
|
|
||
| # process from the largest axis to the smallest | ||
| axis = list(axis) | ||
| axis.sort(reverse=True) | ||
| ax = axis.pop(0) | ||
| if len(axis) == 1: | ||
| axis = axis[0] | ||
| return squeeze(xp.squeeze(array, axis=ax), axis=axis) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you intend to change the default behaviour from
dtype = geometry.dtypetoxp.float32?