add n-dimensional case to matrix-equals