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

Define Replicate(), Symmetric() and other border options like Inner() instead of using strings #21

Closed
juliohm opened this issue Feb 3, 2017 · 8 comments

Comments

@juliohm
Copy link
Member

juliohm commented Feb 3, 2017

Can you please confirm the new syntax for the following two operations:

img = ones(10,10,10)
kern = ones(3,3,3)

imfilter_fft(img, kern, "inner")
imfilter_fft(img, kern, "symmetric")

Am I correct to say that the new version is:

imfilter(img, centered(kern), Inner(), Algorithm.FFT())
imfilter(img, centered(kern), "symmetric", Algorithm.FFT())

Why Inner() is treated with a separate type unlike other options that are triggered with strings?

@juliohm
Copy link
Member Author

juliohm commented Feb 3, 2017

I have just submitted a journal paper regarding my ImageQuilting.jl package. I need to fix this issue quickly to avoid problems with people trying to use the code for the first time.

@timholy
Copy link
Member

timholy commented Feb 3, 2017

Yes, those are correct.

Why Inner() is treated with a separate type unlike other options that are triggered with strings?

Because with Inner you'll return an OffsetArray whereas with the others you'll return an Array. The algorithm would not be type-stable if we passed "inner" as a string.

@juliohm
Copy link
Member Author

juliohm commented Feb 3, 2017

Hi Tim,

You probably have thought about this interface very carefully, but from the user side this is very tricky. Returning an OffsetArray puts responsibility on the user that now has to check if he has an Array or OffsetArray. For instance, I cannot assume anymore I will always get an Array, because sometimes I use symmetric and sometimes I use Inner(). It is counter-intuitive to have the same conceptual filtering operation returning different types.

Now, related to this issue specifically, can't we make every border scheme a type to be consistent? Symmetric(), Replicate(), would that solve the type-instability too?

@timholy
Copy link
Member

timholy commented Feb 3, 2017

@juliohm
Copy link
Member Author

juliohm commented Feb 4, 2017

Thank you Tim, what about replacing the strings "symmetric", "replicate" by types like Inner()? Would that solve type instability too? It would definitely make the interface consistent.

@timholy
Copy link
Member

timholy commented Feb 4, 2017

There's already Pad(:replicate). At one point I made the padding style Pad{:replicate}(), but then I realized that they all produce the same output type anyway. So I decided to preserve the strings interface.

We could make Replicate() return "replicate". Would that be viewed as being nicer?

@juliohm
Copy link
Member Author

juliohm commented Feb 4, 2017

Hi Tim, ideally these would be their own types in case someone wants to specialize some super optimal implementation in the future, but having Replicate() return the string "replicate" is already more consistent from the user's perspective, definitely.

@juliohm juliohm changed the title Help migrating to the new API Define Replicate(), Symmetric() and other border options like Inner() instead of using strings Feb 4, 2017
@juliohm
Copy link
Member Author

juliohm commented Mar 22, 2018

I am finally putting together all the pieces of this great work. Thanks Tim for your patience.

Everything is consistent as we can simply do imfilter(img, centered(kern), Pad(:symmetric)) and use the Pad type instead of the string.

@juliohm juliohm closed this as completed Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants