MAINT: fix hamming distance regression for exotic arrays, with unit test

closes https://github.com/scikit-learn/scikit-learn/issues/4014