Skip to content

Fix issue 8370 - #8376

Merged
sklam merged 16 commits into
numba:mainfrom
bszollosinagy:fix_issue_8370
Jan 11, 2023
Merged

sklam merged 16 commits into
numba:mainfrom
bszollosinagy:fix_issue_8370

Conversation

@bszollosinagy

Copy link
Copy Markdown
Contributor

Fixes #8370

New unit tests were created, and the solution added, as suggested by @gmarkall

All unit tests pass locally that would exercise ravel() and flatten()

  • python -m numba.runtests -m -v numba.tests.test_array_reductions.TestArrayReductions
  • python -m numba.runtests -m -v numba.tests.test_array_manipulation.TestArrayManipulation
  • python -m numba.runtests -m -v numba.tests.test_closure.TestObjmodeFallback
  • python -m numba.runtests -m -v numba.tests.test_dyn_array.TestNpStack
  • python -m numba.runtests -m -v numba.tests.test_np_functions.TestNPFunctions.test_extract_basic
  • python -m numba.runtests -m -v numba.tests.test_support.TestAssertPreciseEqual

CUDA tests may need to be run, but I simply cannot download the CUDA drivers from Nvidia today for some reason, so maybe a CI test would be more appropriate.

@gmarkall

Copy link
Copy Markdown
Member

Many thanks for the PR!

CUDA tests may need to be run, but I simply cannot download the CUDA drivers from Nvidia today for some reason, so maybe a CI test would be more appropriate.

I'm not sure flatten would work on CUDA since its implementation returns a copy in Numba, and it's not possible to do allocation for the CUDA target - am I missing something here?

@gmarkall

Copy link
Copy Markdown
Member

gpuci run tests

@gmarkall

Copy link
Copy Markdown
Member

(Marking as RFR because the test fail is a CI issue, not an issue with this PR)

Comment thread numba/core/typing/arraydecl.py Outdated
@stuartarchibald stuartarchibald added the Effort - medium Medium size effort needed label Aug 23, 2022
@gmarkall gmarkall added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Aug 23, 2022
@gmarkall gmarkall self-assigned this Aug 23, 2022
@gmarkall gmarkall added this to the Numba 0.57 RC milestone Aug 23, 2022
@bszollosinagy

Copy link
Copy Markdown
Contributor Author

Resolved issue picked up by an automated test: if the source array is mutable, then a simple ravel() should not make it read-only.

@bszollosinagy

Copy link
Copy Markdown
Contributor Author

Ready for review.

@bszollosinagy

Copy link
Copy Markdown
Contributor Author

Note: the algo modification is not a big deal:

  • on calling flatten(), a copy is made by Numba, and therefore the read-only is removed (just like in Numpy, see ref 1).
  • In the case of ravel(), the copy is only made if the "order" of the dimensions has to be converted from Fortran to C, otherwise no copy is made.
    • In case there was a copy, then the read-only is removed (just like in Numpy, see ref 1),
    • in case no copy was needed, then we look at the source array: was it read-only.

That's all.

ref: Numpy removing writeable=False when doing a copy()

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Sep 6, 2022
@gmarkall

Copy link
Copy Markdown
Member

/azp run

@gmarkall

Copy link
Copy Markdown
Member

gpuci run tests

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 1 pipeline(s).

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the updates and your continued efforts! There are a couple of comments on the PR.

In addition, in test_readonly_after_ravel and test_readonly_after_flatten, there is no assertion that checks that an expected output is produced - could you also assert that cfunc and pyfunc both produce the same return value please?

Comment thread numba/tests/test_array_manipulation.py Outdated
Comment thread numba/tests/test_array_manipulation.py Outdated
Comment thread numba/core/typing/arraydecl.py Outdated
Comment thread numba/core/typing/arraydecl.py Outdated
@gmarkall

Copy link
Copy Markdown
Member

Also, apologies for the delay in this round of review.

@gmarkall gmarkall added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jan 10, 2023
…ause different version of Numba return different way to say that you are trying to modify a read-only array.

* added an assertion to check the Numpy and Numba return the same results.
@bszollosinagy
bszollosinagy requested review from gmarkall and removed request for sklam January 10, 2023 20:46
Comment thread numba/tests/test_array_manipulation.py Outdated

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the quick update - just a very small comment on the diff - would you be happy to make this change, then this should be good to approve?

@gmarkall

Copy link
Copy Markdown
Member

Many thanks - just waiting on CI before I approve.

@gmarkall gmarkall added 4 - Waiting on CI Review etc done, waiting for CI to finish and removed 4 - Waiting on author Waiting for author to respond to review labels Jan 11, 2023
@gmarkall

Copy link
Copy Markdown
Member

gpuci run tests

@gmarkall gmarkall added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on CI Review etc done, waiting for CI to finish labels Jan 11, 2023

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the PR and updates! I think this looks good now.

@sklam
sklam merged commit 6c6fe2b into numba:main Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge Effort - medium Medium size effort needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NumbaTypeError: Cannot modify readonly array of type: readonly array(int64, 2d, C)

4 participants