Real LC::InitCavityDists( const std::string &name, const PropertySet &opts ) { double tic = toc(); if( props.verbose >= 1 ) { cerr << this->name() << "::InitCavityDists: "; if( props.cavity == Properties::CavityType::UNIFORM ) cerr << "Using uniform initial cavity distributions" << endl; else if( props.cavity == Properties::CavityType::FULL ) cerr << "Using full " << name << opts << "..."; else if( props.cavity == Properties::CavityType::PAIR ) cerr << "Using pairwise " << name << opts << "..."; else if( props.cavity == Properties::CavityType::PAIR2 ) cerr << "Using pairwise(new) " << name << opts << "..."; } Real maxdiff = 0.0; for( size_t i = 0; i < nrVars(); i++ ) { Real md = CalcCavityDist(i, name, opts); if( md > maxdiff ) maxdiff = md; } if( props.verbose >= 1 ) { cerr << this->name() << "::InitCavityDists used " << toc() - tic << " seconds." << endl; } return maxdiff; }
void CompressInterface::execute() { if( _verbose >= 1 ) { cout << "Called " << name() << " execute method..."; } if (_verbose >= 3) { cout << endl; } double tic = toc(); init(); while(!hasConverged()) { iterate(); _iters++; if( _verbose >= 3 ) { cout << name() << "::execute: #varClusters " << _varClustering.size() << ", #facClusters " << _facClustering.size() << " after " << _iters << " passes (" << toc() - tic << " secs.)" << endl; } } if( _verbose >= 1 ) { cout << "Finished in " << _iters << " iterations (" << toc() - tic << " secs.)" << endl; } }
int main(int argc, char *argv[]) { double clock; struct buffer buf; char *pattern = NULL; char *infile = NULL; char *outdir = strdup("."); parse_commandline(argc, argv, &pattern, &infile, &outdir); if(infile == NULL) return EXIT_FAILURE; MPI_Init(&argc, &argv); tic(&clock); load_file(infile, &buf); toc(&clock, "Read input:"); transfer_partials(pattern, &buf); toc(&clock, "Transfer:"); write_chunks(infile, outdir, &buf); toc(&clock, "Write chunks:"); MPI_Finalize(); free(buf.data); free(pattern); free(infile); return EXIT_SUCCESS; }
/* solve a linear system using Cholesky, LU, and QR, with various orderings */ cs_long_t demo2 (problem *Prob) { cs_cl *A, *C ; cs_complex_t *b, *x, *resid ; double t, tol ; cs_long_t k, m, n, ok, order, nb, ns, *r, *s, *rr, sprank ; cs_cld *D ; if (!Prob) return (0) ; A = Prob->A ; C = Prob->C ; b = Prob->b ; x = Prob->x ; resid = Prob->resid; m = A->m ; n = A->n ; tol = Prob->sym ? 0.001 : 1 ; /* partial pivoting tolerance */ D = cs_cl_dmperm (C, 1) ; /* randomized dmperm analysis */ if (!D) return (0) ; nb = D->nb ; r = D->r ; s = D->s ; rr = D->rr ; sprank = rr [3] ; for (ns = 0, k = 0 ; k < nb ; k++) { ns += ((r [k+1] == r [k]+1) && (s [k+1] == s [k]+1)) ; } printf ("blocks: %g singletons: %g structural rank: %g\n", (double) nb, (double) ns, (double) sprank) ; cs_cl_dfree (D) ; for (order = 0 ; order <= 3 ; order += 3) /* natural and amd(A'*A) */ { if (!order && m > 1000) continue ; printf ("QR ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_cl_qrsol (order, C, x) ; /* min norm(Ax-b) with QR */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } if (m != n || sprank < n) return (1) ; /* return if rect. or singular*/ for (order = 0 ; order <= 3 ; order++) /* try all orderings */ { if (!order && m > 1000) continue ; printf ("LU ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_cl_lusol (order, C, x, tol) ; /* solve Ax=b with LU */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } if (!Prob->sym) return (1) ; for (order = 0 ; order <= 1 ; order++) /* natural and amd(A+A') */ { if (!order && m > 1000) continue ; printf ("Chol ") ; print_order (order) ; rhs (x, b, m) ; /* compute right-hand side */ t = tic () ; ok = cs_cl_cholsol (order, C, x) ; /* solve Ax=b with Cholesky */ printf ("time: %8.2f ", toc (t)) ; print_resid (ok, C, x, b, resid) ; /* print residual */ } return (1) ; }
void ZDvidTile::update(int z) { if (m_z != z || m_image == NULL) { #if defined(_ENABLE_LIBDVIDCPP_2) std::vector<int> offset(3); offset[0] = m_ix; offset[1] = m_iy; offset[2] = z; tic(); try { libdvid::DVIDNodeService service(getDvidTarget().getAddressWithPort(), getDvidTarget().getUuid()); libdvid::BinaryDataPtr data = service.get_tile_slice_binary( "tiles", libdvid::XY, m_res.getLevel(), offset); if (data->length() > 0) { loadDvidSlice(data->get_raw(), data->length(), z); m_image->setScale(1.0 / m_res.getScale(), 1.0 / m_res.getScale()); m_image->setOffset(-getX(), -getY()); } } catch (std::exception &e) { std::cout << e.what() << std::endl; } std::cout << "Tile level: " << m_res.getLevel() << std::endl; std::cout << "Tile reading time: " << toc() << std::endl; #else ZDvidUrl dvidUrl(getDvidTarget()); ZDvidBufferReader bufferReader; /* QFuture<void> result = QtConcurrent::run( &bufferReader, &ZDvidBufferReader::read, QString(dvidUrl.getTileUrl("graytiles", m_res.getLevel(), m_ix, m_iy, z).c_str())); result.waitForFinished(); */ tic(); bufferReader.read( dvidUrl.getTileUrl(getDvidTarget().getMultiscale2dName(), m_res.getLevel(), m_ix, m_iy, z).c_str()); QByteArray buffer = bufferReader.getBuffer(); std::cout << "Tile reading time: " << toc() << std::endl; // ZDvidTileInfo tileInfo = readTileInfo("graytiles"); if (!buffer.isEmpty()) { loadDvidSlice(buffer, z); // m_image->setScale(1.0 / m_res.getScale(), 1.0 / m_res.getScale()); // m_image->setOffset(-getX(), -getY()); // setResolutionLevel(m_res.getLevel()); } #endif } //m_z = z; }
/* ************************************************************************* */ bool choleskyPartial(Matrix& ABC, size_t nFrontal) { const bool debug = ISDEBUG("choleskyPartial"); assert(ABC.rows() == ABC.cols()); assert(ABC.rows() >= 0 && nFrontal <= size_t(ABC.rows())); const size_t n = ABC.rows(); // Compute Cholesky factorization of A, overwrites A. tic(1, "lld"); Eigen::LLT<Matrix, Eigen::Upper> llt = ABC.block(0,0,nFrontal,nFrontal).selfadjointView<Eigen::Upper>().llt(); ABC.block(0,0,nFrontal,nFrontal).triangularView<Eigen::Upper>() = llt.matrixU(); toc(1, "lld"); if(debug) cout << "R:\n" << Eigen::MatrixXd(ABC.topLeftCorner(nFrontal,nFrontal).triangularView<Eigen::Upper>()) << endl; // Compute S = inv(R') * B tic(2, "compute S"); if(n - nFrontal > 0) { ABC.topLeftCorner(nFrontal,nFrontal).triangularView<Eigen::Upper>().transpose().solveInPlace( ABC.topRightCorner(nFrontal, n-nFrontal)); } if(debug) cout << "S:\n" << ABC.topRightCorner(nFrontal, n-nFrontal) << endl; toc(2, "compute S"); // Compute L = C - S' * S tic(3, "compute L"); if(debug) cout << "C:\n" << Eigen::MatrixXd(ABC.bottomRightCorner(n-nFrontal,n-nFrontal).selfadjointView<Eigen::Upper>()) << endl; if(n - nFrontal > 0) ABC.bottomRightCorner(n-nFrontal,n-nFrontal).selfadjointView<Eigen::Upper>().rankUpdate( ABC.topRightCorner(nFrontal, n-nFrontal).transpose(), -1.0); if(debug) cout << "L:\n" << Eigen::MatrixXd(ABC.bottomRightCorner(n-nFrontal,n-nFrontal).selfadjointView<Eigen::Upper>()) << endl; toc(3, "compute L"); // Check last diagonal element - Eigen does not check it bool ok; if(llt.info() == Eigen::Success) { if(nFrontal >= 2) { int exp2, exp1; (void)frexp(ABC(nFrontal-2, nFrontal-2), &exp2); (void)frexp(ABC(nFrontal-1, nFrontal-1), &exp1); ok = (exp2 - exp1 < underconstrainedExponentDifference); } else if(nFrontal == 1) { int exp1; (void)frexp(ABC(0,0), &exp1); ok = (exp1 > -underconstrainedExponentDifference); } else { ok = true; } } else { ok = false; } return ok; }
/* metoda CG */ void CG(double * b, double a, double * x, unsigned int n) { double * r, * p, * w, ro1, ro2, beta, alfa; int i, iterations; r = malloc(sizeof(double)*n); p = malloc(sizeof(double)*n); w = malloc(sizeof(double)*n); bzero(x, sizeof(double)*n); tic(); r[0] = b[0] + a*x[0] - x[1]; for ( i = 1; i < n - 1; ++i ) r[i] = b[i] + a*x[i] - x[i+1] - x[i-1]; r[n-1] = b[n-1] + a*x[n-1] - x[n-2]; ro1 = 0; for ( i = 0; i < n; ++i ) ro1 += r[i]*r[i]; beta = 0; iterations = 0; while ( ++iterations ) { for ( i = 0; i < n; ++i ) p[i] = r[i] + beta*p[i]; w[0] = a*p[0] - p[1]; for ( i = 1; i < n - 1; ++i ) w[i] = a*p[i] - p[i+1] - p[i-1]; w[n-1] = a*p[n-1] - p[n-2]; alfa = 0; for ( i = 0; i < n; ++i ) alfa += p[i]*w[i]; alfa = ro1 / alfa; for ( i = 0; i < n; ++i ) x[i] = x[i] + alfa*p[i]; for ( i = 0; i < n; ++i ) r[i] = r[i] - alfa*w[i]; ro2 = 0; for ( i = 0; i < n; ++i ) ro2 += r[i]*r[i]; if ( ro1 <= EPSILON2 ) { printf("\n| residuum | < epsilon = %e!\n", EPSILON2); STOP(a, x, b, n, iterations, toc(), 1); break; /* gdy wyniki bardzo dokladne, jest dzielenie przez 0 */ } beta = ro2 / ro1; ro1 = ro2; if ( STOP(a, x, b, n, iterations, toc(), 0) ) break; } free(r); free(p); free(w); }
void K3bCddbLocalQuery::doQuery() { emit infoMessage( i18n("Searching entry in %1").arg( m_cddbDir ) ); kapp->processEvents(); //BAD! QString path = preparePath( m_cddbDir ); kdDebug() << "(K3bCddbLocalQuery) searching in dir " << path << " for " << QString::number( toc().discId(), 16 ).rightJustify( 8, '0' ) << endl; for( QStringList::const_iterator it = categories().begin(); it != categories().end(); ++it ) { QString file = path + *it + "/" + QString::number( toc().discId(), 16 ).rightJustify( 8, '0' ); if( QFile::exists( file ) ) { // found file QFile f( file ); if( !f.open( IO_ReadOnly ) ) { kdDebug() << "(K3bCddbLocalQuery) Could not open file" << endl; } else { QTextStream t( &f ); K3bCddbResultEntry entry; parseEntry( t, entry ); K3bCddbResultHeader header; header.discid = QString::number( toc().discId(), 16 ).rightJustify( 8, '0' ); header.category = *it; header.title = entry.cdTitle; header.artist = entry.cdArtist; m_inexactMatches.append(header); } } else { kdDebug() << "(K3bCddbLocalQuery) Could not find local entry in category " << *it << endl; } } if( m_inexactMatches.count() > 0 ) { setError( SUCCESS ); if( m_inexactMatches.count() == 1 ) { queryMatch( m_inexactMatches.first() ); } else { emit inexactMatches( this ); } } else { setError( NO_ENTRY_FOUND ); emit queryFinished( this ); } }
static int test_fit(){ info("Fit\n"); dcell *opdr=dcellread("opdr.bin"); MUV_T FR; FR.M=dspcellread("FRM.bin"); FR.U=dcellread("FRU.bin"); FR.V=dcellread("FRV.bin"); MUV_T FL; FL.M=dspcellread("FLM.bin"); FL.U=dcellread("FLU.bin"); FL.V=dcellread("FLV.bin"); dcell *rhs=NULL; tic; for(int i=0; i<10; i++) MUV(&rhs, &FR, opdr, 1); toc(""); dcell *MUV_f=NULL; tic; for(int i=0; i<10; i++) MUV(&MUV_f, &FL, rhs, 1); toc(""); writebin(rhs,"fit_rhs1.bin"); writebin(MUV_f,"MUV_f.bin"); RECON_T *recon=mycalloc(1,RECON_T); recon->HX=dspcellread("HX.bin"); recon->HA=dspcellread("HA.bin"); recon->W1=dread("W1.bin"); recon->W0=dspread("W0.bin"); recon->NW=dcellread("NW.bin"); recon->fitwt=dread("fitwt.bin"); dcell *rhs2=NULL; tic; for(int i=0; i<10; i++) FitR(&rhs2, recon, opdr, 1); toc(""); writebin(rhs2,"fit_rhs2.bin"); tic; dcell *FitL_f=NULL; for(int i=0; i<10; i++) FitL(&FitL_f, recon, rhs2, 1); toc(""); writebin(FitL_f,"FitL_f.bin"); info("Diff between rhs is %g\n", dcelldiff(rhs, rhs2)); info("Diff between lhs is %g\n", dcelldiff(MUV_f, FitL_f)); dcellfree(rhs); dcellfree(MUV_f); dcellfree(rhs2); dcellfree(FitL_f); return 0; }
void Jacobi(double * b, double a, double * x, unsigned int n) { /* x(k+1) = M N x(k) - M b */ double lambda = ( a + 2.0*cos(PI / (((double) n)+1.0)) ); double px, tx; double eta = ( a - lambda ); unsigned int i; int iterations = 0; bzero( x, sizeof(double)*n ); tic(); while ( ++iterations ) { px = x[0]; x[0] = -( eta*x[0] - x[1] - b[0] ) / lambda; for ( i = 1; i < n - 1; ++i ) { tx = x[i]; x[i] = -( eta*tx - px - x[i+1] - b[i] ) / lambda; px = tx; } x[n-1] = -( eta*x[n-1] - px - b[n-1] ) / lambda; if ( STOP(a, x, b, n, iterations, toc(), 0) ) break; } }
ulong PNStream_SetDataCallback(ulong p1,ulong p2,ulong p3,ulong p4) { ulong result; int i=0; void **pp; fprintf(stderr, "PNStream_SetDataCallback(ulong p1=0x%0x(%d), ", p1, p1); fprintf(stderr, "ulong p2=0x%0x(%d),\n\t", p2, p2); fprintf(stderr, "ulong p3=0x%0x(%d),", p3, p3); fprintf(stderr, "ulong p4=0x%0x(%d))\n", p4, p4); hexdump((void*)p1, 0x24); hexdump((void*)p2, 32); hexdump((void*)p3, 4); hexdump((void*)p4, 32); fprintf(stderr, "content of the callback functions:\n\n"); while(i<8) { hexdump(*((void**)p2+i), (i==0)?32*4:16); i++; } i=0; pp=(*(void***)p2); fprintf(stderr, "content of the callback functions (first entry):\n\n"); while(i<15) { hexdump(*((void**)pp+i), 32); i++; } tic(); result=(*pnsSetDataCallback)(p1,p2,p3,p4); toc(); hexdump((void*)p1, 0x24); // hexdump((void*)p2, 256); // hexdump((void*)p3, 4); hexdump(*((void**)p3), 256); fprintf(stderr, "PNStream_SetDataCallback --> 0x%0x(%d)\n\n\n", result, result); return result; }
float Timer::toc(std::string const &msg) { float duration_one = toc(); printf("%s %.2f\n", msg.c_str(), duration_one); fflush(stdout); return duration_one; }
void SERVICE_fwd(float* in, int in_size, float* out, int out_size, Net<float>* net) { string net_name = net->name(); STATS_INIT("service", "DjiNN service inference"); PRINT_STAT_STRING("network", net_name.c_str()); if (Caffe::mode() == Caffe::CPU) PRINT_STAT_STRING("platform", "cpu"); else PRINT_STAT_STRING("platform", "gpu"); float loss; vector<Blob<float>*> in_blobs = net->input_blobs(); tic(); in_blobs[0]->set_cpu_data(in); vector<Blob<float>*> out_blobs = net->ForwardPrefilled(&loss); memcpy(out, out_blobs[0]->cpu_data(), sizeof(float)); PRINT_STAT_DOUBLE("inference latency", toc()); STATS_END(); if (out_size != out_blobs[0]->count()) LOG(FATAL) << "out_size =! out_blobs[0]->count())"; else memcpy(out, out_blobs[0]->cpu_data(), out_size * sizeof(float)); }
EdgeList generateEdgeList(int argc, char** argv, packed_edge** output){ int log_numverts; int64_t nedges; packed_edge* result; log_numverts = 16; /* In base 2 */ if (argc >= 2) log_numverts = atoi(argv[1]); make_graph(log_numverts, INT64_C(16) << log_numverts, 1, 2, &nedges, &result); printf("nedges=%ld before\n",nedges); //remove loops: #if rmdup tic(); packed_edge* end=thrust::remove_if(result, result+nedges, is_loop()); //sort packed_edge twice: thrust::sort(result,end,pe_less1()); thrust::sort(result,end,pe_less2()); //nedges=(end-result); //printf("nedges=%d after loop\n",nedges); //remove duplicates: end=thrust::unique(result,end); cudaDeviceSynchronize(); elapsed_time+=toc(); printf("remove dup took %f ms\n", elapsed_time); //TEMP: reset elapsed time: elapsed_time=0; nedges=(end-result); printf("nedges=%ld after dup\n",nedges); // #endif uusi::EdgeList el=graph500ToEdgeList((const packed_edge*)result,nedges); *output=result; return el; }
int PreconditionerBlockMS<space_type>::applyInverse ( const vector_type& X, vector_type& Y ) const { tic(); U = X; U.close(); *M_uin = U.template element<0>(); M_uin->close(); *M_pin = U.template element<1>(); M_pin->close(); // Solve eq (12) // solve here eq 15 : Pm v = c backend(_name=M_prefix_11)->solve(_matrix=M_11, _rhs=M_uin, _solution=M_uout ) ; M_uout->close(); // solve here eq 16 backend(_name=M_prefix_22)->solve(_matrix=M_L, _rhs=M_pin, _solution=M_pout ); M_pout->close(); U.template element<0>() = *M_uout; U.template element<1>() = *M_pout; U.close(); Y=U; Y.close(); toc("[PreconditionerBlockMS] applyInverse update solution",FLAGS_v>0); return 0; }
/// Program entry int main( int argc, char* argv[] ) { // Config using real = double; const real p1 = 1.1; const real p2 = 1.2; const real p3 = 1.3; const double warming_time = 1.; const double run_time = 10.; const std::size_t min_run = 3; // Command-line parameters const std::size_t dimension = std::stoull(argv[1]); const std::size_t nsample1 = std::stoull(argv[2]); const std::size_t nsample2 = std::stoull(argv[3]); // Kernel initialization Kernel<real> kernel(dimension, nsample1, nsample2); kernel.init(p1, p2, p3); // Runs std::size_t nrun = 0; bool is_warming = true; double total_duration = 0; tic(); while ( true ) { kernel.run(); total_duration = toc(); // Managing warming and run time if (is_warming && total_duration >= warming_time) { is_warming = false; tic(); } else if (! is_warming) { ++nrun; // Ending benchmark if ( total_duration >= run_time && nrun >= min_run ) break; } } // Checksum const double checksum = kernel.checksum(); // Mean duration const double duration = total_duration / nrun; // Displaying results std::cout << std::fixed; std::cout << duration << " " << checksum << std::endl; return 0; }
Real LC::run() { if( props.verbose >= 1 ) cerr << "Starting " << identify() << "..."; if( props.verbose >= 2 ) cerr << endl; double tic = toc(); Real md = InitCavityDists( props.cavainame, props.cavaiopts ); if( md > _maxdiff ) _maxdiff = md; for( size_t i = 0; i < nrVars(); i++ ) { _pancakes[i] = _cavitydists[i]; foreach( const Neighbor &I, nbV(i) ) { _pancakes[i] *= factor(I); if( props.updates == Properties::UpdateType::SEQRND ) _pancakes[i] *= _phis[i][I.iter]; } _pancakes[i].normalize(); CalcBelief(i); }
double measureDuration(unsigned long iterations, void (*fp)(unsigned long)) { tic(); fp(iterations); toc(); return getElapsedTime(); }
void Timer::stop() { elapsed_ += toc(id_); elapsed_ -= paused_; paused_ = 0; int i = (iterations_ + 1) % (interval_ + 1); if(i == 0) restart(); else iterations_ = i; }
int main_speedtestvector() { std::cout << "Main has started!" << std::endl; tic(); std::vector<double> v1; v1 = fillVec1(); toc(); tic(); std::vector<double> v2(SIZE); std::vector<double> v3 = fillVec2(v2); toc(); std::cout << "Main has finished!" << std::endl; return 0; }
void PreconditionerBlockMS<space_type>::init( void ) { if( Environment::worldComm().isMasterRank() ) std::cout << "Init preconditioner blockms\n"; LOG(INFO) << "Init ...\n"; tic(); BoundaryConditions M_bc = M_model.boundaryConditions(); LOG(INFO) << "Create sub Matrix\n"; map_vector_field<FEELPP_DIM,1,2> m_dirichlet_u { M_bc.getVectorFields<FEELPP_DIM> ( "u", "Dirichlet" ) }; map_scalar_field<2> m_dirichlet_p { M_bc.getScalarFields<2> ( "phi", "Dirichlet" ) }; /* * AA = [[ A - k^2 M, B^t], * [ B , 0 ]] * We need to extract A-k^2 M and add it M to form A+(1-k^2) M = A+g M */ // Is the zero() necessary ? M_11->zero(); this->matrix()->updateSubMatrix(M_11, M_Vh_indices, M_Vh_indices, false); // M_11 = A-k^2 M LOG(INFO) << "Use relax = " << M_relax << std::endl; M_11->addMatrix(M_relax,M_mass); // A-k^2 M + M_relax*M = A+(M_relax-k^2) M auto f2A = form2(_test=M_Vh, _trial=M_Vh,_matrix=M_11); auto f1A = form1(_test=M_Vh); for(auto const & it : m_dirichlet_u ) f2A += on(_range=markedfaces(M_Vh->mesh(),it.first), _expr=it.second,_rhs=f1A, _element=u, _type="elimination_symmetric"); /* * Rebuilding sub-backend */ backend(_name=M_prefix_11, _rebuild=true); backend(_name=M_prefix_22, _rebuild=true); // We have to set the G, Px,Py,Pz or X,Y,Z matrices to AMS if(soption(_name="pc-type", _prefix=M_prefix_11) == "ams") { #if FEELPP_DIM == 3 initAMS(); { if(boption(_name="setAlphaBeta",_prefix=M_prefix_11)) { auto prec = preconditioner(_pc=pcTypeConvertStrToEnum(soption(M_prefix_11+".pc-type")), _backend=backend(_name=M_prefix_11), _prefix=M_prefix_11, _matrix=M_11 ); prec->setMatrix(M_11); prec->attachAuxiliarySparseMatrix("a_alpha",M_a_alpha); prec->attachAuxiliarySparseMatrix("a_beta",M_a_beta); } } #else std::cerr << "ams preconditioner is not interfaced in two dimensions\n"; #endif } toc("[PreconditionerBlockMS] Init",FLAGS_v>0); LOG(INFO) << "Init done\n"; }
int main(void) { /*Matrix& A0 = *new DenseMatrix(new double[4] {1, 2, 3, 4}, 4, 1); disp(A0); Matrix& A1 = reshape(A0, new int[2] {2, 2}); disp(A1);*/ int m = 8; int r = m / 4; Matrix& L = randn(m, r); Matrix& R = randn(m, r); Matrix& A_star = mtimes(L, R.transpose()); Matrix& E_star0 = zeros(size(A_star)); int* indices = randperm(m * m); int nz = m * m / 20; int* nz_indices = new int[nz]; for (int i = 0; i < nz; i++) { nz_indices[i] = indices[i] - 1; } Matrix& E_vec = vec(E_star0); Matrix& Temp = (minus(rand(nz, 1), 0.5).times(100)); // disp(Temp); setSubMatrix(E_vec, nz_indices, nz, new int[1] {0}, 1, Temp); // disp(E_vec); Matrix& E_star = reshape(E_vec, size(E_star0)); // disp(E_star); // Input Matrix& D = A_star.plus(E_star); double lambda = 1 * pow(m, -0.5); RobustPCA& robustPCA = *new RobustPCA(lambda); robustPCA.feedData(D); tic(); robustPCA.run(); fprintf("Elapsed time: %.2f seconds.\n", toc()); // Output Matrix& A_hat = robustPCA.GetLowRankEstimation(); Matrix& E_hat = robustPCA.GetErrorMatrix(); fprintf("A*:\n"); disp(A_star, 4); fprintf("A^:\n"); disp(A_hat, 4); fprintf("E*:\n"); disp(E_star, 4); fprintf("E^:\n"); disp(E_hat, 4); fprintf("rank(A*): %d\n", rank(A_star)); fprintf("rank(A^): %d\n", rank(A_hat)); fprintf("||A* - A^||_F: %.4f\n", norm(A_star.minus(A_hat), "fro")); fprintf("||E* - E^||_F: %.4f\n", norm(E_star.minus(E_hat), "fro")); return EXIT_SUCCESS; }
static int test_tomo(){ info("Tomo\n"); dcell *grad=dcellread("grad.bin"); MUV_T RR; RR.M=dspcellread("RRM.bin"); RR.U=dcellread("RRU.bin"); RR.V=dcellread("RRV.bin"); tic; dcell *rhs=NULL; MUV(&rhs, &RR, grad, 1); toc(""); writebin(rhs,"rhs.bin"); MUV_T RL; RL.M=dspcellread("RLM.bin"); RL.U=dcellread("RLU.bin"); RL.V=dcellread("RLV.bin"); dcell *junk=NULL; tic; for(int i=0; i<1; i++){ MUV(&junk, &RL, rhs, 1); } toc(""); writebin(junk,"MUV1.bin"); RECON_T *recon=mycalloc(1,RECON_T); recon->G0=dspcellread("G0.bin"); recon->TT=dcellread("TT.bin"); recon->PTT=dcellread("PTT.bin"); recon->L2=dspcellread("L2.bin"); recon->ZZT=dspcellread("ZZT.bin"); recon->saneai=dspcellread("saneai.bin"); tic; dcell *rhs2=NULL; TomoR(&rhs2, recon, grad, 1); toc(""); writebin(rhs2,"rhs2.bin"); dcell *junk2=NULL; tic; TomoL(&junk2, recon, rhs, 1); toc(""); writebin(junk2,"TomoL1.bin"); info("Diff between rhs is %g\n", dcelldiff(rhs, rhs2)); info("Diff between lhs is %g\n", dcelldiff(junk,junk2)); return 0; }
ulong RV20toYUV420_RN_FRU_Free(ulong p1) { ulong result; fprintf(stderr, "RV20toYUV420_RN_FRU_Free(ulong p1=0x%0x(%d))\n", p1, p1); tic(); result=(*rvyuvRNFRUFree)(p1); toc(); fprintf(stderr, "RV20toYUV420_RN_FRU_Free --> 0x%0x(%d)\n\n\n", result, result); return result; }
void cmd_nlls() { Real *work, *y, *bounds, *covar, *p; int nQ = count_data(); int ndim = fit[0].pars.n; int i; /* Allocate storage: y, covar, bounds, p */ work = (Real *)malloc(sizeof(Real)*(nQ + ndim*ndim + 3*ndim)); assert(work != NULL); y = work; bounds = y + nQ; covar = bounds + 2*ndim; p = covar + ndim*ndim; write_pop(&set); /* In case fit crashes */ /* Record what we are doing */ if (parFD != NULL) { fprintf(parFD,"# %15d Starting Levenberg-Marquardt\n", GetGen(&set)); fflush(parFD); } /* Copy normalized data values */ copy_normalized_data(y); /* Set bounds */ for (i=0; i < ndim; i++) { bounds[i] = 0.; bounds[i+ndim] = 1.; } /* Get best into p */ pars_set(&fit[0].pars, bestpars); pars_get01(&fit[0].pars, p); /* Call nlls */ tic(); #if 1 box_nlls(step_nlls, ndim, nQ, fit, y, bounds, p, covar); #else nlls(step_nlls, ndim, nQ, fit, y, p, covar); #endif printf("Done LM\n");fflush(stdout); toc(); print_covar(ndim,covar); /* Record LM results */ log_best(); /* Inject new p into the GA */ setChromosome(&set, 0, p); /* Done */ free(work); }
void msm_vidc_debugfs_update(struct msm_vidc_inst *inst, enum msm_vidc_debugfs_event e) { struct msm_vidc_debug *d = &inst->debug; char a[64] = "Frame processing"; switch (e) { case MSM_VIDC_DEBUGFS_EVENT_ETB: inst->count.etb++; if (inst->count.ebd && inst->count.ftb > inst->count.fbd) { d->pdata[FRAME_PROCESSING].name[0] = '\0'; tic(inst, FRAME_PROCESSING, a); } break; case MSM_VIDC_DEBUGFS_EVENT_EBD: inst->count.ebd++; if (inst->count.ebd && inst->count.ebd == inst->count.etb) { toc(inst, FRAME_PROCESSING); dprintk(VIDC_PROF, "EBD: FW needs input buffers\n"); } if (inst->count.ftb == inst->count.fbd) dprintk(VIDC_PROF, "EBD: FW needs output buffers\n"); break; case MSM_VIDC_DEBUGFS_EVENT_FTB: { inst->count.ftb++; if (inst->count.ebd && inst->count.etb > inst->count.ebd) { d->pdata[FRAME_PROCESSING].name[0] = '\0'; tic(inst, FRAME_PROCESSING, a); } } break; case MSM_VIDC_DEBUGFS_EVENT_FBD: inst->debug.samples++; if (inst->count.ebd && inst->count.fbd == inst->count.ftb) { toc(inst, FRAME_PROCESSING); dprintk(VIDC_PROF, "FBD: FW needs output buffers\n"); } if (inst->count.etb == inst->count.ebd) dprintk(VIDC_PROF, "FBD: FW needs input buffers\n"); break; default: dprintk(VIDC_ERR, "Invalid state in debugfs: %d\n", e); break; } }
void test1d(int nfft,int isinverse) { char mensaje [128]; clock_t start; clock_t end; size_t buflen = sizeof(kiss_fft_cpx)*nfft; kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen); kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen); kiss_fft_cfg cfg = kiss_fft_alloc(nfft,0,0); int k; for (k=0;k<nfft;++k) { in[k].r = (rand() % 32767) - 16384; in[k].i = (rand() % 32767) - 16384; } #ifdef DOUBLE_PRECISION for (k=0;k<nfft;++k) { in[k].r *= 32768; in[k].i *= 32768; } #endif if (isinverse) { for (k=0;k<nfft;++k) { in[k].r /= nfft; in[k].i /= nfft; } } /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/ //start=TPM3CNT; //tic tic(); if (isinverse) kiss_ifft(cfg,in,out); else kiss_fft(cfg,in,out); toc(); //end =TPM3CNT; //toc /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/ check(in,out,nfft,isinverse); free(in); free(out); free(cfg); }
ulong PNStream_GetIPNUnknown(ulong p1) { ulong result; fprintf(stderr, "PNStream_GetIPNUnknown(ulong p1=0x%0x(%d))\n", p1, p1); // hexdump((void*)p1, 44); tic(); result=(*pnsGetIPNUnknown)(p1); toc(); // hexdump((void*)p1, 44); fprintf(stderr, "PNStream_GetIPNUnknown --> 0x%0x(%d)\n\n\n", result, result); return result; }
ulong PNCodec_Close(ulong p1) { ulong result; fprintf(stderr, "PNCodec_Close(PNCMain *pncMain=0x%0x(%d))\n", p1, p1); // hexdump((void*)p1, 44); tic(); result=(*pncClose)(p1); toc(); // hexdump((void*)p1, 44); fprintf(stderr, "PNCodec_Close --> 0x%0x(%d)\n\n\n", result, result); return result; }
ulong PNStream_Close(ulong p1) { ulong result; fprintf(stderr, "PNStream_Close(ulong p1=0x%0x(%d))\n", p1, p1); // hexdump((void*)p1, 44); tic(); result=(*pnsClose)(p1); toc(); // hexdump((void*)p1, 44); fprintf(stderr, "PNStream_Close --> 0x%0x(%d)\n\n\n", result, result); return result; }