// Create either a static or an uncounted string. // Diffrence between static and uncounted is in the lifetime // of the string. Static are alive for the lifetime of the process. // Uncounted are not ref counted but will be deleted at some point. ALWAYS_INLINE StringData* StringData::MakeShared(StringSlice sl, bool trueStatic) { if (UNLIKELY(sl.len > StringData::MaxSize)) { throw_string_too_large(sl.len); } auto const cc = CapCode::ceil(sl.len); auto const need = cc.decode() + kCapOverhead; auto const sd = static_cast<StringData*>( trueStatic ? low_malloc(need) : malloc(need) ); auto const data = reinterpret_cast<char*>(sd + 1); sd->m_data = data; auto const count = trueStatic ? StaticValue : UncountedValue; sd->m_hdr.init(cc, HeaderKind::String, count); sd->m_len = sl.len; // m_hash is computed soon. data[sl.len] = 0; auto const mcret = memcpy(data, sl.ptr, sl.len); auto const ret = reinterpret_cast<StringData*>(mcret) - 1; // Recalculating ret from mcret avoids a spill. ret->preCompute(); // get m_hash right assert(ret == sd); assert(ret->isFlat()); assert(trueStatic ? ret->isStatic() : ret->isUncounted()); assert(ret->checkSane()); return ret; }
char *strStr(char *haystack, char *needle) { if(haystack == NULL || needle == NULL) return NULL; if(*haystack == '\0') return *needle == '\0' ? haystack : NULL; if(*needle == '\0') return haystack; int len = 0; while(*(needle + len) != '\0') len++; int* T = new int[len]; preCompute(needle, T, len); int h = 0, n = 0; while(*(haystack + h) != '\0') { if(*(haystack + h) == *(needle + n)) { h++;n++; }else{ if(n == 0){ h++; }else{ n = T[n-1] + 1; } } if(n == len) return haystack + h - len; } return NULL; }
bool UnaryOpExpression::getScalarValue(Variant &value) { if (m_exp) { if (m_op == T_ARRAY) { return m_exp->getScalarValue(value); } if (m_op == T_DICT) { if (m_exp->getScalarValue(value)) { value = Array::ConvertToDict(value.toArray()); return true; } return false; } Variant t; return m_exp->getScalarValue(t) && preCompute(t, value); } if (m_op == T_DICT) { value = DictInit(0).toArray(); return true; } if (m_op != T_ARRAY) return false; value = Array::Create(); return true; }
TER Transactor::apply () { preCompute(); // If the transactor requires a valid account and the transaction doesn't // list one, preflight will have already a flagged a failure. auto const sle = view().peek (keylet::account(account_)); // sle must exist except for transactions // that allow zero account. assert(sle != nullptr || account_ == beast::zero); if (sle) { mPriorBalance = STAmount ((*sle)[sfBalance]).xrp (); mSourceBalance = mPriorBalance; setSeq(); auto result = payFee (); if (result != tesSUCCESS) return result; view().update (sle); } return doApply (); }
bool UnaryOpExpression::getScalarValue(Variant &value) { if (m_exp) { if (m_op == T_ARRAY) { return m_exp->getScalarValue(value); } if (m_op == T_DICT) { if (m_exp->getScalarValue(value)) { value = value.toArray().toDict(); return true; } return false; } if (m_op == T_VEC) { if (m_exp->getScalarValue(value)) { value = value.toArray().toVec(); return true; } return false; } if (m_op == T_KEYSET) { if (m_exp->getScalarValue(value)) { value = value.toArray().toKeyset(); return true; } return false; } Variant t; return m_exp->getScalarValue(t) && preCompute(t, value); } if (m_op == T_DICT) { value = Array::CreateDict(); return true; } if (m_op == T_VEC) { value = Array::CreateVec(); return true; } if (m_op == T_KEYSET) { value = Array::CreateKeyset(); return true; } if (m_op != T_ARRAY) return false; value = Array::Create(); return true; }
StringData* StringData::MakeEmpty() { void* vpEmpty = &s_theEmptyString; auto const sd = static_cast<StringData*>(vpEmpty); auto const data = reinterpret_cast<char*>(sd + 1); sd->m_data = data; sd->m_hdr.init(HeaderKind::String, StaticValue); sd->m_lenAndHash = 0; // len=0, hash=0 data[0] = 0; sd->preCompute(); assert(sd->m_len == 0); assert(sd->capacity() == 0); assert(sd->m_hdr.kind == HeaderKind::String); assert(sd->isFlat()); assert(sd->isStatic()); assert(sd->checkSane()); return sd; }
void StringData::setUncounted() { setRefCount(UncountedValue); preCompute(); }
void StringData::setStatic() { setRefCount(StaticValue); preCompute(); }
void modifVec(std::list<ElementRange> const& __r, eltType const& u,vectorType & UnVec,ExprType const& expr, size_type rowstart, int ComponentShiftFactor, mpl::int_<MESH_POINTS> /**/ ) { const size_type context = ExprType::context|vm::POINT; auto mesh = u.functionSpace()->mesh().get(); auto const* dof = u.functionSpace()->dof().get(); auto const* fe = u.functionSpace()->fe().get(); if ( __r.size() == 0 ) return; auto point_it = __r.begin()->template get<1>(); auto point_en = __r.begin()->template get<2>(); bool findAPoint = false; for( auto lit = __r.begin(), len = __r.end(); lit != len; ++lit ) { point_it = lit->template get<1>(); point_en = lit->template get<2>(); if ( point_it != point_en ) { findAPoint=true; break; } } if ( !findAPoint ) return; auto const& pointForInit = boost::unwrap_ref( *point_it ); size_type eid = pointForInit.elements().begin()->first; size_type ptid_in_element = pointForInit.elements().begin()->second; auto const& elt = mesh->element( eid ); auto gm = mesh->gm(); auto geopc = gm->preCompute( fe->vertexPoints(ptid_in_element) ); auto ctx = gm->template context<context>( elt, geopc ); auto expr_evaluator = expr.evaluator( mapgmc(ctx) ); auto IhLoc = fe->vertexLocalInterpolant(); std::vector<bool> dofdone( dof->nLocalDofWithGhost(), false ); for( auto const& lit : __r ) { point_it = lit.template get<1>(); point_en = lit.template get<2>(); DVLOG(2) << "point " << point_it->id() << " with marker " << point_it->marker() << " nb: " << std::distance(point_it,point_en); if ( point_it == point_en ) continue; for ( ; point_it != point_en;++point_it ) { auto const& thept = boost::unwrap_ref( *point_it ); size_type eid = thept.elements().begin()->first; size_type ptid_in_element = thept.elements().begin()->second; auto const& elt = mesh->element( eid ); geopc = gm->preCompute( fe->vertexPoints(ptid_in_element) ); ctx->update( elt, ptid_in_element, geopc, mpl::int_<0>() ); expr_evaluator.update( mapgmc( ctx ) ); fe->vertexInterpolate( expr_evaluator, IhLoc ); for (int c1=0;c1<eltType::nComponents1;c1++) //for( int c = 0; c < (is_product?nComponents:1); ++c ) { size_type index = dof->localToGlobal( eid, ptid_in_element, c1 ).index(); //size_type thedof = u.start()+ (is_comp_space?Elem1::nComponents:1)*index; // global dof size_type thedof = u.start() + ComponentShiftFactor*index; if ( dofdone[index] ) continue; double value = IhLoc( c1 ); UnVec->set(rowstart+thedof,value); dofdone[index] = true; } } } }
void modifVec(std::list<ElementRange> const& __r, eltType const& u,vectorType & UnVec,ExprType const& expr, size_type rowstart, int ComponentShiftFactor, mpl::int_<MESH_EDGES> /**/ ) { const size_type context = ExprType::context|vm::POINT; auto mesh = u.functionSpace()->mesh().get(); auto const* dof = u.functionSpace()->dof().get(); auto const* fe = u.functionSpace()->fe().get(); if ( __r.size() == 0 ) return; auto edge_it = __r.begin()->template get<1>(); auto edge_en = __r.begin()->template get<2>(); bool findAEdge = false; for( auto lit = __r.begin(), len = __r.end(); lit != len; ++lit ) { edge_it = lit->template get<1>(); edge_en = lit->template get<2>(); if ( edge_it != edge_en ) { findAEdge=true; break; } } if ( !findAEdge ) return; auto const& edgeForInit = boost::unwrap_ref( *edge_it ); auto gm = mesh->gm(); //auto const& firstEntity = *entity_it; size_type eid = edgeForInit.elements().begin()->first; size_type ptid_in_element = edgeForInit.elements().begin()->second; auto const& elt = mesh->element( eid ); auto geopc = gm->preCompute( fe->edgePoints(ptid_in_element) ); auto ctx = gm->template context<context>( elt, geopc ); auto expr_evaluator = expr.evaluator( mapgmc(ctx) ); auto IhLoc = fe->edgeLocalInterpolant(); std::vector<bool> dofdone( dof->nLocalDofWithGhost(), false ); for( auto const& lit : __r ) { edge_it = lit.template get<1>(); edge_en = lit.template get<2>(); for ( ; edge_it != edge_en;++edge_it ) { auto const& theedge = boost::unwrap_ref( *edge_it ); if ( theedge.isGhostCell() ) { LOG(WARNING) << "edge id : " << theedge.id() << " is a ghost edge"; continue; } size_type eid = theedge.elements().begin()->first; size_type edgeid_in_element = theedge.elements().begin()->second; auto const& elt = mesh->element( eid ); geopc = gm->preCompute( fe->edgePoints(edgeid_in_element) ); ctx->update( elt, geopc ); expr_evaluator.update( mapgmc( ctx ) ); fe->edgeInterpolate( expr_evaluator, IhLoc ); for( auto const& ldof : u.functionSpace()->dof()->edgeLocalDof( eid, edgeid_in_element ) ) { size_type index = ldof.index(); if ( dofdone[index] ) continue; //size_type thedof = u.start()+ (is_comp_space?Elem1::nComponents:1)*ldof.index(); size_type thedof = u.start() + ComponentShiftFactor*index; double value = ldof.sign()*IhLoc( ldof.localDofInFace() ); UnVec->set(rowstart+thedof,value); dofdone[index] = true; } } // edge_it } // lit }
void StringData::setStatic() const { _count = RefCountStaticValue; preCompute(); }
void StringData::setUncounted() const { m_count = UncountedValue; preCompute(); }
ExpressionPtr UnaryOpExpression::preOptimize(AnalysisResultConstPtr ar) { Variant value; Variant result; if (m_exp && ar->getPhase() >= AnalysisResult::FirstPreOptimize) { if (m_op == T_UNSET) { if (m_exp->isScalar() || (m_exp->is(KindOfExpressionList) && static_pointer_cast<ExpressionList>(m_exp)->getCount() == 0)) { recomputeEffects(); return CONSTANT("null"); } return ExpressionPtr(); } } if (m_op == T_ISSET && m_exp->is(KindOfExpressionList) && static_pointer_cast<ExpressionList>(m_exp)->getListKind() == ExpressionList::ListKindParam) { auto el = static_pointer_cast<ExpressionList>(m_exp); result = true; int i = 0, n = el->getCount(); for (; i < n; i++) { ExpressionPtr e((*el)[i]); if (!e || !e->isScalar() || !e->getScalarValue(value)) break; if (value.isNull()) { result = false; } } if (i == n) { return replaceValue(makeScalarExpression(ar, result)); } } else if (m_op != T_ARRAY && m_exp && m_exp->isScalar() && m_exp->getScalarValue(value) && preCompute(value, result)) { return replaceValue(makeScalarExpression(ar, result)); } else if (m_op == T_BOOL_CAST) { switch (m_exp->getKindOf()) { default: break; case KindOfBinaryOpExpression: { int op = static_pointer_cast<BinaryOpExpression>(m_exp)->getOp(); switch (op) { case T_LOGICAL_OR: case T_BOOLEAN_OR: case T_LOGICAL_AND: case T_BOOLEAN_AND: case T_LOGICAL_XOR: case T_INSTANCEOF: case '<': case T_IS_SMALLER_OR_EQUAL: case '>': case T_IS_GREATER_OR_EQUAL: case T_SPACESHIP: case T_IS_IDENTICAL: case T_IS_NOT_IDENTICAL: case T_IS_EQUAL: case T_IS_NOT_EQUAL: return m_exp; } break; } case KindOfUnaryOpExpression: { int op = static_pointer_cast<UnaryOpExpression>(m_exp)->getOp(); switch (op) { case T_BOOL_CAST: case '!': case T_ISSET: case T_EMPTY: case T_PRINT: return m_exp; } break; } } } return ExpressionPtr(); }
LKInverseComp::LKInverseComp(char *path) { CvFileStorage *fs; fs = cvOpenFileStorage(path, 0, CV_STORAGE_READ ); nA = (int)cvReadRealByName(fs, 0, "numberOfAppearanceEigenVectors", 0); nS = (int)cvReadRealByName(fs, 0, "numberOfShapeEigenVectors", 0); printf("%d %d \n",nS,nA); //nS=16; // //nA=2; //nS=4;/ nA=10; nA+=1; negNewParam = (float *)malloc(sizeof(float)*(nS+4)); negNewParamnS = (float *)malloc(sizeof(float)*(nS+4)); negNewParam4 = (float *)malloc(sizeof(float)*(nS+4)); ParamnS = (float *)malloc(sizeof(float)*(nS+4)); Param4 = (float *)malloc(sizeof(float)*(nS+4)); ptemp1 = (float *)malloc(sizeof(float)*(nS+4)); ptemp2 = (float *)malloc(sizeof(float)*(nS+4)); param = (float *) malloc((4+nS)*sizeof(float)); nonRigidShapeVectors=(IplImage**)cvAlloc(sizeof(IplImage*) * nS); appearanceVectors=(IplImage**)cvAlloc(sizeof(IplImage*) * nA); globalShapeVectors=(IplImage**)cvAlloc(sizeof(IplImage*) * 4); combineshapevectors=(IplImage**)cvAlloc(sizeof(IplImage*) * (4+nS)); srcShape =cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); destShape =cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); destShapeTemp =cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); destShapewithoutQ =cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); for (int m=0;m<(nS+4);m++) { combineshapevectors[m]=cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); param[m]=0; negNewParam[m]=0; negNewParamnS[m]=0; negNewParam4[m]=0; ParamnS[m]=0; Param4[m]=0; ptemp1[m]=0; ptemp2[m]=0; } for (int m=0;m<4;m++) globalShapeVectors[m]=cvCreateImage(cvSize(totalnumberofpoints,1),IPL_DEPTH_64F,1); CvMat * meanShapeDel=cvCreateMat(numberofpoints,2,CV_64FC1); eigenVal= (CvMat *)cvReadByName( fs,0,"eigenVal",0 ); // minProjVal=(IplImage *)cvReadByName( fs,0,"minProjVal",0 ); // maxProjVal=(IplImage *)cvReadByName( fs,0,"maxProjVal",0 ); meanAppearance=(IplImage *)cvReadByName( fs,0,"avgApp",0 ); ErrorImage = cvCreateMat((meanAppearance->width*meanAppearance->height),1, CV_64FC1); IplImage* meanShapeTemp=(IplImage *)cvReadByName( fs,0,"avgShape",0 ); meanShape=cvCreateImage(cvSize(meanShapeTemp->width,meanShapeTemp->height),IPL_DEPTH_64F,1); cvConvertScale( meanShapeTemp,meanShape,1,0); for (int m=0;m<nS;m++) { char temp[200]; sprintf(temp,"shapeEigenVectors%d",m); nonRigidShapeVectors[m]=(IplImage *)cvReadByName( fs,0,temp,0 ); } for (int m=0;m<nA-1;m++) { char temp[200]; sprintf(temp,"appEigenVectors%d",m); appearanceVectors[m]=(IplImage *)cvReadByName( fs,0,temp,0 ); } appearanceVectors[nA-1]=cvCreateImage(cvSize(appearanceVectors[nA-2]->width,appearanceVectors[nA-2]->height),IPL_DEPTH_32F,1); for(int i=0;i<(appearanceVectors[nA-2]->width);i++) { for(int j=0;j<appearanceVectors[nA-2]->height;j++) { CvScalar s; s.val[0]=1; cvSet2D(appearanceVectors[nA-1],j,i,s); } } // IplImage * newImage = cvCreateImage(cvSize(meanAppearance->width,meanAppearance->height),IPL_DEPTH_8U,1); for (int m=0;m<nA;m++) { // cvZero(newImage); for (int i=0;i<meanAppearance->width;i++) { for (int j=0;j<meanAppearance->height;j++) { CvScalar s= cvGet2D(appearanceVectors[m],j,i); s.val[0]*=255; CvScalar s1= cvGet2D(meanAppearance,j,i); s.val[0]+=s1.val[0]; ////printf("%e \n",s.val[0]); // cvSet2D(newImage,j,i,s); } } // cvNamedWindow("yoyo",1); //cvShowImage("yoyo",newImage); // cvWaitKey(-1); } for (int m=0;m<numberofpoints;m++) { CvScalar s1,s2; s1=cvGet2D(meanShape,0,2*m); s2=cvGet2D(meanShape,0,2*m+1); cvSet2D(meanShapeDel,m,0,s1); cvSet2D(meanShapeDel,m,1,s2); cvSet2D(globalShapeVectors[0],0,2*m,s1); cvSet2D(globalShapeVectors[0],0,2*m+1,s2); cvSet2D(combineshapevectors[0],0,2*m,s1); cvSet2D(combineshapevectors[0],0,2*m+1,s2); s2.val[0]*=-1; cvSet2D(globalShapeVectors[1],0,2*m,s2); cvSet2D(globalShapeVectors[1],0,2*m+1,s1); cvSet2D(combineshapevectors[1],0,2*m,s2); cvSet2D(combineshapevectors[1],0,2*m+1,s1); CvScalar one,zero; one.val[0]=1; zero.val[0]=0; cvSet2D(globalShapeVectors[2],0,2*m,one); cvSet2D(globalShapeVectors[2],0,2*m+1,zero); cvSet2D(globalShapeVectors[3],0,2*m,zero); cvSet2D(globalShapeVectors[3],0,2*m+1,one); cvSet2D(combineshapevectors[2],0,2*m,one); cvSet2D(combineshapevectors[2],0,2*m+1,zero); cvSet2D(combineshapevectors[3],0,2*m,zero); cvSet2D(combineshapevectors[3],0,2*m+1,one); } for (int i=0;i<numberofpoints;i++) { CvScalar avx,avy; avx=cvGet2D( meanShapeDel, i,0); avy=cvGet2D( meanShapeDel, i,1); // ////printf("%e %e \n",avx.val[0],avy.val[0]); } newDelaunayShapeCompute= new delaunay(meanShapeDel); newDelaunay = new delaunay(meanShapeDel); newDelaunayInverse = new delaunay(meanShapeDel); for (int m=0;m<4;m++) { double val= cvNorm(globalShapeVectors[m],NULL , CV_L2, 0 ); cvConvertScale( globalShapeVectors[m],globalShapeVectors[m],1/val,0); ////printf(" %e \n",val); // cvConvertScale( combineshapevectors[m],combineshapevectors[m],val,0); } for (int m=4;m<(nS+4);m++) { for (int j=0;j<totalnumberofpoints;j++) { CvScalar s1 = cvGet2D(nonRigidShapeVectors[m-4],0,j); cvSet2D(combineshapevectors[m],0,j,s1); } } for (int m=0;m<nS+4;m++) { double val= cvNorm(combineshapevectors[m],NULL , CV_L2, 0 ); cvConvertScale( combineshapevectors[m],combineshapevectors[m],1/val,0); ////printf(" %e \n",val); // cvConvertScale( combineshapevectors[m],combineshapevectors[m],val,0); } for (int m=0;m<nA;m++) { double val= cvNorm(appearanceVectors[m],NULL , CV_L2, 0 ); cvConvertScale( appearanceVectors[m],appearanceVectors[m],1/val,0); // //printf(" %e \n",val); } ////printf("%d %d \n",meanAppearance->width,meanAppearance->height); totalNumberOfPixels=newDelaunay->numberOfPixels(); interpolateMean=(float*)malloc(sizeof(float)*totalNumberOfPixels); for (int i=0;i<totalNumberOfPixels;i++) { interpolateMean[i]=0; pixel * pix = newDelaunay->getpixel(i); interpolateMean[i]=interpolate<float>(meanAppearance,double(pix->x+pix->tx),double(pix->y+pix->ty)); } preCompute(); ////printf("%d %d \n",meanAppearance->width,meanAppearance->height); // preCompute(); }
bool UnaryOpExpression::getScalarValue(Variant &value) { if (m_exp) { if (m_op == T_ARRAY) { return m_exp->getScalarValue(value); } if (m_op == T_DICT) { auto exp_list = dynamic_pointer_cast<ExpressionList>(m_exp); if (!exp_list) return false; DictInit init(exp_list->getCount()); auto const result = exp_list->getListScalars( [&](const Variant& n, const Variant& v) { if (!n.isInitialized()) return false; if (!n.isInteger() && !n.isString()) return false; init.setValidKey(n, v); return true; } ); if (!result) return false; value = init.toVariant(); return true; } if (m_op == T_VEC) { auto exp_list = dynamic_pointer_cast<ExpressionList>(m_exp); if (!exp_list) return false; VecArrayInit init(exp_list->getCount()); auto const result = exp_list->getListScalars( [&](const Variant& n, const Variant& v) { if (n.isInitialized()) return false; init.append(v); return true; } ); if (!result) return false; value = init.toVariant(); return true; } if (m_op == T_KEYSET) { auto exp_list = dynamic_pointer_cast<ExpressionList>(m_exp); if (!exp_list) return false; KeysetInit init(exp_list->getCount()); auto const result = exp_list->getListScalars( [&](const Variant& n, const Variant& v) { if (n.isInitialized()) return false; if (!v.isInteger() && !v.isString()) return false; init.add(v); return true; } ); if (!result) return false; value = init.toVariant(); return true; } Variant t; return m_exp->getScalarValue(t) && preCompute(t, value); } if (m_op == T_DICT) { value = Array::CreateDict(); return true; } if (m_op == T_VEC) { value = Array::CreateVec(); return true; } if (m_op == T_KEYSET) { value = Array::CreateKeyset(); return true; } if (m_op != T_ARRAY) return false; value = Array::Create(); return true; }
bool Channel::Load(Tokenizer &token) { char temp[256]; token.FindToken("extrapolate"); for (int j = 0; j < 2; j++) { token.GetToken(temp); if (strcmp(temp, "constant") == 0) { extrap[j] = 'k'; } else if (strcmp(temp, "linear") == 0) { extrap[j] = 'l'; } else if (strcmp(temp, "cycle") == 0) { extrap[j] = 'c'; } else if (strcmp(temp, "cycle_offset") == 0) { extrap[j] = 'o'; } else if (strcmp(temp, "bounce") == 0) { extrap[j] = 'b'; } } token.FindToken("keys"); int numKeys = token.GetInt(); token.FindToken("{"); for (int i = 0; i < numKeys; i++) { Keyframe newKeyframe = Keyframe(); newKeyframe.Time = token.GetFloat(); newKeyframe.Value = token.GetFloat(); token.GetToken(temp); if (strcmp(temp, "flat") == 0) { newKeyframe.RuleIn = 'f'; newKeyframe.TangentIn = 0; } else if (strcmp(temp, "linear") == 0) { newKeyframe.RuleIn = 'l'; } else if (strcmp(temp, "smooth") == 0) { newKeyframe.RuleIn = 's'; } else { newKeyframe.RuleIn = 'f'; newKeyframe.RuleIn = atof(temp); } token.GetToken(temp); if (strcmp(temp, "flat") == 0) { newKeyframe.RuleOut = 'f'; newKeyframe.TangentOut = 0; } else if (strcmp(temp, "linear") == 0) { newKeyframe.RuleOut = 'l'; } else if (strcmp(temp, "smooth") == 0) { newKeyframe.RuleOut = 's'; } else { newKeyframe.RuleOut = 'f'; newKeyframe.TangentOut = atof(temp); } keyframes.push_back(newKeyframe); } startTime = keyframes[0].Time; endTime = keyframes[keyframes.size()-1].Time; preCompute(); return true; }