JWS C Library
C language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00049 #ifndef MATRIX_MATH_H 00050 #define MATRIX_MATH_H 00051 00052 00053 #include <jwsc/config.h> 00054 00055 #include <stdlib.h> 00056 #include <inttypes.h> 00057 00058 #include "jwsc/base/error.h" 00059 #include "jwsc/math/complex.h" 00060 #include "jwsc/vector/vector.h" 00061 #include "jwsc/matrix/matrix.h" 00062 00063 00064 #ifdef __cplusplus 00065 namespace jwsc { 00066 extern "C" { 00067 #endif 00068 00069 00078 void add_scalar_to_matrix_f(Matrix_f** m_out, const Matrix_f* m_in, float a); 00079 00081 void add_scalar_to_matrix_d(Matrix_d** m_out, const Matrix_d* m_in, double a); 00082 00084 void add_scalar_to_matrix_cf 00085 ( 00086 Matrix_cf** m_out, 00087 const Matrix_cf* m_in, 00088 Complex_f z 00089 ); 00090 00092 void add_scalar_to_matrix_cd 00093 ( 00094 Matrix_cd** m_out, 00095 const Matrix_cd* m_in, 00096 Complex_d z 00097 ); 00098 00112 void multiply_matrix_by_scalar_f 00113 ( 00114 Matrix_f** m_out, 00115 const Matrix_f* m_in, 00116 float a 00117 ); 00118 00120 void multiply_matrix_by_scalar_d 00121 ( 00122 Matrix_d** m_out, 00123 const Matrix_d* m_in, 00124 double a 00125 ); 00126 00128 void multiply_matrix_by_scalar_cf 00129 ( 00130 Matrix_cf** m_out, 00131 const Matrix_cf* m_in, 00132 Complex_f z 00133 ); 00134 00136 void multiply_matrix_by_scalar_cd 00137 ( 00138 Matrix_cd** m_out, 00139 const Matrix_cd* m_in, 00140 Complex_d z 00141 ); 00142 00156 Error* multiply_matrices_f 00157 ( 00158 Matrix_f** m_out, 00159 const Matrix_f* m_1, 00160 const Matrix_f* m_2 00161 ); 00162 00164 Error* multiply_matrices_d 00165 ( 00166 Matrix_d** m_out, 00167 const Matrix_d* m_1, 00168 const Matrix_d* m_2 00169 ); 00170 00172 Error* multiply_matrices_cf 00173 ( 00174 Matrix_cf** m_out, 00175 const Matrix_cf* m_1, 00176 const Matrix_cf* m_2 00177 ); 00178 00180 Error* multiply_matrices_cd 00181 ( 00182 Matrix_cd** m_out, 00183 const Matrix_cd* m_1, 00184 const Matrix_cd* m_2 00185 ); 00186 00200 Error* multiply_matrices_elt_wise_f 00201 ( 00202 Matrix_f** m_out, 00203 const Matrix_f* m_1, 00204 const Matrix_f* m_2 00205 ); 00206 00208 Error* multiply_matrices_elt_wise_d 00209 ( 00210 Matrix_d** m_out, 00211 const Matrix_d* m_1, 00212 const Matrix_d* m_2 00213 ); 00214 00218 Error* multiply_matrices_elt_wise_cf 00219 ( 00220 Matrix_cf** m_out, 00221 const Matrix_cf* m_1, 00222 const Matrix_cf* m_2 00223 ); 00224 00228 Error* multiply_matrices_elt_wise_cd 00229 ( 00230 Matrix_cd** m_out, 00231 const Matrix_cd* m_1, 00232 const Matrix_cd* m_2 00233 ); 00234 00248 void transpose_matrix_f(Matrix_f** m_out, const Matrix_f* m_in); 00249 00251 void transpose_matrix_d(Matrix_d** m_out, const Matrix_d* m_in); 00252 00254 void transpose_matrix_cf(Matrix_cf** m_out, const Matrix_cf* m_in); 00255 00257 void transpose_matrix_cd(Matrix_cd** m_out, const Matrix_cd* m_in); 00258 00272 Error* multiply_matrix_and_vector_f 00273 ( 00274 Vector_f** v_out, 00275 const Matrix_f* m_in, 00276 const Vector_f* v_in 00277 ); 00278 00280 Error* multiply_matrix_and_vector_d 00281 ( 00282 Vector_d** v_out, 00283 const Matrix_d* m_in, 00284 const Vector_d* v_in 00285 ); 00286 00288 Error* multiply_matrix_and_vector_cf 00289 ( 00290 Vector_cf** v_out, 00291 const Matrix_cf* m_in, 00292 const Vector_cf* v_in 00293 ); 00294 00296 Error* multiply_matrix_and_vector_cd 00297 ( 00298 Vector_cd** v_out, 00299 const Matrix_cd* m_in, 00300 const Vector_cd* v_in 00301 ); 00302 00316 Error* add_matrices_f 00317 ( 00318 Matrix_f** m_out, 00319 const Matrix_f* m_1, 00320 const Matrix_f* m_2 00321 ); 00322 00324 Error* add_matrices_d 00325 ( 00326 Matrix_d** m_out, 00327 const Matrix_d* m_1, 00328 const Matrix_d* m_2 00329 ); 00330 00332 Error* add_matrices_cf 00333 ( 00334 Matrix_cf** m_out, 00335 const Matrix_cf* m_1, 00336 const Matrix_cf* m_2 00337 ); 00338 00340 Error* add_matrices_cd 00341 ( 00342 Matrix_cd** m_out, 00343 const Matrix_cd* m_1, 00344 const Matrix_cd* m_2 00345 ); 00346 00360 Error* subtract_matrices_f 00361 ( 00362 Matrix_f** m_out, 00363 const Matrix_f* m_1, 00364 const Matrix_f* m_2 00365 ); 00366 00368 Error* subtract_matrices_d 00369 ( 00370 Matrix_d** m_out, 00371 const Matrix_d* m_1, 00372 const Matrix_d* m_2 00373 ); 00374 00376 Error* subtract_matrices_cf 00377 ( 00378 Matrix_cf** m_out, 00379 const Matrix_cf* m_1, 00380 const Matrix_cf* m_2 00381 ); 00382 00384 Error* subtract_matrices_cd 00385 ( 00386 Matrix_cd** m_out, 00387 const Matrix_cd* m_1, 00388 const Matrix_cd* m_2 00389 ); 00390 00404 void calc_matrix_asum_f(float* sum_out, const Matrix_f* m); 00405 00407 void calc_matrix_asum_d(double* sum_out, const Matrix_d* m); 00408 00422 void normalize_matrix_sum_f(Matrix_f** m_out, const Matrix_f* m_in); 00423 00425 void normalize_matrix_sum_d(Matrix_d** m_out, const Matrix_d* m_in); 00426 00440 void calc_frobenius_norm_f(float* norm_out, const Matrix_f* m); 00441 00443 void calc_frobenius_norm_d(double* norm_out, const Matrix_d* m); 00444 00462 Error* calc_frobenius_norm_diff_f 00463 ( 00464 float* norm_out, 00465 const Matrix_f* m_1, 00466 const Matrix_f* m_2 00467 ); 00468 00473 Error* calc_frobenius_norm_diff_d 00474 ( 00475 double* norm_out, 00476 const Matrix_d* m_1, 00477 const Matrix_d* m_2 00478 ); 00479 00497 Error* calc_frobenius_norm_abs_diff_f 00498 ( 00499 float* norm_out, 00500 const Matrix_f* m_1, 00501 const Matrix_f* m_2 00502 ); 00503 00508 Error* calc_frobenius_norm_abs_diff_d 00509 ( 00510 double* norm_out, 00511 const Matrix_d* m_1, 00512 const Matrix_d* m_2 00513 ); 00514 00520 #if defined JWSC_HAVE_LAPACK 00521 00529 Error* lu_decompose_matrix_f 00530 ( 00531 Matrix_f** m_out, 00532 Vector_i32** pivot_out, 00533 const Matrix_f* m_in 00534 ); 00535 00537 Error* lu_decompose_matrix_d 00538 ( 00539 Matrix_d** m_out, 00540 Vector_i32** pivot_out, 00541 const Matrix_d* m_in 00542 ); 00543 00545 #endif 00546 00547 00548 00549 00550 #if defined JWSC_HAVE_LAPACK 00551 00559 Error* invert_matrix_f(Matrix_f** m_out, const Matrix_f* m_in); 00560 00562 Error* invert_matrix_d(Matrix_d** m_out, const Matrix_d* m_in); 00563 00565 #endif 00566 00567 00568 00569 00570 #if defined JWSC_HAVE_LAPACK 00571 00579 Error* invert_lu_matrix_f 00580 ( 00581 Matrix_f** m_out, 00582 const Matrix_f* m_in, 00583 const Vector_i32* pivot 00584 ); 00585 00587 Error* invert_lu_matrix_d 00588 ( 00589 Matrix_d** m_out, 00590 const Matrix_d* m_in, 00591 const Vector_i32* pivot 00592 ); 00593 00595 #endif 00596 00597 00598 00599 00600 #if defined JWSC_HAVE_LAPACK 00601 00612 Error* calc_matrix_determinant_f(float* det_out, const Matrix_f* m); 00613 00615 Error* calc_matrix_determinant_d(double* det_out, const Matrix_d* m); 00616 00618 #endif 00619 00620 00621 00622 00634 Error* calc_lu_matrix_determinant_f 00635 ( 00636 float* det_out, 00637 const Matrix_f* m, 00638 const Vector_i32* pivot 00639 ); 00640 00645 Error* calc_lu_matrix_determinant_d 00646 ( 00647 double* det_out, 00648 const Matrix_d* m, 00649 const Vector_i32* pivot 00650 ); 00651 00657 #if defined JWSC_HAVE_LAPACK 00658 00669 Error* solve_real_symmetric_matrix_eigenproblem_f 00670 ( 00671 Matrix_f** V_out, 00672 Vector_f** D_out, 00673 const Matrix_f* M 00674 ); 00675 00680 Error* solve_real_symmetric_matrix_eigenproblem_d 00681 ( 00682 Matrix_d** V_out, 00683 Vector_d** D_out, 00684 const Matrix_d* M 00685 ); 00686 00688 #endif 00689 00690 00691 00692 00693 #if defined JWSC_HAVE_LAPACK 00694 00702 Error* singular_value_decompose_matrix_f 00703 ( 00704 Matrix_f** U_out, 00705 Vector_f** S_out, 00706 Matrix_f** Vt_out, 00707 const Matrix_f* M 00708 ); 00709 00711 Error* singular_value_decompose_matrix_d 00712 ( 00713 Matrix_d** U_out, 00714 Vector_d** S_out, 00715 Matrix_d** Vt_out, 00716 const Matrix_d* M 00717 ); 00718 00720 #endif 00721 00722 00723 00724 00725 #if defined JWSC_HAVE_LAPACK 00726 00737 Error* pseudoinvert_matrix_no_svd_f 00738 ( 00739 Matrix_f** M_out, 00740 const Matrix_f* M_in 00741 ); 00742 00747 Error* pseudoinvert_matrix_no_svd_d 00748 ( 00749 Matrix_d** M_out, 00750 const Matrix_d* M_in 00751 ); 00752 00754 #endif 00755 00756 00757 00758 00759 #if defined JWSC_HAVE_LAPACK 00760 00771 Error* pseudoinvert_matrix_f 00772 ( 00773 Matrix_f** M_out, 00774 const Matrix_f* M_in 00775 ); 00776 00781 Error* pseudoinvert_matrix_d 00782 ( 00783 Matrix_d** M_out, 00784 const Matrix_d* M_in 00785 ); 00786 00788 #endif 00789 00790 00791 00792 00801 void create_euler_rotation_matrix_f 00802 ( 00803 Matrix_f** m_out, 00804 float phi, 00805 float theta, 00806 float psi 00807 ); 00808 00810 void create_euler_rotation_matrix_d 00811 ( 00812 Matrix_d** m_out, 00813 float phi, 00814 float theta, 00815 float psi 00816 ); 00817 00834 Error* create_3d_rotation_matrix_1_f 00835 ( 00836 Matrix_f** m_out, 00837 float phi, 00838 const Vector_f* v 00839 ); 00840 00845 Error* create_3d_rotation_matrix_1_d 00846 ( 00847 Matrix_d** m_out, 00848 double phi, 00849 const Vector_d* v 00850 ); 00851 00856 Error* create_3d_rotation_matrix_2_f 00857 ( 00858 Matrix_f** m_out, 00859 float phi, 00860 float x, 00861 float y, 00862 float z 00863 ); 00864 00869 Error* create_3d_rotation_matrix_2_d 00870 ( 00871 Matrix_d** m_out, 00872 double phi, 00873 double x, 00874 double y, 00875 double z 00876 ); 00877 00894 Error* create_3d_homo_rotation_matrix_1_f 00895 ( 00896 Matrix_f** m_out, 00897 float phi, 00898 const Vector_f* v 00899 ); 00900 00905 Error* create_3d_homo_rotation_matrix_1_d 00906 ( 00907 Matrix_d** m_out, 00908 double phi, 00909 const Vector_d* v 00910 ); 00911 00916 Error* create_3d_homo_rotation_matrix_2_f 00917 ( 00918 Matrix_f** m_out, 00919 float phi, 00920 float x, 00921 float y, 00922 float z 00923 ); 00924 00929 Error* create_3d_homo_rotation_matrix_2_d 00930 ( 00931 Matrix_d** m_out, 00932 double phi, 00933 double x, 00934 double y, 00935 double z 00936 ); 00937 00951 Error* create_3d_scaling_matrix_1_f 00952 ( 00953 Matrix_f** m_out, 00954 const Vector_f* v 00955 ); 00956 00958 Error* create_3d_scaling_matrix_1_d 00959 ( 00960 Matrix_d** m_out, 00961 const Vector_d* v 00962 ); 00963 00966 Error* create_3d_scaling_matrix_2_f 00967 ( 00968 Matrix_f** m_out, 00969 float x, 00970 float y, 00971 float z 00972 ); 00973 00975 Error* create_3d_scaling_matrix_2_d 00976 ( 00977 Matrix_d** m_out, 00978 double x, 00979 double y, 00980 double z 00981 ); 00982 00996 Error* create_3d_homo_scaling_matrix_1_f 00997 ( 00998 Matrix_f** m_out, 00999 const Vector_f* v 01000 ); 01001 01003 Error* create_3d_homo_scaling_matrix_1_d 01004 ( 01005 Matrix_d** m_out, 01006 const Vector_d* v 01007 ); 01008 01010 Error* create_3d_homo_scaling_matrix_2_f 01011 ( 01012 Matrix_f** m_out, 01013 float x, 01014 float y, 01015 float z 01016 ); 01017 01019 Error* create_3d_homo_scaling_matrix_2_d 01020 ( 01021 Matrix_d** m_out, 01022 double x, 01023 double y, 01024 double z 01025 ); 01026 01043 Error* create_3d_homo_translation_matrix_1_f 01044 ( 01045 Matrix_f** m_out, 01046 const Vector_f* v 01047 ); 01048 01053 Error* create_3d_homo_translation_matrix_1_d 01054 ( 01055 Matrix_d** m_out, 01056 const Vector_d* v 01057 ); 01058 01063 Error* create_3d_homo_translation_matrix_2_f 01064 ( 01065 Matrix_f** m_out, 01066 float x, 01067 float y, 01068 float z 01069 ); 01070 01075 Error* create_3d_homo_translation_matrix_2_d 01076 ( 01077 Matrix_d** m_out, 01078 double x, 01079 double y, 01080 double z 01081 ); 01082 01086 #ifdef __cplusplus 01087 } 01088 } 01089 #endif 01090 01091 01092 #endif