Closed baggepinnen closed 4 years ago
It appears that the number of allocations is very unstable between julia versions. I upped the threshold to 64 bytes from the previous 32, but on nightly there are some 240 bytes allocated.
Ah ok, maybe it’s not such a good idea to test allocations. Some of them could be dynamic dispatches since Julia doesn’t dispatch on keyword arguments; what do you think of making the cost the 2nd argument instead of a keyword argument? Could add an extra method to provide the default value of norm
, and replace handle_C
with just a dispatch to precompute_cost
for a non-AbstractMatrix method.
It’s breaking but seems like it might be a better interface.
Edit: and maybe rename precompute_cost
to compute_cost_matrix
? I’m thinking if we use it in the tutorial it’ll be more obvious what it’s for with that name.
C
is now the second positional argument, and one can provide either a precomputed matrix, or a cost function. If nothing is provided, norm(x-y)
is used.
sinkhorn_divergence
is an outlier here in that it does currently not support a precomputed cost matrix, since it requires three different matrices.
I also loosened the allocation threshold so that it accepts some wiggle room for whatever happens on julia#master
Great! I used github's feature to apply all your suggested changes. I've never used that before so I hope I didn't crew up :P
Good catch with the potential silent failure, hadn't considered that.
I haven’t used it much either but looks like it worked! Mind adding a test for the new error path? I’m not sure why we aren’t getting a codecov comment but I’ve never had 100% coverage before this repo and would like to keep it 😅.
Awesome, thanks! I'll tag a release shortly. edit: https://github.com/JuliaRegistries/General/pull/12940
Awesome, I'm already using this in https://github.com/baggepinnen/SpectralDistances.jl 😍
Cool! That looks like a really nice package. Please feel free to open issues if you run into any problems down the line!
This PR allows the user to supply either a cost function like before, or a precomputed cost matrix. If the matrix is supplied, the support points of the measures are not required. This PR is non-breaking, but it introduces some extra allocations in case the user does not supply a precomputed cost matrix. Despite the extra allocations, this PR should be a net positive for speed since it saves a lot of computations. Addresses #4