// Singular Value Decomposition and associated matrix operations // // R. Perry, 10 Jan 2022 #include #include // rand(), srand(), RAND_MAX, atoi(), getenv(), malloc(), exit() #include // time() #include "svd.h" namespace Svd { // non-template functions: // set srand() using time(0) or SRAND environment variable unsigned int SRAND() { char *env = getenv( "SRAND"); unsigned int seed = 0; if( env) seed = atoi(env); if( seed == 0) seed = time(0); srand( seed); return seed; } // 0.0 <= drand < 1.0 double drand() { return rand()/(RAND_MAX+1.0); } // print error message and exit void error( const char *msg) { std::cerr << msg << std::endl; exit(1); } // malloc with exit on error void *emalloc( unsigned long size) { void *r = malloc(size); if( !r) { error( "svd: malloc() failed"); } return r; } } // namespace Svd