gemm opt speed up: small refactoring to call less fct.
Refactor condition and use isinstance
Define local fct outside of the loop.