Fix the tests & build. Close #549.
Merge branch 'master' into scale-rearrange