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 rand! etc. in favor of x .= rand.()? #19796

Closed
stevengj opened this issue Dec 31, 2016 · 10 comments
Closed

deprecate rand! etc. in favor of x .= rand.()? #19796

stevengj opened this issue Dec 31, 2016 · 10 comments
Labels
broadcast Applying a function over a collection

Comments

@stevengj
Copy link
Member

Since we can now do x .= rand.() to evaluate rand() for each element of x, do we still need rand! etcetera?

See also #12277.

@stevengj stevengj added the broadcast Applying a function over a collection label Dec 31, 2016
@stevengj
Copy link
Member Author

stevengj commented Dec 31, 2016

(Though rand!() does have an optimized SIMD implementation IIRC.)

The argument is similar for deprecating fill!(a, x) in favor of a .= x and scale!(a, x) in favor of a .*= x.

@KristofferC
Copy link
Member

Can't the specific broadcast function that x .= rand.() lowers into be overloaded to use the optimized version?

@stevengj
Copy link
Member Author

stevengj commented Dec 31, 2016

Yes, it can. Of course, it won't work if you fuse the rand.() with additional operations.

@KristofferC
Copy link
Member

Yes, but that should be fine I think. You couldn't used the optimized one if you wrote the fused version manually anyway, right?

@stevengj
Copy link
Member Author

Right.

@TotalVerb
Copy link
Contributor

TotalVerb commented Jan 1, 2017

Can one replace use cases like rand!(similar(X)) with similar(X) .= rand.()? I suspect this is possible, though perhaps not as readable.

@stevengj
Copy link
Member Author

stevengj commented Jan 1, 2017

@TotalVerb, that would work. I agree it's more verbose, but I don't think that construct is very common; I can only find two packages that use it in test scripts, and in both cases they could have used rand(size(X)...) as well.

@stevengj
Copy link
Member Author

stevengj commented Jan 1, 2017

On the other hand, x .= rand.() is not a drop-in replacement for rand!(x) if eltype(x) != Float64, so I think probably we should keep rand!.

(The argument for replacing fill! and scale! remains, however.)

@stevengj stevengj closed this as completed Jan 1, 2017
@Sacha0
Copy link
Member

Sacha0 commented Jan 25, 2017

On the other hand, x .= rand.() is not a drop-in replacement for rand!(x) if eltype(x) != Float64, so I think probably we should keep rand!.

Though slightly more verbose, perhaps x .= rand.(eltype(x)) with appropriate rand(::Type{...}) methods could work?

(The argument for replacing fill! and scale! remains, however.)

Perhaps fill! and scale! deserve dedicated issues? (Edit: Discussion relevant to fill! in #19598 (comment).) Best!

@Sacha0
Copy link
Member

Sacha0 commented Jan 25, 2017

(Also relevant to randn! and randexp!.)

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
Projects
None yet
Development

No branches or pull requests

4 participants