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 00052 #ifndef MATRIX_H 00053 #define MATRIX_H 00054 00055 00056 #include <jwsc/config.h> 00057 00058 #include <stdlib.h> 00059 #include <inttypes.h> 00060 00061 #include "jwsc/base/error.h" 00062 #include "jwsc/math/complex.h" 00063 #include "jwsc/vector/vector.h" 00064 00065 00066 #ifdef __cplusplus 00067 namespace jwsc { 00068 extern "C" { 00069 #endif 00070 00071 00073 typedef struct 00074 { 00076 uint32_t num_rows; 00077 00079 uint32_t num_cols; 00080 00082 int8_t** elts; 00083 } 00084 Matrix_i8; 00085 00087 typedef struct 00088 { 00090 uint32_t num_rows; 00091 00093 uint32_t num_cols; 00094 00096 int16_t** elts; 00097 } 00098 Matrix_i16; 00099 00101 typedef struct 00102 { 00104 uint32_t num_rows; 00105 00107 uint32_t num_cols; 00108 00110 int32_t** elts; 00111 } 00112 Matrix_i32; 00113 00115 typedef struct 00116 { 00118 uint32_t num_rows; 00119 00121 uint32_t num_cols; 00122 00124 int64_t** elts; 00125 } 00126 Matrix_i64; 00127 00128 00130 typedef struct 00131 { 00133 int32_t num_rows; 00134 00136 int32_t num_cols; 00137 00139 uint8_t** elts; 00140 } 00141 Matrix_u8; 00142 00144 typedef struct 00145 { 00147 uint32_t num_rows; 00148 00150 uint32_t num_cols; 00151 00153 uint16_t** elts; 00154 } 00155 Matrix_u16; 00156 00158 typedef struct 00159 { 00161 uint32_t num_rows; 00162 00164 uint32_t num_cols; 00165 00167 uint32_t** elts; 00168 } 00169 Matrix_u32; 00170 00172 typedef struct 00173 { 00175 uint32_t num_rows; 00176 00178 uint32_t num_cols; 00179 00181 uint64_t** elts; 00182 } 00183 Matrix_u64; 00184 00186 typedef struct 00187 { 00189 uint32_t num_rows; 00190 00192 uint32_t num_cols; 00193 00195 float** elts; 00196 } 00197 Matrix_f; 00198 00200 typedef struct 00201 { 00203 uint32_t num_rows; 00204 00206 uint32_t num_cols; 00207 00209 double** elts; 00210 } 00211 Matrix_d; 00212 00214 typedef struct 00215 { 00217 uint32_t num_rows; 00218 00220 uint32_t num_cols; 00221 00223 Complex_f** elts; 00224 } 00225 Matrix_cf; 00226 00228 typedef struct 00229 { 00231 uint32_t num_rows; 00232 00234 uint32_t num_cols; 00235 00237 Complex_d** elts; 00238 } 00239 Matrix_cd; 00240 00241 00243 typedef enum 00244 { 00245 MATRIX_ROW_VECTOR, 00246 MATRIX_COL_VECTOR 00247 } 00248 Matrix_vector; 00249 00250 00251 00252 00261 void create_matrix_u32 00262 ( 00263 Matrix_u32** m_out, 00264 uint32_t num_rows, 00265 uint32_t num_cols 00266 ); 00267 00269 void create_matrix_i32 00270 ( 00271 Matrix_i32** m_out, 00272 uint32_t num_rows, 00273 uint32_t num_cols 00274 ); 00275 00277 void create_matrix_i64 00278 ( 00279 Matrix_i64** m_out, 00280 uint32_t num_rows, 00281 uint32_t num_cols 00282 ); 00283 00285 void create_matrix_f 00286 ( 00287 Matrix_f** m_out, 00288 uint32_t num_rows, 00289 uint32_t num_cols 00290 ); 00291 00293 void create_matrix_d 00294 ( 00295 Matrix_d** m_out, 00296 uint32_t num_rows, 00297 uint32_t num_cols 00298 ); 00299 00301 void create_matrix_cf 00302 ( 00303 Matrix_cf** m_out, 00304 uint32_t num_rows, 00305 uint32_t num_cols 00306 ); 00307 00309 void create_matrix_cd 00310 ( 00311 Matrix_cd** m_out, 00312 uint32_t num_rows, 00313 uint32_t num_cols 00314 ); 00315 00329 void create_init_matrix_u32 00330 ( 00331 Matrix_u32** m_out, 00332 uint32_t num_rows, 00333 uint32_t num_cols, 00334 uint32_t val 00335 ); 00336 00338 void create_init_matrix_i32 00339 ( 00340 Matrix_i32** m_out, 00341 uint32_t num_rows, 00342 uint32_t num_cols, 00343 int32_t val 00344 ); 00345 00347 void create_init_matrix_i64 00348 ( 00349 Matrix_i64** m_out, 00350 uint32_t num_rows, 00351 uint32_t num_cols, 00352 int64_t val 00353 ); 00354 00356 void create_init_matrix_f 00357 ( 00358 Matrix_f** m_out, 00359 uint32_t num_rows, 00360 uint32_t num_cols, 00361 float val 00362 ); 00363 00365 void create_init_matrix_d 00366 ( 00367 Matrix_d** m_out, 00368 uint32_t num_rows, 00369 uint32_t num_cols, 00370 double val 00371 ); 00372 00374 void create_init_matrix_cf 00375 ( 00376 Matrix_cf** m_out, 00377 uint32_t num_rows, 00378 uint32_t num_cols, 00379 Complex_f val 00380 ); 00381 00383 void create_init_matrix_cd 00384 ( 00385 Matrix_cd** m_out, 00386 uint32_t num_rows, 00387 uint32_t num_cols, 00388 Complex_d val 00389 ); 00390 00405 void create_identity_matrix_u32(Matrix_u32** m_out, uint32_t size); 00406 00408 void create_identity_matrix_i32(Matrix_i32** m_out, uint32_t size); 00409 00411 void create_identity_matrix_i64(Matrix_i64** m_out, uint32_t size); 00412 00414 void create_identity_matrix_f(Matrix_f** m_out, uint32_t size); 00415 00417 void create_identity_matrix_d(Matrix_d** m_out, uint32_t size); 00418 00433 void create_zero_matrix_u32 00434 ( 00435 Matrix_u32** m_out, 00436 uint32_t num_rows, 00437 uint32_t num_cols 00438 ); 00439 00441 void create_zero_matrix_i32 00442 ( 00443 Matrix_i32** m_out, 00444 uint32_t num_rows, 00445 uint32_t num_cols 00446 ); 00447 00449 void create_zero_matrix_i64 00450 ( 00451 Matrix_i64** m_out, 00452 uint32_t num_rows, 00453 uint32_t num_cols 00454 ); 00455 00457 void create_zero_matrix_f 00458 ( 00459 Matrix_f** m_out, 00460 uint32_t num_rows, 00461 uint32_t num_cols 00462 ); 00463 00465 void create_zero_matrix_d 00466 ( 00467 Matrix_d** m_out, 00468 uint32_t num_rows, 00469 uint32_t num_cols 00470 ); 00471 00473 void create_zero_matrix_cf 00474 ( 00475 Matrix_cf** m_out, 00476 uint32_t num_rows, 00477 uint32_t num_cols 00478 ); 00479 00481 void create_zero_matrix_cd 00482 ( 00483 Matrix_cd** m_out, 00484 uint32_t num_rows, 00485 uint32_t num_cols 00486 ); 00487 00502 void create_diagnonal_matrix_u32 00503 ( 00504 Matrix_u32** m_out, 00505 const Vector_u32* v 00506 ); 00507 00509 void create_diagonal_matrix_i32 00510 ( 00511 Matrix_i32** m_out, 00512 const Vector_i32* v 00513 ); 00514 00516 void create_diagonal_matrix_i64 00517 ( 00518 Matrix_i64** m_out, 00519 const Vector_i64* v 00520 ); 00521 00523 void create_diagonal_matrix_f 00524 ( 00525 Matrix_f** m_out, 00526 const Vector_f* v 00527 ); 00528 00530 void create_diagonal_matrix_d 00531 ( 00532 Matrix_d** m_out, 00533 const Vector_d* v 00534 ); 00535 00537 void create_diagonal_matrix_cf 00538 ( 00539 Matrix_cf** m_out, 00540 const Vector_cf* v 00541 ); 00542 00544 void create_diagonal_matrix_cd 00545 ( 00546 Matrix_cd** m_out, 00547 const Vector_cd* v 00548 ); 00549 00564 void create_random_matrix_u32 00565 ( 00566 Matrix_u32** m_out, 00567 uint32_t num_rows, 00568 uint32_t num_cols, 00569 uint32_t min, 00570 uint32_t max 00571 ); 00572 00574 void create_random_matrix_i32 00575 ( 00576 Matrix_i32** m_out, 00577 uint32_t num_rows, 00578 uint32_t num_cols, 00579 int32_t min, 00580 int32_t max 00581 ); 00582 00584 void create_random_matrix_i64 00585 ( 00586 Matrix_i64** m_out, 00587 uint32_t num_rows, 00588 uint32_t num_cols, 00589 int64_t min, 00590 int64_t max 00591 ); 00592 00594 void create_random_matrix_f 00595 ( 00596 Matrix_f** m_out, 00597 uint32_t num_rows, 00598 uint32_t num_cols, 00599 float min, 00600 float max 00601 ); 00602 00604 void create_random_matrix_d 00605 ( 00606 Matrix_d** m_out, 00607 uint32_t num_rows, 00608 uint32_t num_cols, 00609 double min, 00610 double max 00611 ); 00612 00614 void create_random_matrix_cf 00615 ( 00616 Matrix_cf** m_out, 00617 uint32_t num_rows, 00618 uint32_t num_cols, 00619 Complex_f min, 00620 Complex_f max 00621 ); 00622 00624 void create_random_matrix_cd 00625 ( 00626 Matrix_cd** m_out, 00627 uint32_t num_rows, 00628 uint32_t num_cols, 00629 Complex_d min, 00630 Complex_d max 00631 ); 00632 00646 Error* copy_matrix_u32(Matrix_u32** m_out, const Matrix_u32* m_in); 00647 00649 Error* copy_matrix_i32(Matrix_i32** m_out, const Matrix_i32* m_in); 00650 00652 Error* copy_matrix_i64(Matrix_i64** m_out, const Matrix_i64* m_in); 00653 00655 Error* copy_matrix_f(Matrix_f** m_out, const Matrix_f* m_in); 00656 00658 Error* copy_matrix_d(Matrix_d** m_out, const Matrix_d* m_in); 00659 00661 Error* copy_matrix_cf(Matrix_cf** m_out, const Matrix_cf* m_in); 00662 00664 Error* copy_matrix_cd(Matrix_cd** m_out, const Matrix_cd* m_in); 00665 00679 Error* copy_matrix_block_u32 00680 ( 00681 Matrix_u32** m_out, 00682 const Matrix_u32* m_in, 00683 uint32_t row_offset, 00684 uint32_t col_offset, 00685 uint32_t num_rows, 00686 uint32_t num_cols 00687 ); 00688 00690 Error* copy_matrix_block_i32 00691 ( 00692 Matrix_i32** m_out, 00693 const Matrix_i32* m_in, 00694 uint32_t row_offset, 00695 uint32_t col_offset, 00696 uint32_t num_rows, 00697 uint32_t num_cols 00698 ); 00699 00701 Error* copy_matrix_block_i64 00702 ( 00703 Matrix_i64** m_out, 00704 const Matrix_i64* m_in, 00705 uint32_t row_offset, 00706 uint32_t col_offset, 00707 uint32_t num_rows, 00708 uint32_t num_cols 00709 ); 00710 00712 Error* copy_matrix_block_f 00713 ( 00714 Matrix_f** m_out, 00715 const Matrix_f* m_in, 00716 uint32_t row_offset, 00717 uint32_t col_offset, 00718 uint32_t num_rows, 00719 uint32_t num_cols 00720 ); 00721 00723 Error* copy_matrix_block_d 00724 ( 00725 Matrix_d** m_out, 00726 const Matrix_d* m_in, 00727 uint32_t row_offset, 00728 uint32_t col_offset, 00729 uint32_t num_rows, 00730 uint32_t num_cols 00731 ); 00732 00734 Error* copy_matrix_block_cf 00735 ( 00736 Matrix_cf** m_out, 00737 const Matrix_cf* m_in, 00738 uint32_t row_offset, 00739 uint32_t col_offset, 00740 uint32_t num_rows, 00741 uint32_t num_cols 00742 ); 00743 00745 Error* copy_matrix_block_cd 00746 ( 00747 Matrix_cd** m_out, 00748 const Matrix_cd* m_in, 00749 uint32_t row_offset, 00750 uint32_t col_offset, 00751 uint32_t num_rows, 00752 uint32_t num_cols 00753 ); 00754 00768 Error* copy_matrix_block_into_matrix_u32 00769 ( 00770 Matrix_u32* m_1, 00771 uint32_t row_offset_1, 00772 uint32_t col_offset_1, 00773 const Matrix_u32* m_2, 00774 uint32_t row_offset_2, 00775 uint32_t col_offset_2, 00776 uint32_t num_rows, 00777 uint32_t num_cols 00778 ); 00779 00781 Error* copy_matrix_block_into_matrix_i32 00782 ( 00783 Matrix_i32* m_1, 00784 uint32_t row_offset_1, 00785 uint32_t col_offset_1, 00786 const Matrix_i32* m_2, 00787 uint32_t row_offset_2, 00788 uint32_t col_offset_2, 00789 uint32_t num_rows, 00790 uint32_t num_cols 00791 ); 00792 00794 Error* copy_matrix_block_into_matrix_i64 00795 ( 00796 Matrix_i64* m_1, 00797 uint32_t row_offset_1, 00798 uint32_t col_offset_1, 00799 const Matrix_i64* m_2, 00800 uint32_t row_offset_2, 00801 uint32_t col_offset_2, 00802 uint32_t num_rows, 00803 uint32_t num_cols 00804 ); 00805 00810 Error* copy_matrix_block_into_matrix_f 00811 ( 00812 Matrix_f* m_1, 00813 uint32_t row_offset_1, 00814 uint32_t col_offset_1, 00815 const Matrix_f* m_2, 00816 uint32_t row_offset_2, 00817 uint32_t col_offset_2, 00818 uint32_t num_rows, 00819 uint32_t num_cols 00820 ); 00821 00826 Error* copy_matrix_block_into_matrix_d 00827 ( 00828 Matrix_d* m_1, 00829 uint32_t row_offset_1, 00830 uint32_t col_offset_1, 00831 const Matrix_d* m_2, 00832 uint32_t row_offset_2, 00833 uint32_t col_offset_2, 00834 uint32_t num_rows, 00835 uint32_t num_cols 00836 ); 00837 00842 Error* copy_matrix_block_into_matrix_cf 00843 ( 00844 Matrix_cf* m_1, 00845 uint32_t row_offset_1, 00846 uint32_t col_offset_1, 00847 const Matrix_cf* m_2, 00848 uint32_t row_offset_2, 00849 uint32_t col_offset_2, 00850 uint32_t num_rows, 00851 uint32_t num_cols 00852 ); 00853 00858 Error* copy_matrix_block_into_matrix_cd 00859 ( 00860 Matrix_cd* m_1, 00861 uint32_t row_offset_1, 00862 uint32_t col_offset_1, 00863 const Matrix_cd* m_2, 00864 uint32_t row_offset_2, 00865 uint32_t col_offset_2, 00866 uint32_t num_rows, 00867 uint32_t num_cols 00868 ); 00869 00883 Error* copy_vector_into_matrix_u32 00884 ( 00885 Matrix_u32** m_out, 00886 const Matrix_u32* m_in, 00887 const Vector_u32* v, 00888 Matrix_vector orient, 00889 uint32_t index 00890 ); 00891 00893 Error* copy_vector_into_matrix_i32 00894 ( 00895 Matrix_i32** m_out, 00896 const Matrix_i32* m_in, 00897 const Vector_i32* v, 00898 Matrix_vector orient, 00899 uint32_t index 00900 ); 00901 00903 Error* copy_vector_into_matrix_i64 00904 ( 00905 Matrix_i64** m_out, 00906 const Matrix_i64* m_in, 00907 const Vector_i64* v, 00908 Matrix_vector orient, 00909 uint32_t index 00910 ); 00911 00913 Error* copy_vector_into_matrix_f 00914 ( 00915 Matrix_f** m_out, 00916 const Matrix_f* m_in, 00917 const Vector_f* v, 00918 Matrix_vector orient, 00919 uint32_t index 00920 ); 00921 00923 Error* copy_vector_into_matrix_d 00924 ( 00925 Matrix_d** m_out, 00926 const Matrix_d* m_in, 00927 const Vector_d* v, 00928 Matrix_vector orient, 00929 uint32_t index 00930 ); 00931 00933 Error* copy_vector_into_matrix_cf 00934 ( 00935 Matrix_cf** m_out, 00936 const Matrix_cf* m_in, 00937 const Vector_cf* v, 00938 Matrix_vector orient, 00939 uint32_t index 00940 ); 00941 00943 Error* copy_vector_into_matrix_cd 00944 ( 00945 Matrix_cd** m_out, 00946 const Matrix_cd* m_in, 00947 const Vector_cd* v, 00948 Matrix_vector orient, 00949 uint32_t index 00950 ); 00951 00965 Error* copy_vector_from_matrix_u32 00966 ( 00967 Vector_u32** v_out, 00968 const Matrix_u32* m, 00969 Matrix_vector orient, 00970 uint32_t index 00971 ); 00972 00974 Error* copy_vector_from_matrix_i32 00975 ( 00976 Vector_i32** v_out, 00977 const Matrix_i32* m, 00978 Matrix_vector orient, 00979 uint32_t index 00980 ); 00981 00983 Error* copy_vector_from_matrix_i64 00984 ( 00985 Vector_i64** v_out, 00986 const Matrix_i64* m, 00987 Matrix_vector orient, 00988 uint32_t index 00989 ); 00990 00992 Error* copy_vector_from_matrix_f 00993 ( 00994 Vector_f** v_out, 00995 const Matrix_f* m, 00996 Matrix_vector orient, 00997 uint32_t index 00998 ); 00999 01001 Error* copy_vector_from_matrix_d 01002 ( 01003 Vector_d** v_out, 01004 const Matrix_d* m, 01005 Matrix_vector orient, 01006 uint32_t index 01007 ); 01008 01010 Error* copy_vector_from_matrix_cf 01011 ( 01012 Vector_cf** v_out, 01013 const Matrix_cf* m, 01014 Matrix_vector orient, 01015 uint32_t index 01016 ); 01017 01019 Error* copy_vector_from_matrix_cd 01020 ( 01021 Vector_cd** v_out, 01022 const Matrix_cd* m, 01023 Matrix_vector orient, 01024 uint32_t index 01025 ); 01026 01040 void free_matrix_u32(Matrix_u32* m); 01041 01043 void free_matrix_i32(Matrix_i32* m); 01044 01046 void free_matrix_i64(Matrix_i64* m); 01047 01049 void free_matrix_f(Matrix_f* m); 01050 01052 void free_matrix_d(Matrix_d* m); 01053 01055 void free_matrix_cf(Matrix_cf* m); 01056 01058 void free_matrix_cd(Matrix_cd* m); 01059 01063 #ifdef __cplusplus 01064 } 01065 } 01066 #endif 01067 01068 01069 #endif