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

corrected std function #767

Merged
merged 6 commits into from
Apr 29, 2021
Merged

corrected std function #767

merged 6 commits into from
Apr 29, 2021

Conversation

coquelin77
Copy link
Member

Description

see title

Issue/s resolved: #766

Changes proposed:

  • corrected bug

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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

@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #767 (07bbe4c) into master (8fe40bc) will decrease coverage by 0.00%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #767      +/-   ##
==========================================
- Coverage   95.22%   95.22%   -0.01%     
==========================================
  Files          64       64              
  Lines        8717     8728      +11     
==========================================
+ Hits         8301     8311      +10     
- Misses        416      417       +1     
Flag Coverage Δ
gpu 94.31% <71.42%> (-0.04%) ⬇️
unit 90.68% <85.71%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
heat/core/statistics.py 97.94% <92.85%> (-0.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fe40bc...07bbe4c. Read the comment docs.

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 @coquelin77, just a few comments:

heat/core/statistics.py Outdated Show resolved Hide resolved
if not isinstance(ddof, int):
raise TypeError(f"ddof must be integer, is {type(ddof)}")
elif ddof > 1:
raise NotImplementedError("Not implemented for ddof > 1.")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is "only" not implemented for the distributed or GPU case, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think it wasnt allowed by torch when i wrote that. but i guess it is now. ill take that out. worst case, we put it back in later

unbiased = bool(ddof)
ddof = 1 if unbiased else ddof
if not x.is_distributed() and str(x.device)[:3] == "cpu":
loc = np.std(x._DNDarray__array.numpy(), axis=axis, ddof=ddof)
Copy link
Contributor

Choose a reason for hiding this comment

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

here ddof > 1 would be ok

Copy link
Member Author

Choose a reason for hiding this comment

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

oh this was because numpy's std function is/was faster than torch's

if not axis:
return np.sqrt(var(x, axis, ddof, **kwargs))
if not isinstance(ddof, int):
raise TypeError(f"ddof must be integer, is {type(ddof)}")
Copy link
Contributor

Choose a reason for hiding this comment

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

This one line is not covered by tests.

@ClaudiaComito ClaudiaComito merged commit 4a08aa5 into master Apr 29, 2021
@ClaudiaComito ClaudiaComito deleted the bug/766-numpy-in-std branch April 29, 2021 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std(axis) returns an array (??) of n DNDarrays instead of a DNDarray of size n
2 participants