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

Like method for default zeros, ones, rand methods #3

Closed
aminya opened this issue Aug 24, 2019 · 3 comments
Closed

Like method for default zeros, ones, rand methods #3

aminya opened this issue Aug 24, 2019 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aminya
Copy link
Member

aminya commented Aug 24, 2019

Like method is added for manually defined methods, but still needs to be added for default zeros, ones, rand methods

Different tasks of this to do plan:

  1. Ask in Discourse forum or Slack group for ideas

Achievement check:

having both:

zerosM(Int32, 2, 2)
zerosM(2, 2, like=ones(Int32,2,2) )
@aminya
Copy link
Member Author

aminya commented Aug 24, 2019

Here's what I do for copying all the methods

 zerosM(args...) = zeros(args...) 

Other than editing Julia Base, one way which seems that may work is to exclude args to not be a type.
Do we have something like !:T?
This is my crazy prototype (doesn't work obviously):

zerosM(args::T...; like::AbstractArray) where {T!::Type{T1}} where {T1} = zeros(eltype(like), args...) 

@aminya aminya added enhancement New feature or request help wanted Extra attention is needed labels Aug 24, 2019
@aminya
Copy link
Member Author

aminya commented Oct 15, 2019

julia> fun(x::Integer) = 1
fun (generic function with 1 method)

julia> fun(x::Integer; y::Array) = 1
fun (generic function with 1 method)

julia> fun(x::Integer, y::Array) = 1
fun (generic function with 2 methods)

The 2nd definition doesn't create another method
I know that I can make keyword optional by

julia> fun(x::Integer; y::Array= nothing) = 1
fun (generic function with 1 method)

But in my situation, I am expanding another function's methods, and the function has fun(x::Integer) = 1 originally, and I don't want to overwrite that method.

However, the keyword arguments never participate in dispatch, and so there is no way other than redefining the original methods.

JuliaLang/julia#9498

https://discourse.julialang.org/t/rules-for-method-dispatch-with-keyword-arguments/23626/3

@aminya
Copy link
Member Author

aminya commented Oct 15, 2019

For other cases, probably it is better to not use a keyword argument and simply pass the Array as the first argument to the function.

I will redefine the methods using metaprogramming.

@aminya aminya closed this as completed in 0bd1469 Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant