int main(int argc, char** argv) { Matrix<int,ColMajor> Ai(rows,cols); // a column-major integer matrix Matrix<float> Af(rows,cols); // a row-major single precision floating point matrix Matrix<double> Ad(rows,cols); // a row-major double precision floating point matrix // grab seed from the current timestamp unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); // instance a random number generator std::default_random_engine generator (seed); // instance a uniform distribution std::uniform_real_distribution<double> random(0.0, 1.0); // note that the loop order is not optimal for the integer matrix size_t k=1; for (size_t i=0;i<rows;++i) { for (size_t j=0;j<cols;++j, k++) { Ai(i,j) = k; Af(i,j) = k+random(generator); // add some random stuff for fun Ad(i,j) = k+random(generator); // add some random stuff for fun } } // print matrices to screen std::cout << "== Integer matrix ==" << std::endl; Ai.print(); std::cout << "== Float matrix ==" << std::endl; Af.print(7); std::cout << "== Double matrix ==" << std::endl; Ad.print(16); return 0; }
static void fontPrintTextImpl(FT_Bitmap* bitmap, int xofs, int yofs, u32 text_color, u32* framebuffer, int width, int height, int lineSize){ int x, y; u8* line = bitmap->buffer; u32* fbLine = framebuffer + xofs + yofs * lineSize; for (y = 0; y < bitmap->rows; y++) { u8* column = line; u32* fbColumn = fbLine; for (x = 0; x < bitmap->width; x++) { if (x + xofs < width && x + xofs >= 0 && y + yofs < height && y + yofs >= 0) { u8 val = *column; u32 color = *fbColumn; float f_val = ((float)val) / 255.0; f_val *= Af(text_color); float r = min(1.0, Rf(text_color) * f_val + Rf(color) * (1.0 - f_val)); float g = min(1.0, Gf(text_color) * f_val + Gf(color) * (1.0 - f_val)); float b = min(1.0, Bf(text_color) * f_val + Bf(color) * (1.0 - f_val)); float a = min(1.0, Af(color) + f_val); *fbColumn = RGBAf(r, g, b, a); } column++; fbColumn++; } line += bitmap->pitch; fbLine += lineSize; } // gePrintDebug(0x100, "fontPrintTextImpl(bitmap, %d, %d, 0x%8.8X, framebuffer, %d, %d, %d)\n", xofs, yofs, color, width, height, lineSize); /* u8* line = bitmap->buffer; u32* fbLine = framebuffer + xofs + yofs * lineSize; for (y = 0; y < bitmap->rows; y++) { u8* column = line; u32* fbColumn = fbLine; for (x = 0; x < bitmap->width; x++) { if (x + xofs < width && x + xofs >= 0 && y + yofs < height && y + yofs >= 0) { u8 val = *column; color = *fbColumn; u8 r = color & 0xff; u8 g = (color >> 8) & 0xff; u8 b = (color >> 16) & 0xff; u8 a = (color >> 24) & 0xff; r = rf * val / 255 + (255 - val) * r / 255; g = gf * val / 255 + (255 - val) * g / 255; b = bf * val / 255 + (255 - val) * b / 255; a = af * val / 255 + (255 - val) * a / 255; *fbColumn = RGBA(r, g, b, a); // *fbColumn = RGBA(255, 255, 255, val); } column++; fbColumn++; } line += bitmap->pitch; fbLine += lineSize; } */ }
void RpalParser::At() { pushProc("At()"); Af(); string temp = _nt; while (_nt == "*" || _nt == "/") { read_token(_nt); Af(); build(temp, 2); temp = _nt; } popProc("At()"); }
float AffineTransformerImpl::applyTransformation(InputArray inPts, OutputArray outPts) { Mat pts1 = inPts.getMat(); CV_Assert((pts1.channels()==2) && (pts1.cols>0)); //Apply transformation in the complete set of points Mat fAffine; transform(pts1, fAffine, affineMat); // Ensambling output // if (outPts.needed()) { outPts.create(1,fAffine.cols, CV_32FC2); Mat outMat = outPts.getMat(); for (int i=0; i<fAffine.cols; i++) outMat.at<Point2f>(0,i)=fAffine.at<Point2f>(0,i); } // Updating Transform Cost // Mat Af(2, 2, CV_32F); Af.at<float>(0,0)=affineMat.at<float>(0,0); Af.at<float>(0,1)=affineMat.at<float>(1,0); Af.at<float>(1,0)=affineMat.at<float>(0,1); Af.at<float>(1,1)=affineMat.at<float>(1,1); SVD mysvd(Af, SVD::NO_UV); Mat singVals=mysvd.w; transformCost=std::log((singVals.at<float>(0,0)+FLT_MIN)/(singVals.at<float>(1,0)+FLT_MIN)); return transformCost; }
void RpalParser::Af() { pushProc("Af()"); Ap(); while (_nt == "**") { read_token(_nt); Af(); build("**", 2); } popProc("Af()"); }
void DenseLinearEigenSystem<double>::eigensolve_lapack_without_vectors() { #ifndef LAPACK std::string problem; problem = "The DenseLinearEigenSystem::eigensolve_lapack_without_vectors method has been called\n"; problem += "but the compiler option -DLAPACK was not provided when\n"; problem += "the library was built."; throw ExceptionExternal( problem ); #else std::size_t N = p_A -> nrows(); // Cache issues of varying significance plague problems of size 2^j + 2^k + ... // when LDA = N, so this is my shameless 'tweak' to maintain predictable // performance, at least for N <=1024 or so. int padding( 0 ); if ( ( N % 2 == 0 ) && ( N > 127 ) ) { padding = 1; } #ifdef PARANOID if ( ( p_A -> nrows() != p_B -> nrows() ) || ( p_A -> ncols() != p_B -> ncols() ) ) { std::string problem( "The DenseLinearEigenSystem::eigensolve_lapack_without_vectors method has detected a failure \n" ); throw ExceptionGeom( problem, p_A -> nrows(), p_A -> ncols(), p_B -> nrows(), p_B -> ncols() ); } #endif FortranData Af( *p_A, true, padding ); FortranData Bf( *p_B, true, padding ); // eigenvalue storage DenseVector<double> alpha_r( N, 0.0 ); DenseVector<double> alpha_i( N, 0.0 ); DenseVector<double> beta( N, 0.0 ); // eigenvector storage DenseVector<double> vec_left( 1, 0.0 ); DenseVector<double> vec_right( 1, 0.0 ); // some workspace for the LAPACK routine DenseVector<double> work( 1, 0.0 ); int info( 0 ); // Call FORTRAN LAPACK to get the required workspace LAPACK_DGGEV( ( char* ) "N", ( char* ) "N", N, Af.base(), N + padding, Bf.base(), N + padding, &alpha_r[ 0 ], &alpha_i[ 0 ], &beta[ 0 ], &vec_left[ 0 ], 1, &vec_right[ 0 ], 1, &work[ 0 ], -1, info ); int required_workspace = ( int ) work[ 0 ]; #ifdef DEBUG std::cout << " [DEBUG] DenseLinearEigenSystem::eigensolve_lapack_without_vectors is requesting \n"; std::cout << " [DEBUG] a workspace vector of size " << required_workspace << "\n"; #endif work.resize( required_workspace ); // call FORTRAN LAPACK again with the optimum workspace LAPACK_DGGEV( ( char* ) "N", ( char* ) "N", N, Af.base(), N + padding, Bf.base(), N + padding, &alpha_r[ 0 ], &alpha_i[ 0 ], &beta[ 0 ], &vec_left[ 0 ], 1, &vec_right[ 0 ], 1, &work[ 0 ], required_workspace, info ); if ( 0 != info ) { std::string problem( "The DenseLinearEigenSystem::eigensolve_lapack_without_vectors method has detected a failure. \n" ); throw ExceptionExternal( problem, info ); } // create a complex eigenvalue vector EIGENVALUES_ALPHA = DenseVector<D_complex>( N, 0.0 ); for ( std::size_t i = 0; i < N; ++i ) { const D_complex eye( 0.0, 1.0 ); EIGENVALUES_ALPHA[ i ] = alpha_r[ i ] + alpha_i[ i ] * eye; } // set the eigenvalue member data EIGENVALUES_BETA = beta; #endif }
void DenseLinearEigenSystem< double >::eigensolve_lapack_with_vectors() { #ifndef LAPACK std::string problem; problem = "The DenseLinearEigenSystem::eigensolve_lapack_with_vectors method has been called\n"; problem += "but the compiler option -DLAPACK was not provided when\n"; problem += "the library was built."; throw ExceptionExternal( problem ); #else std::size_t N = p_A -> nrows(); // Cache contention issues of varying significance plague problems of size 2^j + 2^k + ... // when LDA = N, so this is my shameless 'tweak' to maintain predictable // performance, at least for N <=1024 or so. int padding( 0 ); if ( ( N % 2 == 0 ) && ( N > 127 ) ) { padding = 1; } #ifdef PARANOID if ( ( p_A -> nrows() != p_B -> nrows() ) || ( p_A -> ncols() != p_B -> ncols() ) ) { std::string problem( "The DenseLinearEigenSystem::eigensolve_lapack_with_vectors method has detected a failure. \n" ); throw ExceptionGeom( problem, p_A -> nrows(), p_A -> ncols(), p_B -> nrows(), p_B -> ncols() ); } #endif // Convert to fortran data incl. a transpose of the // input matrices so they are in column_major format then include padding FortranData Af( *p_A, true, padding ); FortranData Bf( *p_B, true, padding ); // eigenvalue storage DenseVector<double> alpha_r( N, 0.0 ); DenseVector<double> alpha_i( N, 0.0 ); DenseVector<double> beta( N, 0.0 ); // new the right eigenvector storage DenseVector<double> vec_left( 1, 0.0 ); DenseVector<double> vec_right( N * N, 0.0 ); // some workspace for the LAPACK routine DenseVector<double> work( 1, 0.0 ); // return integer for LAPACK int info( 0 ); // Call FORTRAN LAPACK to get the required workspace LAPACK_DGGEV( ( char* ) "N", ( char* ) "V", N, Af.base(), N + padding, Bf.base(), N + padding, &alpha_r[ 0 ], &alpha_i[ 0 ], &beta[ 0 ], &vec_left[ 0 ], 1, &vec_right[ 0 ], N, &work[ 0 ], -1, info ); int required_workspace = 4 * int( work[ 0 ] ); #ifdef DEBUG std::cout << "[DEBUG] DenseLinearEigenSystem::eigensolve_lapack_with_vectors is requesting \n"; std::cout << "[DEBUG] a workspace vector of size " << required_workspace << "\n"; #endif work.resize( required_workspace ); // call FORTRAN LAPACK again with the optimum workspace LAPACK_DGGEV( ( char* ) "N", ( char* ) "V", N, Af.base(), N + padding, Bf.base(), N + padding, &alpha_r[ 0 ], &alpha_i[ 0 ], &beta[ 0 ], &vec_left[ 0 ], 1, &vec_right[ 0 ], N, &work[ 0 ], required_workspace, info ); if ( 0 != info ) { std::string problem( "The DenseLinearEigenSystem::eigensolve_lapack_with_vectors method has detected a failure.\n" ); throw ExceptionExternal( problem, info ); } // create a complex eigenvalue vector EIGENVALUES_ALPHA = DenseVector<D_complex>( N, 0.0 ); // complex eigenvector matrix ALL_EIGENVECTORS = DenseMatrix<D_complex>( N, N, 0.0 ); // step through the eigenvalues for ( std::size_t i = 0; i < N; ++i ) { const D_complex eye( 0.0, 1.0 ); // make the complex vector of alpha EIGENVALUES_ALPHA[ i ] = alpha_r[ i ] + alpha_i[ i ] * eye; if ( std::abs( alpha_i[ i ] ) > 0.0 ) { // eigenvector is complex for ( std::size_t k = 0; k < N; ++k ) { ALL_EIGENVECTORS[ i ][ k ] = vec_right[ i * N + k ] + eye * vec_right[ ( i + 1 ) * N + k ]; // store the conjugate too for completeness ALL_EIGENVECTORS[ i + 1 ][ k ] = vec_right[ i * N + k ] - eye * vec_right[ ( i + 1 ) * N + k ]; } ++i; } else // eigenvector is real { for ( std::size_t k = 0; k < N; ++k ) { ALL_EIGENVECTORS( i, k ) = vec_right[ i * N + k ]; } } } // set the eigenvalue member data EIGENVALUES_BETA = beta; #endif }
void geClearColor(u32 color){ libge_context->clear_color = color; glClearColor(Rf(libge_context->clear_color), Gf(libge_context->clear_color), Bf(libge_context->clear_color), Af(libge_context->clear_color)); }