Fixed undefined behavior in isScalar and isDiagonal private methods