-
Notifications
You must be signed in to change notification settings - Fork 152
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
Alternative approaches to prop_flat_map
due to shrinking behavior?
#181
Comments
Upon further reflection, it seems to me that these kind of data structures warrant custom |
Alternatively, you could try to generate from a triple
This might give you the best results, but it would seem likely that there is some new combinator that you could derive for this that works for matrices in general. One could then e.g. build up an extended set of combinator for more advanced data structures as a library (though proptest is fairly large already, so it's probably best to have this as separate crate). |
@Centril: Thank you very much for your input! I suppose your first option is immediately the most pragmatic, I can maybe try that out. Though it does have some issues: If for examples
Do you already have an inkling on how such a combinator might look like? Basically like flat map, but one that prefers to shrink its "outer" layer first? I am not sure how the current flat map shrinker works, but how does one obtain the shrunk values for the inner layer if one shrinks the outer layer first? I suppose I'll find the answer if I dive into the code. Thinking more about it, it does however seem like some kind of generalization of the |
I don't have the code for the flat map shrinker in my mental cache right now so I would recommend looking at the code. :) Studying the code for vectors and flat mapping does seem sensible though. |
I'm using
proptest
to generate random matrices (dense and sparse). I do so as follows:(rows, cols)
.prop_flat_map
on this strategy and generate a vector ofrows * cols
number of items.Here's a concrete example:
This is simple and works very well. However, if I understand correctly, the shrinking procedure for
flat_map
prefers to try to shrink the "inner" strategy (the set of elements) before it tries to shrink the "outer" strategy (rows/cols). This is problematic, because oftenproptest
never tries to reduce the dimension of the matrices, instead favoring trying to reduce the size of the individual elements. If I increasePROPTEST_MAX_SHRINK_ITERS
, it will typically manage to reduce the size as well, but this obviously takes longer to run and I guess there are no guarantees.I have so far been able to think of a good way around this. I suppose in principle, one could generate a large number of elements first, flat map on this and take only
rows * cols
items from this set, but this seems highly inefficient and you'd need to set a maximum number of elements and it would require some additional care in choosing the rows and cols properly. Does anyone have an idea for how I can approach this problem differently? Any help would be greatly appreciated!The text was updated successfully, but these errors were encountered: