libsc
1.6.0
|
00001 /* 00002 This file is part of the SC Library. 00003 The SC Library provides support for parallel scientific applications. 00004 00005 Copyright (C) 2010 The University of Texas System 00006 00007 The SC Library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 The SC Library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with the SC Library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 00021 */ 00022 00023 #ifndef SC_DMATRIX_H 00024 #define SC_DMATRIX_H 00025 00026 #include <sc_blas.h> 00027 #include <sc_containers.h> 00028 00029 SC_EXTERN_C_BEGIN; 00030 00031 typedef struct sc_dmatrix 00032 { 00033 double **e; 00034 sc_bint_t m, n; 00035 int view; 00036 } 00037 sc_dmatrix_t; 00038 00044 int sc_darray_is_valid (const double *darray, size_t nelem); 00045 00053 int sc_darray_is_range (const double *darray, size_t nelem, 00054 double low, double high); 00055 00060 size_t sc_dmatrix_memory_used (sc_dmatrix_t * dmatrix); 00061 00062 /* 00063 * The sc_dmatrix_new/clone functions abort on allocation errors. 00064 * There is no need to check the return value. 00065 */ 00066 sc_dmatrix_t *sc_dmatrix_new (sc_bint_t m, sc_bint_t n); 00067 sc_dmatrix_t *sc_dmatrix_new_zero (sc_bint_t m, sc_bint_t n); 00068 sc_dmatrix_t *sc_dmatrix_clone (const sc_dmatrix_t * dmatrix); 00069 00074 sc_dmatrix_t *sc_dmatrix_new_data (sc_bint_t m, sc_bint_t n, 00075 double *data); 00076 00081 sc_dmatrix_t *sc_dmatrix_new_view (sc_bint_t m, sc_bint_t n, 00082 sc_dmatrix_t * orig); 00083 00091 sc_dmatrix_t *sc_dmatrix_new_view_offset (sc_bint_t o, 00092 sc_bint_t m, sc_bint_t n, 00093 sc_dmatrix_t * orig); 00094 00097 void sc_dmatrix_reshape (sc_dmatrix_t * dmatrix, sc_bint_t m, 00098 sc_bint_t n); 00099 00105 void sc_dmatrix_resize (sc_dmatrix_t * dmatrix, 00106 sc_bint_t m, sc_bint_t n); 00107 00115 void sc_dmatrix_resize_in_place (sc_dmatrix_t * dmatrix, 00116 sc_bint_t m, sc_bint_t n); 00117 00119 void sc_dmatrix_destroy (sc_dmatrix_t * dmatrix); 00120 00124 int sc_dmatrix_is_valid (const sc_dmatrix_t * A); 00125 00130 int sc_dmatrix_is_symmetric (const sc_dmatrix_t * A, 00131 double tolerance); 00132 00133 void sc_dmatrix_set_zero (sc_dmatrix_t * dmatrix); 00134 void sc_dmatrix_set_value (sc_dmatrix_t * dmatrix, 00135 double value); 00136 00139 void sc_dmatrix_scale (double alpha, sc_dmatrix_t * X); 00140 00143 void sc_dmatrix_shift (double alpha, sc_dmatrix_t * X); 00144 00147 void sc_dmatrix_alphadivide (double alpha, sc_dmatrix_t * X); 00148 00151 void sc_dmatrix_pow (double exponent, sc_dmatrix_t * X); 00152 00155 void sc_dmatrix_fabs (const sc_dmatrix_t * X, 00156 sc_dmatrix_t * Y); 00157 00160 void sc_dmatrix_sqrt (const sc_dmatrix_t * X, 00161 sc_dmatrix_t * Y); 00162 00165 void sc_dmatrix_getsign (const sc_dmatrix_t * X, 00166 sc_dmatrix_t * Y); 00167 00170 void sc_dmatrix_greaterequal (const sc_dmatrix_t * X, 00171 double bound, sc_dmatrix_t * Y); 00172 00175 void sc_dmatrix_lessequal (const sc_dmatrix_t * X, 00176 double bound, sc_dmatrix_t * Y); 00177 00180 void sc_dmatrix_maximum (const sc_dmatrix_t * X, 00181 sc_dmatrix_t * Y); 00182 00185 void sc_dmatrix_minimum (const sc_dmatrix_t * X, 00186 sc_dmatrix_t * Y); 00187 00190 void sc_dmatrix_dotmultiply (const sc_dmatrix_t * X, 00191 sc_dmatrix_t * Y); 00192 00195 void sc_dmatrix_dotdivide (const sc_dmatrix_t * X, 00196 sc_dmatrix_t * Y); 00197 00198 void sc_dmatrix_copy (const sc_dmatrix_t * X, 00199 sc_dmatrix_t * Y); 00200 00201 void sc_dmatrix_transpose (const sc_dmatrix_t * X, 00202 sc_dmatrix_t * Y); 00203 00206 void sc_dmatrix_add (double alpha, const sc_dmatrix_t * X, 00207 sc_dmatrix_t * Y); 00208 00217 void sc_dmatrix_vector (sc_trans_t transa, 00218 sc_trans_t transx, 00219 sc_trans_t transy, 00220 double alpha, const sc_dmatrix_t * A, 00221 const sc_dmatrix_t * X, double beta, 00222 sc_dmatrix_t * Y); 00223 00230 void sc_dmatrix_multiply (sc_trans_t transa, 00231 sc_trans_t transb, double alpha, 00232 const sc_dmatrix_t * A, 00233 const sc_dmatrix_t * B, double beta, 00234 sc_dmatrix_t * C); 00235 00245 void sc_dmatrix_ldivide (sc_trans_t transa, 00246 const sc_dmatrix_t * A, 00247 const sc_dmatrix_t * B, 00248 sc_dmatrix_t * C); 00249 00259 void sc_dmatrix_rdivide (sc_trans_t transb, 00260 const sc_dmatrix_t * A, 00261 const sc_dmatrix_t * B, 00262 sc_dmatrix_t * C); 00263 00269 void sc_dmatrix_write (const sc_dmatrix_t * dmatrix, 00270 FILE * fp); 00271 00272 /* 00273 * The sc_dmatrix_pool recycles matrices of the same size. 00274 */ 00275 typedef struct sc_dmatrix_pool 00276 { 00277 int m, n; 00278 size_t elem_count; 00279 sc_array_t freed; /* buffers the freed elements */ 00280 } 00281 sc_dmatrix_pool_t; 00282 00288 sc_dmatrix_pool_t *sc_dmatrix_pool_new (int m, int n); 00289 00295 void sc_dmatrix_pool_destroy (sc_dmatrix_pool_t * dmpool); 00296 00302 sc_dmatrix_t *sc_dmatrix_pool_alloc (sc_dmatrix_pool_t * dmpool); 00303 00309 void sc_dmatrix_pool_free (sc_dmatrix_pool_t * dmpool, 00310 sc_dmatrix_t * dm); 00311 00312 SC_EXTERN_C_END; 00313 00314 #endif /* !SC_DMATRIX_H */