JWS C Library
C language utility library
vector.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 
00048 #ifndef VECTOR_H 
00049 #define VECTOR_H 
00050 
00051 
00052 #include <jwsc/config.h>
00053 
00054 #include <stdlib.h>
00055 #include <inttypes.h>
00056 
00057 #include "jwsc/base/error.h"
00058 #include "jwsc/math/complex.h"
00059 
00060 
00061 #ifdef __cplusplus
00062 namespace jwsc {
00063 extern "C" {
00064 #endif
00065 
00066 
00068 typedef struct
00069 {
00071     uint32_t num_elts;
00072 
00074     int8_t* elts;
00075 }
00076 Vector_i8;
00077 
00079 typedef struct
00080 {
00082     uint32_t num_elts;
00083 
00085     int16_t* elts;
00086 }
00087 Vector_i16;
00088 
00090 typedef struct
00091 {
00093     uint32_t num_elts;
00094 
00096     int32_t* elts;
00097 }
00098 Vector_i32;
00099 
00101 typedef struct
00102 {
00104     uint32_t num_elts;
00105 
00107     int64_t* elts;
00108 }
00109 Vector_i64;
00110 
00112 typedef struct
00113 {
00115     uint32_t num_elts;
00116 
00118     uint8_t* elts;
00119 }
00120 Vector_u8;
00121 
00123 typedef struct
00124 {
00126     uint32_t num_elts;
00127 
00129     uint16_t* elts;
00130 }
00131 Vector_u16;
00132 
00134 typedef struct
00135 {
00137     uint32_t num_elts;
00138 
00140     uint32_t* elts;
00141 }
00142 Vector_u32;
00143 
00145 typedef struct
00146 {
00148     uint32_t num_elts;
00149 
00151     uint64_t* elts;
00152 }
00153 Vector_u64;
00154 
00156 typedef struct
00157 {
00159     uint32_t num_elts;
00160 
00162     float* elts;
00163 }
00164 Vector_f;
00165 
00167 typedef struct
00168 {
00170     uint32_t num_elts;
00171 
00173     double* elts;
00174 }
00175 Vector_d;
00176 
00178 typedef struct
00179 {
00181     uint32_t num_elts;
00182 
00184     Complex_f* elts;
00185 }
00186 Vector_cf;
00187 
00189 typedef struct
00190 {
00192     uint32_t num_elts;
00193 
00195     Complex_d* elts;
00196 }
00197 Vector_cd;
00198 
00199 
00200 
00201 
00210 void create_vector_u32(Vector_u32** v_out, uint32_t num_elts);
00211 
00213 void create_vector_i32(Vector_i32** v_out, uint32_t num_elts);
00214 
00216 void create_vector_i64(Vector_i64** v_out, uint32_t num_elts);
00217 
00219 void create_vector_f(Vector_f** v_out, uint32_t num_elts);
00220 
00222 void create_vector_d(Vector_d** v_out, uint32_t num_elts);
00223 
00225 void create_vector_cf(Vector_cf** v_out, uint32_t num_elts);
00226 
00228 void create_vector_cd(Vector_cd** v_out, uint32_t num_elts);
00229 
00243 void create_init_vector_u32(Vector_u32** v_out, uint32_t num_elts,uint32_t val);
00244 
00246 void create_init_vector_i32(Vector_i32** v_out, uint32_t num_elts, int32_t val);
00247 
00249 void create_init_vector_i64(Vector_i64** v_out, uint32_t num_elts, int64_t val);
00250 
00252 void create_init_vector_f(Vector_f** v_out, uint32_t num_elts, float val);
00253 
00255 void create_init_vector_d(Vector_d** v_out, uint32_t num_elts, double val);
00256 
00258 void create_init_vector_cf(Vector_cf** v_out, uint32_t num_elts, Complex_f val);
00259 
00261 void create_init_vector_cd(Vector_cd** v_out, uint32_t num_elts, Complex_d val);
00262 
00277 void create_zero_vector_u32(Vector_u32** v_out, uint32_t num_elts);
00278 
00280 void create_zero_vector_i32(Vector_i32** v_out, uint32_t num_elts);
00281 
00283 void create_zero_vector_i64(Vector_i64** v_out, uint32_t num_elts);
00284 
00286 void create_zero_vector_f(Vector_f** v_out, uint32_t num_elts);
00287 
00289 void create_zero_vector_d(Vector_d** v_out, uint32_t num_elts);
00290 
00292 void create_zero_vector_cf(Vector_cf** v_out, uint32_t num_elts);
00293 
00295 void create_zero_vector_cd(Vector_cd** v_out, uint32_t num_elts);
00296 
00311 void create_random_vector_u32
00312 (
00313     Vector_u32** v_out, 
00314     uint32_t     num_elts,
00315     uint32_t     min,
00316     uint32_t     max
00317 );
00318 
00320 void create_random_vector_i32
00321 (
00322     Vector_i32** v_out, 
00323     uint32_t     num_elts,
00324     int32_t      min,
00325     int32_t      max
00326 );
00327 
00329 void create_random_vector_i64
00330 (
00331     Vector_i64** v_out, 
00332     uint32_t     num_elts,
00333     int64_t      min,
00334     int64_t      max
00335 );
00336 
00338 void create_random_vector_f
00339 (
00340     Vector_f** v_out, 
00341     uint32_t   num_elts,
00342     float      min,
00343     float      max
00344 );
00345 
00347 void create_random_vector_d
00348 (
00349     Vector_d** v_out, 
00350     uint32_t   num_elts,
00351     double     min,
00352     double     max
00353 );
00354 
00356 void create_random_vector_cf
00357 (
00358     Vector_cf** v_out, 
00359     uint32_t    num_elts,
00360     Complex_f   min,
00361     Complex_f   max
00362 );
00363 
00365 void create_random_vector_cd
00366 (
00367     Vector_cd** v_out, 
00368     uint32_t    num_elts,
00369     Complex_d   min,
00370     Complex_d   max
00371 );
00372 
00386 Error* copy_vector_u32(Vector_u32** v_out, const Vector_u32* v_in);
00387 
00389 Error* copy_vector_i32(Vector_i32** v_out, const Vector_i32* v_in);
00390 
00392 Error* copy_vector_i64(Vector_i64** v_out, const Vector_i64* v_in);
00393 
00395 Error* copy_vector_f(Vector_f** v_out, const Vector_f* v_in);
00396 
00398 Error* copy_vector_d(Vector_d** v_out, const Vector_d* v_in);
00399 
00401 Error* copy_vector_cf(Vector_cf** v_out, const Vector_cf* v_in);
00402 
00404 Error* copy_vector_cd(Vector_cd** v_out, const Vector_cd* v_in);
00405 
00419 Error* copy_vector_section_u32
00420 (
00421     Vector_u32**      v_out, 
00422     const Vector_u32* v_in,
00423     uint32_t          offset,
00424     uint32_t          num_elts
00425 );
00426 
00428 Error* copy_vector_section_i32
00429 (
00430     Vector_i32**      v_out, 
00431     const Vector_i32* v_in,
00432     uint32_t          offset,
00433     uint32_t          num_elts
00434 );
00435 
00437 Error* copy_vector_section_i64
00438 (
00439     Vector_i64**      v_out, 
00440     const Vector_i64* v_in,
00441     uint32_t          offset,
00442     uint32_t          num_elts
00443 );
00444 
00446 Error* copy_vector_section_f
00447 (
00448     Vector_f**      v_out, 
00449     const Vector_f* v_in,
00450     uint32_t        offset,
00451     uint32_t        num_elts
00452 );
00453 
00455 Error* copy_vector_section_d
00456 (
00457     Vector_d**      v_out, 
00458     const Vector_d* v_in,
00459     uint32_t        offset,
00460     uint32_t        num_elts
00461 );
00462 
00464 Error* copy_vector_section_cf
00465 (
00466     Vector_cf**      v_out, 
00467     const Vector_cf* v_in,
00468     uint32_t         offset,
00469     uint32_t         num_elts
00470 );
00471 
00473 Error* copy_vector_section_cd
00474 (
00475     Vector_cd**      v_out, 
00476     const Vector_cd* v_in,
00477     uint32_t         offset,
00478     uint32_t         num_elts
00479 );
00480 
00494 Error* copy_vector_section_into_vector_u32
00495 (
00496     Vector_u32*       v_1, 
00497     uint32_t          offset_1,
00498     const Vector_u32* v_2,
00499     uint32_t          offset_2,
00500     uint32_t          num_elts
00501 );
00502 
00504 Error* copy_vector_section_into_vector_i32
00505 (
00506     Vector_i32*       v_1, 
00507     uint32_t          offset_1,
00508     const Vector_i32* v_2,
00509     uint32_t          offset_2,
00510     uint32_t          num_elts
00511 );
00512 
00514 Error* copy_vector_section_into_vector_i64
00515 (
00516     Vector_i64*       v_1, 
00517     uint32_t          offset_1,
00518     const Vector_i64* v_2,
00519     uint32_t          offset_2,
00520     uint32_t          num_elts
00521 );
00522 
00527 Error* copy_vector_section_into_vector_f
00528 (
00529     Vector_f*       v_1, 
00530     uint32_t        offset_1,
00531     const Vector_f* v_2,
00532     uint32_t        offset_2,
00533     uint32_t        num_elts
00534 );
00535 
00540 Error* copy_vector_section_into_vector_d
00541 (
00542     Vector_d*       v_1, 
00543     uint32_t        offset_1,
00544     const Vector_d* v_2,
00545     uint32_t        offset_2,
00546     uint32_t        num_elts
00547 );
00548 
00553 Error* copy_vector_section_into_vector_cf
00554 (
00555     Vector_cf*       v_1, 
00556     uint32_t         offset_1,
00557     const Vector_cf* v_2,
00558     uint32_t         offset_2,
00559     uint32_t         num_elts
00560 );
00561 
00566 Error* copy_vector_section_into_vector_cd
00567 (
00568     Vector_cd*       v_1, 
00569     uint32_t         offset_1,
00570     const Vector_cd* v_2,
00571     uint32_t         offset_2,
00572     uint32_t         num_elts
00573 );
00574 
00588 void cat_vectors_u32
00589 (
00590     Vector_u32**      v_out, 
00591     const Vector_u32* v_1, 
00592     const Vector_u32* v_2
00593 );
00594 
00596 void cat_vectors_i32
00597 (
00598     Vector_i32**      v_out, 
00599     const Vector_i32* v_1, 
00600     const Vector_i32* v_2
00601 );
00602 
00604 void cat_vectors_i64
00605 (
00606     Vector_i64**      v_out, 
00607     const Vector_i64* v_1, 
00608     const Vector_i64* v_2
00609 );
00610 
00612 void cat_vectors_f
00613 (
00614     Vector_f**      v_out, 
00615     const Vector_f* v_1, 
00616     const Vector_f* v_2
00617 );
00618 
00620 void cat_vectors_d
00621 (
00622     Vector_d**      v_out, 
00623     const Vector_d* v_1, 
00624     const Vector_d* v_2
00625 );
00626 
00628 void cat_vectors_cf
00629 (
00630     Vector_cf**      v_out, 
00631     const Vector_cf* v_1, 
00632     const Vector_cf* v_2
00633 );
00634 
00636 void cat_vectors_cd
00637 (
00638     Vector_cd**      v_out, 
00639     const Vector_cd* v_1, 
00640     const Vector_cd* v_2
00641 );
00642 
00656 void free_vector_u32(Vector_u32* v);
00657 
00659 void free_vector_i32(Vector_i32* v);
00660 
00662 void free_vector_i64(Vector_i64* v);
00663 
00665 void free_vector_f(Vector_f* v);
00666 
00668 void free_vector_d(Vector_d* v);
00669 
00671 void free_vector_cf(Vector_cf* v);
00672 
00674 void free_vector_cd(Vector_cd* v);
00675 
00679 #ifdef __cplusplus
00680 }
00681 }
00682 #endif
00683 
00684 
00685 #endif