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() { scanf("%d %d%c",&n,&m,&c); while(1) { scanf("%c",&c); if(c == '\n') break; s[k++] = c; } for(int h=0; h<k; h++) { if(s[h] != ' ' && !isalpha(s[h])) a = h; d[h+1] = a+1; } for(int h=1; h<=k; h++) { if(h-d[h] > n) dp[h] = dp[ma(h-m,d[h])]+1; else dp[h] = dp[ma(0,h-n)]+1; } //for(int h=1; h<=k; h++) printf("%d _ %d\n",h,dp[h]); printf("%d",dp[k]); }
AssimpScene::AssimpScene( OpenGLFunctions & gl , const QString & filePath , const bool normalize) : m_valid(false) { Assimp::Importer importer; const aiScene * scene = import(importer, filePath); if (!scene) return; m_aabb = retrieveAxisAlignedBoundingBox(scene); if (normalize) { QVector3D d = m_aabb.urb() - m_aabb.llf(); m_scale = abs(1.f / ma(d.x(), ma(d.y(), d.z()))); m_normalize.scale(m_scale); m_normalize.translate(-m_aabb.center()); } setupVAOs(gl, scene); m_valid = true; }
char findlit(char* literal) { struct litlist* h1; char temp; if (!lsentinel) { lsentinel = (struct litlist*)ma(sizeof(struct litlist)); lsentinel->next=0; lsentinel->sym=65; llist=lsentinel; } h1=llist; strcpy(lsentinel->lit,literal); temp=lsentinel->sym; while (strcmp(h1->lit,literal)) { temp=h1->sym; h1=h1->next; } if (h1==lsentinel) { lsentinel = (struct litlist*)ma(sizeof(struct litlist)); h1->next = lsentinel; h1->sym=temp+1; } return (h1->sym); }
long int maxSubArray2(int a[], int siz) { long int ma(long int,long int); long int maxsofar = 0,i; long int currentmax = 0; for(i = 0; i < siz; i++) { currentmax = ma(currentmax + a[i], 0); maxsofar = ma(maxsofar, currentmax); } return maxsofar; }
/*! * \brief LAArmadillo::multiply * Multiply m by s * \param result * \param s * \param m */ void LAArmadillo::multiply(OiMat &result, const double &s, const OiMat &m){ arma::mat ma(m.getRowCount(), m.getColCount()); this->oiMat2Arma(ma, m); this->arma2OiMat(result, (s * ma)); }
int main(int argc, char* argv[]) { Maze m; Maze::Step src(1, 1), des(6, 5); std::cout<<(m.findPath(src, des) == true ? "find a path" : "No path") <<std::endl; Maze m1; m1.findAllPath(src, des); char a[12][20] = { {L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,L,L,L,L,L,L,L,W,L,L,L,L,L}, {L,L,W,W,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L}, {L,L,W,W,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,W,W,L,L,L,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,L,W,W,L,L,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,L,L,W,W,W,L,L,L,L,L,L,L,L}, {L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L}, {L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L}, {L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L}, {L,L,L,L,W,W,L,L,L,L,W,W,W,W,W,W,L,L,L,L} }; Matrix ma(a); ma.changeW2O(5,8); std::cout<<"After change W to O"<<std::endl; ma.output(); return 0; }
template<class T, class U, class LEQ> void merge_sort_leq (array<T>& a, array<U>& b) { ASSERT (N(a) == N(b), "arrays of the same length expected"); array<T> ma (N(a)); array<U> mb (N(b)); merge_sort_sub<T,U,LEQ> (a, b, 0, N(a), ma, mb); }
jvmtiError JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) { LoadedClassesClosure closure(env); { // To get a consistent list of classes we need MultiArray_lock to ensure // array classes aren't created. MutexLocker ma(MultiArray_lock); // Iterate through all classes in ClassLoaderDataGraph // and collect them using the LoadedClassesClosure ClassLoaderDataGraph::loaded_classes_do(&closure); } // Return results by extracting the collected contents into a list // allocated via JvmtiEnv jclass* result_list; jvmtiError error = env->Allocate(closure.get_count() * sizeof(jclass), (unsigned char**)&result_list); if (error == JVMTI_ERROR_NONE) { int count = closure.extract(result_list); *classCountPtr = count; *classesPtr = result_list; } return error; }
/************************************************************************* Method that injects a mouse movement event into the system *************************************************************************/ bool System::injectMouseMove(float delta_x, float delta_y) { MouseEventArgs ma(0); MouseCursor& mouse = MouseCursor::getSingleton(); ma.moveDelta.d_x = delta_x * d_mouseScalingFactor; ma.moveDelta.d_y = delta_y * d_mouseScalingFactor; // only continue setup and injection if mouse position has changed if ((ma.moveDelta.d_x != 0) || (ma.moveDelta.d_y != 0)) { ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.clickCount = 0; ma.button = NoButton; // move the mouse cursor & update position in args. mouse.offsetPosition(ma.moveDelta); ma.position = mouse.getPosition(); return mouseMoveInjection_impl(ma); } return false; }
int main(){ for(int i=0; i<1001; i++) for(int j=0; j<1001; j++) dp[i][j] = 1; for(int i=2; i<1001; i++) dp[0][i] = dp[i][0] = 0; dp[0][0] = 0; for(int i=1; i<1001; i++) for(int j=1; j<1001; j++) if(dp[i][j]) for(int h=2; ma(h*i, h*j)<1001; h++) dp[h*i][h*j] = 0; for(int i=1; i<1001; i++) for(int j=0; j<1001; j++) dp[i][j] += dp[i-1][j]; for(int i=0; i<1001; i++) for(int j=1; j<1001; j++) dp[i][j] += dp[i][j-1]; scanf("%d",&t); for(int i=1; i<=t; i++) { scanf("%d",&n); printf("%d %d %d\n",i,n,dp[n][n]); } }
int main() { std::cout << "Chess engine by Gareth George" << std::endl; std::cout << "\tnow with beautiful colorful chess boards!" << std::endl; Board* board = new Board; Move move; MoveApplicator ma(board); int moveCount = 0; while (true) { moveCount++; board->minimax((Player) 1, 1, move, INT_MIN, INT_MAX, 6); std::cout << "moves: " << moveCount << std::endl; std::cout << "\tmove: "<< move.toString() << std::endl; ma.apply(move); board->print(); moveCount++; board->minimax((Player) -1, -1, move, INT_MIN, INT_MAX, 6); std::cout << "moves: " << moveCount << std::endl; std::cout << "\tmove: "<< move.toString() << std::endl; ma.apply(move); board->print(); sleep(2); } delete board; return 0; }
void Mouse::move(int xx, int yy) { for(MoveAction ma : moveActionTable[state]) ma(xx, yy); x = xx; y = yy; }
int main(int argc, char *argv[]) { bool error = false; // set the flag to run cQuit = false; // establish a connection to the IRC server std::cout << "Connecting to MindAlign" << std::endl; CKMindAlignProtocol ma("mahub-bot", 2323, "mahub-bot", 6667, "_bkitdev", "pickle"); // log that we're ready to go std::cout << "Connected and ready to go" << std::endl; // create a responder myResponder r; ma.addToResponders(&r); while (!cQuit) { std::cout << "chatting again..." << std::endl; ma.sendMessage("beatyro", "Another trip through the loop"); sleep(5); } ma.disconnect(); if (error) { std::cout << "FAILURE" << std::endl; } else { std::cout << "SUCCESS" << std::endl; } }
/*! * \brief LAArmadillo::transpose * Transpose m * \param result * \param m */ void LAArmadillo::transpose(OiMat &result, const OiMat &m){ arma::mat ma(m.getRowCount(), m.getColCount()); this->oiMat2Arma(ma, m); this->arma2OiMat(result, ma.t()); }
void PRU2MDPprogress::buildActions(const PRUmodule *mod, map<string,domain_type>::const_iterator iParam, const MDPaction &action, map<string, domain_type> *SVdomain, PRU2MDPstateStore &states) { if (iParam == mod->parameters.end()) { // All parameters are instanciated MDPaction *act = new MDPaction(action); actions.push_back(act); PRUstate res(stateVariables); // makes a local copy of SV that will be updated with out SVUs for (vector<PRUoutcome*>::const_iterator itO = mod->outcomes.begin(); itO != mod->outcomes.end(); ++itO) { PRUoutcome *out = *itO; for (vector<string>::const_iterator itSVU = out->stateVariableUpdate.begin(); itSVU != out->stateVariableUpdate.end(); ++itSVU) { vector<string> vec; boost::algorithm::split(vec, *itSVU, boost::algorithm::is_any_of(":= "), boost::algorithm::token_compress_on ); if (vec.size()!=2) std::cerr << "Unreadable SVU : " << *itSVU << std::endl; else { if (vec[1][0] == '$') { // this is an action parameter string p = vec[1].substr(1); const string &v = act->getParameter(p); if (v == MDPaction::NIL) std::cerr << "Unknown action parameter "<<vec[1]<<std::endl; else res[vec[0]] = v; } else { // res[vec[0]] = vec[1]; // but needs a pointer (no local string !) domain_type &dom = (*SVdomain)[vec[0]]; for (domain_type::const_iterator it = dom.begin(); it != dom.end(); ++it) { if (*it == vec[1]) { res[vec[0]] = (*it); break; } } // for *it in this SV domain } // if not an action parameter } // if correct SVU element } // for itSVU in *itO SV Updates // Here, res contains the updated state variables MDPstate *s = states.getState(lay->name, act, out, res); act->outcomes.insert(s); } // for *itO in mod->outcomes } else { // Some action parameter is to be instanciated yet string name = iParam->first; domain_type::const_iterator it = iParam->second.begin(); domain_type::const_iterator itEnd = iParam->second.end(); ++iParam; for (;it != itEnd; ++it) { MDPaction ma(action,name,*it); buildActions(mod, iParam, ma, SVdomain, states); } // for *it in the current parameter's domain --iParam; } // if more parameters } // buildActions(*mod, iParam)
std::string expandSuperatoms(const Settings& vars, const Molecule &molecule ) { logEnterFunction(); std::string molString; ArrayOutput so(molString); MolfileSaver ma(so); ma.saveMolecule(vars, molecule); if (!vars.general.ExpandAbbreviations) return molString; indigoSetOption("treat-x-as-pseudoatom", "true"); indigoSetOption("ignore-stereochemistry-errors", "true"); int mol = indigoLoadMoleculeFromString(molString.c_str()); if (mol == -1) { fprintf(stderr, "%s\n", indigoGetLastError()); return molString; } int expCount = indigoExpandAbbreviations(mol); if (expCount == -1) { fprintf(stderr, "%s\n", indigoGetLastError()); return molString; } std::string newMolfile = indigoMolfile(mol); indigoFree(mol); return newMolfile; }
virtual IIntegerImpl *PowCascade(const IIntegerImpl * const x0, const IIntegerImpl * const e0, const IIntegerImpl * const x1, const IIntegerImpl * const e1) const { CryptoPP::ModularArithmetic ma(m_data); return new CppIntegerImpl(ma.CascadeExponentiate( GetData(x0), GetData(e0), GetData(x1), GetData(e1))); }
/************************************************************************* Method that injects a new position for the mouse cursor. *************************************************************************/ bool System::injectMousePosition(float x_pos, float y_pos) { Point new_position(x_pos, y_pos); MouseCursor& mouse = MouseCursor::getSingleton(); // setup mouse movement event args object. MouseEventArgs ma(0); ma.moveDelta = new_position - mouse.getPosition(); // only continue setup and injection if mouse position has changed if ((ma.moveDelta.d_x != 0) || (ma.moveDelta.d_y != 0)) { ma.sysKeys = d_sysKeys; ma.wheelChange = 0; ma.clickCount = 0; ma.button = NoButton; // move mouse cursor to new position mouse.setPosition(new_position); // update position in args (since actual position may be constrained) ma.position = mouse.getPosition(); return mouseMoveInjection_impl(ma); } return false; }
int main() { // points on the squares [-1,1]^2 and [-2,2]^2 Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1), Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)}; Min_annulus ma(P, P+8); assert (ma.is_valid()); // get center of annulus Min_annulus::Coordinate_iterator coord_it; std::cout << "center:"; // homogeneous point, (0,0,1) for (coord_it = ma.center_coordinates_begin(); coord_it != ma.center_coordinates_end(); ++coord_it) std::cout << " " << *coord_it; std::cout << std::endl; // get inner squared radius, 1^2+1^2 = 2 std::cout << "Inner squared radius: " << CGAL::to_double(ma.squared_inner_radius_numerator()) / CGAL::to_double(ma.squared_radii_denominator()) << std::endl; // get outer squared radius, 2^2+2^2 = 8 std::cout << "Outer squared radius: " << CGAL::to_double(ma.squared_outer_radius_numerator()) / CGAL::to_double(ma.squared_radii_denominator()) << std::endl; return 0; }
bool DSA_Verifier::Verify(const byte* sha_digest, const byte* sig) { const Integer& p = key_.GetModulus(); const Integer& q = key_.GetSubGroupOrder(); const Integer& g = key_.GetSubGroupGenerator(); const Integer& y = key_.GetPublicPart(); int sz = q.ByteCount(); r_.Decode(sig, sz); s_.Decode(sig + sz, sz); if (r_ >= q || r_ < 1 || s_ >= q || s_ < 1) return false; Integer H(sha_digest, SHA::DIGEST_SIZE); // sha Hash(m) Integer w = s_.InverseMod(q); Integer u1 = (H * w) % q; Integer u2 = (r_ * w) % q; // verify r == ((g^u1 * y^u2) mod p) mod q ModularArithmetic ma(p); Integer v = ma.CascadeExponentiate(g, u1, y, u2); v %= q; return r_ == v; }
/* Reallocation wrapper function for nbnxn data structures */ void nbnxn_realloc_void(void **ptr, int nbytes_copy,int nbytes_new, nbnxn_alloc_t *ma, nbnxn_free_t *mf) { void *ptr_new; ma(&ptr_new,nbytes_new); if (nbytes_new > 0 && ptr_new == NULL) { gmx_fatal(FARGS, "Allocation of %d bytes failed", nbytes_new); } if (nbytes_copy > 0) { if (nbytes_new < nbytes_copy) { gmx_incons("In nbnxn_realloc_void: new size less than copy size"); } memcpy(ptr_new,*ptr,nbytes_copy); } if (*ptr != NULL) { mf(*ptr); } *ptr = ptr_new; }
void ChIntegrableIIorder::StateGatherDerivative(ChStateDelta& Dydt) { ChStateDelta mv(GetNcoords_v(), Dydt.GetIntegrable()); ChStateDelta ma(GetNcoords_v(), Dydt.GetIntegrable()); StateGatherAcceleration(ma); Dydt.PasteMatrix(mv, 0, 0); Dydt.PasteMatrix(ma, GetNcoords_v(), 0); }
bool areFilesEqual(const fs::path &a, const fs::path &b) { MMap ma(a.string()); MMap mb(b.string()); if(ma.len() != mb.len()) { return false; } return std::memcmp(ma.map(), mb.map(), ma.len()) == 0; }
void testObj::test<4>(void) { Transaction t( c_.createNewTransaction("abc") ); AlertPtrNN alert=makeNewAlert(); MetaAlertPtr ma( new Persistency::MetaAlert(alert, 123u) ); MetaAlertAutoPtr ptr=c_.metaAlert(ma, t); ensure("NULL pointer received", ptr.get()!=NULL ); ensureCalls(3); }
unique_ptr<RenderableObject> RenderableObject::quad(int startX, int startY, int width, int height, const glm::vec4 &color, GLenum primitive) { glm::vec3 mi(startX, startY, 0.0f); glm::vec3 ma(startX + width, startY + height, 0.0f); vector<glm::vec3> vertices; vector<glm::vec3> normals; vector<glm::vec3> texCoords; float d = 0.1; vertices.push_back(glm::vec3(mi.x, mi.y, d)); vertices.push_back(glm::vec3(mi.x, ma.y, d)); vertices.push_back(glm::vec3(ma.x, ma.y, d)); vertices.push_back(glm::vec3(ma.x, mi.y, d)); normals.push_back(glm::vec3(0.0f, 1.0f, 0.0f)); normals.push_back(glm::vec3(0.0f, 1.0f, 0.0f)); normals.push_back(glm::vec3(0.0f, 1.0f, 0.0f)); normals.push_back(glm::vec3(0.0f, 1.0f, 0.0f)); texCoords.push_back(glm::vec3(0.0f, 0.0f, 0.0f)); texCoords.push_back(glm::vec3(0.0f, 1.0f, 0.0f)); texCoords.push_back(glm::vec3(1.0f, 1.0f, 0.0f)); texCoords.push_back(glm::vec3(1.0f, 0.0f, 0.0f)); // Indices vector<GLuint> indices ={ 0, 1, 2, 0, 2, 3 }; uint nrVertices = vertices.size(); vector<RenderableObject::Vertex> attrData(nrVertices); for(uint i=0; i<nrVertices; ++i) { glm::vec3 v = vertices[i]; glm::vec3 n = normals[i]; glm::vec3 t = texCoords[i]; attrData[i].Position = v; attrData[i].Normal = n; attrData[i].Color = color; attrData[i].TexCoords = glm::vec4(t.x, t.y, 0.0f, 0.0f); } unique_ptr<RenderableObject> vbo(new RenderableObject); vbo->setData(attrData, indices, primitive); return vbo; }
/*! * \brief LAArmadillo::multiply * Multiply v by m * \param result * \param m * \param v */ void LAArmadillo::multiply(OiVec &result, const OiMat &m, const OiVec &v){ int vecSize = v.getSize(); arma::vec va(vecSize); arma::mat ma(m.getRowCount(), vecSize); this->oiVec2Arma(va, v); this->oiMat2Arma(ma, m); this->arma2OiVec(result, (ma * va)); }
int maxwidth(struct node *root) { if(root) { int h=hight(root); int *con=(int *)calloc(sizeof(int),h); int level=0; getwidth(root,con,level); return ma(con,h); } }
Z void callafunc(A func,A cbdata,A arg0,I n,A arg1,A arg2,A arg3) { E e; e = (E)(ma(7)); e->n=5; e->f=(I)func; e->a[0]=(I)cbdata; e->a[1]=(I)arg0; e->a[2]=(I)((1<=n)?arg1:aplus_nl); e->a[3]=(I)((2<=n)?arg2:aplus_nl); e->a[4]=(I)((3<=n)?arg3:aplus_nl); dc((A)ez(ME(e))); mf((I *)e); }
/* Initializes an nbnxn_atomdata_output_t data structure */ static void nbnxn_atomdata_output_init(nbnxn_atomdata_output_t *out, int nb_kernel_type, int nenergrp,int stride, nbnxn_alloc_t *ma) { int cj_size; out->f = NULL; ma((void **)&out->fshift,SHIFTS*DIM*sizeof(*out->fshift)); out->nV = nenergrp*nenergrp; ma((void **)&out->Vvdw,out->nV*sizeof(*out->Vvdw)); ma((void **)&out->Vc ,out->nV*sizeof(*out->Vc )); if (nb_kernel_type == nbk4xN_X86_SIMD128 || nb_kernel_type == nbk4xN_X86_SIMD256) { cj_size = nbnxn_kernel_to_cj_size(nb_kernel_type); out->nVS = nenergrp*nenergrp*stride*(cj_size>>1)*cj_size; ma((void **)&out->VSvdw,out->nVS*sizeof(*out->VSvdw)); ma((void **)&out->VSc ,out->nVS*sizeof(*out->VSc )); }