Problem 385. Poker Series 09: IsHighCard
Solution Stats
Problem Comments
Solution Comments
-
6 Comments
This solution doesn't work on R2015a or R2015b. It seems that the behavior of circshift is changed. For example, circshift(sparse(logical([1 2 3])),[0 1]) on R2015b returns all zeros.
Hi Peng, it seems that last major changes to circshift were introduced in 2014a (dim selection added). I'm not able to check this version, 2015a also returns falses. Anyway, (not) nice bug :).
Hi Jan, I don't have 2014a either. But I was able to check with 2013a available here: http://anycodes.cn (On the left hand side, you can select to run MATLAB). While circshift(sparse(logical([1 2 3])),[0 1]) and circshift(sparse(+logical([1 2 3])),[0 1]) produce different output on 2015a and 2015b, they give the same result (up to a class difference) on 2013a.
It's definitely a bug. It seems the newest version of circshift doesn't handle sparse logical matrices properly. It somehow changes trues to falses, but treat them like nonzeros. This leads to some funny logical properties because of the way the algorithms for sparse matrices work. Check following code: A = circshift(sparse([false false true false true]),[0 1]); A, nonzeros(A); full(A), A|1, A&1, ~A, xor(A,1), xor(A,0), and(A,A), or(A,A), A==~~A, isequal(A,~~A), isequal(A|0,A), %(etc.);
B = sparse([false false true false true]); B, B = B([end 1:end-1]), ...
This is my favourite:
C = circshift(sparse(true),1);
Haha, this is definitely a funny example to elaborate on the improper behavior of circshift/sparse when dealing with sparse logical matrix. I agree with you this is a bug, but still not very sure the bug is due to circshift or sparse. Maybe somebody can report this bug to MATHWORKS...
Problem Recent Solvers52
Suggested Problems
-
1997 Solvers
-
Find the two most distant points
2331 Solvers
-
Back to basics 11 - Max Integer
755 Solvers
-
Back to basics 20 - singleton dimensions
265 Solvers
-
421 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!