escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #ifndef __PASO_UTIL_H__ 00019 #define __PASO_UTIL_H__ 00020 00021 /****************************************************************************/ 00022 00023 /* Some utility routines: */ 00024 00025 /****************************************************************************/ 00026 00027 /* Copyrights by ACcESS Australia, 2003,2004,2005 */ 00028 /* author: l.gross@uq.edu.au */ 00029 00030 /****************************************************************************/ 00031 00032 #include "Paso.h" 00033 00034 namespace paso { 00035 00036 namespace util { 00037 00040 void applyGivensRotations(dim_t N, double* v, const double* c, const double* s); 00041 00043 index_t arg_max(dim_t N, dim_t* lambda); 00044 00046 int comparIndex(const void* index1, const void* index2); 00047 00049 index_t cumsum(dim_t N, index_t* array); 00050 00051 index_t cumsum_maskedTrue(dim_t N, index_t* array, int* mask); 00052 00053 index_t cumsum_maskedFalse(dim_t N, index_t* array, int* mask); 00054 00056 index_t iMax(dim_t N, const index_t* array); 00057 00059 double innerProduct(dim_t N, const double* x, const double* y, 00060 Esys_MPIInfo* mpiinfo); 00061 00063 bool isAny(dim_t N, index_t* array, index_t value); 00064 00066 double l2(dim_t N, const double* x, Esys_MPIInfo* mpiinfo); 00067 00070 void linearCombination(dim_t N, double* z, double a, const double* x, double b, 00071 const double* y); 00072 00074 double lsup(dim_t N, const double* x, Esys_MPIInfo* mpiinfo); 00075 00077 dim_t numPositives(dim_t N, const double* x); 00078 00081 void update(dim_t N, double a, double* x, double b, const double* y); 00082 00084 void zeroes(dim_t N, double* x); 00085 00087 inline void copy(dim_t N, double* out, const double* in) 00088 { 00089 linearCombination(N, out, 1., in, 0., in); 00090 } 00091 00093 inline void scale(dim_t N, double* x, double a) 00094 { 00095 update(N, a, x, 0, x); 00096 } 00097 00099 inline void AXPY(dim_t N, double* x, double a, const double* y) 00100 { 00101 update(N, 1., x, a, y); 00102 } 00103 00105 inline bool samesign(double a, double b) 00106 { 00107 return (a>=0 && b>=0) || (a<=0 && b<=0); 00108 } 00109 00110 } // namespace util 00111 } // namespace paso 00112 00113 #endif // __PASO_UTIL_H__ 00114