Added a transpose function that handles row stride for input and output matrices.