| 844 | |
| 845 | template<typename typ> |
| 846 | static inline void * |
| 847 | linearize_matrix(typ *dst, |
| 848 | typ *src, |
| 849 | const LINEARIZE_DATA_t* data) |
| 850 | { |
| 851 | using ftyp = fortran_type_t<typ>; |
| 852 | if (dst) { |
| 853 | int i, j; |
| 854 | typ* rv = dst; |
| 855 | fortran_int columns = (fortran_int)data->columns; |
| 856 | fortran_int column_strides = |
| 857 | (fortran_int)(data->column_strides/sizeof(typ)); |
| 858 | fortran_int one = 1; |
| 859 | for (i = 0; i < data->rows; i++) { |
| 860 | if (column_strides > 0) { |
| 861 | copy(&columns, |
| 862 | (ftyp*)src, &column_strides, |
| 863 | (ftyp*)dst, &one); |
| 864 | } |
| 865 | else if (column_strides < 0) { |
| 866 | copy(&columns, |
| 867 | ((ftyp*)src + (columns-1)*column_strides), |
| 868 | &column_strides, |
| 869 | (ftyp*)dst, &one); |
| 870 | } |
| 871 | else { |
| 872 | /* |
| 873 | * Zero stride has undefined behavior in some BLAS |
| 874 | * implementations (e.g. OSX Accelerate), so do it |
| 875 | * manually |
| 876 | */ |
| 877 | for (j = 0; j < columns; ++j) { |
| 878 | memcpy(dst + j, src, sizeof(typ)); |
| 879 | } |
| 880 | } |
| 881 | src += data->row_strides/sizeof(typ); |
| 882 | dst += data->output_lead_dim; |
| 883 | } |
| 884 | return rv; |
| 885 | } else { |
| 886 | return src; |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | template<typename typ> |
| 891 | static inline void * |
no test coverage detected