-
Notifications
You must be signed in to change notification settings - Fork 66
fix #925: ht.nonzero() returns tuple of 1-D arrays instead of n-D arrays #937
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
Changes from 24 commits
f7adcf2
2ab82b5
f261e8e
9b863a7
2b2622a
a15b299
8910bf7
f8dc8b8
767eabc
3cd1d33
61cef7f
74b1a30
93cd831
2a25d22
e154ab9
7c57942
114e74e
14aae08
dd1b83d
7e6ad4a
aeb5b6e
03e1287
420f064
a00ed61
d4a8813
67fcdc8
39103fa
3ed205c
70dded6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: ci | ||
|
|
||
| on: | ||
| pull_request_review: | ||
| types: [submitted] | ||
|
|
||
| jobs: | ||
| approved: | ||
| if: github.event.review.state == 'approved' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| py-version: | ||
| - 3.7 | ||
| - 3.8 | ||
| mpi: [ 'openmpi' ] | ||
| install-options: [ '.', '.[hdf5,netcdf]' ] | ||
| pytorch-version: | ||
| - 'torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2' | ||
| - 'torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1' | ||
| - 'torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0' | ||
|
|
||
|
|
||
| name: Python ${{ matrix.py-version }} with ${{ matrix.pytorch-version }}; options ${{ matrix.install-options }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
| - name: Setup MPI | ||
| uses: mpi4py/setup-mpi@v1 | ||
| with: | ||
| mpi: ${{ matrix.mpi }} | ||
| - name: Use Python ${{ matrix.py-version }} | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: ${{ matrix.py-version }} | ||
| architecture: x64 | ||
| - name: Test | ||
| run: | | ||
| pip install pytest | ||
| pip install ${{ matrix.pytorch-version }} -f https://download.pytorch.org/whl/torch_stable.html | ||
| pip install ${{ matrix.install-options }} | ||
| mpirun -n 3 pytest heat/ | ||
| mpirun -n 4 pytest heat/ |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| cff-version: 1.2.0 | ||
| message: "If you use this software, please cite it as below." | ||
| authors: | ||
| - family-names: "Götz" | ||
| given-names: "Markus" | ||
| - family-names: "Debus" | ||
| given-names: "Charlotte" | ||
| - family-names: "Coquelin" | ||
| given-names: "Daniel" | ||
| - family-names: "Krajsek" | ||
| given-names: "Kai" | ||
| - family-names: "Comito" | ||
| given-names: "Claudia" | ||
| - family-names: "Knechtges" | ||
| given-names: "Philipp" | ||
| - family-names: "Hagemeier" | ||
| given-names: "Björn" | ||
| - family-names: "Tarnawa" | ||
| given-names: "Michael" | ||
| - family-names: "Hanselmann" | ||
| given-names: "Simon" | ||
| - family-names: "Siggel" | ||
| given-names: "Martin" | ||
| - family-names: "Basermann" | ||
| given-names: "Achim" | ||
| - family-names: "Streit" | ||
| given-names: "Achim" | ||
| title: "Heat - Helmholtz Analytics Toolkit" | ||
| version: 1.1.0 | ||
| date-released: 2021-09-21 | ||
| url: "https://github.com/helmholtz-analytics/heat" | ||
| preferred-citation: | ||
| type: conference-paper | ||
| authors: | ||
| - family-names: "Götz" | ||
| given-names: "Markus" | ||
| - family-names: "Debus" | ||
| given-names: "Charlotte" | ||
| - family-names: "Coquelin" | ||
| given-names: "Daniel" | ||
| - family-names: "Krajsek" | ||
| given-names: "Kai" | ||
| - family-names: "Comito" | ||
| given-names: "Claudia" | ||
| - family-names: "Knechtges" | ||
| given-names: "Philipp" | ||
| - family-names: "Hagemeier" | ||
| given-names: "Björn" | ||
| - family-names: "Tarnawa" | ||
| given-names: "Michael" | ||
| - family-names: "Hanselmann" | ||
| given-names: "Simon" | ||
| - family-names: "Siggel" | ||
| given-names: "Martin" | ||
| - family-names: "Basermann" | ||
| given-names: "Achim" | ||
| - family-names: "Streit" | ||
| given-names: "Achim" | ||
| title: "HeAT -- a Distributed and GPU-accelerated Tensor Framework for Data Analytics" | ||
| year: 2020 | ||
| collection-title: "2020 IEEE International Conference on Big Data (IEEE Big Data 2020)" | ||
| collection-doi: 10.1109/BigData50022.2020.9378050 | ||
| conference: | ||
| name: 2020 IEEE International Conference on Big Data (IEEE Big Data 2020) | ||
| date-start: 2020-12-10 | ||
| date-end: 2020-12-13 | ||
| start: 276 | ||
| end: 287 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,13 @@ | |
| __all__ = ["nonzero", "where"] | ||
|
|
||
|
|
||
| def nonzero(x: DNDarray) -> DNDarray: | ||
| def nonzero(x: DNDarray) -> Tuple: | ||
| """ | ||
| Return a :class:`~heat.core.dndarray.DNDarray` containing the indices of the elements that are non-zero.. (using ``torch.nonzero``) | ||
| Return a Tuple of :class:`~heat.core.dndarray.DNDarray`s, one for each dimension of a, | ||
|
Member
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. "... one for each dimension of |
||
| containing the indices of the non-zero elements in that dimension. (using ``torch.nonzero``) | ||
|
Member
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. I know it was there before you started working on it, but I would remove "(using |
||
| If ``x`` is split then the result is split in the 0th dimension. However, this :class:`~heat.core.dndarray.DNDarray` | ||
| can be UNBALANCED as it contains the indices of the non-zero elements on each node. | ||
| Returns an array with one entry for each dimension of ``x``, containing the indices of the non-zero elements in that dimension. | ||
| The values in ``x`` are always tested and returned in row-major, C-style order. | ||
| The values in ``x`` are always tested and returned in column-major, F-style order. | ||
|
Member
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. No, they are still tested in row-major, C-style order, otherwise |
||
| The corresponding non-zero values can be obtained with: ``x[nonzero(x)]``. | ||
|
|
||
| Parameters | ||
|
|
@@ -32,10 +32,8 @@ def nonzero(x: DNDarray) -> DNDarray: | |
| >>> import heat as ht | ||
| >>> x = ht.array([[3, 0, 0], [0, 4, 1], [0, 6, 0]], split=0) | ||
| >>> ht.nonzero(x) | ||
| DNDarray([[0, 0], | ||
| [1, 1], | ||
| [1, 2], | ||
| [2, 1]], dtype=ht.int64, device=cpu:0, split=0) | ||
| (DNDarray([0, 1, 1, 2], dtype=ht.int64, device=cpu:0, split=None), | ||
| DNDarray([0, 1, 2, 1], dtype=ht.int64, device=cpu:0, split=None)) | ||
| >>> y = ht.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], split=0) | ||
| >>> y > 3 | ||
| DNDarray([[False, False, False], | ||
|
|
@@ -48,6 +46,8 @@ def nonzero(x: DNDarray) -> DNDarray: | |
| [2, 0], | ||
| [2, 1], | ||
| [2, 2]], dtype=ht.int64, device=cpu:0, split=0) | ||
| (DNDarray([1, 1, 1, 2, 2, 2], dtype=ht.int64, device=cpu:0, split=None), | ||
| DNDarray([0, 1, 2, 0, 1, 2], dtype=ht.int64, device=cpu:0, split=None)) | ||
| >>> y[ht.nonzero(y > 3)] | ||
| DNDarray([4, 5, 6, 7, 8, 9], dtype=ht.int64, device=cpu:0, split=0) | ||
| """ | ||
|
|
@@ -56,14 +56,14 @@ def nonzero(x: DNDarray) -> DNDarray: | |
| except AttributeError: | ||
| raise TypeError("Input must be a DNDarray, is {}".format(type(x))) | ||
|
|
||
| lcl_nonzero = torch.nonzero(input=local_x, as_tuple=False) | ||
|
|
||
| if x.split is None: | ||
| # if there is no split then just return the values from torch | ||
| lcl_nonzero = torch.nonzero(input=local_x, as_tuple=False) | ||
| gout = list(lcl_nonzero.size()) | ||
| is_split = None | ||
| else: | ||
| # a is split | ||
| lcl_nonzero = torch.nonzero(input=local_x, as_tuple=False) | ||
| # adjust local indices along split dimension | ||
| _, displs = x.counts_displs() | ||
| lcl_nonzero[..., x.split] += displs[x.comm.rank] | ||
|
ClaudiaComito marked this conversation as resolved.
Outdated
|
||
|
|
@@ -73,20 +73,18 @@ def nonzero(x: DNDarray) -> DNDarray: | |
| gout[0] = x.comm.allreduce(gout[0], MPI.SUM) | ||
| is_split = 0 | ||
|
|
||
| if x.ndim == 1: | ||
| lcl_nonzero = lcl_nonzero.squeeze(dim=1) | ||
| for g in range(len(gout) - 1, -1, -1): | ||
| if gout[g] == 1: | ||
| del gout[g] | ||
|
|
||
| return DNDarray( | ||
| lcl_nonzero, | ||
| gshape=tuple(gout), | ||
| dtype=types.canonical_heat_type(lcl_nonzero.dtype), | ||
| split=is_split, | ||
| device=x.device, | ||
| comm=x.comm, | ||
| balanced=False, | ||
| lcl_nonzero = lcl_nonzero.transpose(0, 1) | ||
|
|
||
|
Member
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.
|
||
| return tuple( | ||
| DNDarray( | ||
| lcl_nonzero, | ||
| gshape=tuple(gout), | ||
| dtype=types.canonical_heat_type(lcl_nonzero.dtype), | ||
| split=is_split, | ||
| device=x.device, | ||
| comm=x.comm, | ||
| balanced=False, | ||
| ) | ||
| ) | ||
|
ClaudiaComito marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.