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

Deprecate vectorized clamp methods in favor of compact broadcast syntax #18609

Closed
wants to merge 1 commit into from

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Sep 20, 2016

This PR deprecates all remaining vectorized clamp methods in favor of compact broadcast syntax. Ref. #16285, #17302, #18495, #18512, #18513, #18558, #18564, #18566, #18571 #18575, #18576, #18586, #18590, #18593, #18607, and #18608. Best!

(Unlike with float, real, etc., the remaining vectorized clamp methods never alias their input. This PR should be less controversial than #18495, #18512, and #18513 as a result.)

@@ -38,10 +38,10 @@ import Core.Intrinsics: sqrt_llvm, box, unbox, powi_llvm
clamp(x, lo, hi)

Return `x` if `lo <= x <= hi`. If `x < lo`, return `lo`. If `x > hi`, return `hi`. Arguments
are promoted to a common type. Operates elementwise over `x` if `x` is an array.
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need a rerun of make docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

That it does! Good catch. Fixed. Thanks!

@@ -313,7 +313,7 @@ seek(io, 0)
@test readdlm(io, eltype(A)) == parent(A)

amin, amax = extrema(parent(A))
@test clamp(A, (amax+amin)/2, amax) == clamp(parent(A), (amax+amin)/2, amax)
@test clamp.(A, (amax+amin)/2, amax).parent == clamp.(parent(A), (amax+amin)/2, amax)
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this need .parent now?

Copy link
Member Author

Choose a reason for hiding this comment

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

The operation on the left produces a TestHelpers.OAs.OffsetArray (from test/TestHelpers.jl) whereas that on the right produces an Array. Comparing an OffsetArray to an Array seems to fail even when their contents are identical, hence the .parent. Thoughts? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

and without broadcast what type did it return?

Copy link
Contributor

Choose a reason for hiding this comment

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

An OffsetArray ought not to be substituted for an Array. If broadcast is not preserving offsets, then that needs to be fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing vectorized clamp methods return an Array subtype independent of the input type (for example, clamping a SparseMatrixCSC or OffsetArray yields an Array). On the other hand broadcast better preserves the input type (for example, clamping a SparseMatrixCSC yields a SparseMatrixCSC and the analog holds for OffsetArrays). Thoughts? Thanks!

Copy link
Contributor

@TotalVerb TotalVerb Sep 21, 2016

Choose a reason for hiding this comment

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

Since clamp is not zero-preserving, I think the old behaviour for SparseMatrixCSC was preferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, only zero-preserving if the bounds include the origin, but sometimes preserving structure wouldn't be type stable

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! Tricky. Special case sparse and structured matrix types?

Copy link
Contributor

Choose a reason for hiding this comment

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

the broadcast code will now check if this is zero preserving right? and return dense-in-sparse-format if not?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should, yes. Best!

@kshyatt kshyatt added maths Mathematical functions broadcast Applying a function over a collection labels Sep 21, 2016
@simonbyrne simonbyrne added this to the 0.6.0 milestone Dec 12, 2016
@Sacha0
Copy link
Member Author

Sacha0 commented Dec 23, 2016

Rebased. Best!

@Sacha0
Copy link
Member Author

Sacha0 commented Dec 31, 2016

Subsumed by #19791.

@Sacha0 Sacha0 closed this Dec 31, 2016
@Sacha0 Sacha0 deleted the devecclamp branch December 31, 2016 05:09
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 maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants