Skip to content
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

Add copy kwarg to asarray #991

Closed
wants to merge 14 commits into from
Closed

Add copy kwarg to asarray #991

wants to merge 14 commits into from

Conversation

neosunhan
Copy link
Collaborator

Description

Enables copy kwarg in asarray. The keyword defaults to False for backward compatibility.

Issue/s resolved: #990

Type of change

  • New feature (non-breaking change which adds functionality)

Due Diligence

  • All split configurations tested
  • Multiple dtypes tested in relevant functions
  • Documentation updated (if needed)
  • Updated changelog.md under the title "Pending Additions"

Does this change modify the behaviour of other functions? If so, which?

no

skip ci

@ghost
Copy link

ghost commented Jul 15, 2022

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codecov
Copy link

codecov bot commented Jul 15, 2022

Codecov Report

Merging #991 (51ca6ec) into release/1.2.x (4368ee4) will increase coverage by 0.00%.
The diff coverage is 92.59%.

@@              Coverage Diff               @@
##           release/1.2.x     #991   +/-   ##
==============================================
  Coverage          91.80%   91.80%           
==============================================
  Files                 65       65           
  Lines              10075    10152   +77     
==============================================
+ Hits                9249     9320   +71     
- Misses               826      832    +6     
Flag Coverage Δ
unit 91.80% <92.59%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
heat/core/manipulations.py 98.63% <ø> (ø)
heat/core/tests/test_suites/basic_test.py 98.07% <ø> (ø)
heat/nn/data_parallel.py 84.13% <ø> (ø)
heat/regression/lasso.py 92.42% <ø> (ø)
heat/core/factories.py 98.05% <86.95%> (-1.95%) ⬇️
heat/core/dndarray.py 96.92% <100.00%> (+0.12%) ⬆️
heat/core/random.py 99.67% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@neosunhan neosunhan marked this pull request as draft July 15, 2022 06:37
@neosunhan neosunhan marked this pull request as ready for review July 18, 2022 12:06
@neosunhan neosunhan requested review from mtar and ClaudiaComito July 18, 2022 13:30
Copy link
Contributor

@ClaudiaComito ClaudiaComito left a comment

Choose a reason for hiding this comment

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

Thanks a lot @neosunhan ! I only have a comment about the array-API behaviour when copy=False, let me know what you think.

@@ -434,6 +434,7 @@ def array(
def asarray(
obj: Iterable,
dtype: Optional[Type[datatype]] = None,
copy: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the array-API standard, asarray(copy=False) should return ValueError if a copy turns out to be necessary.
https://data-apis.org/array-api/latest/API_specification/generated/signatures.creation_functions.asarray.html

I propose to set this default to None (we won't copy unless necessary), which is basically the default numpy users expect. Then if the users specify asarray(copy=False) and copying is necessary, we can return a ValueError.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed the default and added a check in the event copy=False.

@ClaudiaComito
Copy link
Contributor

@JuanPedroGHM have we got a fitting label for these changes re: auto-generated changelog? I was going to suggest array-API. Also, I'm thinking we need some kind of roadblock for when we're about to merge a PR that hasn't been labelled properly.

@ClaudiaComito ClaudiaComito added enhancement New feature or request array API labels Oct 5, 2022
Copy link
Collaborator

@mtar mtar left a comment

Choose a reason for hiding this comment

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

Now that we have a CI running again, we can finally review some PRs. 😃

heat/core/factories.py Outdated Show resolved Hide resolved
Comment on lines +490 to +497
if isinstance(copy, bool) and not copy:
if not (
isinstance(obj, DNDarray)
and (dtype is None or dtype == obj.dtype)
and (is_split is None or is_split == obj.split)
and (device is None or device == obj.device)
):
raise ValueError("copy is necessary")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The check is too broad. In some cases, numpy arrays and torch tensors can also be used without copying.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the check fits better in the array function where the real logic is.

@neosunhan neosunhan marked this pull request as draft October 26, 2022 13:37
Co-authored-by: mtar <m.tarnawa@fz-juelich.de>
@ClaudiaComito ClaudiaComito marked this pull request as ready for review February 9, 2023 11:13
@ClaudiaComito ClaudiaComito changed the base branch from main to release/1.2.x March 6, 2023 05:25
@ClaudiaComito
Copy link
Contributor

Switched base branch from main to release/1.2.x so we can release this sooner.

@ClaudiaComito ClaudiaComito modified the milestones: v1.2.3, 1.3.0 Mar 29, 2023
@ClaudiaComito ClaudiaComito self-assigned this Apr 17, 2023
@ClaudiaComito ClaudiaComito changed the base branch from release/1.2.x to main June 13, 2023 12:10
@ClaudiaComito
Copy link
Contributor

Closing this as it is addressed in #1119

@mtar mtar deleted the features/990-asarray-copy branch February 28, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array API enhancement New feature or request GSoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add copy kwarg to asarray
3 participants