void ChFunction_Fillet3::SetupCoefficients() { ChMatrixDynamic<> ma(4, 4); ChMatrixDynamic<> mb(4, 1); ChMatrixDynamic<> mx(4, 1); mb(0, 0) = y1; mb(1, 0) = y2; mb(2, 0) = dy1; mb(3, 0) = dy2; ma(0, 3) = 1.0; ma(1, 0) = pow(end, 3); ma(1, 1) = pow(end, 2); ma(1, 2) = end; ma(1, 3) = 1.0; ma(2, 2) = 1.0; ma(3, 0) = 3 * pow(end, 2); ma(3, 1) = 2 * end; ma(3, 2) = 1.0; ChLinearAlgebra::Solve_LinSys(ma, &mb, &mx); c1 = mx(0, 0); c2 = mx(1, 0); c3 = mx(2, 0); c4 = mx(3, 0); }
int main() { long i,j,h,m,k,p,ans,nn; scanf("%d%d",&m,&k); while (m>0) { nn=(1<<k)-1; memset(dp,0,sizeof(dp)); for (i=1;i<=m;i++) { scanf("%d",&a[i]); p=1<<(a[i]-1); for (j=0;j<=nn;j++) for (h=1;h<=k;h++) dp[i][j][h]=dp[i-1][j][h]; for (j=0;j<=nn;j++) if ((j&p)>0) dp[i][j][a[i]]=dp[i-1][j][a[i]]+1; for (j=0;j<=nn;j++) if ((j&p)==0) for (h=1;h<=k;h++) if (dp[i-1][j][h]) dp[i][j+p][a[i]]=mx(dp[i][j+p][a[i]],dp[i-1][j][h]+1); } ans=0; for (j=0;j<=nn;j++) for (h=1;h<=5;h++) ans=mx(ans,dp[m][j][h]); printf("%d\n",m-ans); scanf("%d%d",&m,&k); } return 0; }
n*g(n u,n w) { n y=u/(U-1),*s=put(d,d+v+2,y),z=w/(U-1),k,l=t(y,z,s,&k), m=l,*r[4],g[4],*f; c p; for(mx(r,s,0),mx(g,k,l); p=*(1+g)<*g,(m>*(g+1))+(*g<m);s=*f<m?m=*f,*(r+p):s)*(f=g+p+2)=t (y,z,*(r+p)+=p?-2:2,p+g);rt s; }
void estiva_zerofillrow(MX *A, long i) { long j; mx(A,1,1) = mx(A,1,1); i--; for ( j = 0; j < A->w; j++ ) if(A->A[i][j] != 0.0) A->A[i][j] = 0.0; }
main(){ static MX *A; static double *x, *b; initmx(A,3,3); ary1(x, 3); ary1(b, 3); mx(A,1,1) = 1.0; mx(A,1,2) = 0.0; b[1] = 3.0; mx(A,2,1) = 0.0; mx(A,2,2) = 1.0; b[2] = 2.0; solver(A,x,b); printf("%f\n", x[1] ); printf("%f\n", x[2] ); }
const char* between(const char* src) { for (size_t i = 0; i < lo; ++i) { src = mx(src); if (!src) return 0; } for (size_t i = lo; i <= hi; ++i) { const char* new_src = mx(src); if (!new_src) return src; src = new_src; } return src; }
void estiva_transmx(MX **MT, MX *M) { long i, j, J; initmx((*MT), M->n+1, M->w+1); mx(M,1,1) = mx(M,1,1); for(i=1;i<= M->n;i++) for(j=0; j< M->w; j++) { J = M->IA[i-1][j]; if (J != 0) mx((*MT),J,i) = M->A[i-1][j]; } }
void ss(long n,long w[MAXN],double a[MAXN],double b[MAXN]) { long i,j,h; double pa,pb,ba,bb; long tw[MAXN]; double ta[MAXN]; double tb[MAXN]; if (n==1) { if ((ans<a[1]+b[1]) && (a[1]+b[1]<r)) ans=a[1]+b[1]; return; } for (i=1;i<n;i++) for (j=i+1;j<=n;j++) { memset(tw,0,sizeof(tw)); memset(ta,0,sizeof(ta)); memset(tb,0,sizeof(tb)); for (h=1;h<j;h++) { tw[h]=w[h]; ta[h]=a[h]; tb[h]=b[h]; } for (h=j;h<n;h++) { tw[h]=w[h+1]; ta[h]=a[h+1]; tb[h]=b[h+1]; } tw[i]=w[i]+w[j]; pa=w[j]*1.0/(w[i]+w[j]); pb=1-pa; ba=mx(pa+a[i],a[j]-pb); bb=mx(pb+b[j],b[i]-pa); if (n==2) { if ((ans<ba+bb) && (ba+bb<r)) ans=ba+bb; return; } ta[i]=ba; tb[i]=bb; ss(n-1,tw,ta,tb); ta[i]=bb; tb[i]=ba; ss(n-1,tw,ta,tb); } }
TEST(BitMap, contains__unaligned) { BitMapMemory mx(aligned_size); BitMapMemory my(aligned_size); BitMapView x = mx.make_view(unaligned_size, even_bits); BitMapView y = my.make_view(unaligned_size, even_bits); // Check that a missing bit beyond the end of x doesn't count. { BitMapView aligned = BitMapView(mx.memory(), aligned_size); const idx_t index = aligned_size - 2; STATIC_ASSERT(unaligned_size <= index); WithBitClear wbc(aligned, index); EXPECT_TRUE(x.contains(y)); } // Check that a missing bit in the final partial word does count. { idx_t index = unaligned_size - 2; ASSERT_LE(BitMap::word_align_down(unaligned_size), index); WithBitClear wbc(x, index); EXPECT_FALSE(x.contains(y)); } }
geometry_msgs::Pose JacoPose::constructPoseMsg() { geometry_msgs::Pose pose; tf::Quaternion position_quaternion; // TODO: QUICK FIX, bake this as a quaternion: tf::Matrix3x3 mx( 1, 0, 0, 0, cos(ThetaX), -sin(ThetaX), 0, sin(ThetaX), cos(ThetaX)); tf::Matrix3x3 my( cos(ThetaY), 0, sin(ThetaY), 0, 1, 0, -sin(ThetaY), 0, cos(ThetaY)); tf::Matrix3x3 mz( cos(ThetaZ), -sin(ThetaZ), 0, sin(ThetaZ), cos(ThetaZ), 0, 0, 0, 1); tf::Matrix3x3 mg = mx * my * mz; mg.getRotation(position_quaternion); // NOTE: This doesn't work, as angles reported by the API are not fixed. // position_quaternion.setRPY(ThetaX, ThetaY, ThetaZ); tf::quaternionTFToMsg(position_quaternion, pose.orientation); pose.position.x = X; pose.position.y = Y; pose.position.z = Z; return pose; }
int main() { long i,j,k,n,m,l,t; scanf("%d%d",&n,&m); memset(p,0,sizeof(p)); for (i=1;i<=n;i++) for (j=1;j<=m;j++) { scanf("%lf",&p[i][j]); p[i][j]=1-p[i][j]; } memset(dp,0,sizeof(dp)); l=(1<<n)-1; dp[0]=1.0; for (i=1;i<=m;i++) { for (k=1;k<=n;k++) { t=1<<(k-1); for (j=l;j>=t;j--) if ((j&t)!=0) dp[j]=mx(dp[j],dp[j-t]*p[k][i]); } } printf("%.9lf\n",dp[l]); return 0; }
TEST(BitMap, intersects__unaligned) { BitMapMemory mx(aligned_size); BitMapMemory my(aligned_size); BitMapView x = mx.make_view(unaligned_size, even_bits); BitMapView y = my.make_view(unaligned_size, zero_bits); EXPECT_FALSE(x.intersects(y)); // Check that adding a bit beyond the end of y doesn't count. { BitMapView aligned_x = BitMapView(mx.memory(), aligned_size); BitMapView aligned_y = BitMapView(my.memory(), aligned_size); const idx_t index = aligned_size - 2; STATIC_ASSERT(unaligned_size <= index); ASSERT_TRUE(aligned_x.at(index)); WithBitSet wbs(aligned_y, index); EXPECT_FALSE(x.intersects(y)); } // Check that adding a bit in the final partial word does count. { idx_t index = unaligned_size - 2; ASSERT_LE(BitMap::word_align_down(unaligned_size), index); ASSERT_TRUE(x.at(index)); WithBitSet wbs(y, index); EXPECT_TRUE(x.intersects(y)); } }
main(int argc, char **argv){ int i, n = 512; static MX *A; static double *x, *b; initop(argc,argv); initmx(A,n+1,8); ary1(x, n+1); ary1(b, n+1); for ( i =1; i<=n; i++){ mx(A,i,i) = 2.0; b[i] = 1.0; } for (i=1;i<n;i++) mx(A,i,i+1) = -1.0; for (i=1;i<n;i++) mx(A,i+1,i) = -1.0; solver(A,x,b); for (i=1;i<=n;i++) printf("%f\n", x[i] ); }
const char* find_first_in_interval(const char* beg, const char* end) { while ((beg < end) && *beg) { if (mx(beg)) return beg; ++beg; } return 0; }
PooledConnection* ConnectionPool::get(const char* policyName, LMREG::CppTable* params) { PooledConnection* cnn = NULL; { JG_S::KAutoThreadMutex mx(m_mx); ConnectionSetting* cnnSetting = (ConnectionSetting*)m_settings.callPolicy(policyName, *params); if(!cnnSetting) return NULL; const char* cnnName = cnnSetting->m_name.c_str(); ConnectionList& lst = m_cnnMap[cnnName]; cnn = lst.pop_front(); if(!cnn) { cnn = PooledConnection::Alloc(); cnn->reset(); cnn->m_setting = cnnSetting; } } if(!cnn->keepAlive()) { this->release(cnn); return NULL; } return cnn; }
PooledConnection* ConnectionPool::getOrDefault(const char* policyName, LMREG::CppTable* params) { if(!m_settings.empty()) { return this->get(policyName, params); } { PooledConnection* cnn = NULL; JG_S::KAutoThreadMutex mx(m_mx); ConnectionSetting* cnnSetting = m_settings.defaultConnection(); if(!cnnSetting) return NULL; ConnectionList& lst = m_cnnMap[m_settings.defaultName()]; cnn = lst.pop_front(); if(!cnn) { cnn = PooledConnection::Alloc(); cnn->reset(); cnn->m_setting = cnnSetting; } if(!cnn->keepAlive()) { this->release(cnn); return NULL; } return cnn; } }
void dfs(double r,long f,long p) { long i,b; if (eq(r,0)==0) { flag=true; ansp=p+1; return; } if (p==1) { return; } if (r<0.000000001) return; f=mx(long(0.9999999999/r)-1,f); while ((eq(dd[f],r)==1) && (f<=100000)) { f++; } for (i=f;i<=100000;i++) { if (eq(p*dd[i],r)==-1) { break; } ans[p]=i; dfs(r-dd[i],i+1,p-1); if (flag) return; } return; }
void ValueStackSax::pushOnVectorValue(value::Value* val) { if (not m_valuestack.empty()) { if (m_valuestack.top()->isSet()) { m_valuestack.top()->toSet().add(val); } else if (m_valuestack.top()->isMap()) { m_valuestack.top()->toMap().add(m_lastkey, val); } else if (m_valuestack.top()->isMatrix()) { value::Matrix& mx(m_valuestack.top()->toMatrix()); if (not val->isNull()) { mx.addToLastCell(val); } mx.moveLastCell(); } } else { m_result.push_back(val); } if (val->isSet() or val->isMap() or val->isTuple() or val->isTable() or val->isMatrix()) { m_valuestack.push(val); } if (val->isNull()) { delete val; } }
void ChIntegrableIIorder::StateGather(ChState& y, double& T) { ChState mx(GetNcoords_x(), y.GetIntegrable()); ChStateDelta mv(GetNcoords_v(), y.GetIntegrable()); this->StateGather(mx, mv, T); y.PasteMatrix(mx, 0, 0); y.PasteMatrix(mv, GetNcoords_x(), 0); }
void ChIntegrableIIorder::StateScatter(const ChState& y, const double T) { ChState mx(GetNcoords_x(), y.GetIntegrable()); ChStateDelta mv(GetNcoords_v(), y.GetIntegrable()); mx.PasteClippedMatrix(y, 0, 0, GetNcoords_x(), 1, 0, 0); mv.PasteClippedMatrix(y, GetNcoords_x(), 0, GetNcoords_v(), 1, 0, 0); StateScatter(mx, mv, T); }
void ChIntegrableIIorder::StateIncrement(ChState& y_new, // resulting y_new = y + Dy const ChState& y, // initial state y const ChStateDelta& Dy // state increment Dy ) { if (y.GetRows() == this->GetNcoords_x()) { // Incrementing the x part only, user provided only x in y={x, dx/dt} StateIncrementX(y_new, y, Dy); return; } if (y.GetRows() == this->GetNcoords_y()) { // Incrementing y in y={x, dx/dt}. // PERFORMANCE WARNING! temporary vectors allocated on heap. This is only to support // compatibility with 1st order integrators. ChState mx(this->GetNcoords_x(), y.GetIntegrable()); ChStateDelta mv(this->GetNcoords_v(), y.GetIntegrable()); mx.PasteClippedMatrix(y, 0, 0, this->GetNcoords_x(), 1, 0, 0); mv.PasteClippedMatrix(y, this->GetNcoords_x(), 0, this->GetNcoords_v(), 1, 0, 0); ChStateDelta mDx(this->GetNcoords_v(), y.GetIntegrable()); ChStateDelta mDv(this->GetNcoords_a(), y.GetIntegrable()); mDx.PasteClippedMatrix(Dy, 0, 0, this->GetNcoords_v(), 1, 0, 0); mDv.PasteClippedMatrix(Dy, this->GetNcoords_v(), 0, this->GetNcoords_a(), 1, 0, 0); ChState mx_new(this->GetNcoords_x(), y.GetIntegrable()); ChStateDelta mv_new(this->GetNcoords_v(), y.GetIntegrable()); StateIncrementX(mx_new, mx, mDx); // increment positions mv_new = mv + mDv; // increment speeds y_new.PasteMatrix(mx_new, 0, 0); y_new.PasteMatrix(mv_new, this->GetNcoords_x(), 0); return; } throw ChException("StateIncrement() called with a wrong number of elements"); }
void SBShapelet::SBShapeletImpl::fillXImage(ImageView<double> im, double x0, double dx, int izero, double y0, double dy, int jzero) const { dbg<<"SBShapelet fillXImage\n"; dbg<<"x = "<<x0<<" + i * "<<dx<<", izero = "<<izero<<std::endl; dbg<<"y = "<<y0<<" + j * "<<dy<<", jzero = "<<jzero<<std::endl; const int m = im.getNCol(); const int n = im.getNRow(); double* ptr = im.getData(); const int skip = im.getNSkip(); assert(im.getStep() == 1); x0 /= _sigma; dx /= _sigma; y0 /= _sigma; dy /= _sigma; tmv::Matrix<double> mx(m,n); for (int i=0; i<m; ++i,x0+=dx) mx.row(i).setAllTo(x0); tmv::Matrix<double> my(m,n); for (int j=0; j<n; ++j,y0+=dy) my.col(j).setAllTo(y0); tmv::Matrix<double> val(m,n); fillXValue(val.view(),mx,my); typedef tmv::VIt<double,1,tmv::NonConj> It; It valit = val.linearView().begin(); for (int j=0; j<n; ++j,ptr+=skip) { for (int i=0; i<m; ++i) *ptr++ = *valit++; } }
/** * Sets up the relation between a cc event and an action */ void MidiMap::registerCCEvent( int parameter , MidiAction * pAction ){ QMutexLocker mx(&__mutex); if( parameter >= 0 and parameter < 128 ) { delete __cc_array[ parameter ]; __cc_array[ parameter ] = pAction; } }
/** * Sets up the relation between a note event and an action */ void MidiMap::registerNoteEvent( int note, MidiAction* pAction ) { QMutexLocker mx(&__mutex); if( note >= 0 && note < 128 ) { delete __note_array[ note ]; __note_array[ note ] = pAction; } }
// returns volume Real computeOBB(const std::vector<Vector3r>& pts, const Matrix3r& rot, Vector3r& center, Vector3r& halfSize){ const Real inf=std::numeric_limits<Real>::infinity(); Vector3r mn(inf,inf,inf), mx(-inf,-inf,-inf); FOREACH(const Vector3r& pt, pts){ Vector3r ptT=rot*pt; mn=mn.cwiseMin(ptT); mx=mx.cwiseMax(ptT); }
void estiva_mulmx(double **tp, MX *A, double *x){ long i, j, J, m = A->n, n = A->w; double *t; ary1(*tp, m+1); t = *tp; for(i=0; i< m; i++) t[i] = 0.0; mx(A,1,1) = mx(A,1,1); for(i=0; i< m; i++) for(j=0; j< n; j++) { J = A->IA[i][j]; if (0<J) t[i] += A->A[i][j]*x[J-1]; } }
/** * Sets up the relation between a mmc event and an action */ void MidiMap::registerMMCEvent( QString eventString , MidiAction* pAction ) { QMutexLocker mx(&__mutex); if( mmcMap[ eventString ] != NULL){ delete mmcMap[ eventString ]; } mmcMap[ eventString ] = pAction; }
const char* non_greedy(const char* src) { while (!delim(src)) { const char* p = mx(src); if (p == src) return 0; if (p == 0) return 0; src = p; } return src; }
int main() { long n,k,l,a,b; scanf("%ld%ld%ld",&k,&l,&n); a=mx(calc(k,l,n),calc(k,0,n-1)); b=mn(calc2(k,l,n),calc2(0,l,n-1)+3); printf("%ld %ld\n",a,b); return 0; }
KCharset* KCharset::getLocalCharset() { if(m_localCharset) return m_localCharset; ::System::Sync::KAutoThreadMutex mx(_mx_getLocalCharset); if(m_localCharset) return m_localCharset; int lang = KLanguage().getCurrentLanguage(); m_localCharset = KCharset::getCharset((KLanguage::EnumLanguage)lang); return m_localCharset; }