JuliaDSP / Wavelets.jl

A Julia package for fast discrete wavelet transforms and utilities
Other
185 stars 30 forks source link

High-level API abstraction #15

Closed gummif closed 9 years ago

gummif commented 9 years ago

For construction of wavelet transform types, the currect API is

wavelet("db2"; transform="filter", boundary="per")

Any thoughts whether using symbols

wavelet("db2"; transform=:filter, boundary=:per)

or types

wavelet("db2"; transform=FilterWavelet(), boundary=PerBoundary())
# or using const objects
wavelet("db2"; transform=FilterWT, boundary=PerWB)

might be better, or more elegant?

daanhb commented 9 years ago

This came up on julia-users once, and the "julian" way seems to be to use a symbol. See e.g. here. I would even write :periodic, rather than :per.

Types for these choices are definitely useful internally, so you can dispatch on them, but I see you have them already.

Btw - thanks for this work!

jfsantos commented 9 years ago

We use types in DSP.jl, since it helps with dispatching. You could add symbols or strings as "syntactic sugar", but in the end you'll want to call the methods with specific types anyways.

gummif commented 9 years ago

Right, thanks. These functions are just "syntactic sugar" for the equivalent, but maybe more complex

OrthoFilter{PerBoundary}("db2")

I think the suggestion to use

wavelet("db2"; transform=:filter, boundary=:periodic)

is good.

simonster commented 9 years ago

For Julia to be able to infer the type of wavelet you're constructing, you would need one of the following approaches:

I'm not sure exactly what performance hit you'll get if the wavelet type is not inferred. If methods on all wavelet types have the same return types and there are not too many, you'll get a slowdown in method dispatch but not much else. If methods that have different return types for different wavelets, or if there are too many methods of the same function, you may get a multiple order of magnitude slowdown if you try to e.g. loop over the result of dwt in the same function that calls it.

gummif commented 9 years ago

Thanks for these comments. See #16 .