some matrix function implementations