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 00056 #include <jwsc/config.h> 00057 00058 #include <stdlib.h> 00059 #include <assert.h> 00060 #include <math.h> 00061 #include <inttypes.h> 00062 00063 #include "jwsc/base/error.h" 00064 #include "jwsc/math/complex.h" 00065 #include "jwsc/math/blas.h" 00066 #include "jwsc/matrix/matrix.h" 00067 #include "jwsc/matblock/matblock.h" 00068 00069 #ifdef JWSC_HAVE_DMALLOC 00070 #include <dmalloc.h> 00071 #endif 00072 00073 00090 void create_matblock_u8 00091 ( 00092 Matblock_u8** m_out, 00093 uint32_t num_mats, 00094 uint32_t num_rows, 00095 uint32_t num_cols 00096 ) 00097 { 00098 uint32_t mat; 00099 uint32_t row; 00100 uint8_t* elts; 00101 uint8_t** row_ptrs; 00102 Matblock_u8* m; 00103 00104 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00105 00106 if (*m_out == NULL) 00107 { 00108 assert(*m_out = malloc(sizeof(Matblock_u8))); 00109 (*m_out)->num_mats = 0; 00110 (*m_out)->num_rows = 0; 00111 (*m_out)->num_cols = 0; 00112 (*m_out)->elts = NULL; 00113 } 00114 m = *m_out; 00115 00116 if (m->num_mats != num_mats || 00117 m->num_rows != num_rows || 00118 m->num_cols != num_cols) 00119 { 00120 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00121 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(uint8_t)); 00122 assert(elts); 00123 00124 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00125 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(uint8_t*)); 00126 assert(row_ptrs); 00127 00128 m->elts = realloc(m->elts, num_mats*sizeof(uint8_t**)); 00129 assert(m->elts); 00130 00131 for (mat = 0; mat < num_mats; mat++) 00132 { 00133 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00134 00135 for (row = 0; row < num_rows; row++) 00136 { 00137 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00138 } 00139 } 00140 m->num_mats = num_mats; 00141 m->num_rows = num_rows; 00142 m->num_cols = num_cols; 00143 } 00144 } 00145 00155 void create_matblock_u32 00156 ( 00157 Matblock_u32** m_out, 00158 uint32_t num_mats, 00159 uint32_t num_rows, 00160 uint32_t num_cols 00161 ) 00162 { 00163 uint32_t mat; 00164 uint32_t row; 00165 uint32_t* elts; 00166 uint32_t** row_ptrs; 00167 Matblock_u32* m; 00168 00169 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00170 00171 if (*m_out == NULL) 00172 { 00173 assert(*m_out = malloc(sizeof(Matblock_u32))); 00174 (*m_out)->num_mats = 0; 00175 (*m_out)->num_rows = 0; 00176 (*m_out)->num_cols = 0; 00177 (*m_out)->elts = NULL; 00178 } 00179 m = *m_out; 00180 00181 if (m->num_mats != num_mats || 00182 m->num_rows != num_rows || 00183 m->num_cols != num_cols) 00184 { 00185 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00186 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(uint32_t)); 00187 assert(elts); 00188 00189 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00190 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(uint32_t*)); 00191 assert(row_ptrs); 00192 00193 m->elts = realloc(m->elts, num_mats*sizeof(uint32_t**)); 00194 assert(m->elts); 00195 00196 for (mat = 0; mat < num_mats; mat++) 00197 { 00198 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00199 00200 for (row = 0; row < num_rows; row++) 00201 { 00202 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00203 } 00204 } 00205 m->num_mats = num_mats; 00206 m->num_rows = num_rows; 00207 m->num_cols = num_cols; 00208 } 00209 } 00210 00220 void create_matblock_i32 00221 ( 00222 Matblock_i32** m_out, 00223 uint32_t num_mats, 00224 uint32_t num_rows, 00225 uint32_t num_cols 00226 ) 00227 { 00228 uint32_t mat; 00229 uint32_t row; 00230 int32_t* elts; 00231 int32_t** row_ptrs; 00232 Matblock_i32* m; 00233 00234 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00235 00236 if (*m_out == NULL) 00237 { 00238 assert(*m_out = malloc(sizeof(Matblock_i32))); 00239 (*m_out)->num_mats = 0; 00240 (*m_out)->num_rows = 0; 00241 (*m_out)->num_cols = 0; 00242 (*m_out)->elts = NULL; 00243 } 00244 m = *m_out; 00245 00246 if (m->num_mats != num_mats || 00247 m->num_rows != num_rows || 00248 m->num_cols != num_cols) 00249 { 00250 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00251 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(int32_t)); 00252 assert(elts); 00253 00254 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00255 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(int32_t*)); 00256 assert(row_ptrs); 00257 00258 m->elts = realloc(m->elts, num_mats*sizeof(int32_t**)); 00259 assert(m->elts); 00260 00261 for (mat = 0; mat < num_mats; mat++) 00262 { 00263 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00264 00265 for (row = 0; row < num_rows; row++) 00266 { 00267 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00268 } 00269 } 00270 m->num_mats = num_mats; 00271 m->num_rows = num_rows; 00272 m->num_cols = num_cols; 00273 } 00274 } 00275 00285 void create_matblock_i64 00286 ( 00287 Matblock_i64** m_out, 00288 uint32_t num_mats, 00289 uint32_t num_rows, 00290 uint32_t num_cols 00291 ) 00292 { 00293 uint32_t mat; 00294 uint32_t row; 00295 int64_t* elts; 00296 int64_t** row_ptrs; 00297 Matblock_i64* m; 00298 00299 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00300 00301 if (*m_out == NULL) 00302 { 00303 assert(*m_out = malloc(sizeof(Matblock_i64))); 00304 (*m_out)->num_mats = 0; 00305 (*m_out)->num_rows = 0; 00306 (*m_out)->num_cols = 0; 00307 (*m_out)->elts = NULL; 00308 } 00309 m = *m_out; 00310 00311 if (m->num_mats != num_mats || 00312 m->num_rows != num_rows || 00313 m->num_cols != num_cols) 00314 { 00315 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00316 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(int64_t)); 00317 assert(elts); 00318 00319 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00320 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(int64_t*)); 00321 assert(row_ptrs); 00322 00323 m->elts = realloc(m->elts, num_mats*sizeof(int64_t**)); 00324 assert(m->elts); 00325 00326 for (mat = 0; mat < num_mats; mat++) 00327 { 00328 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00329 00330 for (row = 0; row < num_rows; row++) 00331 { 00332 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00333 } 00334 } 00335 m->num_mats = num_mats; 00336 m->num_rows = num_rows; 00337 m->num_cols = num_cols; 00338 } 00339 } 00340 00350 void create_matblock_f 00351 ( 00352 Matblock_f** m_out, 00353 uint32_t num_mats, 00354 uint32_t num_rows, 00355 uint32_t num_cols 00356 ) 00357 { 00358 uint32_t mat; 00359 uint32_t row; 00360 float* elts; 00361 float** row_ptrs; 00362 Matblock_f* m; 00363 00364 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00365 00366 if (*m_out == NULL) 00367 { 00368 assert(*m_out = malloc(sizeof(Matblock_f))); 00369 (*m_out)->num_mats = 0; 00370 (*m_out)->num_rows = 0; 00371 (*m_out)->num_cols = 0; 00372 (*m_out)->elts = NULL; 00373 } 00374 m = *m_out; 00375 00376 if (m->num_mats != num_mats || 00377 m->num_rows != num_rows || 00378 m->num_cols != num_cols) 00379 { 00380 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00381 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(float)); 00382 assert(elts); 00383 00384 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00385 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(float*)); 00386 assert(row_ptrs); 00387 00388 m->elts = realloc(m->elts, num_mats*sizeof(float**)); 00389 assert(m->elts); 00390 00391 for (mat = 0; mat < num_mats; mat++) 00392 { 00393 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00394 00395 for (row = 0; row < num_rows; row++) 00396 { 00397 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00398 } 00399 } 00400 m->num_mats = num_mats; 00401 m->num_rows = num_rows; 00402 m->num_cols = num_cols; 00403 } 00404 } 00405 00415 void create_matblock_d 00416 ( 00417 Matblock_d** m_out, 00418 uint32_t num_mats, 00419 uint32_t num_rows, 00420 uint32_t num_cols 00421 ) 00422 { 00423 uint32_t mat; 00424 uint32_t row; 00425 double* elts; 00426 double** row_ptrs; 00427 Matblock_d* m; 00428 00429 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00430 00431 if (*m_out == NULL) 00432 { 00433 assert(*m_out = malloc(sizeof(Matblock_d))); 00434 (*m_out)->num_mats = 0; 00435 (*m_out)->num_rows = 0; 00436 (*m_out)->num_cols = 0; 00437 (*m_out)->elts = NULL; 00438 } 00439 m = *m_out; 00440 00441 if (m->num_mats != num_mats || 00442 m->num_rows != num_rows || 00443 m->num_cols != num_cols) 00444 { 00445 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00446 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(double)); 00447 assert(elts); 00448 00449 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00450 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(double*)); 00451 assert(row_ptrs); 00452 00453 m->elts = realloc(m->elts, num_mats*sizeof(double**)); 00454 assert(m->elts); 00455 00456 for (mat = 0; mat < num_mats; mat++) 00457 { 00458 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00459 00460 for (row = 0; row < num_rows; row++) 00461 { 00462 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00463 } 00464 } 00465 m->num_mats = num_mats; 00466 m->num_rows = num_rows; 00467 m->num_cols = num_cols; 00468 } 00469 } 00470 00480 void create_matblock_cf 00481 ( 00482 Matblock_cf** m_out, 00483 uint32_t num_mats, 00484 uint32_t num_rows, 00485 uint32_t num_cols 00486 ) 00487 { 00488 uint32_t mat; 00489 uint32_t row; 00490 Complex_f* elts; 00491 Complex_f** row_ptrs; 00492 Matblock_cf* m; 00493 00494 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00495 00496 if (*m_out == NULL) 00497 { 00498 assert(*m_out = malloc(sizeof(Matblock_cf))); 00499 (*m_out)->num_mats = 0; 00500 (*m_out)->num_rows = 0; 00501 (*m_out)->num_cols = 0; 00502 (*m_out)->elts = NULL; 00503 } 00504 m = *m_out; 00505 00506 if (m->num_mats != num_mats || 00507 m->num_rows != num_rows || 00508 m->num_cols != num_cols) 00509 { 00510 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00511 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(Complex_f)); 00512 assert(elts); 00513 00514 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00515 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(Complex_f*)); 00516 assert(row_ptrs); 00517 00518 m->elts = realloc(m->elts, num_mats*sizeof(Complex_f**)); 00519 assert(m->elts); 00520 00521 for (mat = 0; mat < num_mats; mat++) 00522 { 00523 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00524 00525 for (row = 0; row < num_rows; row++) 00526 { 00527 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00528 } 00529 } 00530 m->num_mats = num_mats; 00531 m->num_rows = num_rows; 00532 m->num_cols = num_cols; 00533 } 00534 } 00535 00545 void create_matblock_cd 00546 ( 00547 Matblock_cd** m_out, 00548 uint32_t num_mats, 00549 uint32_t num_rows, 00550 uint32_t num_cols 00551 ) 00552 { 00553 uint32_t mat; 00554 uint32_t row; 00555 Complex_d* elts; 00556 Complex_d** row_ptrs; 00557 Matblock_cd* m; 00558 00559 assert(num_mats > 0 && num_rows > 0 && num_cols > 0); 00560 00561 if (*m_out == NULL) 00562 { 00563 assert(*m_out = malloc(sizeof(Matblock_cd))); 00564 (*m_out)->num_mats = 0; 00565 (*m_out)->num_rows = 0; 00566 (*m_out)->num_cols = 0; 00567 (*m_out)->elts = NULL; 00568 } 00569 m = *m_out; 00570 00571 if (m->num_mats != num_mats || 00572 m->num_rows != num_rows || 00573 m->num_cols != num_cols) 00574 { 00575 elts = (m->num_mats > 0 && m->num_rows > 0) ? **(m->elts) : NULL; 00576 elts = realloc(elts, num_mats*num_rows*num_cols*sizeof(Complex_d)); 00577 assert(elts); 00578 00579 row_ptrs = (m->num_mats > 0) ? *(m->elts) : NULL; 00580 row_ptrs = realloc(row_ptrs, num_mats*num_rows*sizeof(Complex_d*)); 00581 assert(row_ptrs); 00582 00583 m->elts = realloc(m->elts, num_mats*sizeof(Complex_d**)); 00584 assert(m->elts); 00585 00586 for (mat = 0; mat < num_mats; mat++) 00587 { 00588 m->elts[ mat ] = &(row_ptrs[ mat*num_rows ]); 00589 00590 for (row = 0; row < num_rows; row++) 00591 { 00592 m->elts[ mat ][ row ] = &(elts[ (row+mat*num_rows)*num_cols ]); 00593 } 00594 } 00595 m->num_mats = num_mats; 00596 m->num_rows = num_rows; 00597 m->num_cols = num_cols; 00598 } 00599 } 00600 00623 void create_init_matblock_u8 00624 ( 00625 Matblock_u8** m_out, 00626 uint32_t num_mats, 00627 uint32_t num_rows, 00628 uint32_t num_cols, 00629 uint8_t val 00630 ) 00631 { 00632 uint8_t num_elts; 00633 uint8_t elt; 00634 uint8_t* m_elts; 00635 00636 create_matblock_u8(m_out, num_mats, num_rows, num_cols); 00637 m_elts = **((*m_out)->elts); 00638 num_elts = num_mats*num_rows*num_cols; 00639 00640 for (elt = 0; elt < num_elts; elt++) 00641 { 00642 m_elts[ elt ] = val; 00643 } 00644 } 00645 00656 void create_init_matblock_u32 00657 ( 00658 Matblock_u32** m_out, 00659 uint32_t num_mats, 00660 uint32_t num_rows, 00661 uint32_t num_cols, 00662 uint32_t val 00663 ) 00664 { 00665 uint32_t num_elts; 00666 uint32_t elt; 00667 uint32_t* m_elts; 00668 00669 create_matblock_u32(m_out, num_mats, num_rows, num_cols); 00670 m_elts = **((*m_out)->elts); 00671 num_elts = num_mats*num_rows*num_cols; 00672 00673 for (elt = 0; elt < num_elts; elt++) 00674 { 00675 m_elts[ elt ] = val; 00676 } 00677 } 00678 00689 void create_init_matblock_i32 00690 ( 00691 Matblock_i32** m_out, 00692 uint32_t num_mats, 00693 uint32_t num_rows, 00694 uint32_t num_cols, 00695 int32_t val 00696 ) 00697 { 00698 uint32_t num_elts; 00699 uint32_t elt; 00700 int32_t* m_elts; 00701 00702 create_matblock_i32(m_out, num_mats, num_rows, num_cols); 00703 m_elts = **((*m_out)->elts); 00704 num_elts = num_mats*num_rows*num_cols; 00705 00706 for (elt = 0; elt < num_elts; elt++) 00707 { 00708 m_elts[ elt ] = val; 00709 } 00710 } 00711 00722 void create_init_matblock_i64 00723 ( 00724 Matblock_i64** m_out, 00725 uint32_t num_mats, 00726 uint32_t num_rows, 00727 uint32_t num_cols, 00728 int64_t val 00729 ) 00730 { 00731 uint32_t num_elts; 00732 uint32_t elt; 00733 int64_t* m_elts; 00734 00735 create_matblock_i64(m_out, num_mats, num_rows, num_cols); 00736 m_elts = **((*m_out)->elts); 00737 num_elts = num_mats*num_rows*num_cols; 00738 00739 for (elt = 0; elt < num_elts; elt++) 00740 { 00741 m_elts[ elt ] = val; 00742 } 00743 } 00744 00755 void create_init_matblock_f 00756 ( 00757 Matblock_f** m_out, 00758 uint32_t num_mats, 00759 uint32_t num_rows, 00760 uint32_t num_cols, 00761 float val 00762 ) 00763 { 00764 uint32_t num_elts; 00765 uint32_t elt; 00766 float* m_elts; 00767 00768 create_matblock_f(m_out, num_mats, num_rows, num_cols); 00769 m_elts = **((*m_out)->elts); 00770 num_elts = num_mats*num_rows*num_cols; 00771 00772 for (elt = 0; elt < num_elts; elt++) 00773 { 00774 m_elts[ elt ] = val; 00775 } 00776 } 00777 00788 void create_init_matblock_d 00789 ( 00790 Matblock_d** m_out, 00791 uint32_t num_mats, 00792 uint32_t num_rows, 00793 uint32_t num_cols, 00794 double val 00795 ) 00796 { 00797 uint32_t num_elts; 00798 uint32_t elt; 00799 double* m_elts; 00800 00801 create_matblock_d(m_out, num_mats, num_rows, num_cols); 00802 m_elts = **((*m_out)->elts); 00803 num_elts = num_mats*num_rows*num_cols; 00804 00805 for (elt = 0; elt < num_elts; elt++) 00806 { 00807 m_elts[ elt ] = val; 00808 } 00809 } 00810 00821 void create_init_matblock_cf 00822 ( 00823 Matblock_cf** m_out, 00824 uint32_t num_mats, 00825 uint32_t num_rows, 00826 uint32_t num_cols, 00827 Complex_f val 00828 ) 00829 { 00830 uint32_t num_elts; 00831 uint32_t elt; 00832 Complex_f* m_elts; 00833 00834 create_matblock_cf(m_out, num_mats, num_rows, num_cols); 00835 m_elts = **((*m_out)->elts); 00836 num_elts = num_mats*num_rows*num_cols; 00837 00838 for (elt = 0; elt < num_elts; elt++) 00839 { 00840 m_elts[ elt ] = val; 00841 } 00842 } 00843 00854 void create_init_matblock_cd 00855 ( 00856 Matblock_cd** m_out, 00857 uint32_t num_mats, 00858 uint32_t num_rows, 00859 uint32_t num_cols, 00860 Complex_d val 00861 ) 00862 { 00863 uint32_t num_elts; 00864 uint32_t elt; 00865 Complex_d* m_elts; 00866 00867 create_matblock_cd(m_out, num_mats, num_rows, num_cols); 00868 m_elts = **((*m_out)->elts); 00869 num_elts = num_mats*num_rows*num_cols; 00870 00871 for (elt = 0; elt < num_elts; elt++) 00872 { 00873 m_elts[ elt ] = val; 00874 } 00875 } 00876 00899 void create_zero_matblock_u8 00900 ( 00901 Matblock_u8** m_out, 00902 uint32_t num_mats, 00903 uint32_t num_rows, 00904 uint32_t num_cols 00905 ) 00906 { 00907 create_init_matblock_u8(m_out, num_mats, num_rows, num_cols, 0); 00908 } 00909 00919 void create_zero_matblock_u32 00920 ( 00921 Matblock_u32** m_out, 00922 uint32_t num_mats, 00923 uint32_t num_rows, 00924 uint32_t num_cols 00925 ) 00926 { 00927 create_init_matblock_u32(m_out, num_mats, num_rows, num_cols, 0); 00928 } 00929 00939 void create_zero_matblock_i32 00940 ( 00941 Matblock_i32** m_out, 00942 uint32_t num_mats, 00943 uint32_t num_rows, 00944 uint32_t num_cols 00945 ) 00946 { 00947 create_init_matblock_i32(m_out, num_mats, num_rows, num_cols, 0); 00948 } 00949 00959 void create_zero_matblock_i64 00960 ( 00961 Matblock_i64** m_out, 00962 uint32_t num_mats, 00963 uint32_t num_rows, 00964 uint32_t num_cols 00965 ) 00966 { 00967 create_init_matblock_i64(m_out, num_mats, num_rows, num_cols, 0); 00968 } 00969 00979 void create_zero_matblock_f 00980 ( 00981 Matblock_f** m_out, 00982 uint32_t num_mats, 00983 uint32_t num_rows, 00984 uint32_t num_cols 00985 ) 00986 { 00987 create_init_matblock_f(m_out, num_mats, num_rows, num_cols, 0); 00988 } 00989 00999 void create_zero_matblock_d 01000 ( 01001 Matblock_d** m_out, 01002 uint32_t num_mats, 01003 uint32_t num_rows, 01004 uint32_t num_cols 01005 ) 01006 { 01007 create_init_matblock_d(m_out, num_mats, num_rows, num_cols, 0); 01008 } 01009 01019 void create_zero_matblock_cf 01020 ( 01021 Matblock_cf** m_out, 01022 uint32_t num_mats, 01023 uint32_t num_rows, 01024 uint32_t num_cols 01025 ) 01026 { 01027 Complex_f z = {0}; 01028 create_init_matblock_cf(m_out, num_mats, num_rows, num_cols, z); 01029 } 01030 01040 void create_zero_matblock_cd 01041 ( 01042 Matblock_cd** m_out, 01043 uint32_t num_mats, 01044 uint32_t num_rows, 01045 uint32_t num_cols 01046 ) 01047 { 01048 Complex_d z = {0}; 01049 create_init_matblock_cd(m_out, num_mats, num_rows, num_cols, z); 01050 } 01051 01081 void create_random_matblock_u32 01082 ( 01083 Matblock_u32** m_out, 01084 uint32_t num_mats, 01085 uint32_t num_rows, 01086 uint32_t num_cols, 01087 uint32_t min, 01088 uint32_t max 01089 ) 01090 { 01091 uint32_t num_elts; 01092 uint32_t elt; 01093 uint32_t* m_elts; 01094 double r; 01095 01096 create_matblock_u32(m_out, num_mats, num_rows, num_cols); 01097 m_elts = **((*m_out)->elts); 01098 num_elts = num_mats*num_rows*num_cols; 01099 01100 for (elt = 0; elt < num_elts; elt++) 01101 { 01102 r = (double)rand() / (double)RAND_MAX; 01103 m_elts[ elt ] = min + (uint32_t)floor((max - min)*r + 0.5); 01104 } 01105 } 01106 01123 void create_random_matblock_i32 01124 ( 01125 Matblock_i32** m_out, 01126 uint32_t num_mats, 01127 uint32_t num_rows, 01128 uint32_t num_cols, 01129 int32_t min, 01130 int32_t max 01131 ) 01132 { 01133 uint32_t num_elts; 01134 uint32_t elt; 01135 int32_t* m_elts; 01136 double r; 01137 01138 create_matblock_i32(m_out, num_mats, num_rows, num_cols); 01139 m_elts = **((*m_out)->elts); 01140 num_elts = num_mats*num_rows*num_cols; 01141 01142 for (elt = 0; elt < num_elts; elt++) 01143 { 01144 r = (double)rand() / (double)RAND_MAX; 01145 m_elts[ elt ] = min + (int32_t)floor((max - min)*r + 0.5); 01146 } 01147 } 01148 01165 void create_random_matblock_i64 01166 ( 01167 Matblock_i64** m_out, 01168 uint32_t num_mats, 01169 uint32_t num_rows, 01170 uint32_t num_cols, 01171 int64_t min, 01172 int64_t max 01173 ) 01174 { 01175 uint32_t num_elts; 01176 uint32_t elt; 01177 int64_t* m_elts; 01178 double r; 01179 01180 create_matblock_i64(m_out, num_mats, num_rows, num_cols); 01181 m_elts = **((*m_out)->elts); 01182 num_elts = num_mats*num_rows*num_cols; 01183 01184 for (elt = 0; elt < num_elts; elt++) 01185 { 01186 r = (double)rand() / (double)RAND_MAX; 01187 m_elts[ elt ] = min + (int64_t)floor((max - min)*r + 0.5); 01188 } 01189 } 01190 01207 void create_random_matblock_f 01208 ( 01209 Matblock_f** m_out, 01210 uint32_t num_mats, 01211 uint32_t num_rows, 01212 uint32_t num_cols, 01213 float min, 01214 float max 01215 ) 01216 { 01217 uint32_t num_elts; 01218 uint32_t elt; 01219 float* m_elts; 01220 float r; 01221 01222 create_matblock_f(m_out, num_mats, num_rows, num_cols); 01223 m_elts = **((*m_out)->elts); 01224 num_elts = num_mats*num_rows*num_cols; 01225 01226 for (elt = 0; elt < num_elts; elt++) 01227 { 01228 r = (float)rand() / (float)RAND_MAX; 01229 m_elts[ elt ] = min + (max - min)*r; 01230 } 01231 } 01232 01249 void create_random_matblock_d 01250 ( 01251 Matblock_d** m_out, 01252 uint32_t num_mats, 01253 uint32_t num_rows, 01254 uint32_t num_cols, 01255 double min, 01256 double max 01257 ) 01258 { 01259 uint32_t num_elts; 01260 uint32_t elt; 01261 double* m_elts; 01262 double r; 01263 01264 create_matblock_d(m_out, num_mats, num_rows, num_cols); 01265 m_elts = **((*m_out)->elts); 01266 num_elts = num_mats*num_rows*num_cols; 01267 01268 for (elt = 0; elt < num_elts; elt++) 01269 { 01270 r = (double)rand() / (double)RAND_MAX; 01271 m_elts[ elt ] = min + (max - min)*r; 01272 } 01273 } 01274 01291 void create_random_matblock_cf 01292 ( 01293 Matblock_cf** m_out, 01294 uint32_t num_mats, 01295 uint32_t num_rows, 01296 uint32_t num_cols, 01297 Complex_f min, 01298 Complex_f max 01299 ) 01300 { 01301 uint32_t num_elts; 01302 uint32_t elt; 01303 Complex_f* m_elts; 01304 float r; 01305 01306 create_matblock_cf(m_out, num_mats, num_rows, num_cols); 01307 m_elts = **((*m_out)->elts); 01308 num_elts = num_mats*num_rows*num_cols; 01309 01310 for (elt = 0; elt < num_elts; elt++) 01311 { 01312 r = (float)rand() / (float)RAND_MAX; 01313 m_elts[ elt ].r = min.r + (max.r - min.r)*r; 01314 r = (float)rand() / (float)RAND_MAX; 01315 m_elts[ elt ].i = min.i + (max.i - min.i)*r; 01316 } 01317 } 01318 01335 void create_random_matblock_cd 01336 ( 01337 Matblock_cd** m_out, 01338 uint32_t num_mats, 01339 uint32_t num_rows, 01340 uint32_t num_cols, 01341 Complex_d min, 01342 Complex_d max 01343 ) 01344 { 01345 uint32_t num_elts; 01346 uint32_t elt; 01347 Complex_d* m_elts; 01348 double r; 01349 01350 create_matblock_cd(m_out, num_mats, num_rows, num_cols); 01351 m_elts = **((*m_out)->elts); 01352 num_elts = num_mats*num_rows*num_cols; 01353 01354 for (elt = 0; elt < num_elts; elt++) 01355 { 01356 r = (double)rand() / (double)RAND_MAX; 01357 m_elts[ elt ].r = min.r + (max.r - min.r)*r; 01358 r = (double)rand() / (double)RAND_MAX; 01359 m_elts[ elt ].i = min.i + (max.i - min.i)*r; 01360 } 01361 } 01362 01387 Error* copy_matblock_u32(Matblock_u32** m_out, const Matblock_u32* m_in) 01388 { 01389 uint32_t num_elts; 01390 uint32_t elt; 01391 uint32_t* m_out_elts; 01392 uint32_t* m_in_elts; 01393 01394 if (*m_out == m_in) 01395 { 01396 return JWSC_EARG("Copying a matblock into itself is not supported"); 01397 } 01398 01399 create_matblock_u32(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01400 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01401 01402 m_out_elts = **((*m_out)->elts); 01403 m_in_elts = **(m_in->elts); 01404 01405 for (elt = 0; elt < num_elts; elt++) 01406 { 01407 m_out_elts[ elt ] = m_in_elts[ elt ]; 01408 } 01409 01410 return NULL; 01411 } 01412 01425 Error* copy_matblock_i32(Matblock_i32** m_out, const Matblock_i32* m_in) 01426 { 01427 uint32_t num_elts; 01428 uint32_t elt; 01429 int32_t* m_out_elts; 01430 int32_t* m_in_elts; 01431 01432 if (*m_out == m_in) 01433 { 01434 return JWSC_EARG("Copying a matblock into itself is not supported"); 01435 } 01436 01437 create_matblock_i32(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01438 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01439 01440 m_out_elts = **((*m_out)->elts); 01441 m_in_elts = **(m_in->elts); 01442 01443 for (elt = 0; elt < num_elts; elt++) 01444 { 01445 m_out_elts[ elt ] = m_in_elts[ elt ]; 01446 } 01447 01448 return NULL; 01449 } 01450 01463 Error* copy_matblock_i64(Matblock_i64** m_out, const Matblock_i64* m_in) 01464 { 01465 uint32_t num_elts; 01466 uint32_t elt; 01467 int64_t* m_out_elts; 01468 int64_t* m_in_elts; 01469 01470 if (*m_out == m_in) 01471 { 01472 return JWSC_EARG("Copying a matblock into itself is not supported"); 01473 } 01474 01475 create_matblock_i64(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01476 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01477 01478 m_out_elts = **((*m_out)->elts); 01479 m_in_elts = **(m_in->elts); 01480 01481 for (elt = 0; elt < num_elts; elt++) 01482 { 01483 m_out_elts[ elt ] = m_in_elts[ elt ]; 01484 } 01485 01486 return NULL; 01487 } 01488 01501 Error* copy_matblock_f(Matblock_f** m_out, const Matblock_f* m_in) 01502 { 01503 uint32_t num_elts; 01504 float* m_out_elts; 01505 float* m_in_elts; 01506 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01507 #else 01508 uint32_t elt; 01509 #endif 01510 01511 if (*m_out == m_in) 01512 { 01513 return JWSC_EARG("Copying a matblock into itself is not supported"); 01514 } 01515 01516 create_matblock_f(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01517 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01518 01519 m_out_elts = **((*m_out)->elts); 01520 m_in_elts = **(m_in->elts); 01521 01522 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01523 blas_scopy(num_elts, m_in_elts, 1, m_out_elts, 1); 01524 #else 01525 for (elt = 0; elt < num_elts; elt++) 01526 { 01527 m_out_elts[ elt ] = m_in_elts[ elt ]; 01528 } 01529 #endif 01530 01531 return NULL; 01532 } 01533 01546 Error* copy_matblock_d(Matblock_d** m_out, const Matblock_d* m_in) 01547 { 01548 uint32_t num_elts; 01549 double* m_out_elts; 01550 double* m_in_elts; 01551 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01552 #else 01553 uint32_t elt; 01554 #endif 01555 01556 if (*m_out == m_in) 01557 { 01558 return JWSC_EARG("Copying a matblock into itself is not supported"); 01559 } 01560 01561 create_matblock_d(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01562 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01563 01564 m_out_elts = **((*m_out)->elts); 01565 m_in_elts = **(m_in->elts); 01566 01567 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01568 blas_dcopy(num_elts, m_in_elts, 1, m_out_elts, 1); 01569 #else 01570 for (elt = 0; elt < num_elts; elt++) 01571 { 01572 m_out_elts[ elt ] = m_in_elts[ elt ]; 01573 } 01574 #endif 01575 01576 return NULL; 01577 } 01578 01591 Error* copy_matblock_cf(Matblock_cf** m_out, const Matblock_cf* m_in) 01592 { 01593 uint32_t num_elts; 01594 Complex_f* m_out_elts; 01595 Complex_f* m_in_elts; 01596 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01597 #else 01598 uint32_t elt; 01599 #endif 01600 01601 if (*m_out == m_in) 01602 { 01603 return JWSC_EARG("Copying a matblock into itself is not supported"); 01604 } 01605 01606 create_matblock_cf(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01607 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01608 01609 m_out_elts = **((*m_out)->elts); 01610 m_in_elts = **(m_in->elts); 01611 01612 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01613 blas_ccopy(num_elts, m_in_elts, 1, m_out_elts, 1); 01614 #else 01615 for (elt = 0; elt < num_elts; elt++) 01616 { 01617 m_out_elts[ elt ] = m_in_elts[ elt ]; 01618 } 01619 #endif 01620 01621 return NULL; 01622 } 01623 01636 Error* copy_matblock_cd(Matblock_cd** m_out, const Matblock_cd* m_in) 01637 { 01638 uint32_t num_elts; 01639 Complex_d* m_out_elts; 01640 Complex_d* m_in_elts; 01641 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01642 #else 01643 uint32_t elt; 01644 #endif 01645 01646 if (*m_out == m_in) 01647 { 01648 return JWSC_EARG("Copying a matblock into itself is not supported"); 01649 } 01650 01651 create_matblock_cd(m_out, m_in->num_mats, m_in->num_rows, m_in->num_cols); 01652 num_elts = m_in->num_mats*m_in->num_rows*m_in->num_cols; 01653 01654 m_out_elts = **((*m_out)->elts); 01655 m_in_elts = **(m_in->elts); 01656 01657 #if defined JWSC_HAVE_BLAS || defined JWSC_HAVE_ACCELERATE 01658 blas_zcopy(num_elts, m_in_elts, 1, m_out_elts, 1); 01659 #else 01660 for (elt = 0; elt < num_elts; elt++) 01661 { 01662 m_out_elts[ elt ] = m_in_elts[ elt ]; 01663 } 01664 #endif 01665 01666 return NULL; 01667 } 01668 01704 Error* copy_matblock_block_u32 01705 ( 01706 Matblock_u32** m_out, 01707 const Matblock_u32* m_in, 01708 uint32_t mat_offset, 01709 uint32_t row_offset, 01710 uint32_t col_offset, 01711 uint32_t num_mats, 01712 uint32_t num_rows, 01713 uint32_t num_cols 01714 ) 01715 { 01716 uint32_t mat, row, col; 01717 Matblock_u32* m; 01718 01719 if (*m_out == m_in) 01720 { 01721 return JWSC_EARG("Copying a matblock into itself is not supported"); 01722 } 01723 01724 if (m_in->num_mats < (mat_offset+num_mats) || 01725 m_in->num_rows < (row_offset+num_rows) || 01726 m_in->num_cols < (col_offset+num_cols)) 01727 { 01728 free_matblock_u32(*m_out); m_out = NULL; 01729 return JWSC_EARG("Section to copy outside bounds of input matblock"); 01730 } 01731 01732 create_matblock_u32(m_out, num_mats, num_rows, num_cols); 01733 m = *m_out; 01734 01735 for (mat = 0; mat < num_mats; mat++) 01736 { 01737 for (row = 0; row < num_rows; row++) 01738 { 01739 for (col = 0; col < num_cols; col++) 01740 { 01741 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 01742 [ row+row_offset ] 01743 [ col+col_offset ]; 01744 } 01745 } 01746 } 01747 01748 return NULL; 01749 } 01750 01774 Error* copy_matblock_block_i32 01775 ( 01776 Matblock_i32** m_out, 01777 const Matblock_i32* m_in, 01778 uint32_t mat_offset, 01779 uint32_t row_offset, 01780 uint32_t col_offset, 01781 uint32_t num_mats, 01782 uint32_t num_rows, 01783 uint32_t num_cols 01784 ) 01785 { 01786 uint32_t mat, row, col; 01787 Matblock_i32* m; 01788 01789 if (*m_out == m_in) 01790 { 01791 return JWSC_EARG("Copying a matblock into itself is not supported"); 01792 } 01793 01794 if (m_in->num_mats < (mat_offset+num_mats) || 01795 m_in->num_rows < (row_offset+num_rows) || 01796 m_in->num_cols < (col_offset+num_cols)) 01797 { 01798 free_matblock_i32(*m_out); m_out = NULL; 01799 return JWSC_EARG("Section to copy outside bounds of input matblock"); 01800 } 01801 01802 create_matblock_i32(m_out, num_mats, num_rows, num_cols); 01803 m = *m_out; 01804 01805 for (mat = 0; mat < num_mats; mat++) 01806 { 01807 for (row = 0; row < num_rows; row++) 01808 { 01809 for (col = 0; col < num_cols; col++) 01810 { 01811 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 01812 [ row+row_offset ] 01813 [ col+col_offset ]; 01814 } 01815 } 01816 } 01817 01818 return NULL; 01819 } 01820 01844 Error* copy_matblock_block_i64 01845 ( 01846 Matblock_i64** m_out, 01847 const Matblock_i64* m_in, 01848 uint32_t mat_offset, 01849 uint32_t row_offset, 01850 uint32_t col_offset, 01851 uint32_t num_mats, 01852 uint32_t num_rows, 01853 uint32_t num_cols 01854 ) 01855 { 01856 uint32_t mat, row, col; 01857 Matblock_i64* m; 01858 01859 if (*m_out == m_in) 01860 { 01861 return JWSC_EARG("Copying a matblock into itself is not supported"); 01862 } 01863 01864 if (m_in->num_mats < (mat_offset+num_mats) || 01865 m_in->num_rows < (row_offset+num_rows) || 01866 m_in->num_cols < (col_offset+num_cols)) 01867 { 01868 free_matblock_i64(*m_out); m_out = NULL; 01869 return JWSC_EARG("Section to copy outside bounds of input matblock"); 01870 } 01871 01872 create_matblock_i64(m_out, num_mats, num_rows, num_cols); 01873 m = *m_out; 01874 01875 for (mat = 0; mat < num_mats; mat++) 01876 { 01877 for (row = 0; row < num_rows; row++) 01878 { 01879 for (col = 0; col < num_cols; col++) 01880 { 01881 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 01882 [ row+row_offset ] 01883 [ col+col_offset ]; 01884 } 01885 } 01886 } 01887 01888 return NULL; 01889 } 01890 01914 Error* copy_matblock_block_f 01915 ( 01916 Matblock_f** m_out, 01917 const Matblock_f* m_in, 01918 uint32_t mat_offset, 01919 uint32_t row_offset, 01920 uint32_t col_offset, 01921 uint32_t num_mats, 01922 uint32_t num_rows, 01923 uint32_t num_cols 01924 ) 01925 { 01926 uint32_t mat, row, col; 01927 Matblock_f* m; 01928 01929 if (*m_out == m_in) 01930 { 01931 return JWSC_EARG("Copying a matblock into itself is not supported"); 01932 } 01933 01934 if (m_in->num_mats < (mat_offset+num_mats) || 01935 m_in->num_rows < (row_offset+num_rows) || 01936 m_in->num_cols < (col_offset+num_cols)) 01937 { 01938 free_matblock_f(*m_out); m_out = NULL; 01939 return JWSC_EARG("Section to copy outside bounds of input matblock"); 01940 } 01941 01942 create_matblock_f(m_out, num_mats, num_rows, num_cols); 01943 m = *m_out; 01944 01945 for (mat = 0; mat < num_mats; mat++) 01946 { 01947 for (row = 0; row < num_rows; row++) 01948 { 01949 for (col = 0; col < num_cols; col++) 01950 { 01951 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 01952 [ row+row_offset ] 01953 [ col+col_offset ]; 01954 } 01955 } 01956 } 01957 01958 return NULL; 01959 } 01960 01984 Error* copy_matblock_block_d 01985 ( 01986 Matblock_d** m_out, 01987 const Matblock_d* m_in, 01988 uint32_t mat_offset, 01989 uint32_t row_offset, 01990 uint32_t col_offset, 01991 uint32_t num_mats, 01992 uint32_t num_rows, 01993 uint32_t num_cols 01994 ) 01995 { 01996 uint32_t mat, row, col; 01997 Matblock_d* m; 01998 01999 if (*m_out == m_in) 02000 { 02001 return JWSC_EARG("Copying a matblock into itself is not supported"); 02002 } 02003 02004 if (m_in->num_mats < (mat_offset+num_mats) || 02005 m_in->num_rows < (row_offset+num_rows) || 02006 m_in->num_cols < (col_offset+num_cols)) 02007 { 02008 free_matblock_d(*m_out); m_out = NULL; 02009 return JWSC_EARG("Section to copy outside bounds of input matblock"); 02010 } 02011 02012 create_matblock_d(m_out, num_mats, num_rows, num_cols); 02013 m = *m_out; 02014 02015 for (mat = 0; mat < num_mats; mat++) 02016 { 02017 for (row = 0; row < num_rows; row++) 02018 { 02019 for (col = 0; col < num_cols; col++) 02020 { 02021 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 02022 [ row+row_offset ] 02023 [ col+col_offset ]; 02024 } 02025 } 02026 } 02027 02028 return NULL; 02029 } 02030 02054 Error* copy_matblock_block_cf 02055 ( 02056 Matblock_cf** m_out, 02057 const Matblock_cf* m_in, 02058 uint32_t mat_offset, 02059 uint32_t row_offset, 02060 uint32_t col_offset, 02061 uint32_t num_mats, 02062 uint32_t num_rows, 02063 uint32_t num_cols 02064 ) 02065 { 02066 uint32_t mat, row, col; 02067 Matblock_cf* m; 02068 02069 if (*m_out == m_in) 02070 { 02071 return JWSC_EARG("Copying a matblock into itself is not supported"); 02072 } 02073 02074 if (m_in->num_mats < (mat_offset+num_mats) || 02075 m_in->num_rows < (row_offset+num_rows) || 02076 m_in->num_cols < (col_offset+num_cols)) 02077 { 02078 free_matblock_cf(*m_out); m_out = NULL; 02079 return JWSC_EARG("Section to copy outside bounds of input matblock"); 02080 } 02081 02082 create_matblock_cf(m_out, num_mats, num_rows, num_cols); 02083 m = *m_out; 02084 02085 for (mat = 0; mat < num_mats; mat++) 02086 { 02087 for (row = 0; row < num_rows; row++) 02088 { 02089 for (col = 0; col < num_cols; col++) 02090 { 02091 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 02092 [ row+row_offset ] 02093 [ col+col_offset ]; 02094 } 02095 } 02096 } 02097 02098 return NULL; 02099 } 02100 02124 Error* copy_matblock_block_cd 02125 ( 02126 Matblock_cd** m_out, 02127 const Matblock_cd* m_in, 02128 uint32_t mat_offset, 02129 uint32_t row_offset, 02130 uint32_t col_offset, 02131 uint32_t num_mats, 02132 uint32_t num_rows, 02133 uint32_t num_cols 02134 ) 02135 { 02136 uint32_t mat, row, col; 02137 Matblock_cd* m; 02138 02139 if (*m_out == m_in) 02140 { 02141 return JWSC_EARG("Copying a matblock into itself is not supported"); 02142 } 02143 02144 if (m_in->num_mats < (mat_offset+num_mats) || 02145 m_in->num_rows < (row_offset+num_rows) || 02146 m_in->num_cols < (col_offset+num_cols)) 02147 { 02148 free_matblock_cd(*m_out); m_out = NULL; 02149 return JWSC_EARG("Section to copy outside bounds of input matblock"); 02150 } 02151 02152 create_matblock_cd(m_out, num_mats, num_rows, num_cols); 02153 m = *m_out; 02154 02155 for (mat = 0; mat < num_mats; mat++) 02156 { 02157 for (row = 0; row < num_rows; row++) 02158 { 02159 for (col = 0; col < num_cols; col++) 02160 { 02161 m->elts[ mat ][ row ][ col ] = m_in->elts[ mat+mat_offset ] 02162 [ row+row_offset ] 02163 [ col+col_offset ]; 02164 } 02165 } 02166 } 02167 02168 return NULL; 02169 } 02170 02207 Error* copy_matblock_block_into_matblock_u32 02208 ( 02209 Matblock_u32* m_1, 02210 uint32_t mat_offset_1, 02211 uint32_t row_offset_1, 02212 uint32_t col_offset_1, 02213 const Matblock_u32* m_2, 02214 uint32_t mat_offset_2, 02215 uint32_t row_offset_2, 02216 uint32_t col_offset_2, 02217 uint32_t num_mats, 02218 uint32_t num_rows, 02219 uint32_t num_cols 02220 ) 02221 { 02222 uint32_t mat, row, col; 02223 02224 if (m_1 == m_2) 02225 { 02226 return JWSC_EARG("Copying a matblock into itself is not supported"); 02227 } 02228 02229 /* Test if the size of the block to copy is in the bounds of the input 02230 * matblock. */ 02231 if (m_2->num_mats < (mat_offset_2+num_mats) || 02232 m_2->num_rows < (row_offset_2+num_rows) || 02233 m_2->num_cols < (col_offset_2+num_cols) || 02234 m_1->num_mats < (mat_offset_1+num_mats) || 02235 m_1->num_rows < (row_offset_1+num_rows) || 02236 m_1->num_cols < (col_offset_1+num_cols)) 02237 { 02238 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02239 } 02240 02241 for (mat = 0; mat < num_mats; mat++) 02242 { 02243 for (row = 0; row < num_rows; row++) 02244 { 02245 for (col = 0; col < num_cols; col++) 02246 { 02247 m_1->elts[ mat+mat_offset_1 ] 02248 [ row+row_offset_1 ] 02249 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02250 [ row+row_offset_2 ] 02251 [ col+col_offset_2 ]; 02252 } 02253 } 02254 } 02255 02256 return NULL; 02257 } 02258 02283 Error* copy_matblock_block_into_matblock_i32 02284 ( 02285 Matblock_i32* m_1, 02286 uint32_t mat_offset_1, 02287 uint32_t row_offset_1, 02288 uint32_t col_offset_1, 02289 const Matblock_i32* m_2, 02290 uint32_t mat_offset_2, 02291 uint32_t row_offset_2, 02292 uint32_t col_offset_2, 02293 uint32_t num_mats, 02294 uint32_t num_rows, 02295 uint32_t num_cols 02296 ) 02297 { 02298 uint32_t mat, row, col; 02299 02300 if (m_1 == m_2) 02301 { 02302 return JWSC_EARG("Copying a matblock into itself is not supported"); 02303 } 02304 02305 /* Test if the size of the block to copy is in the bounds of the input 02306 * matblock. */ 02307 if (m_2->num_mats < (mat_offset_2+num_mats) || 02308 m_2->num_rows < (row_offset_2+num_rows) || 02309 m_2->num_cols < (col_offset_2+num_cols) || 02310 m_1->num_mats < (mat_offset_1+num_mats) || 02311 m_1->num_rows < (row_offset_1+num_rows) || 02312 m_1->num_cols < (col_offset_1+num_cols)) 02313 { 02314 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02315 } 02316 02317 for (mat = 0; mat < num_mats; mat++) 02318 { 02319 for (row = 0; row < num_rows; row++) 02320 { 02321 for (col = 0; col < num_cols; col++) 02322 { 02323 m_1->elts[ mat+mat_offset_1 ] 02324 [ row+row_offset_1 ] 02325 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02326 [ row+row_offset_2 ] 02327 [ col+col_offset_2 ]; 02328 } 02329 } 02330 } 02331 02332 return NULL; 02333 } 02334 02359 Error* copy_matblock_block_into_matblock_i64 02360 ( 02361 Matblock_i64* m_1, 02362 uint32_t mat_offset_1, 02363 uint32_t row_offset_1, 02364 uint32_t col_offset_1, 02365 const Matblock_i64* m_2, 02366 uint32_t mat_offset_2, 02367 uint32_t row_offset_2, 02368 uint32_t col_offset_2, 02369 uint32_t num_mats, 02370 uint32_t num_rows, 02371 uint32_t num_cols 02372 ) 02373 { 02374 uint32_t mat, row, col; 02375 02376 if (m_1 == m_2) 02377 { 02378 return JWSC_EARG("Copying a matblock into itself is not supported"); 02379 } 02380 02381 /* Test if the size of the block to copy is in the bounds of the input 02382 * matblock. */ 02383 if (m_2->num_mats < (mat_offset_2+num_mats) || 02384 m_2->num_rows < (row_offset_2+num_rows) || 02385 m_2->num_cols < (col_offset_2+num_cols) || 02386 m_1->num_mats < (mat_offset_1+num_mats) || 02387 m_1->num_rows < (row_offset_1+num_rows) || 02388 m_1->num_cols < (col_offset_1+num_cols)) 02389 { 02390 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02391 } 02392 02393 for (mat = 0; mat < num_mats; mat++) 02394 { 02395 for (row = 0; row < num_rows; row++) 02396 { 02397 for (col = 0; col < num_cols; col++) 02398 { 02399 m_1->elts[ mat+mat_offset_1 ] 02400 [ row+row_offset_1 ] 02401 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02402 [ row+row_offset_2 ] 02403 [ col+col_offset_2 ]; 02404 } 02405 } 02406 } 02407 02408 return NULL; 02409 } 02410 02435 Error* copy_matblock_block_into_matblock_f 02436 ( 02437 Matblock_f* m_1, 02438 uint32_t mat_offset_1, 02439 uint32_t row_offset_1, 02440 uint32_t col_offset_1, 02441 const Matblock_f* m_2, 02442 uint32_t mat_offset_2, 02443 uint32_t row_offset_2, 02444 uint32_t col_offset_2, 02445 uint32_t num_mats, 02446 uint32_t num_rows, 02447 uint32_t num_cols 02448 ) 02449 { 02450 uint32_t mat, row, col; 02451 02452 if (m_1 == m_2) 02453 { 02454 return JWSC_EARG("Copying a matblock into itself is not supported"); 02455 } 02456 02457 /* Test if the size of the block to copy is in the bounds of the input 02458 * matblock. */ 02459 if (m_2->num_mats < (mat_offset_2+num_mats) || 02460 m_2->num_rows < (row_offset_2+num_rows) || 02461 m_2->num_cols < (col_offset_2+num_cols) || 02462 m_1->num_mats < (mat_offset_1+num_mats) || 02463 m_1->num_rows < (row_offset_1+num_rows) || 02464 m_1->num_cols < (col_offset_1+num_cols)) 02465 { 02466 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02467 } 02468 02469 for (mat = 0; mat < num_mats; mat++) 02470 { 02471 for (row = 0; row < num_rows; row++) 02472 { 02473 for (col = 0; col < num_cols; col++) 02474 { 02475 m_1->elts[ mat+mat_offset_1 ] 02476 [ row+row_offset_1 ] 02477 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02478 [ row+row_offset_2 ] 02479 [ col+col_offset_2 ]; 02480 } 02481 } 02482 } 02483 02484 return NULL; 02485 } 02486 02511 Error* copy_matblock_block_into_matblock_d 02512 ( 02513 Matblock_d* m_1, 02514 uint32_t mat_offset_1, 02515 uint32_t row_offset_1, 02516 uint32_t col_offset_1, 02517 const Matblock_d* m_2, 02518 uint32_t mat_offset_2, 02519 uint32_t row_offset_2, 02520 uint32_t col_offset_2, 02521 uint32_t num_mats, 02522 uint32_t num_rows, 02523 uint32_t num_cols 02524 ) 02525 { 02526 uint32_t mat, row, col; 02527 02528 if (m_1 == m_2) 02529 { 02530 return JWSC_EARG("Copying a matblock into itself is not supported"); 02531 } 02532 02533 /* Test if the size of the block to copy is in the bounds of the input 02534 * matblock. */ 02535 if (m_2->num_mats < (mat_offset_2+num_mats) || 02536 m_2->num_rows < (row_offset_2+num_rows) || 02537 m_2->num_cols < (col_offset_2+num_cols) || 02538 m_1->num_mats < (mat_offset_1+num_mats) || 02539 m_1->num_rows < (row_offset_1+num_rows) || 02540 m_1->num_cols < (col_offset_1+num_cols)) 02541 { 02542 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02543 } 02544 02545 for (mat = 0; mat < num_mats; mat++) 02546 { 02547 for (row = 0; row < num_rows; row++) 02548 { 02549 for (col = 0; col < num_cols; col++) 02550 { 02551 m_1->elts[ mat+mat_offset_1 ] 02552 [ row+row_offset_1 ] 02553 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02554 [ row+row_offset_2 ] 02555 [ col+col_offset_2 ]; 02556 } 02557 } 02558 } 02559 02560 return NULL; 02561 } 02562 02587 Error* copy_matblock_block_into_matblock_cf 02588 ( 02589 Matblock_cf* m_1, 02590 uint32_t mat_offset_1, 02591 uint32_t row_offset_1, 02592 uint32_t col_offset_1, 02593 const Matblock_cf* m_2, 02594 uint32_t mat_offset_2, 02595 uint32_t row_offset_2, 02596 uint32_t col_offset_2, 02597 uint32_t num_mats, 02598 uint32_t num_rows, 02599 uint32_t num_cols 02600 ) 02601 { 02602 uint32_t mat, row, col; 02603 02604 if (m_1 == m_2) 02605 { 02606 return JWSC_EARG("Copying a matblock into itself is not supported"); 02607 } 02608 02609 /* Test if the size of the block to copy is in the bounds of the input 02610 * matblock. */ 02611 if (m_2->num_mats < (mat_offset_2+num_mats) || 02612 m_2->num_rows < (row_offset_2+num_rows) || 02613 m_2->num_cols < (col_offset_2+num_cols) || 02614 m_1->num_mats < (mat_offset_1+num_mats) || 02615 m_1->num_rows < (row_offset_1+num_rows) || 02616 m_1->num_cols < (col_offset_1+num_cols)) 02617 { 02618 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02619 } 02620 02621 for (mat = 0; mat < num_mats; mat++) 02622 { 02623 for (row = 0; row < num_rows; row++) 02624 { 02625 for (col = 0; col < num_cols; col++) 02626 { 02627 m_1->elts[ mat+mat_offset_1 ] 02628 [ row+row_offset_1 ] 02629 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02630 [ row+row_offset_2 ] 02631 [ col+col_offset_2 ]; 02632 } 02633 } 02634 } 02635 02636 return NULL; 02637 } 02638 02663 Error* copy_matblock_block_into_matblock_cd 02664 ( 02665 Matblock_cd* m_1, 02666 uint32_t mat_offset_1, 02667 uint32_t row_offset_1, 02668 uint32_t col_offset_1, 02669 const Matblock_cd* m_2, 02670 uint32_t mat_offset_2, 02671 uint32_t row_offset_2, 02672 uint32_t col_offset_2, 02673 uint32_t num_mats, 02674 uint32_t num_rows, 02675 uint32_t num_cols 02676 ) 02677 { 02678 uint32_t mat, row, col; 02679 02680 if (m_1 == m_2) 02681 { 02682 return JWSC_EARG("Copying a matblock into itself is not supported"); 02683 } 02684 02685 /* Test if the size of the block to copy is in the bounds of the input 02686 * matblock. */ 02687 if (m_2->num_mats < (mat_offset_2+num_mats) || 02688 m_2->num_rows < (row_offset_2+num_rows) || 02689 m_2->num_cols < (col_offset_2+num_cols) || 02690 m_1->num_mats < (mat_offset_1+num_mats) || 02691 m_1->num_rows < (row_offset_1+num_rows) || 02692 m_1->num_cols < (col_offset_1+num_cols)) 02693 { 02694 return JWSC_EARG("Block to copy outside bounds of input matblock"); 02695 } 02696 02697 for (mat = 0; mat < num_mats; mat++) 02698 { 02699 for (row = 0; row < num_rows; row++) 02700 { 02701 for (col = 0; col < num_cols; col++) 02702 { 02703 m_1->elts[ mat+mat_offset_1 ] 02704 [ row+row_offset_1 ] 02705 [ col+col_offset_1 ] = m_2->elts[ mat+mat_offset_2 ] 02706 [ row+row_offset_2 ] 02707 [ col+col_offset_2 ]; 02708 } 02709 } 02710 } 02711 02712 return NULL; 02713 } 02714 02743 Error* copy_matrix_into_matblock_u32 02744 ( 02745 Matblock_u32** mb_out, 02746 const Matblock_u32* mb_in, 02747 const Matrix_u32* m, 02748 Matblock_matrix orient, 02749 uint32_t index 02750 ) 02751 { 02752 uint32_t num_mats, num_rows, num_cols; 02753 uint32_t mat, row, col; 02754 uint32_t num_indices; 02755 02756 Matblock_u32* mb; 02757 02758 num_mats = mb_in->num_mats; 02759 num_rows = mb_in->num_rows; 02760 num_cols = mb_in->num_cols; 02761 02762 switch (orient) 02763 { 02764 case MATBLOCK_MAT_MATRIX: 02765 num_indices = mb_in->num_mats; 02766 if (num_rows != m->num_rows || num_cols != m->num_cols) 02767 { 02768 return JWSC_EARG("Incompatible matrix and matblock size"); 02769 } 02770 break; 02771 case MATBLOCK_ROW_MATRIX: 02772 num_indices = mb_in->num_rows; 02773 if (num_mats != m->num_rows || num_cols != m->num_cols) 02774 { 02775 return JWSC_EARG("Incompatible matrix and matblock size"); 02776 } 02777 break; 02778 default: 02779 num_indices = mb_in->num_cols; 02780 if (num_mats != m->num_rows || num_rows != m->num_cols) 02781 { 02782 return JWSC_EARG("Incompatible matrix and matblock size"); 02783 } 02784 } 02785 if (index >= num_indices) 02786 { 02787 return JWSC_EARG("Invalid index to copy into matblock"); 02788 } 02789 02790 if (*mb_out != mb_in) 02791 { 02792 copy_matblock_u32(mb_out, mb_in); 02793 } 02794 mb = *mb_out; 02795 02796 switch (orient) 02797 { 02798 case MATBLOCK_MAT_MATRIX: 02799 for (row = 0; row < num_rows; row++) 02800 { 02801 for (col = 0; col < num_cols; col++) 02802 { 02803 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 02804 } 02805 } 02806 break; 02807 case MATBLOCK_ROW_MATRIX: 02808 for (mat = 0; mat < num_mats; mat++) 02809 { 02810 for (col = 0; col < num_cols; col++) 02811 { 02812 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 02813 } 02814 } 02815 break; 02816 default: 02817 for (mat = 0; mat < num_mats; mat++) 02818 { 02819 for (row = 0; row < num_rows; row++) 02820 { 02821 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 02822 } 02823 } 02824 } 02825 02826 return NULL; 02827 } 02828 02845 Error* copy_matrix_into_matblock_i32 02846 ( 02847 Matblock_i32** mb_out, 02848 const Matblock_i32* mb_in, 02849 const Matrix_i32* m, 02850 Matblock_matrix orient, 02851 uint32_t index 02852 ) 02853 { 02854 uint32_t num_mats, num_rows, num_cols; 02855 uint32_t mat, row, col; 02856 uint32_t num_indices; 02857 02858 Matblock_i32* mb; 02859 02860 num_mats = mb_in->num_mats; 02861 num_rows = mb_in->num_rows; 02862 num_cols = mb_in->num_cols; 02863 02864 switch (orient) 02865 { 02866 case MATBLOCK_MAT_MATRIX: 02867 num_indices = mb_in->num_mats; 02868 if (num_rows != m->num_rows || num_cols != m->num_cols) 02869 { 02870 return JWSC_EARG("Incompatible matrix and matblock size"); 02871 } 02872 break; 02873 case MATBLOCK_ROW_MATRIX: 02874 num_indices = mb_in->num_rows; 02875 if (num_mats != m->num_rows || num_cols != m->num_cols) 02876 { 02877 return JWSC_EARG("Incompatible matrix and matblock size"); 02878 } 02879 break; 02880 default: 02881 num_indices = mb_in->num_cols; 02882 if (num_mats != m->num_rows || num_rows != m->num_cols) 02883 { 02884 return JWSC_EARG("Incompatible matrix and matblock size"); 02885 } 02886 } 02887 if (index >= num_indices) 02888 { 02889 return JWSC_EARG("Invalid index to copy into matblock"); 02890 } 02891 02892 if (*mb_out != mb_in) 02893 { 02894 copy_matblock_i32(mb_out, mb_in); 02895 } 02896 mb = *mb_out; 02897 02898 switch (orient) 02899 { 02900 case MATBLOCK_MAT_MATRIX: 02901 for (row = 0; row < num_rows; row++) 02902 { 02903 for (col = 0; col < num_cols; col++) 02904 { 02905 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 02906 } 02907 } 02908 break; 02909 case MATBLOCK_ROW_MATRIX: 02910 for (mat = 0; mat < num_mats; mat++) 02911 { 02912 for (col = 0; col < num_cols; col++) 02913 { 02914 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 02915 } 02916 } 02917 break; 02918 default: 02919 for (mat = 0; mat < num_mats; mat++) 02920 { 02921 for (row = 0; row < num_rows; row++) 02922 { 02923 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 02924 } 02925 } 02926 } 02927 02928 return NULL; 02929 } 02930 02947 Error* copy_matrix_into_matblock_i64 02948 ( 02949 Matblock_i64** mb_out, 02950 const Matblock_i64* mb_in, 02951 const Matrix_i64* m, 02952 Matblock_matrix orient, 02953 uint32_t index 02954 ) 02955 { 02956 uint32_t num_mats, num_rows, num_cols; 02957 uint32_t mat, row, col; 02958 uint32_t num_indices; 02959 02960 Matblock_i64* mb; 02961 02962 num_mats = mb_in->num_mats; 02963 num_rows = mb_in->num_rows; 02964 num_cols = mb_in->num_cols; 02965 02966 switch (orient) 02967 { 02968 case MATBLOCK_MAT_MATRIX: 02969 num_indices = mb_in->num_mats; 02970 if (num_rows != m->num_rows || num_cols != m->num_cols) 02971 { 02972 return JWSC_EARG("Incompatible matrix and matblock size"); 02973 } 02974 break; 02975 case MATBLOCK_ROW_MATRIX: 02976 num_indices = mb_in->num_rows; 02977 if (num_mats != m->num_rows || num_cols != m->num_cols) 02978 { 02979 return JWSC_EARG("Incompatible matrix and matblock size"); 02980 } 02981 break; 02982 default: 02983 num_indices = mb_in->num_cols; 02984 if (num_mats != m->num_rows || num_rows != m->num_cols) 02985 { 02986 return JWSC_EARG("Incompatible matrix and matblock size"); 02987 } 02988 } 02989 if (index >= num_indices) 02990 { 02991 return JWSC_EARG("Invalid index to copy into matblock"); 02992 } 02993 02994 if (*mb_out != mb_in) 02995 { 02996 copy_matblock_i64(mb_out, mb_in); 02997 } 02998 mb = *mb_out; 02999 03000 switch (orient) 03001 { 03002 case MATBLOCK_MAT_MATRIX: 03003 for (row = 0; row < num_rows; row++) 03004 { 03005 for (col = 0; col < num_cols; col++) 03006 { 03007 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 03008 } 03009 } 03010 break; 03011 case MATBLOCK_ROW_MATRIX: 03012 for (mat = 0; mat < num_mats; mat++) 03013 { 03014 for (col = 0; col < num_cols; col++) 03015 { 03016 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 03017 } 03018 } 03019 break; 03020 default: 03021 for (mat = 0; mat < num_mats; mat++) 03022 { 03023 for (row = 0; row < num_rows; row++) 03024 { 03025 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 03026 } 03027 } 03028 } 03029 03030 return NULL; 03031 } 03032 03049 Error* copy_matrix_into_matblock_f 03050 ( 03051 Matblock_f** mb_out, 03052 const Matblock_f* mb_in, 03053 const Matrix_f* m, 03054 Matblock_matrix orient, 03055 uint32_t index 03056 ) 03057 { 03058 uint32_t num_mats, num_rows, num_cols; 03059 uint32_t mat, row, col; 03060 uint32_t num_indices; 03061 03062 Matblock_f* mb; 03063 03064 num_mats = mb_in->num_mats; 03065 num_rows = mb_in->num_rows; 03066 num_cols = mb_in->num_cols; 03067 03068 switch (orient) 03069 { 03070 case MATBLOCK_MAT_MATRIX: 03071 num_indices = mb_in->num_mats; 03072 if (num_rows != m->num_rows || num_cols != m->num_cols) 03073 { 03074 return JWSC_EARG("Incompatible matrix and matblock size"); 03075 } 03076 break; 03077 case MATBLOCK_ROW_MATRIX: 03078 num_indices = mb_in->num_rows; 03079 if (num_mats != m->num_rows || num_cols != m->num_cols) 03080 { 03081 return JWSC_EARG("Incompatible matrix and matblock size"); 03082 } 03083 break; 03084 default: 03085 num_indices = mb_in->num_cols; 03086 if (num_mats != m->num_rows || num_rows != m->num_cols) 03087 { 03088 return JWSC_EARG("Incompatible matrix and matblock size"); 03089 } 03090 } 03091 if (index >= num_indices) 03092 { 03093 return JWSC_EARG("Invalid index to copy into matblock"); 03094 } 03095 03096 if (*mb_out != mb_in) 03097 { 03098 copy_matblock_f(mb_out, mb_in); 03099 } 03100 mb = *mb_out; 03101 03102 switch (orient) 03103 { 03104 case MATBLOCK_MAT_MATRIX: 03105 for (row = 0; row < num_rows; row++) 03106 { 03107 for (col = 0; col < num_cols; col++) 03108 { 03109 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 03110 } 03111 } 03112 break; 03113 case MATBLOCK_ROW_MATRIX: 03114 for (mat = 0; mat < num_mats; mat++) 03115 { 03116 for (col = 0; col < num_cols; col++) 03117 { 03118 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 03119 } 03120 } 03121 break; 03122 default: 03123 for (mat = 0; mat < num_mats; mat++) 03124 { 03125 for (row = 0; row < num_rows; row++) 03126 { 03127 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 03128 } 03129 } 03130 } 03131 03132 return NULL; 03133 } 03134 03151 Error* copy_matrix_into_matblock_d 03152 ( 03153 Matblock_d** mb_out, 03154 const Matblock_d* mb_in, 03155 const Matrix_d* m, 03156 Matblock_matrix orient, 03157 uint32_t index 03158 ) 03159 { 03160 uint32_t num_mats, num_rows, num_cols; 03161 uint32_t mat, row, col; 03162 uint32_t num_indices; 03163 03164 Matblock_d* mb; 03165 03166 num_mats = mb_in->num_mats; 03167 num_rows = mb_in->num_rows; 03168 num_cols = mb_in->num_cols; 03169 03170 switch (orient) 03171 { 03172 case MATBLOCK_MAT_MATRIX: 03173 num_indices = mb_in->num_mats; 03174 if (num_rows != m->num_rows || num_cols != m->num_cols) 03175 { 03176 return JWSC_EARG("Incompatible matrix and matblock size"); 03177 } 03178 break; 03179 case MATBLOCK_ROW_MATRIX: 03180 num_indices = mb_in->num_rows; 03181 if (num_mats != m->num_rows || num_cols != m->num_cols) 03182 { 03183 return JWSC_EARG("Incompatible matrix and matblock size"); 03184 } 03185 break; 03186 default: 03187 num_indices = mb_in->num_cols; 03188 if (num_mats != m->num_rows || num_rows != m->num_cols) 03189 { 03190 return JWSC_EARG("Incompatible matrix and matblock size"); 03191 } 03192 } 03193 if (index >= num_indices) 03194 { 03195 return JWSC_EARG("Invalid index to copy into matblock"); 03196 } 03197 03198 if (*mb_out != mb_in) 03199 { 03200 copy_matblock_d(mb_out, mb_in); 03201 } 03202 mb = *mb_out; 03203 03204 switch (orient) 03205 { 03206 case MATBLOCK_MAT_MATRIX: 03207 for (row = 0; row < num_rows; row++) 03208 { 03209 for (col = 0; col < num_cols; col++) 03210 { 03211 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 03212 } 03213 } 03214 break; 03215 case MATBLOCK_ROW_MATRIX: 03216 for (mat = 0; mat < num_mats; mat++) 03217 { 03218 for (col = 0; col < num_cols; col++) 03219 { 03220 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 03221 } 03222 } 03223 break; 03224 default: 03225 for (mat = 0; mat < num_mats; mat++) 03226 { 03227 for (row = 0; row < num_rows; row++) 03228 { 03229 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 03230 } 03231 } 03232 } 03233 03234 return NULL; 03235 } 03236 03253 Error* copy_matrix_into_matblock_cf 03254 ( 03255 Matblock_cf** mb_out, 03256 const Matblock_cf* mb_in, 03257 const Matrix_cf* m, 03258 Matblock_matrix orient, 03259 uint32_t index 03260 ) 03261 { 03262 uint32_t num_mats, num_rows, num_cols; 03263 uint32_t mat, row, col; 03264 uint32_t num_indices; 03265 03266 Matblock_cf* mb; 03267 03268 num_mats = mb_in->num_mats; 03269 num_rows = mb_in->num_rows; 03270 num_cols = mb_in->num_cols; 03271 03272 switch (orient) 03273 { 03274 case MATBLOCK_MAT_MATRIX: 03275 num_indices = mb_in->num_mats; 03276 if (num_rows != m->num_rows || num_cols != m->num_cols) 03277 { 03278 return JWSC_EARG("Incompatible matrix and matblock size"); 03279 } 03280 break; 03281 case MATBLOCK_ROW_MATRIX: 03282 num_indices = mb_in->num_rows; 03283 if (num_mats != m->num_rows || num_cols != m->num_cols) 03284 { 03285 return JWSC_EARG("Incompatible matrix and matblock size"); 03286 } 03287 break; 03288 default: 03289 num_indices = mb_in->num_cols; 03290 if (num_mats != m->num_rows || num_rows != m->num_cols) 03291 { 03292 return JWSC_EARG("Incompatible matrix and matblock size"); 03293 } 03294 } 03295 if (index >= num_indices) 03296 { 03297 return JWSC_EARG("Invalid index to copy into matblock"); 03298 } 03299 03300 if (*mb_out != mb_in) 03301 { 03302 copy_matblock_cf(mb_out, mb_in); 03303 } 03304 mb = *mb_out; 03305 03306 switch (orient) 03307 { 03308 case MATBLOCK_MAT_MATRIX: 03309 for (row = 0; row < num_rows; row++) 03310 { 03311 for (col = 0; col < num_cols; col++) 03312 { 03313 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 03314 } 03315 } 03316 break; 03317 case MATBLOCK_ROW_MATRIX: 03318 for (mat = 0; mat < num_mats; mat++) 03319 { 03320 for (col = 0; col < num_cols; col++) 03321 { 03322 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 03323 } 03324 } 03325 break; 03326 default: 03327 for (mat = 0; mat < num_mats; mat++) 03328 { 03329 for (row = 0; row < num_rows; row++) 03330 { 03331 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 03332 } 03333 } 03334 } 03335 03336 return NULL; 03337 } 03338 03355 Error* copy_matrix_into_matblock_cd 03356 ( 03357 Matblock_cd** mb_out, 03358 const Matblock_cd* mb_in, 03359 const Matrix_cd* m, 03360 Matblock_matrix orient, 03361 uint32_t index 03362 ) 03363 { 03364 uint32_t num_mats, num_rows, num_cols; 03365 uint32_t mat, row, col; 03366 uint32_t num_indices; 03367 03368 Matblock_cd* mb; 03369 03370 num_mats = mb_in->num_mats; 03371 num_rows = mb_in->num_rows; 03372 num_cols = mb_in->num_cols; 03373 03374 switch (orient) 03375 { 03376 case MATBLOCK_MAT_MATRIX: 03377 num_indices = mb_in->num_mats; 03378 if (num_rows != m->num_rows || num_cols != m->num_cols) 03379 { 03380 return JWSC_EARG("Incompatible matrix and matblock size"); 03381 } 03382 break; 03383 case MATBLOCK_ROW_MATRIX: 03384 num_indices = mb_in->num_rows; 03385 if (num_mats != m->num_rows || num_cols != m->num_cols) 03386 { 03387 return JWSC_EARG("Incompatible matrix and matblock size"); 03388 } 03389 break; 03390 default: 03391 num_indices = mb_in->num_cols; 03392 if (num_mats != m->num_rows || num_rows != m->num_cols) 03393 { 03394 return JWSC_EARG("Incompatible matrix and matblock size"); 03395 } 03396 } 03397 if (index >= num_indices) 03398 { 03399 return JWSC_EARG("Invalid index to copy into matblock"); 03400 } 03401 03402 if (*mb_out != mb_in) 03403 { 03404 copy_matblock_cd(mb_out, mb_in); 03405 } 03406 mb = *mb_out; 03407 03408 switch (orient) 03409 { 03410 case MATBLOCK_MAT_MATRIX: 03411 for (row = 0; row < num_rows; row++) 03412 { 03413 for (col = 0; col < num_cols; col++) 03414 { 03415 mb->elts[ index ][ row ][ col ] = m->elts[ row ][ col ]; 03416 } 03417 } 03418 break; 03419 case MATBLOCK_ROW_MATRIX: 03420 for (mat = 0; mat < num_mats; mat++) 03421 { 03422 for (col = 0; col < num_cols; col++) 03423 { 03424 mb->elts[ mat ][ index ][ col ] = m->elts[ mat ][ col ]; 03425 } 03426 } 03427 break; 03428 default: 03429 for (mat = 0; mat < num_mats; mat++) 03430 { 03431 for (row = 0; row < num_rows; row++) 03432 { 03433 mb->elts[ mat ][ row ][ index ] = m->elts[ mat ][ row ]; 03434 } 03435 } 03436 } 03437 03438 return NULL; 03439 } 03440 03466 Error* copy_matrix_from_matblock_u32 03467 ( 03468 Matrix_u32** m_out, 03469 const Matblock_u32* mb, 03470 Matblock_matrix orient, 03471 uint32_t index 03472 ) 03473 { 03474 uint32_t num_mats, num_rows, num_cols; 03475 uint32_t mat, row, col; 03476 uint32_t num_indices; 03477 03478 Matrix_u32* m = NULL; 03479 03480 num_mats = mb->num_mats; 03481 num_rows = mb->num_rows; 03482 num_cols = mb->num_cols; 03483 03484 switch (orient) 03485 { 03486 case MATBLOCK_MAT_MATRIX: 03487 num_indices = mb->num_mats; 03488 break; 03489 case MATBLOCK_ROW_MATRIX: 03490 num_indices = mb->num_rows; 03491 break; 03492 default: 03493 num_indices = mb->num_cols; 03494 } 03495 if (index >= num_indices) 03496 { 03497 return JWSC_EARG("Invalid index to copy from matblock"); 03498 } 03499 03500 switch (orient) 03501 { 03502 case MATBLOCK_MAT_MATRIX: 03503 create_matrix_u32(m_out, num_rows, num_cols); 03504 m = *m_out; 03505 for (row = 0; row < num_rows; row++) 03506 { 03507 for (col = 0; col < num_cols; col++) 03508 { 03509 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03510 } 03511 } 03512 break; 03513 case MATBLOCK_ROW_MATRIX: 03514 create_matrix_u32(m_out, num_mats, num_cols); 03515 m = *m_out; 03516 for (mat = 0; mat < num_mats; mat++) 03517 { 03518 for (col = 0; col < num_cols; col++) 03519 { 03520 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03521 } 03522 } 03523 break; 03524 default: 03525 create_matrix_u32(m_out, num_mats, num_rows); 03526 m = *m_out; 03527 for (mat = 0; mat < num_mats; mat++) 03528 { 03529 for (row = 0; row < num_rows; row++) 03530 { 03531 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03532 } 03533 } 03534 } 03535 03536 return NULL; 03537 } 03538 03552 Error* copy_matrix_from_matblock_i32 03553 ( 03554 Matrix_i32** m_out, 03555 const Matblock_i32* mb, 03556 Matblock_matrix orient, 03557 uint32_t index 03558 ) 03559 { 03560 uint32_t num_mats, num_rows, num_cols; 03561 uint32_t mat, row, col; 03562 uint32_t num_indices; 03563 03564 Matrix_i32* m = NULL; 03565 03566 num_mats = mb->num_mats; 03567 num_rows = mb->num_rows; 03568 num_cols = mb->num_cols; 03569 03570 switch (orient) 03571 { 03572 case MATBLOCK_MAT_MATRIX: 03573 num_indices = mb->num_mats; 03574 break; 03575 case MATBLOCK_ROW_MATRIX: 03576 num_indices = mb->num_rows; 03577 break; 03578 default: 03579 num_indices = mb->num_cols; 03580 } 03581 if (index >= num_indices) 03582 { 03583 return JWSC_EARG("Invalid index to copy from matblock"); 03584 } 03585 03586 switch (orient) 03587 { 03588 case MATBLOCK_MAT_MATRIX: 03589 create_matrix_i32(m_out, num_rows, num_cols); 03590 m = *m_out; 03591 for (row = 0; row < num_rows; row++) 03592 { 03593 for (col = 0; col < num_cols; col++) 03594 { 03595 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03596 } 03597 } 03598 break; 03599 case MATBLOCK_ROW_MATRIX: 03600 create_matrix_i32(m_out, num_mats, num_cols); 03601 m = *m_out; 03602 for (mat = 0; mat < num_mats; mat++) 03603 { 03604 for (col = 0; col < num_cols; col++) 03605 { 03606 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03607 } 03608 } 03609 break; 03610 default: 03611 create_matrix_i32(m_out, num_mats, num_rows); 03612 m = *m_out; 03613 for (mat = 0; mat < num_mats; mat++) 03614 { 03615 for (row = 0; row < num_rows; row++) 03616 { 03617 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03618 } 03619 } 03620 } 03621 03622 return NULL; 03623 } 03624 03638 Error* copy_matrix_from_matblock_i64 03639 ( 03640 Matrix_i64** m_out, 03641 const Matblock_i64* mb, 03642 Matblock_matrix orient, 03643 uint32_t index 03644 ) 03645 { 03646 uint32_t num_mats, num_rows, num_cols; 03647 uint32_t mat, row, col; 03648 uint32_t num_indices; 03649 03650 Matrix_i64* m = NULL; 03651 03652 num_mats = mb->num_mats; 03653 num_rows = mb->num_rows; 03654 num_cols = mb->num_cols; 03655 03656 switch (orient) 03657 { 03658 case MATBLOCK_MAT_MATRIX: 03659 num_indices = mb->num_mats; 03660 break; 03661 case MATBLOCK_ROW_MATRIX: 03662 num_indices = mb->num_rows; 03663 break; 03664 default: 03665 num_indices = mb->num_cols; 03666 } 03667 if (index >= num_indices) 03668 { 03669 return JWSC_EARG("Invalid index to copy from matblock"); 03670 } 03671 03672 switch (orient) 03673 { 03674 case MATBLOCK_MAT_MATRIX: 03675 create_matrix_i64(m_out, num_rows, num_cols); 03676 m = *m_out; 03677 for (row = 0; row < num_rows; row++) 03678 { 03679 for (col = 0; col < num_cols; col++) 03680 { 03681 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03682 } 03683 } 03684 break; 03685 case MATBLOCK_ROW_MATRIX: 03686 create_matrix_i64(m_out, num_mats, num_cols); 03687 m = *m_out; 03688 for (mat = 0; mat < num_mats; mat++) 03689 { 03690 for (col = 0; col < num_cols; col++) 03691 { 03692 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03693 } 03694 } 03695 break; 03696 default: 03697 create_matrix_i64(m_out, num_mats, num_rows); 03698 m = *m_out; 03699 for (mat = 0; mat < num_mats; mat++) 03700 { 03701 for (row = 0; row < num_rows; row++) 03702 { 03703 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03704 } 03705 } 03706 } 03707 03708 return NULL; 03709 } 03710 03724 Error* copy_matrix_from_matblock_f 03725 ( 03726 Matrix_f** m_out, 03727 const Matblock_f* mb, 03728 Matblock_matrix orient, 03729 uint32_t index 03730 ) 03731 { 03732 uint32_t num_mats, num_rows, num_cols; 03733 uint32_t mat, row, col; 03734 uint32_t num_indices; 03735 03736 Matrix_f* m = NULL; 03737 03738 num_mats = mb->num_mats; 03739 num_rows = mb->num_rows; 03740 num_cols = mb->num_cols; 03741 03742 switch (orient) 03743 { 03744 case MATBLOCK_MAT_MATRIX: 03745 num_indices = mb->num_mats; 03746 break; 03747 case MATBLOCK_ROW_MATRIX: 03748 num_indices = mb->num_rows; 03749 break; 03750 default: 03751 num_indices = mb->num_cols; 03752 } 03753 if (index >= num_indices) 03754 { 03755 return JWSC_EARG("Invalid index to copy from matblock"); 03756 } 03757 03758 switch (orient) 03759 { 03760 case MATBLOCK_MAT_MATRIX: 03761 create_matrix_f(m_out, num_rows, num_cols); 03762 m = *m_out; 03763 for (row = 0; row < num_rows; row++) 03764 { 03765 for (col = 0; col < num_cols; col++) 03766 { 03767 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03768 } 03769 } 03770 break; 03771 case MATBLOCK_ROW_MATRIX: 03772 create_matrix_f(m_out, num_mats, num_cols); 03773 m = *m_out; 03774 for (mat = 0; mat < num_mats; mat++) 03775 { 03776 for (col = 0; col < num_cols; col++) 03777 { 03778 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03779 } 03780 } 03781 break; 03782 default: 03783 create_matrix_f(m_out, num_mats, num_rows); 03784 m = *m_out; 03785 for (mat = 0; mat < num_mats; mat++) 03786 { 03787 for (row = 0; row < num_rows; row++) 03788 { 03789 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03790 } 03791 } 03792 } 03793 03794 return NULL; 03795 } 03796 03810 Error* copy_matrix_from_matblock_d 03811 ( 03812 Matrix_d** m_out, 03813 const Matblock_d* mb, 03814 Matblock_matrix orient, 03815 uint32_t index 03816 ) 03817 { 03818 uint32_t num_mats, num_rows, num_cols; 03819 uint32_t mat, row, col; 03820 uint32_t num_indices; 03821 03822 Matrix_d* m = NULL; 03823 03824 num_mats = mb->num_mats; 03825 num_rows = mb->num_rows; 03826 num_cols = mb->num_cols; 03827 03828 switch (orient) 03829 { 03830 case MATBLOCK_MAT_MATRIX: 03831 num_indices = mb->num_mats; 03832 break; 03833 case MATBLOCK_ROW_MATRIX: 03834 num_indices = mb->num_rows; 03835 break; 03836 default: 03837 num_indices = mb->num_cols; 03838 } 03839 if (index >= num_indices) 03840 { 03841 return JWSC_EARG("Invalid index to copy from matblock"); 03842 } 03843 03844 switch (orient) 03845 { 03846 case MATBLOCK_MAT_MATRIX: 03847 create_matrix_d(m_out, num_rows, num_cols); 03848 m = *m_out; 03849 for (row = 0; row < num_rows; row++) 03850 { 03851 for (col = 0; col < num_cols; col++) 03852 { 03853 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03854 } 03855 } 03856 break; 03857 case MATBLOCK_ROW_MATRIX: 03858 create_matrix_d(m_out, num_mats, num_cols); 03859 m = *m_out; 03860 for (mat = 0; mat < num_mats; mat++) 03861 { 03862 for (col = 0; col < num_cols; col++) 03863 { 03864 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03865 } 03866 } 03867 break; 03868 default: 03869 create_matrix_d(m_out, num_mats, num_rows); 03870 m = *m_out; 03871 for (mat = 0; mat < num_mats; mat++) 03872 { 03873 for (row = 0; row < num_rows; row++) 03874 { 03875 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03876 } 03877 } 03878 } 03879 03880 return NULL; 03881 } 03882 03896 Error* copy_matrix_from_matblock_cf 03897 ( 03898 Matrix_cf** m_out, 03899 const Matblock_cf* mb, 03900 Matblock_matrix orient, 03901 uint32_t index 03902 ) 03903 { 03904 uint32_t num_mats, num_rows, num_cols; 03905 uint32_t mat, row, col; 03906 uint32_t num_indices; 03907 03908 Matrix_cf* m = NULL; 03909 03910 num_mats = mb->num_mats; 03911 num_rows = mb->num_rows; 03912 num_cols = mb->num_cols; 03913 03914 switch (orient) 03915 { 03916 case MATBLOCK_MAT_MATRIX: 03917 num_indices = mb->num_mats; 03918 break; 03919 case MATBLOCK_ROW_MATRIX: 03920 num_indices = mb->num_rows; 03921 break; 03922 default: 03923 num_indices = mb->num_cols; 03924 } 03925 if (index >= num_indices) 03926 { 03927 return JWSC_EARG("Invalid index to copy from matblock"); 03928 } 03929 03930 switch (orient) 03931 { 03932 case MATBLOCK_MAT_MATRIX: 03933 create_matrix_cf(m_out, num_rows, num_cols); 03934 m = *m_out; 03935 for (row = 0; row < num_rows; row++) 03936 { 03937 for (col = 0; col < num_cols; col++) 03938 { 03939 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 03940 } 03941 } 03942 break; 03943 case MATBLOCK_ROW_MATRIX: 03944 create_matrix_cf(m_out, num_mats, num_cols); 03945 m = *m_out; 03946 for (mat = 0; mat < num_mats; mat++) 03947 { 03948 for (col = 0; col < num_cols; col++) 03949 { 03950 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 03951 } 03952 } 03953 break; 03954 default: 03955 create_matrix_cf(m_out, num_mats, num_rows); 03956 m = *m_out; 03957 for (mat = 0; mat < num_mats; mat++) 03958 { 03959 for (row = 0; row < num_rows; row++) 03960 { 03961 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 03962 } 03963 } 03964 } 03965 03966 return NULL; 03967 } 03968 03982 Error* copy_matrix_from_matblock_cd 03983 ( 03984 Matrix_cd** m_out, 03985 const Matblock_cd* mb, 03986 Matblock_matrix orient, 03987 uint32_t index 03988 ) 03989 { 03990 uint32_t num_mats, num_rows, num_cols; 03991 uint32_t mat, row, col; 03992 uint32_t num_indices; 03993 03994 Matrix_cd* m = NULL; 03995 03996 num_mats = mb->num_mats; 03997 num_rows = mb->num_rows; 03998 num_cols = mb->num_cols; 03999 04000 switch (orient) 04001 { 04002 case MATBLOCK_MAT_MATRIX: 04003 num_indices = mb->num_mats; 04004 break; 04005 case MATBLOCK_ROW_MATRIX: 04006 num_indices = mb->num_rows; 04007 break; 04008 default: 04009 num_indices = mb->num_cols; 04010 } 04011 if (index >= num_indices) 04012 { 04013 return JWSC_EARG("Invalid index to copy from matblock"); 04014 } 04015 04016 switch (orient) 04017 { 04018 case MATBLOCK_MAT_MATRIX: 04019 create_matrix_cd(m_out, num_rows, num_cols); 04020 m = *m_out; 04021 for (row = 0; row < num_rows; row++) 04022 { 04023 for (col = 0; col < num_cols; col++) 04024 { 04025 m->elts[ row ][ col ] = mb->elts[ index ][ row ][ col ]; 04026 } 04027 } 04028 break; 04029 case MATBLOCK_ROW_MATRIX: 04030 create_matrix_cd(m_out, num_mats, num_cols); 04031 m = *m_out; 04032 for (mat = 0; mat < num_mats; mat++) 04033 { 04034 for (col = 0; col < num_cols; col++) 04035 { 04036 m->elts[ mat ][ col ] = mb->elts[ mat ][ index ][ col ]; 04037 } 04038 } 04039 break; 04040 default: 04041 create_matrix_cd(m_out, num_mats, num_rows); 04042 m = *m_out; 04043 for (mat = 0; mat < num_mats; mat++) 04044 { 04045 for (row = 0; row < num_rows; row++) 04046 { 04047 m->elts[ mat ][ row ] = mb->elts[ mat ][ row ][ index ]; 04048 } 04049 } 04050 } 04051 04052 return NULL; 04053 } 04054 04068 void free_matblock_u8(Matblock_u8* m) 04069 { 04070 if (m == NULL) return; 04071 04072 free(**(m->elts)); 04073 free(*(m->elts)); 04074 free(m->elts); 04075 free(m); 04076 } 04077 04079 void free_matblock_u32(Matblock_u32* m) 04080 { 04081 if (m == NULL) return; 04082 04083 free(**(m->elts)); 04084 free(*(m->elts)); 04085 free(m->elts); 04086 free(m); 04087 } 04088 04090 void free_matblock_i32(Matblock_i32* m) 04091 { 04092 if (m == NULL) return; 04093 04094 free(**(m->elts)); 04095 free(*(m->elts)); 04096 free(m->elts); 04097 free(m); 04098 } 04099 04101 void free_matblock_i64(Matblock_i64* m) 04102 { 04103 if (m == NULL) return; 04104 04105 free(**(m->elts)); 04106 free(*(m->elts)); 04107 free(m->elts); 04108 free(m); 04109 } 04110 04112 void free_matblock_f(Matblock_f* m) 04113 { 04114 if (m == NULL) return; 04115 04116 free(**(m->elts)); 04117 free(*(m->elts)); 04118 free(m->elts); 04119 free(m); 04120 } 04121 04123 void free_matblock_d(Matblock_d* m) 04124 { 04125 if (m == NULL) return; 04126 04127 free(**(m->elts)); 04128 free(*(m->elts)); 04129 free(m->elts); 04130 free(m); 04131 } 04132 04134 void free_matblock_cf(Matblock_cf* m) 04135 { 04136 if (m == NULL) return; 04137 04138 free(**(m->elts)); 04139 free(*(m->elts)); 04140 free(m->elts); 04141 free(m); 04142 } 04143 04145 void free_matblock_cd(Matblock_cd* m) 04146 { 04147 if (m == NULL) return; 04148 04149 free(**(m->elts)); 04150 free(*(m->elts)); 04151 free(m->elts); 04152 free(m); 04153 } 04154