-
Notifications
You must be signed in to change notification settings - Fork 110
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
feat:add modes to conv function (#399) #403
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a reasonable feature to add. Ideally we'd only do the convolution for the requested output, but until we can implement that I think doing this extra copy is reasonable. I think we should mention that options besides :full
will result in an extra copy of the result, which can cause non-trivial memory usage when convolving large arrays.
It's not clear to me if the code, as it is, would work with ND arrays. It seems like you're only doing the first two dimensions.
I don't understand why you made new function names for each of the modes, could the copying be implemented in the method that accepts the mode
keyword argument? I would prefer to not rename conv
's methods unless it's necessary for some reason.
The method chain for conv
is a bit of a mess right now, but it's not clear to me that you could use mode
keyword argument with all of the cases that are now supported by conv
.
src/dspbase.jl
Outdated
sv = size(v) | ||
conv_res = conv_full(u, v) | ||
if N != 1 | ||
conv_res[Int(floor.(sv[1]/2 + 1)):Int(floor.(sv[1]/2) + su[1]), Int(floor.(sv[2]/2 + 1)):Int(floor.(sv[2]/2) + su[2]), axes(conv_res)[3:end]...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only apply this to the first two dimensions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always think that n-dimensional convolution only needs to be cut on the first two dimensions.
It may take me a few days to have free time to fix it.
OK, I'll revise it in a few days.
Could you explain all of the cases that are now supported by |
add central part of the convolution add only parts of the convolution that are computed without zero-padded edges
I made some changes to the previous problem. I think it can merge now. |
I'd try to avoid the copy by always computing the |
Additional comment: I would prefer to use strings for the three possible parameter values, i.e. |
Using |
What performance difference do you expect for comparing an argument once? According to what I read (especially the SO answer by @StefanKarpinski), using symbols as arguments only make sense when strings won't work, e.g. type templates. I've also searched for the use of symbols as arguments in the standard library, but there are none AFAIK. So it's not really clear why people started using that. Please do not interpret my comments here as criticism, if you want to use symbols in DSP.jl then by all means go ahead and do it. I just want to understand the reasons to do so, and so far I have not heard a compelling argument except when strings do not work. I also don't understand your arguments:
What do you mean by "constant-propagation" and which optimizations can the compiler use?
But if none of these matter why is it still a good reason then? There are reasons to use strings instead (easier for newcomers).
Consistency with what? It's not used in the standard library. It's also not used in DSP.jl, or is it?
I agree. But one could use strings. |
A very prominent example from Base is the julia> printstyled("Hello world!", color=:blue)
Hello world!
julia> printstyled("Hello world!", color="blue")
ERROR: TypeError: in keyword argument color, expected Union{Int64, Symbol}, got a value of type String But from a very brief look, it's indeed not as common as I thought it would be. OTOH, are
Note that |
This is what symbols were made for - if you're doing metaprogramming then symbols are absolutely necessary, I don't doubt that.
Yes! I didn't know that!
Such arguments are apparently pretty uncommon in general, for example I found
OK. But I doubt that this matters in any real-world (or even contrived) use case. So in summary, parameters accepting a limited number of values are pretty uncommon, and Julia Base as well as the standard library use both variants, so unfortunately it's not even consistent there. I think as long as a package is consistent it doesn't matter what is used, but I'd always keep in mind that many users coming from other languages will be confused by the use of symbols. |
First, I noticed that
Is it possible to accept both
Return |
You're right, I didn't see that. Then yes, to be consistent both functions should accept either symbols or strings, but I wouldn't do both (but again, that's not my call).
I guess? |
The realization of #399