mat ls_solve_od(const mat &A, const mat &B) { int m=A.rows(), n=A.cols(), N=B.cols(), j; double beta; mat A2(A), B2(B), B3(n,N), submat, submat2; vec tmp(n), v; // it_assert1(m >= n, "The system is under-determined!"); //it_assert1(m == B.rows(), "The number of rows in A must equal the number of rows in B!"); // Perform a Householder QR factorization for (j=0; j<n; j++) { house(rvectorize(A2(j, m-1, j, j)), v, beta); v *= sqrt(beta); // submat.ref(A2, j,m-1, j,n-1); submat = A2(j,m-1,j,n-1); sub_v_vT_m(submat, v); // submat.ref(B2, j,m-1, 0,N-1); submat = B2(j,m-1,0,N-1); sub_v_vT_m(submat, v); } // submat.ref(A2, 0,n-1,0,n-1); // submat2.ref(B2, 0,n-1,0,N-1); submat = A2(0,n-1,0,n-1); submat2 = B2(0,n-1,0,N-1); for (j=0; j<N; j++) { backward_substitution(submat, submat2.get_col(j), tmp); B3.set_col(j, tmp); } return B3; }
void prefi::initialize() { B(0) = 1.0; A1(0) = 1.0; A1(1) = 1.0/(2.0*M_PI*fc1); A2(0) = 1.0; A2(1) = 1.0/(2.0*M_PI*fc2); }
static void FillPBufferAttribs_ByBits(nsTArray<EGLint>& aAttrs, int redBits, int greenBits, int blueBits, int alphaBits, int depthBits, int stencilBits) { aAttrs.Clear(); #if defined(A1) || defined(A2) #error The temp-macro names we want are already defined. #endif #define A1(_x) do { aAttrs.AppendElement(_x); } while (0) #define A2(_x,_y) do { A1(_x); A1(_y); } while (0) A2(LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT); A2(LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_PBUFFER_BIT); A2(LOCAL_EGL_RED_SIZE, redBits); A2(LOCAL_EGL_GREEN_SIZE, greenBits); A2(LOCAL_EGL_BLUE_SIZE, blueBits); A2(LOCAL_EGL_ALPHA_SIZE, alphaBits); A2(LOCAL_EGL_DEPTH_SIZE, depthBits); A2(LOCAL_EGL_STENCIL_SIZE, stencilBits); A1(LOCAL_EGL_NONE); #undef A1 #undef A2 }
int main () { Eigen::MatrixXd A(3,2); A << -1, 0, 0, -1, 1, 1; Eigen::VectorXd b(3); b << 0, 0, 1; iris::Polyhedron p(A, b); Eigen::MatrixXd A2(2,2); A2 << 2, 3, 4, 5; Eigen::VectorXd b2(2); b2 << 6, 7; iris::Polyhedron other(A2, b2); p.appendConstraints(other); valuecheck(p.getNumberOfConstraints(), 5); Eigen::MatrixXd A_expected(5,2); A_expected << -1, 0, 0, -1, 1, 1, 2, 3, 4, 5; valuecheckMatrix(p.getA(), A_expected, 1e-12); return 0; }
void testQLDSolver() { BaseVariable xy("xy",2); BaseVariable z("z",1); CompositeVariable T("T", xy, z); MatrixXd A1(1,1); A1 << 1; VectorXd b1(1); b1 << -3; LinearFunction lf1(z, A1, b1); LinearConstraint c1(&lf1, true); MatrixXd A2(1,2); A2 << 3,1 ; VectorXd b2(1); b2 << 0; LinearFunction lf2(xy, A2, b2); LinearConstraint c2(&lf2, true); MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ; VectorXd b3(2); b3 << 0, 1; LinearFunction lf3(xy, A3, b3); LinearConstraint c3(&lf3, false); QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0); QuadraticObjective obj(&objFunc); QLDSolver solver; solver.addConstraint(c1); solver.addConstraint(c2); solver.addConstraint(c3); solver.addObjective(obj); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); solver.removeConstraint(c1); IdentityFunction id(z); VectorXd lz(1); lz << 1; VectorXd uz(1); uz << 2; IdentityConstraint bnd1(&id, lz, uz); solver.addBounds(bnd1); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); BaseVariable t("t", 2); VectorXd ut(2); ut << -4,-1; BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR); BoundConstraint bnd2(&bf, false); solver.addBounds(bnd2); QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0); QuadraticObjective obj2(&objFunc2); solver.addObjective(obj2); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); Vector2d c3l(-1,-1); c3.setL(c3l); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); }
std::string makeFormattedString( const char* aFormat, const A1& a1 = A1(), const A2& a2 = A2(), const A3& a3 = A3(), const A4& a4 = A4(), const A5& a5 = A5(), const A6& a6 = A6(), const A7& a7 = A7(), const A8& a8 = A8(), const A9& a9 = A9(), const A10& a10 = A10(), const A11& a11 = A11(), const A12& a12 = A12(), const A13& a13 = A13(), const A14& a14 = A14(), const A15& a15 = A15(), const A16& a16 = A16(), const A17& a17 = A17(), const A18& a18 = A18(), const A19& a19 = A19(), const A20& a20 = A20() ) { return makeStringByPrintf(aFormat, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 ); }
eOverlapType GetOverlapType(const CArea& a1, const CArea& a2) { CArea A1(a1); A1.Subtract(a2); if(A1.m_curves.size() == 0) { return eInside; } CArea A2(a2); A2.Subtract(a1); if(A2.m_curves.size() == 0) { return eOutside; } A1 = a1; A1.Intersect(a2); if(A1.m_curves.size() == 0) { return eSiblings; } return eCrossing; }
void inter_cone(t_caster *caster, t_object *cone) { double a; double b; double c; double delt; init_temp_pos(caster, cone); a = A2(caster->temp_vec.x, caster->temp_vec.y, caster->temp_vec.z, cone->data.angle); b = B2(caster->temp_vec.x, caster->temp_pos.x, caster->temp_vec.y, caster->temp_pos.y, caster->temp_vec.z, caster->temp_pos.z, cone->data.angle); c = C2(caster->temp_pos.x, caster->temp_pos.y, caster->temp_pos.z, cone->data.angle); delt = (pow(b, 2.0) - 4.0 * (a * c)); if (delt >= 0.0) { cone->dist = get_nearest((-b - sqrt(delt)) / (2.0 * a), (-b + sqrt(delt)) / (2.0 * a)); if (cone->dist > 0.0 && cone->dist < caster->intersection.dist) { caster->intersection.brightness = cone->brightness; init_intersection(caster, cone); rotate_caster(caster, cone); } } }
inline CPLSafeInt<unsigned> operator*( const CPLSafeInt<unsigned>& A, const CPLSafeInt<unsigned>& B ) { #ifdef BUILTIN_OVERFLOW_CHECK_AVAILABLE unsigned res; if( __builtin_umul_overflow(A.v(), B.v(), &res) ) throw CPLSafeIntOverflow(); return CPLSM(res); #elif defined(_MSC_VER) msl::utilities::SafeInt<unsigned, CPLMSVCSafeIntException> A2(A.v()); msl::utilities::SafeInt<unsigned, CPLMSVCSafeIntException> B2(B.v()); return CPLSM(static_cast<unsigned>(A2 * B2)); #elif defined(CPL_HAS_GINT64) const unsigned a = A.v(); const unsigned b = B.v(); const GUInt64 res = static_cast<GUInt64>(a) * b; if( res > std::numeric_limits<unsigned>::max() ) { throw CPLSafeIntOverflow(); } return CPLSM(static_cast<unsigned>(res)); #else const unsigned a = A.v(); const unsigned b = B.v(); if( b > 0 && a > std::numeric_limits<unsigned>::max() / b ) throw CPLSafeIntOverflow(); return CPLSM(a*b); #endif }
int main(){ TTableContext Context; // create scheme Schema AnimalS; AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr)); AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr)); AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr)); AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt)); TIntV RelevantCols; RelevantCols.Add(0); RelevantCols.Add(1); RelevantCols.Add(2); // create table PTable T = TTable::LoadSS("Animals", AnimalS, "tests/animals.txt", Context, RelevantCols); //PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt"); T->Unique("Animal"); TTable Ts = *T; // did we fix problem with copy-c'tor ? //PTable Ts = TTable::LoadSS("Animals_s", AnimalS, "../../testfiles/animals.txt", RelevantCols); //Ts->Unique(AnimalUnique); // test Select // create predicate tree: find all animals that are big and african or medium and Australian TPredicate::TAtomicPredicate A1(atStr, true, EQ, "Location", "", 0, 0, "Africa"); TPredicate::TPredicateNode N1(A1); // Location == "Africa" TPredicate::TAtomicPredicate A2(atStr, true, EQ, "Size", "", 0, 0, "big"); TPredicate::TPredicateNode N2(A2); // Size == "big" TPredicate::TPredicateNode N3(AND); N3.AddLeftChild(&N1); N3.AddRightChild(&N2); TPredicate::TAtomicPredicate A4(atStr, true, EQ, "Location", "", 0, 0, "Australia"); TPredicate::TPredicateNode N4(A4); TPredicate::TAtomicPredicate A5(atStr, true, EQ, "Size", "", 0, 0, "medium"); TPredicate::TPredicateNode N5(A5); TPredicate::TPredicateNode N6(AND); N6.AddLeftChild(&N4); N6.AddRightChild(&N5); TPredicate::TPredicateNode N7(OR); N7.AddLeftChild(&N3); N7.AddRightChild(&N6); TPredicate Pred(&N7); TIntV SelectedRows; Ts.Select(Pred, SelectedRows); TStrV GroupBy; GroupBy.Add("Location"); T->Group(GroupBy, "LocationGroup"); GroupBy.Add("Size"); T->Group(GroupBy, "LocationSizeGroup"); T->Count("LocationCount", "Location"); PTable Tj = T->Join("Location", Ts, "Location"); TStrV UniqueAnimals; UniqueAnimals.Add("Animals_1.Animal"); UniqueAnimals.Add("Animals_2.Animal"); Tj->Unique(UniqueAnimals, false); //print table T->SaveSS("tests/animals_out_T.txt"); Ts.SaveSS("tests/animals_out_Ts.txt"); Tj->SaveSS("tests/animals_out_Tj.txt"); return 0; }
inline CPLSafeInt<int> operator*( const CPLSafeInt<int>& A, const CPLSafeInt<int>& B ) { #ifdef BUILTIN_OVERFLOW_CHECK_AVAILABLE int res; if( __builtin_smul_overflow(A.v(), B.v(), &res) ) throw CPLSafeIntOverflow(); return CPLSM(res); #elif defined(_MSC_VER) msl::utilities::SafeInt<int, CPLMSVCSafeIntException> A2(A.v()); msl::utilities::SafeInt<int, CPLMSVCSafeIntException> B2(B.v()); return CPLSM(static_cast<int>(A2 * B2)); #elif defined(CPL_HAS_GINT64) const int a = A.v(); const int b = B.v(); const GInt64 res = static_cast<GInt64>(a) * b; if( res < std::numeric_limits<int>::min() || res > std::numeric_limits<int>::max() ) { throw CPLSafeIntOverflow(); } return CPLSM(static_cast<int>(res)); #else return SafeMulSigned(A,B); #endif }
bool PGCicrcleTaskPt::CrossPoint(const ProjPt& prev, const ProjPt& next, ProjPt& optimized) { ProjPt A = prev - m_Center; ProjPt B = next - m_Center; ProjPt A2(A.m_X * A.m_X, A.m_Y * A.m_Y); ProjPt B2(B.m_X * B.m_X, B.m_Y * B.m_Y); double R2 = (m_Radius * m_Radius); bool PrevOutside = (A2.m_X + A2.m_Y) > R2; bool NextOutside = (B2.m_X + B2.m_Y) > R2; if (!PrevOutside && !NextOutside) { return false; // no cross point } ProjPt AB = B - A; double a = (AB.m_X * AB.m_X) + (AB.m_Y * AB.m_Y); double b = 2 * ((AB.m_X * A.m_X) + (AB.m_Y * A.m_Y)); double c = A2.m_X + A2.m_Y - R2; double bb4ac = (b * b) -(4 * a * c); if (bb4ac < 0.0) { return false; } bool bCrossPoint = false; double k = 0.0; if (bb4ac == 0.0) { LKASSERT(a); // one point k = -b / (2 * a); bCrossPoint = true; } if (bb4ac > 0.0) { // Two point, if ((PrevOutside && m_bExit) || (!PrevOutside && NextOutside)) { LKASSERT(a); k = (-b + sqrt(bb4ac)) / (2 * a); // ouput : prev ouside && Exit TP || prev inside && next outside bCrossPoint = true; } else { LKASSERT(a); k = (-b - sqrt(bb4ac)) / (2 * a); // input : prev outside && Enter TP bCrossPoint = true; } } if (bCrossPoint) { ProjPt O = prev + ((next - prev) * k); if (dot_product((next - prev), O - prev) > 0.0 && dot_product((prev - next), O - next) > 0.0) { optimized = O; return true; } } // no point return false; }
/*! \fn Real vecpot2b1i(Real (*A2)(Real,Real,Real), Real (*A3)(Real,Real,Real), * const GridS *pG, const int i, const int j, const int k) * \brief Compute B-field components from a vector potential. * * THESE FUNCTIONS COMPUTE MAGNETIC FIELD COMPONENTS FROM COMPONENTS OF A * SPECIFIED VECTOR POTENTIAL USING STOKES' THEOREM AND SIMPSON'S QUADRATURE. * NOTE: THIS IS ONLY GUARANTEED TO WORK IF THE POTENTIAL IS OF CLASS C^1. * WRITTEN BY AARON SKINNER. */ Real vecpot2b1i(Real (*A2)(Real,Real,Real), Real (*A3)(Real,Real,Real), const GridS *pG, const int i, const int j, const int k) { Real x1,x2,x3,b1i=0.0,lsf=1.0,rsf=1.0,dx2=pG->dx2; Real f2(Real y); Real f3(Real z); a2func = A2; a3func = A3; cc_pos(pG,i,j,k,&x1,&x2,&x3); xmin = x1 - 0.5*pG->dx1; xmax = x1 + 0.5*pG->dx1; ymin = x2 - 0.5*pG->dx2; ymax = x2 + 0.5*pG->dx2; zmin = x3 - 0.5*pG->dx3; zmax = x3 + 0.5*pG->dx3; xsav = xmin; #ifdef CYLINDRICAL lsf = xmin; rsf = xmin; dx2 = xmin*pG->dx2; #endif if (A2 != NULL) { if (ymin == ymax) b1i += rsf*A2(xmin,ymin,zmin) - lsf*A2(xmin,ymin,zmax); else { zsav = zmin; b1i += rsf*qsimp(f2,ymin,ymax); zsav = zmax; b1i -= lsf*qsimp(f2,ymin,ymax); } } if (A3 != NULL) { if (zmin == zmax) b1i += A3(xmin,ymax,zmin) - A3(xmin,ymin,zmin); else { ysav = ymax; b1i += qsimp(f3,zmin,zmax); ysav = ymin; b1i -= qsimp(f3,zmin,zmax); } } if (pG->dx2 > 0.0) b1i /= dx2; if (pG->dx3 > 0.0) b1i /= pG->dx3; return b1i; }
/*! \fn Real vecpot2b3i(Real (*A1)(Real,Real,Real), Real (*A2)(Real,Real,Real), * const GridS *pG, const int i, const int j, const int k) * \brief Compute B-field components from a vector potential. * * THESE FUNCTIONS COMPUTE MAGNETIC FIELD COMPONENTS FROM COMPONENTS OF A * SPECIFIED VECTOR POTENTIAL USING STOKES' THEOREM AND SIMPSON'S QUADRATURE. * NOTE: THIS IS ONLY GUARANTEED TO WORK IF THE POTENTIAL IS OF CLASS C^1. * WRITTEN BY AARON SKINNER. */ Real vecpot2b3i(Real (*A1)(Real,Real,Real), Real (*A2)(Real,Real,Real), const GridS *pG, const int i, const int j, const int k) { Real x1,x2,x3,b3i=0.0,lsf=1.0,rsf=1.0,dx2=pG->dx2; Real f1(Real x); Real f2(Real y); a1func = A1; a2func = A2; cc_pos(pG,i,j,k,&x1,&x2,&x3); xmin = x1 - 0.5*pG->dx1; xmax = x1 + 0.5*pG->dx1; ymin = x2 - 0.5*pG->dx2; ymax = x2 + 0.5*pG->dx2; zmin = x3 - 0.5*pG->dx3; zmax = x3 + 0.5*pG->dx3; zsav = zmin; #ifdef CYLINDRICAL rsf = xmax; lsf = xmin; dx2 = x1*pG->dx2; #endif if (A1 != NULL) { if (xmin == xmax) b3i += A1(xmin,ymin,zmin) - A1(xmin,ymax,zmin); else { ysav = ymin; b3i += qsimp(f1,xmin,xmax); ysav = ymax; b3i -= qsimp(f1,xmin,xmax); } } if (A2 != NULL) { if (ymin == ymax) b3i += rsf*A2(xmax,ymin,zmin) - lsf*A2(xmin,ymin,zmin); else { xsav = xmax; b3i += rsf*qsimp(f2,ymin,ymax); xsav = xmin; b3i -= lsf*qsimp(f2,ymin,ymax); } } if (pG->dx1 > 0.0) b3i /= pG->dx1; if (pG->dx2 > 0.0) b3i /= dx2; return b3i; }
std::vector < Derived > lidarBoostEngine::lk_optical_flow( const MatrixBase<Derived>& I1, const MatrixBase<Derived> &I2, int win_sz) { //Instantiate optical flow matrices std::vector < Derived > uv(2); //Create masks Matrix2d robX, robY, robT; robX << -1, 1, -1, 1; robY << -1, -1, 1, 1; robT << -1, -1, -1, -1; Derived Ix, Iy, It, A, solutions, x_block, y_block, t_block; //Apply masks to images and average the result Ix = 0.5 * ( conv2d( I1, robX ) + conv2d( I2, robX ) ); Iy = 0.5 * ( conv2d( I1, robY ) + conv2d( I2, robY ) ); It = 0.5 * ( conv2d( I1, robT ) + conv2d( I2, robT ) ); uv[0] = Derived::Zero( I1.rows(), I1.cols() ); uv[1] = Derived::Zero( I1.rows(), I1.cols() ); int hw = win_sz/2; for( int i = hw+1; i < I1.rows()-hw; i++ ) { for ( int j = hw+1; j < I1.cols()-hw; j++ ) { //Take a small block of window size in the filtered images x_block = Ix.block( i-hw, j-hw, win_sz, win_sz); y_block = Iy.block( i-hw, j-hw, win_sz, win_sz); t_block = It.block( i-hw, j-hw, win_sz, win_sz); //Convert these blocks in vectors Map<Derived> A1( x_block.data(), win_sz*win_sz, 1); Map<Derived> A2( y_block.data(), win_sz*win_sz, 1); Map<Derived> B( t_block.data(), win_sz*win_sz, 1); //Organize the vectors in a matrix A = Derived( win_sz*win_sz, 2 ); A.block(0, 0, win_sz*win_sz, 1) = A1; A.block(0, 1, win_sz*win_sz, 1) = A2; //Solve the linear least square system solutions = (A.transpose() * A).ldlt().solve(A.transpose() * B); //Insert the solutions in the optical flow matrices uv[0](i, j) = solutions(0); uv[1](i, j) = solutions(1); } } return uv; }
inline void SyrkLN ( T alpha, const DistMatrix<T>& A, T beta, DistMatrix<T>& C, bool conjugate=false ) { #ifndef RELEASE PushCallStack("internal::SyrkLN"); if( A.Grid() != C.Grid() ) throw std::logic_error ("A and C must be distributed over the same grid"); if( A.Height() != C.Height() || A.Height() != C.Width() ) { std::ostringstream msg; msg << "Nonconformal SyrkLN:\n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str().c_str() ); } #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); // Temporary distributions DistMatrix<T,MC, STAR> A1_MC_STAR(g); DistMatrix<T,VR, STAR> A1_VR_STAR(g); DistMatrix<T,STAR,MR > A1Trans_STAR_MR(g); A1_MC_STAR.AlignWith( C ); A1_VR_STAR.AlignWith( C ); A1Trans_STAR_MR.AlignWith( C ); // Start the algorithm ScaleTrapezoid( beta, LEFT, LOWER, 0, C ); LockedPartitionRight( A, AL, AR, 0 ); while( AR.Width() > 0 ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); //--------------------------------------------------------------------// A1_VR_STAR = A1_MC_STAR = A1; A1Trans_STAR_MR.TransposeFrom( A1_VR_STAR, conjugate ); LocalTrrk( LOWER, alpha, A1_MC_STAR, A1Trans_STAR_MR, T(1), C ); //--------------------------------------------------------------------// SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); } #ifndef RELEASE PopCallStack(); #endif }
int main() { // Primary Operators AnnihilationOperator A1(0); // 1st freedom NumberOperator N1(0); IdentityOperator Id1(0); AnnihilationOperator A2(1); // 2nd freedom NumberOperator N2(1); IdentityOperator Id2(1); SigmaPlus Sp(2); // 3rd freedom IdentityOperator Id3(2); Operator Sm = Sp.hc(); // Hermitian conjugate Operator Ac1 = A1.hc(); Operator Ac2 = A2.hc(); // Hamiltonian double E = 20.0; double chi = 0.4; double omega = -0.7; double eta = 0.001; Complex I(0.0,1.0); Operator H = (E*I)*(Ac1-A1) + (0.5*chi*I)*(Ac1*Ac1*A2 - A1*A1*Ac2) + omega*Sp*Sm + (eta*I)*(A2*Sp-Ac2*Sm); // Lindblad operators double gamma1 = 1.0; double gamma2 = 1.0; double kappa = 0.1; const int nL = 3; Operator L[nL]={sqrt(2*gamma1)*A1,sqrt(2*gamma2)*A2,sqrt(2*kappa)*Sm}; // Initial state State phi1(50,FIELD); // see paper Section 4.2 State phi2(50,FIELD); State phi3(2,SPIN); State stateList[3] = {phi1,phi2,phi3}; State psiIni(3,stateList); // Trajectory double dt = 0.01; // basic time step int numdts = 100; // time interval between outputs = numdts*dt int numsteps = 5; // total integration time = numsteps*numdts*dt int nOfMovingFreedoms = 2; double epsilon = 0.01; // cutoff probability int nPad = 2; // pad size //ACG gen(38388389); // random number generator with seed //ComplexNormal rndm(&gen); // Complex Gaussian random numbers ComplexNormalTest rndm(899101); // Simple portable random number generator AdaptiveStep stepper(psiIni, H, nL, L); // see paper Section 5 // Output const int nOfOut = 3; Operator outlist[nOfOut]={ Sp*A2*Sm*Sp, Sm*Sp*A2*Sm, A2 }; char *flist[nOfOut]={"X1.out","X2.out","A2.out"}; int pipe[] = {1,5,9,11}; // controls standard output (see `onespin.cc') // Simulate one trajectory (for several trajectories see `onespin.cc') Trajectory traj(psiIni, dt, stepper, &rndm); // see paper Section 5 traj.plotExp( nOfOut, outlist, flist, pipe, numdts, numsteps, nOfMovingFreedoms, epsilon, nPad ); }
Tensor::Tensor() : A1(3,3), A2(3,3), A3(3,3) { int i, j; for (i=1; i<=3; i++) for (j=1; j<=3; j++) { A1(i, j) = 0.0; A2(i, j) = 0.0; A3(i, j) = 0.0; } }
int main() { vector<float> A2(N*N); vector<float> B2(N*N); cout << "t4:" << endl; prob2_2_v2(A2, B2); cout << "-------" << endl; return 0; }
void Tensor::set(int i, int j, int k, double f) { switch(i) { case 1: A1(j, k) = f; break; case 2: A2(j, k) = f; break; case 3: A3(j, k) = f; break; default: ostringstream ii; ii << "Tensor index out of range: " << i << "\n"; throw ii.str(); break; } }
int hpx_main(boost::program_options::variables_map& vm) { { orthotope<double> A0({3, 3}) , A1({3, 3}) , A2({3, 3}) , A3({3, 3}) , A4({3, 3}) , A5({4, 4}) ; // QR {{1, 3, 6}, {3, 5, 7}, {6, 7, 4}} A0.row(0, 1, 3, 6 ); A0.row(1, 3, 5, 7 ); A0.row(2, 6, 7, 4 ); // QR {{12, -51, 4}, {6, 167, -68}, {-4, 24, -41}} A1.row(0, 12, -51, 4 ); A1.row(1, 6, 167, -68 ); A1.row(2, -4, 24, -41 ); // QR {{2, -2, 18}, {2, 1, 0}, {1, 2, 0}} A2.row(0, 2, -2, 18 ); A2.row(1, 2, 1, 0 ); A2.row(2, 1, 2, 0 ); // QR {{0, 1, 1}, {1, 1, 2}, {0, 0, 3}} A3.row(0, 0, 1, 1 ); A3.row(1, 1, 1, 2 ); A3.row(2, 0, 0, 3 ); // QR {{1, 1, -1}, {1, 2, 1}, {1, 2, -1}} A4.row(0, 1, 1, -1 ); A4.row(1, 1, 2, 1 ); A4.row(2, 1, 2, -1 ); // QR {{4, -2, 2, 8}, {-2, 6, 2, 4}, {2, 2, 10, -6}, {8, 4, -6, 12}} A5.row(0, 4, -2, 2, 8 ); A5.row(1, -2, 6, 2, 4 ); A5.row(2, 2, 2, 10, -6 ); A5.row(3, 8, 4, -6, 12 ); householders(A0); householders(A1); householders(A2); householders(A3); householders(A4); householders(A5); } return hpx::finalize(); }
int main(int argc, char **argv) { int a; int *p = NULL; A2(&a); // A2 > C printf("a = 0x%x\n", a); A(p); // A > B > C return 0; }
void CreateDoubleWayInteraction::paintEvent(QPaintEvent* /* anEvent */, QPainter& thePainter) { if (R1 && (!R1->layer() || R1->isDeleted())) { // The roads were begon and then undoed. Restarting.... HaveFirst = false; view()->setInteracting(false); R1 = R2 = NULL; } qreal rB = view()->pixelPerM()*DockData.RoadDistance->text().toDouble()/2; if (!HaveFirst) { thePainter.setPen(QColor(0,0,0)); thePainter.drawEllipse(int(LastCursor.x()-rB),int(LastCursor.y()-rB),int(rB*2),int(rB*2)); } else { Coord PreviousPoint; if (R1 && R1->size()) PreviousPoint = PreviousPoints[R1->size()-1]; else PreviousPoint = FirstPoint; if (distance(COORD_TO_XY(PreviousPoint), LastCursor) > 1) { qreal rA = FirstDistance * view()->pixelPerM()/2; LineF FA1(COORD_TO_XY(PreviousPoint),LastCursor); LineF FA2(FA1); LineF FB1(FA1); LineF FB2(FA1); FA1.slide(-rA); FA2.slide(rA); FB1.slide(-rB); FB2.slide(rB); QPointF A1(FA1.project(COORD_TO_XY(PreviousPoint))); QPointF A2(FA2.project(COORD_TO_XY(PreviousPoint))); QPointF B1(FB1.project(LastCursor)); QPointF B2(FB2.project(LastCursor)); QBrush SomeBrush(QColor(0xff,0x77,0x11,128)); QPen TP(SomeBrush,view()->pixelPerM()*4); if (DockData.DriveRight->isChecked()) { ::draw(thePainter,TP,Feature::OneWay, B1,A1,rB/4,view()->projection()); ::draw(thePainter,TP,Feature::OneWay, A2,B2,rB/4,view()->projection()); } else { ::draw(thePainter,TP,Feature::OneWay, A1,B1,rB/4,view()->projection()); ::draw(thePainter,TP,Feature::OneWay, B2,A2,rB/4,view()->projection()); } } } }
void ThreadProc( PBYTE *pMem ) { int i; InterlockedIncrement( (PLONG)&nThreads ); Sleep(500); // wait for more threads to start up too.. // initial state - have to do an allocate.... // Release( Allocate( 1 ) ); // DebugDumpMem(); for( i = 0; i < 10; i++ ) { T1 (A1(pMem)); // Sleep(0); T2 (A1(pMem)); // Sleep(0); T3 (A1(pMem)); // Sleep(0); T3i (A1(pMem)); // Sleep(0); T3is(A1(pMem)); // Sleep(0); T4 (A1(pMem)); // Sleep(0); T5 (A1(pMem)); // Sleep(0); T1 (A2(pMem)); // Sleep(0); T2 (A2(pMem)); // Sleep(0); T3 (A2(pMem)); // Sleep(0); T3i (A2(pMem)); // Sleep(0); T3is(A2(pMem)); // Sleep(0); T4 (A2(pMem)); // Sleep(0); T5 (A1(pMem)); // Sleep(0); T1 (A2i(pMem)); // Sleep(0); T2 (A2i(pMem)); // Sleep(0); T3 (A2i(pMem)); // Sleep(0); T3i (A2i(pMem)); // Sleep(0); T3is(A2i(pMem)); // Sleep(0); T4 (A2i(pMem)); // Sleep(0); T5 (A1(pMem)); // Sleep(0); } InterlockedDecrement( (PLONG)&nThreads ); ExitThread(0); }
double & Tensor::operator() (int i, int j, int k) { switch(i) { case 1: return A1(j, k); break; case 2: return A2(j, k); break; case 3: return A3(j, k); break; default: ostringstream ii; ii << "Trying to access " << i << j << k << "th element of tensor"; ii << *this; throw ii.str(); break; } }
vec ls_solve_od(const mat &A, const vec &b) { int m=A.rows(), n=A.cols(); double beta; mat A2(A), submat; vec b2(b), v; // it_assert1(m >= n, "The system is under-determined!"); // it_assert1(m == b.size(), "The number of rows in A must equal the length of b!"); // Perform a Householder QR factorization for (int j=0; j<n; j++) { house(rvectorize(A2(j, m-1, j, j)), v, beta); v *= sqrt(beta); // submat.ref(A2, j,m-1, j,n-1); submat = A2(j,m-1,j,n-1); // Time-consuming sub_v_vT_m(submat, v); b2.set_subvector(j,m-1, b2(j,m-1)- v*(v*b2(j,m-1))); } return backward_substitution(A2(0,n-1,0,n-1), b2(0,n-1)); }
int main(int argc, char* argv[]) { /* Checks for valid number of arguments passed in. */ if(argc < 2) { perror("Invalid command line arguments! <Frame Size> "); } string frame_size = argv[1]; A2 A2(frame_size); A2.lru(); A2.clock(); A2.opt(); }
real_2d_array PPCA::toR(complex_2d_array A){ real_2d_array A2; A2.setlength(A.rows(), A.cols()); for(int i=0; i<A.rows(); i++){ for(int j=0; j<A.cols(); j++){ A2(i,j) = A(i,j).x;} } return A2; }
inline CPLSafeInt<GInt64> operator*( const CPLSafeInt<GInt64>& A, const CPLSafeInt<GInt64>& B ) { #if defined(BUILTIN_OVERFLOW_CHECK_AVAILABLE) && defined(__x86_64__) GInt64 res; if( __builtin_smulll_overflow(A.v(), B.v(), &res) ) throw CPLSafeIntOverflow(); return CPLSM(res); #elif defined(_MSC_VER) msl::utilities::SafeInt<GInt64, CPLMSVCSafeIntException> A2(A.v()); msl::utilities::SafeInt<GInt64, CPLMSVCSafeIntException> B2(B.v()); return CPLSM(static_cast<GInt64>(A2 * B2)); #else return SafeMulSigned(A,B); #endif }
int main() { int n = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, num = 0; int count_a1 = 0, count_a2 = 0, count_a3 = 0, count_a4 = 0, count_a5 = 0; int flag_A2 = 1; scanf("%d", &n); for (; n > 0; n--) { scanf("%d", &num); A1(num, &a1, &count_a1); A2(num, &a2, &count_a2, &flag_A2); A3(num, &a3, &count_a3); A4(num, &a4, &count_a4); A5(num, &a5, &count_a5); } if (count_a1 > 0) printf("%d ", a1); else printf("N "); if (count_a2 > 0) printf("%d ", a2); else printf("N "); if (count_a3 > 0) printf("%d ", a3); else printf("N "); if (count_a4 > 0) printf("%.1lf ", (double)a4 / count_a4); else printf("N "); if (count_a5 > 0) printf("%d", a5); else printf("N"); return 0; }