JWS C Library
C language utility library
matblock.h
Go to the documentation of this file.
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 
00053 #ifndef MATBLOCK_H 
00054 #define MATBLOCK_H 
00055 
00056 
00057 #include <jwsc/config.h>
00058 
00059 #include <stdlib.h>
00060 #include <inttypes.h>
00061 
00062 #include "jwsc/base/error.h"
00063 #include "jwsc/math/complex.h"
00064 #include "jwsc/matrix/matrix.h"
00065 
00066 
00067 #ifdef __cplusplus
00068 namespace jwsc {
00069 extern "C" {
00070 #endif
00071 
00072 
00074 typedef struct
00075 {
00077     uint32_t num_mats;
00078 
00080     uint32_t num_rows;
00081 
00083     uint32_t num_cols;
00084 
00086     int8_t*** elts;
00087 }
00088 Matblock_i8;
00089 
00091 typedef struct
00092 {
00094     uint32_t num_mats;
00095 
00097     uint32_t num_rows;
00098 
00100     uint32_t num_cols;
00101 
00103     int16_t*** elts;
00104 }
00105 Matblock_i16;
00106 
00108 typedef struct
00109 {
00111     uint32_t num_mats;
00112 
00114     uint32_t num_rows;
00115 
00117     uint32_t num_cols;
00118 
00120     int32_t*** elts;
00121 }
00122 Matblock_i32;
00123 
00125 typedef struct
00126 {
00128     uint32_t num_mats;
00129 
00131     uint32_t num_rows;
00132 
00134     uint32_t num_cols;
00135 
00137     int64_t*** elts;
00138 }
00139 Matblock_i64;
00140 
00141 
00143 typedef struct
00144 {
00146     int32_t num_mats;
00147 
00149     int32_t num_rows;
00150 
00152     int32_t num_cols;
00153 
00155     uint8_t*** elts;
00156 }
00157 Matblock_u8;
00158 
00160 typedef struct
00161 {
00163     int32_t num_mats;
00164 
00166     uint32_t num_rows;
00167 
00169     uint32_t num_cols;
00170 
00172     uint16_t*** elts;
00173 }
00174 Matblock_u16;
00175 
00177 typedef struct
00178 {
00180     int32_t num_mats;
00181 
00183     uint32_t num_rows;
00184 
00186     uint32_t num_cols;
00187 
00189     uint32_t*** elts;
00190 }
00191 Matblock_u32;
00192 
00194 typedef struct
00195 {
00197     int32_t num_mats;
00198 
00200     uint32_t num_rows;
00201 
00203     uint32_t num_cols;
00204 
00206     uint64_t*** elts;
00207 }
00208 Matblock_u64;
00209 
00211 typedef struct
00212 {
00214     uint32_t num_mats;
00215 
00217     uint32_t num_rows;
00218 
00220     uint32_t num_cols;
00221 
00223     float*** elts;
00224 }
00225 Matblock_f;
00226 
00228 typedef struct
00229 {
00231     uint32_t num_mats;
00232 
00234     uint32_t num_rows;
00235 
00237     uint32_t num_cols;
00238 
00240     double*** elts;
00241 }
00242 Matblock_d;
00243 
00245 typedef struct
00246 {
00248     uint32_t num_mats;
00249 
00251     uint32_t num_rows;
00252 
00254     uint32_t num_cols;
00255 
00257     Complex_f*** elts;
00258 }
00259 Matblock_cf;
00260 
00262 typedef struct
00263 {
00265     uint32_t num_mats;
00266 
00268     uint32_t num_rows;
00269 
00271     uint32_t num_cols;
00272 
00274     Complex_d*** elts;
00275 }
00276 Matblock_cd;
00277 
00278 
00280 typedef enum
00281 {
00282     MATBLOCK_MAT_MATRIX,
00283     MATBLOCK_ROW_MATRIX,
00284     MATBLOCK_COL_MATRIX
00285 }
00286 Matblock_matrix;
00287 
00288 
00297 void create_matblock_u8
00298 (
00299     Matblock_u8** m_out, 
00300     uint32_t      num_mats, 
00301     uint32_t      num_rows, 
00302     uint32_t      num_cols
00303 );
00304 
00306 void create_matblock_u32
00307 (
00308     Matblock_u32** m_out, 
00309     uint32_t       num_mats, 
00310     uint32_t       num_rows, 
00311     uint32_t       num_cols
00312 );
00313 
00315 void create_matblock_i32
00316 (
00317     Matblock_i32** m_out, 
00318     uint32_t       num_mats, 
00319     uint32_t       num_rows, 
00320     uint32_t       num_cols
00321 );
00322 
00324 void create_matblock_i64
00325 (
00326     Matblock_i64** m_out, 
00327     uint32_t       num_mats, 
00328     uint32_t       num_rows, 
00329     uint32_t       num_cols
00330 );
00331 
00333 void create_matblock_f
00334 (
00335     Matblock_f** m_out, 
00336     uint32_t     num_mats, 
00337     uint32_t     num_rows, 
00338     uint32_t     num_cols
00339 );
00340 
00342 void create_matblock_d
00343 (
00344     Matblock_d** m_out, 
00345     uint32_t     num_mats, 
00346     uint32_t     num_rows, 
00347     uint32_t     num_cols
00348 );
00349 
00351 void create_matblock_cf
00352 (
00353     Matblock_cf** m_out, 
00354     uint32_t      num_mats, 
00355     uint32_t      num_rows, 
00356     uint32_t      num_cols
00357 );
00358 
00360 void create_matblock_cd
00361 (
00362     Matblock_cd** m_out, 
00363     uint32_t      num_mats, 
00364     uint32_t      num_rows, 
00365     uint32_t      num_cols
00366 );
00367 
00381 void create_init_matblock_u8
00382 (
00383     Matblock_u8** m_out, 
00384     uint32_t      num_mats, 
00385     uint32_t      num_rows, 
00386     uint32_t      num_cols,
00387     uint8_t       val
00388 );
00389 
00391 void create_init_matblock_u32
00392 (
00393     Matblock_u32** m_out, 
00394     uint32_t       num_mats, 
00395     uint32_t       num_rows, 
00396     uint32_t       num_cols,
00397     uint32_t       val
00398 );
00399 
00401 void create_init_matblock_i32
00402 (
00403     Matblock_i32** m_out, 
00404     uint32_t       num_mats, 
00405     uint32_t       num_rows, 
00406     uint32_t       num_cols,
00407     int32_t        val
00408 );
00409 
00411 void create_init_matblock_i64
00412 (
00413     Matblock_i64** m_out, 
00414     uint32_t       num_mats, 
00415     uint32_t       num_rows, 
00416     uint32_t       num_cols,
00417     int64_t        val
00418 );
00419 
00421 void create_init_matblock_f
00422 (
00423     Matblock_f** m_out, 
00424     uint32_t     num_mats, 
00425     uint32_t     num_rows, 
00426     uint32_t     num_cols,
00427     float        val
00428 );
00429 
00431 void create_init_matblock_d
00432 (
00433     Matblock_d** m_out, 
00434     uint32_t     num_mats, 
00435     uint32_t     num_rows, 
00436     uint32_t     num_cols,
00437     double       val
00438 );
00439 
00441 void create_init_matblock_cf
00442 (
00443     Matblock_cf** m_out, 
00444     uint32_t      num_mats, 
00445     uint32_t      num_rows, 
00446     uint32_t      num_cols,
00447     Complex_f     val
00448 );
00449 
00451 void create_init_matblock_cd
00452 (
00453     Matblock_cd** m_out, 
00454     uint32_t      num_mats, 
00455     uint32_t      num_rows, 
00456     uint32_t      num_cols,
00457     Complex_d     val
00458 );
00459 
00474 void create_zero_matblock_u8
00475 (
00476     Matblock_u8** m_out, 
00477     uint32_t      num_mats, 
00478     uint32_t      num_rows, 
00479     uint32_t      num_cols
00480 );
00481 
00483 void create_zero_matblock_u32
00484 (
00485     Matblock_u32** m_out, 
00486     uint32_t       num_mats, 
00487     uint32_t       num_rows, 
00488     uint32_t       num_cols
00489 );
00490 
00492 void create_zero_matblock_i32
00493 (
00494     Matblock_i32** m_out, 
00495     uint32_t       num_mats, 
00496     uint32_t       num_rows, 
00497     uint32_t       num_cols
00498 );
00499 
00501 void create_zero_matblock_i64
00502 (
00503     Matblock_i64** m_out, 
00504     uint32_t       num_mats, 
00505     uint32_t       num_rows, 
00506     uint32_t       num_cols
00507 );
00508 
00510 void create_zero_matblock_f
00511 (
00512     Matblock_f** m_out, 
00513     uint32_t     num_mats, 
00514     uint32_t     num_rows, 
00515     uint32_t     num_cols
00516 );
00517 
00519 void create_zero_matblock_d
00520 (
00521     Matblock_d** m_out, 
00522     uint32_t     num_mats, 
00523     uint32_t     num_rows, 
00524     uint32_t     num_cols
00525 );
00526 
00528 void create_zero_matblock_cf
00529 (
00530     Matblock_cf** m_out, 
00531     uint32_t      num_mats, 
00532     uint32_t      num_rows, 
00533     uint32_t      num_cols
00534 );
00535 
00537 void create_zero_matblock_cd
00538 (
00539     Matblock_cd** m_out, 
00540     uint32_t      num_mats, 
00541     uint32_t      num_rows, 
00542     uint32_t      num_cols
00543 );
00544 
00559 void create_random_matblock_u32
00560 (
00561     Matblock_u32** m_out, 
00562     uint32_t       num_mats, 
00563     uint32_t       num_rows, 
00564     uint32_t       num_cols,
00565     uint32_t       min,
00566     uint32_t       max
00567 );
00568 
00570 void create_random_matblock_i32
00571 (
00572     Matblock_i32** m_out, 
00573     uint32_t       num_mats, 
00574     uint32_t       num_rows, 
00575     uint32_t       num_cols,
00576     int32_t        min,
00577     int32_t        max
00578 );
00579 
00581 void create_random_matblock_i64
00582 (
00583     Matblock_i64** m_out, 
00584     uint32_t       num_mats, 
00585     uint32_t       num_rows, 
00586     uint32_t       num_cols,
00587     int64_t        min,
00588     int64_t        max
00589 );
00590 
00592 void create_random_matblock_f
00593 (
00594     Matblock_f** m_out, 
00595     uint32_t     num_mats, 
00596     uint32_t     num_rows, 
00597     uint32_t     num_cols,
00598     float        min,
00599     float        max
00600 );
00601 
00603 void create_random_matblock_d
00604 (
00605     Matblock_d** m_out, 
00606     uint32_t     num_mats, 
00607     uint32_t     num_rows, 
00608     uint32_t     num_cols,
00609     double       min,
00610     double       max
00611 );
00612 
00614 void create_random_matblock_cf
00615 (
00616     Matblock_cf** m_out, 
00617     uint32_t      num_mats, 
00618     uint32_t      num_rows, 
00619     uint32_t      num_cols,
00620     Complex_f     min,
00621     Complex_f     max
00622 );
00623 
00625 void create_random_matblock_cd
00626 (
00627     Matblock_cd** m_out, 
00628     uint32_t      num_mats, 
00629     uint32_t      num_rows, 
00630     uint32_t      num_cols,
00631     Complex_d     min,
00632     Complex_d     max
00633 );
00634 
00648 Error* copy_matblock_u32(Matblock_u32** m_out, const Matblock_u32* m_in);
00649 
00651 Error* copy_matblock_i32(Matblock_i32** m_out, const Matblock_i32* m_in);
00652 
00654 Error* copy_matblock_i64(Matblock_i64** m_out, const Matblock_i64* m_in);
00655 
00657 Error* copy_matblock_f(Matblock_f** m_out, const Matblock_f* m_in);
00658 
00660 Error* copy_matblock_d(Matblock_d** m_out, const Matblock_d* m_in);
00661 
00663 Error* copy_matblock_cf(Matblock_cf** m_out, const Matblock_cf* m_in);
00664 
00666 Error* copy_matblock_cd(Matblock_cd** m_out, const Matblock_cd* m_in);
00667 
00681 Error* copy_matblock_block_u32
00682 (
00683     Matblock_u32**      m_out, 
00684     const Matblock_u32* m_in,
00685     uint32_t            mat_offset,
00686     uint32_t            row_offset,
00687     uint32_t            col_offset,
00688     uint32_t            num_mats,
00689     uint32_t            num_rows,
00690     uint32_t            num_cols
00691 );
00692 
00694 Error* copy_matblock_block_i32
00695 (
00696     Matblock_i32**      m_out, 
00697     const Matblock_i32* m_in,
00698     uint32_t            mat_offset,
00699     uint32_t            row_offset,
00700     uint32_t            col_offset,
00701     uint32_t            num_mats,
00702     uint32_t            num_rows,
00703     uint32_t            num_cols
00704 );
00705 
00707 Error* copy_matblock_block_i64
00708 (
00709     Matblock_i64**      m_out, 
00710     const Matblock_i64* m_in,
00711     uint32_t            mat_offset,
00712     uint32_t            row_offset,
00713     uint32_t            col_offset,
00714     uint32_t            num_mats,
00715     uint32_t            num_rows,
00716     uint32_t            num_cols
00717 );
00718 
00721 Error* copy_matblock_block_f
00722 (
00723     Matblock_f**      m_out, 
00724     const Matblock_f* m_in,
00725     uint32_t          mat_offset,
00726     uint32_t          row_offset,
00727     uint32_t          col_offset,
00728     uint32_t          num_mats,
00729     uint32_t          num_rows,
00730     uint32_t          num_cols
00731 );
00732 
00735 Error* copy_matblock_block_d
00736 (
00737     Matblock_d**      m_out, 
00738     const Matblock_d* m_in,
00739     uint32_t          mat_offset,
00740     uint32_t          row_offset,
00741     uint32_t          col_offset,
00742     uint32_t          num_mats,
00743     uint32_t          num_rows,
00744     uint32_t          num_cols
00745 );
00746 
00751 Error* copy_matblock_block_cf
00752 (
00753     Matblock_cf**      m_out, 
00754     const Matblock_cf* m_in,
00755     uint32_t           mat_offset,
00756     uint32_t           row_offset,
00757     uint32_t           col_offset,
00758     uint32_t           num_mats,
00759     uint32_t           num_rows,
00760     uint32_t           num_cols
00761 );
00762 
00767 Error* copy_matblock_block_cd
00768 (
00769     Matblock_cd**      m_out, 
00770     const Matblock_cd* m_in,
00771     uint32_t           mat_offset,
00772     uint32_t           row_offset,
00773     uint32_t           col_offset,
00774     uint32_t           num_mats,
00775     uint32_t           num_rows,
00776     uint32_t           num_cols
00777 );
00778 
00795 Error* copy_matblock_block_into_matblock_u32
00796 (
00797     Matblock_u32*       m_1, 
00798     uint32_t            mat_offset_1,
00799     uint32_t            row_offset_1,
00800     uint32_t            col_offset_1,
00801     const Matblock_u32* m_2,
00802     uint32_t            mat_offset_2,
00803     uint32_t            row_offset_2,
00804     uint32_t            col_offset_2,
00805     uint32_t            num_mats,
00806     uint32_t            num_rows,
00807     uint32_t            num_cols
00808 );
00809 
00814 Error* copy_matblock_block_into_matblock_i32
00815 (
00816     Matblock_i32*       m_1, 
00817     uint32_t            mat_offset_1,
00818     uint32_t            row_offset_1,
00819     uint32_t            col_offset_1,
00820     const Matblock_i32* m_2,
00821     uint32_t            mat_offset_2,
00822     uint32_t            row_offset_2,
00823     uint32_t            col_offset_2,
00824     uint32_t            num_mats,
00825     uint32_t            num_rows,
00826     uint32_t            num_cols
00827 );
00828 
00833 Error* copy_matblock_block_into_matblock_i64
00834 (
00835     Matblock_i64*       m_1, 
00836     uint32_t            mat_offset_1,
00837     uint32_t            row_offset_1,
00838     uint32_t            col_offset_1,
00839     const Matblock_i64* m_2,
00840     uint32_t            mat_offset_2,
00841     uint32_t            row_offset_2,
00842     uint32_t            col_offset_2,
00843     uint32_t            num_mats,
00844     uint32_t            num_rows,
00845     uint32_t            num_cols
00846 );
00847 
00852 Error* copy_matblock_block_into_matblock_f
00853 (
00854     Matblock_f*       m_1, 
00855     uint32_t          mat_offset_1,
00856     uint32_t          row_offset_1,
00857     uint32_t          col_offset_1,
00858     const Matblock_f* m_2,
00859     uint32_t          mat_offset_2,
00860     uint32_t          row_offset_2,
00861     uint32_t          col_offset_2,
00862     uint32_t          num_mats,
00863     uint32_t          num_rows,
00864     uint32_t          num_cols
00865 );
00866 
00871 Error* copy_matblock_block_into_matblock_d
00872 (
00873     Matblock_d*       m_1, 
00874     uint32_t          mat_offset_1,
00875     uint32_t          row_offset_1,
00876     uint32_t          col_offset_1,
00877     const Matblock_d* m_2,
00878     uint32_t          mat_offset_2,
00879     uint32_t          row_offset_2,
00880     uint32_t          col_offset_2,
00881     uint32_t          num_mats,
00882     uint32_t          num_rows,
00883     uint32_t          num_cols
00884 );
00885 
00890 Error* copy_matblock_block_into_matblock_cf
00891 (
00892     Matblock_cf*       m_1, 
00893     uint32_t           mat_offset_1,
00894     uint32_t           row_offset_1,
00895     uint32_t           col_offset_1,
00896     const Matblock_cf* m_2,
00897     uint32_t           mat_offset_2,
00898     uint32_t           row_offset_2,
00899     uint32_t           col_offset_2,
00900     uint32_t           num_mats,
00901     uint32_t           num_rows,
00902     uint32_t           num_cols
00903 );
00904 
00909 Error* copy_matblock_block_into_matblock_cd
00910 (
00911     Matblock_cd*       m_1, 
00912     uint32_t           mat_offset_1,
00913     uint32_t           row_offset_1,
00914     uint32_t           col_offset_1,
00915     const Matblock_cd* m_2,
00916     uint32_t           mat_offset_2,
00917     uint32_t           row_offset_2,
00918     uint32_t           col_offset_2,
00919     uint32_t           num_mats,
00920     uint32_t           num_rows,
00921     uint32_t           num_cols
00922 );
00923 
00937 Error* copy_matrix_into_matblock_u32
00938 (
00939     Matblock_u32**      mb_out,
00940     const Matblock_u32* mb_in,
00941     const Matrix_u32*   m,
00942     Matblock_matrix     orient,
00943     uint32_t            index
00944 );
00945 
00947 Error* copy_matrix_into_matblock_i32
00948 (
00949     Matblock_i32**      mb_out,
00950     const Matblock_i32* mb_in,
00951     const Matrix_i32*   m,
00952     Matblock_matrix     orient,
00953     uint32_t            index
00954 );
00955 
00957 Error* copy_matrix_into_matblock_i64
00958 (
00959     Matblock_i64**      mb_out,
00960     const Matblock_i64* mb_in,
00961     const Matrix_i64*   m,
00962     Matblock_matrix     orient,
00963     uint32_t            index
00964 );
00965 
00967 Error* copy_matrix_into_matblock_f
00968 (
00969     Matblock_f**      mb_out,
00970     const Matblock_f* mb_in,
00971     const Matrix_f*   m,
00972     Matblock_matrix   orient,
00973     uint32_t          index
00974 );
00975 
00977 Error* copy_matrix_into_matblock_d
00978 (
00979     Matblock_d**      mb_out,
00980     const Matblock_d* mb_in,
00981     const Matrix_d*   m,
00982     Matblock_matrix   orient,
00983     uint32_t          index
00984 );
00985 
00987 Error* copy_matrix_into_matblock_cf
00988 (
00989     Matblock_cf**      mb_out,
00990     const Matblock_cf* mb_in,
00991     const Matrix_cf*   m,
00992     Matblock_matrix    orient,
00993     uint32_t           index
00994 );
00995 
00997 Error* copy_matrix_into_matblock_cd
00998 (
00999     Matblock_cd**      mb_out,
01000     const Matblock_cd* mb_in,
01001     const Matrix_cd*   m,
01002     Matblock_matrix    orient,
01003     uint32_t           index
01004 );
01005 
01019 Error* copy_matrix_from_matblock_u32
01020 (
01021     Matrix_u32**        m_out,
01022     const Matblock_u32* mb,
01023     Matblock_matrix     orient,
01024     uint32_t            index
01025 );
01026 
01028 Error* copy_matrix_from_matblock_i32
01029 (
01030     Matrix_i32**        m_out,
01031     const Matblock_i32* mb,
01032     Matblock_matrix     orient,
01033     uint32_t            index
01034 );
01035 
01037 Error* copy_matrix_from_matblock_i64
01038 (
01039     Matrix_i64**        m_out,
01040     const Matblock_i64* mb,
01041     Matblock_matrix     orient,
01042     uint32_t            index
01043 );
01044 
01046 Error* copy_matrix_from_matblock_f
01047 (
01048     Matrix_f**        m_out,
01049     const Matblock_f* mb,
01050     Matblock_matrix   orient,
01051     uint32_t          index
01052 );
01053 
01055 Error* copy_matrix_from_matblock_d
01056 (
01057     Matrix_d**        m_out,
01058     const Matblock_d* mb,
01059     Matblock_matrix   orient,
01060     uint32_t          index
01061 );
01062 
01064 Error* copy_matrix_from_matblock_cf
01065 (
01066     Matrix_cf**        m_out,
01067     const Matblock_cf* mb,
01068     Matblock_matrix    orient,
01069     uint32_t           index
01070 );
01071 
01073 Error* copy_matrix_from_matblock_cd
01074 (
01075     Matrix_cd**        m_out,
01076     const Matblock_cd* mb,
01077     Matblock_matrix    orient,
01078     uint32_t           index
01079 );
01080 
01094 void free_matblock_u8(Matblock_u8* m);
01095 
01097 void free_matblock_u32(Matblock_u32* m);
01098 
01100 void free_matblock_i32(Matblock_i32* m);
01101 
01103 void free_matblock_i64(Matblock_i64* m);
01104 
01106 void free_matblock_f(Matblock_f* m);
01107 
01109 void free_matblock_d(Matblock_d* m);
01110 
01112 void free_matblock_cf(Matblock_cf* m);
01113 
01115 void free_matblock_cd(Matblock_cd* m);
01116 
01120 #ifdef __cplusplus
01121 }
01122 }
01123 #endif
01124 
01125 
01126 #endif