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

fix and then specialize sparse broadcast!(f, C, A), strengthen tests #19986

Merged
merged 4 commits into from
Jan 21, 2017

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Jan 12, 2017

In #19895 (comment), @martinholters (thanks!) noticed that the existing sparse broadcast!(f, C, A) specialization does not handle cases where the shapes of destination C and source A differ.

This pull request's first commit removes the incorrect sparse broadcast!(f, C, A) specialization (falling back to the argument-number-generic sparse broadcast! code, which does not suffer from the above issue) and strengthens associated tests. The argument-number-generic code leaves some performance on the table, so the second commit provides a corrected sparse broadcast!(f, C, A) specialization for zero-preserving f, and the third commit likewise for not-zero-preserving f.

While writing this pull request I realized that the sparse broadcast!(f, C, A, B) specializations suffer from the same issue. A fix for that code is in the works. Best!

@Sacha0 Sacha0 added bugfix This change fixes an existing bug sparse Sparse arrays broadcast Applying a function over a collection labels Jan 12, 2017
@Sacha0 Sacha0 added this to the 0.6.0 milestone Jan 12, 2017
@test broadcast!(sin, copy(A), A) == sparse(broadcast!(sin, copy(fA), fA))
# The two following tests are from #19895, and check the absence of an ambiguity
# between a pair of specializations, but #19895 removed both of those specializations,
# so perhaps these tests should be nixed?
Copy link
Member Author

Choose a reason for hiding this comment

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

@martinholters @pabloferz, thoughts? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

A few months down the road, someone decides to add specializations for the common x .= y case to be faster...

Copy link
Member Author

Choose a reason for hiding this comment

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

On that note, perhaps we should add tests for #19895 (comment). Will add a commit. Thanks!

# We first divide the cases into two groups: those in which the input argument does not
# expand vertically, and those in which the input argument expands vertically.
#
# Cases without version expansion
Copy link
Contributor

Choose a reason for hiding this comment

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

vertical?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed on push. Thanks!

# if fofAx is zero, then either A's jth column is empty, or A's jth column
# contains a nonzero value x but f(Ax) is nonetheless zero, so we need store
# nothing in C's jth column. if to the contrary fofAx is nonzero, then we must
# densely populate C's jth column wiht fofAx.
Copy link
Contributor

Choose a reason for hiding this comment

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

with misspelled

Copy link
Member Author

Choose a reason for hiding this comment

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

Yesterday was not a good day for spelling. Fixed on push. Thanks!

_densestructure!(C)
# Populate values
fill!(storedvals(C), fillvalue)
# Cases without version expansion
Copy link
Contributor

Choose a reason for hiding this comment

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

vertical

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed on push. Thanks!

# above. here we simply lightly exercise the relevant broadcast[!] entry points.
@testset "broadcast implementation specialized for a single (input) sparse vector/matrix" begin
# broadcast for a single (input) sparse vector/matrix falls back to map, tested
# extensively above. hre we simply lightly exercise the relevant broadcast entry
Copy link
Contributor

Choose a reason for hiding this comment

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

"here" misspelled

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed on push. Thanks!

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 12, 2017

Added a commit strengthening broadcast!(identity, C, A) tests to guard against reintroduction of ambiguous and/or erroneous specializations. (Ref. #19895 / #19895 (comment)). Best!

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 18, 2017

Absent objections or requests for time, I plan to merge this Thursday morning PST. Best!

@pabloferz
Copy link
Contributor

LGTM

@tkelman tkelman merged commit ac9b2e7 into JuliaLang:master Jan 21, 2017
@Sacha0 Sacha0 deleted the threeargbcbang branch January 21, 2017 22:50
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 21, 2017

Thanks for reviewing / merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection bugfix This change fixes an existing bug sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants