added compatibility with matrix inputs of real numbers