How to make my Julia code fast like MATLAB?

I think the most “julian” advice would be to try and write your structs as specifically as possible while still leaving it as generic/flexible as possible. Which sounds sort of contradictory, but as @sostock suggested, what’s nice about something like

struct Gaussian{F}
  Fx :: F
  ....

which is a very common pattern in the language, is that if you pass in a special struct that has neat methods for accelerated Base.:*, then the Gaussian struct will preserve that special object and all of your code that uses Fx will benefit. But if for some reason I need to pass in an Fx that isn’t a circulant matrix or is somehow incompatible with some part, for example being a type that doesn’t work with the required fft under the hood of circulant matrix implementations, then the resulting Gaussian{Matrix{WeirdType}} will still be nice and type-stable, so you won’t actually have to change any code.

3 Likes