Important invariant removed by assert
If we were allowed to pass a zero tolerance to mgard_compress, then a very powerful unit test would be available.
However, this is removed by mgard_api.cpp, line 19, which asserts that tol >= 1e-8.
Is there a fundamental reason for this restriction? Note that if I remove it and set tol =0, then all returned data decompresses to zero. Is this expected behavior?
It appears that those assertions have been there since the beginning. Let me not speak for @tugluk, but I'd guess that they're just sanity checks. There isn't any mathematical reason we shouldn't allow a zero tol.
I misspoke earlier today – the structured code doesn't use an iterative linear solver, so the decomposition and recomposition routines should be 'exact' inverses. It would be a good test to have.
@tugluk's comments on #31 and #33 made me realize I wasn't considering the quantizer at all. Without digging into the code, here's roughly what I think's going on:
- The original dataset
u_nc(nodal values ofu) is transformed tou_mc(multilevel coefficients). - The 'importance' of multilevel coefficient
u_mc[x]is something like2 ^ sl * u_mc[x]wheresis the smoothness parameter andlis the index of the mesh that introduced nodex. - So, if we want
quantized_u_mc[x](quantized coefficients) to be withinτofu_mc[x]'overall', we need eachquantized_mc[x]to be withinτ / 2 ^ slofu_mc[x](ignoring that we also need to scale by the number of coefficients). - Then the quantizer outputs an integer
Nsuch thatquantized_u_mc[x] = N * τ / 2 ^ slis as close as possible tou_mc[x].
If we want to allow a zero tol (or nonzero tol with s and l arbitrarily large), maybe we could just output the coefficients without quantizing? In the shorter term, we could possibly test the decomposition and recomposition functions alone, without quantizing and dequantizing.
@ben-e-whitney, this is bang on. This is basically what I have in the code, L^infinity is a little different but the idea is the same.
Your suggestion is sure to work (obviously) with a loss in compression, using long ints in the quantizer is also an immediate intermediate solution of sorts.
The reimplemented compress function added in 6b43966ea2735e803bd5d814a0d5c109402e8efe returns an object containing the compressed data along with the parameters passed to the function. I think we will probably add a member indicating which lossless compressor was used on the quantized multilevel coefficients. We could also use that member to indicate that the coefficients weren't quantized at all, and then we could support an error tolerance of zero.