From f07af5a111a4b75cd69d1697aa74a19ea2e4f4d9 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Mon, 7 Jul 2025 04:00:20 +0000 Subject: [PATCH] Initial FP16 support --- docs.html | 127 ++++++++++++++++++- include/armadillo | 4 + include/armadillo_bits/SpMat_meat.hpp | 3 + include/armadillo_bits/arma_cmath.hpp | 98 +++++++++++++++ include/armadillo_bits/diskio_meat.hpp | 16 ++- include/armadillo_bits/fill.hpp | 9 ++ include/armadillo_bits/fn_chi2rnd.hpp | 18 ++- include/armadillo_bits/fn_expmat.hpp | 4 +- include/armadillo_bits/fn_svds.hpp | 48 +++---- include/armadillo_bits/hdf5_misc.hpp | 26 ++++ include/armadillo_bits/mul_herk.hpp | 2 +- include/armadillo_bits/op_chi2rnd_meat.hpp | 8 +- include/armadillo_bits/op_dot_bones.hpp | 15 ++- include/armadillo_bits/op_dot_meat.hpp | 35 +++++- include/armadillo_bits/op_norm2est_meat.hpp | 16 ++- include/armadillo_bits/op_norm_bones.hpp | 9 +- include/armadillo_bits/op_norm_meat.hpp | 76 +++++++++-- include/armadillo_bits/promote_type.hpp | 53 ++++++++ include/armadillo_bits/restrictors.hpp | 36 ++++++ include/armadillo_bits/spop_norm_bones.hpp | 4 +- include/armadillo_bits/spop_norm_meat.hpp | 2 +- include/armadillo_bits/traits.hpp | 61 +++++++++ include/armadillo_bits/typedef_elem.hpp | 77 ++++++++++++ include/armadillo_bits/typedef_mat.hpp | 16 +++ tests2/Makefile | 4 +- tests2/attributes.cpp | 2 +- tests2/bounds.cpp | 2 +- tests2/decomp_eig_gen.cpp | 8 +- tests2/decomp_eig_pair.cpp | 4 +- tests2/decomp_eig_sym.cpp | 6 +- tests2/expr_elem.cpp | 2 +- tests2/expr_misc.cpp | 2 +- tests2/fn_abs.cpp | 33 +++-- tests2/fn_accu.cpp | 28 ++++- tests2/fn_all.cpp | 17 ++- tests2/fn_any.cpp | 18 ++- tests2/fn_as_scalar.cpp | 6 +- tests2/fn_clamp.cpp | 2 +- tests2/fn_cond.cpp | 4 +- tests2/fn_conj.cpp | 18 ++- tests2/fn_conv.cpp | 36 +++++- tests2/fn_conv_to.cpp | 43 +++++-- tests2/fn_cor.cpp | 21 +++- tests2/fn_cov.cpp | 20 ++- tests2/fn_cross.cpp | 29 +++-- tests2/fn_cumprod.cpp | 21 +++- tests2/fn_cumsum.cpp | 25 ++-- tests2/fn_det.cpp | 6 +- tests2/fn_diagmat.cpp | 46 ++++++- tests2/fn_diagvec.cpp | 22 +++- tests2/fn_diff.cpp | 46 ++++--- tests2/fn_dot.cpp | 94 ++++++++++++-- tests2/fn_eigs_gen.cpp | 72 +++++------ tests2/fn_eigs_sym.cpp | 8 +- tests2/fn_eps.cpp | 18 ++- tests2/fn_expmat.cpp | 5 +- tests2/fn_find.cpp | 21 +++- tests2/fn_find_finite.cpp | 20 ++- tests2/fn_find_nonfinite.cpp | 20 ++- tests2/fn_find_nonnan.cpp | 24 +++- tests2/fn_find_unique.cpp | 18 ++- tests2/fn_flip.cpp | 38 +++--- tests2/fn_hess.cpp | 22 ++-- tests2/fn_interp1.cpp | 45 ++++++- tests2/fn_intersect.cpp | 25 +++- tests2/fn_is_finite.cpp | 27 +++- tests2/fn_max.cpp | 125 ++++++++++++++---- tests2/fn_mean.cpp | 60 +++++++-- tests2/fn_min.cpp | 125 ++++++++++++++---- tests2/fn_princomp.cpp | 12 +- tests2/fn_solve.cpp | 6 +- tests2/fn_spsolve.cpp | 44 +++---- tests2/fn_stddev.cpp | 46 ++++++- tests2/fn_sum.cpp | 76 ++++++++++- tests2/fn_symmat.cpp | 90 ++++++++++++- tests2/fn_trace.cpp | 42 ++++++- tests2/fn_trans.cpp | 95 +++++++++++++- tests2/fn_var.cpp | 46 ++++++- tests2/fn_vectorise.cpp | 2 +- tests2/gen_linspace.cpp | 52 ++++---- tests2/gen_ones.cpp | 79 ++++++------ tests2/gen_randu.cpp | 46 ++++--- tests2/gen_zeros.cpp | 87 +++++++------ tests2/gmm.cpp | 4 +- tests2/hdf5.cpp | 84 +++++++++---- tests2/init_auxmem.cpp | 29 +++-- tests2/init_fill.cpp | 4 +- tests2/init_misc.cpp | 6 +- tests2/instantiation.cpp | 4 +- tests2/mat_minus.cpp | 28 ++++- tests2/mat_mul_cx.cpp | 45 ++++++- tests2/mat_mul_real.cpp | 54 +++++++- tests2/mat_neg.cpp | 2 +- tests2/mat_plus.cpp | 32 ++++- tests2/spcol.cpp | 10 +- tests2/spmat.cpp | 132 ++++++++++---------- tests2/sprow.cpp | 4 +- tests2/spsubview.cpp | 46 +++---- tests2/utils.hpp | 27 ++++ 99 files changed, 2589 insertions(+), 646 deletions(-) create mode 100644 tests2/utils.hpp diff --git a/docs.html b/docs.html index e7837272..db9aa430 100644 --- a/docs.html +++ b/docs.html @@ -562,9 +562,10 @@ Conrad Sanderson and Ryan Curtin. output streams streams for printing warnings and errors uword / sword shorthand for unsigned and signed integers cx_double / cx_float shorthand for std::complex<double> and std::complex<float> +fp16 shorthand for low-precision types, if supported Matlab/Armadillo syntax differences examples of Matlab syntax and conceptually corresponding Armadillo syntax example program short example program -config.hpp configuration options +config.hpp configuration options API additions API stability and list of API additions @@ -604,6 +605,10 @@ The root matrix class is Mat<type>, where type +
  • +When compiling with C++23 support, type can also be the low-precision type std::float16_t, if hardware support is detected; +see the low-precision support section for more details +

  • For convenience the following typedefs have been defined: @@ -698,6 +703,17 @@ For convenience the following typedefs have been defined: Mat<sword> + + + fp16_mat + + +  =  + + + Mat<fp16> (only if supported by compiler and hardware) + + @@ -1060,6 +1076,23 @@ For convenience the following typedefs have been defined: Col<sword> + + + fp16_vec + + +  =  + + + fp16_colvec + + +  =  + + + Col<fp16> + + @@ -1311,6 +1344,17 @@ For convenience the following typedefs have been defined: Row<sword> + + + fp16_rowvec + + +  =  + + + Row<fp16> (only if supported by compiler and hardware) + + @@ -18394,6 +18438,86 @@ cx_double val = X(2,3);
    +


    + +fp16 +