vector<double>* OutputFile::getThetaPerSite() { int L=getL(); vector<double>*v=new vector<double>(); for (unsigned int i=0; i<rhos.size(); i++) v->push_back(thetas[i]/L); return v; }
const Matrix& PFEMElement2DBubble::getDamp() { // resize K int ndf = this->getNumDOF(); K.resize(ndf, ndf); K.Zero(); Vector G(6); getG(G); Matrix L(3,3); getL(L); // other matrices for(int a=0; a<3; a++) { for(int b=0; b<3; b++) { K(numDOFs(2*a+1), numDOFs(2*b)) = G(2*b); // GxT K(numDOFs(2*a+1), numDOFs(2*b)+1) = G(2*b+1); // GyT K(numDOFs(2*a), numDOFs(2*b+1)) = -G(2*a); // -Gx K(numDOFs(2*a)+1, numDOFs(2*b+1)) = -G(2*a+1); // -Gy K(numDOFs(2*a+1), numDOFs(2*b+1)) = L(a,b); // bubble } } //opserr<<"K = "<<K; return K; }
vector<double>* OutputFile::getRhoPerSite() { int L=getL(); int b=getB(); vector<double>*v=new vector<double>(); for (unsigned int i=0; i<rhos.size(); i++) v->push_back(rhos[i]/(deltas[i]*b+L-b)); return v; }
LabColour const LabColour::withMultipliedColour (float amount) const { return LabColour ( getL (), getA () * amount, getB () * amount, getAlpha ()); }
LabColour const LabColour::withAddedLuminance (float amount) const { return LabColour ( jlimit (0.f, 100.f, getL() + amount * 100), getA (), getB (), getAlpha ()); }
void LDLDecomposition<T>::getA(MatrixT& A) const { MatrixT L,temp; DiagonalMatrixTemplate<T> D; getL(L); getD(D); D.postMultiply(L,temp); A.mulTransposeB(temp,L); }
Vertex getDiffuseCompTexture(Vertex _3DPoint, int x, int y) { Vector L = getL(_3DPoint); Vector N = _3DPoint.normal; Vertex diffuse_comp; diffuse_comp.x = scalarProduct(N, L) * Il.R * textureR[y][x] * Kd; diffuse_comp.y = scalarProduct(N, L) * Il.G * textureG[y][x] * Kd; diffuse_comp.z = scalarProduct(N, L) * Il.B * textureB[y][x] * Kd; return diffuse_comp; }
Vertex getDiffuseComp(Vertex _3DPoint) { Vector L = getL(_3DPoint); Vector N = _3DPoint.normal; Vertex diffuse_comp; diffuse_comp.x = scalarProduct(N, L) * Il.R * Od.x * Kd; diffuse_comp.y = scalarProduct(N, L) * Il.G * Od.y * Kd; diffuse_comp.z = scalarProduct(N, L) * Il.B * Od.z * Kd; return diffuse_comp; }
Precision Stencil::getCenter( const Position pos, const Index sx, const Index sy, const Index nx, const Index ny, const Precision hx, const Precision hy, const Point origin) const { return getL(pos,sx,sy,nx,ny,hx,hy,origin)[0]; }
Vector getR(Vertex _3DPoint) { Vector L = getL(_3DPoint); Vector N = _3DPoint.normal; Vector R; R.x = (2 * N.x * scalarProduct(N, L)) - L.x; R.y = (2 * N.y * scalarProduct(N, L)) - L.y; R.z = (2 * N.z * scalarProduct(N, L)) - L.z; normalize(R); return R; }
bool LUDiv<T>::checkDecomp(const BaseMatrix<T>& m, std::ostream* fout) const { Matrix<T> mm = m; if (fout) { *fout << "LUDiv:\n"; *fout << "M = "<< (pimpl->istrans?mm.transpose():mm.view())<<std::endl; *fout << "L = "<<getL()<<std::endl; *fout << "U = "<<getU()<<std::endl; *fout << "P = "<<getP()<<std::endl; *fout << " or by interchanges: "; for(ptrdiff_t i=0;i<getP().size();i++) *fout<<(getP().getValues())[i]<<" "; } Matrix<T> lu = getP()*getL()*getU(); RT nm = Norm(lu-(pimpl->istrans ? mm.transpose() : mm.view())); nm /= Norm(getL())*Norm(getU()); if (fout) { *fout << "PLU = "<<lu<<std::endl; *fout << "Norm(M-PLU)/Norm(PLU) = "<<nm<<std::endl; } return nm < mm.doCondition()*RT(mm.colsize())*TMV_Epsilon<T>(); }
long long int getNumberOfMaxHeaps(int n) { if(n<=1) return 1; if(dp[n]!=-1) return dp[n]; int L = getL(n); long long int ans = (choose(n-1,L)*getNumberOfMaxHeaps(L))%MOD*(getNumberOfMaxHeaps(n-1-L)); ans%=MOD; dp[n] = ans; return ans; }
void setupMatrix(Complex w, double ky, double *X, double *K, double Ls, double Ln, int Nx, Complex *M, double dh, double q, double mass, double T, double eta, double n) { #pragma omp parallel for collapse(2) for(int x_k = 0; x_k < Nx; x_k++) { for(int w_k = 0; w_k < Nx; w_k++) { const int idx = x_k*Nx + w_k; M[idx] += - n * (q*q) / T * ( (w_k == x_k ? 1. : 0. ) + 1./(2.*M_PI) * getL(w, ky, K[x_k], K[w_k], X, Ls, Ln, Nx, q, mass, T, eta) * dh ); } } return; }
int getT(char*** ppszOut, const char* szInpBuf, unsigned int* nPos, unsigned int nRows, unsigned int nCols) { char* szBuf = new char[strlen(szInpBuf)]; memcpy(szBuf, szInpBuf, strlen(szInpBuf)); char* szTmp = szBuf; char* szNew = strchr(szTmp+1, '\n')+1; for(unsigned int i = 0; i<nRows; i++) { // std::cout<<"##DEBUG3111##"<<std::endl; char* szInp = new char[nPos[nCols-1]]; memset(szInp, 0, nPos[nCols-1]); // empty the space reserved for the temporary string (for Windows) // std::cout<<"Columns: "<<nPos[nCols-1]<<std::endl; // std::cout<<szNew<<std::endl; // std::cout<<"##DE_LEN = "<<szNew-szTmp<<std::endl; memcpy(szInp, szTmp, szNew-szTmp-1); // load the next line in the temporary string... // std::cout<<"##DEBUG3121##"<<std::endl; // std::cout<<szInp<<std::endl; char** pszOut = new char*[nCols]; // nCols columns maximum... for(unsigned int j = 0; j<nCols; j++) { if(nPos[j]>=nPos[j-(j>0)]) { pszOut[j] = new char[nPos[j]-(j>0)*nPos[j-(j>0)]+1]; // reserve size according to the field size... memset(pszOut[j], 0, nPos[j]-(j>0)*nPos[j-(j>0)]+1); } } getL(ppszOut[i], szInp, nPos, nCols); // ppszOut[i] = pszOut; // load the input table of char*-strings for(unsigned int j = 0; j<nCols; j++) { // std::cout<<"here!!!!!!! "<<j<<"\t"<<nPos[j]<<std::endl; if(nPos[j]>=nPos[j-(j>0)]) { delete[] pszOut[j]; } } delete[] pszOut; delete[] szInp; szTmp = szNew; szNew = strchr(szTmp+1, '\n')+1; } // std::cout<<"##DEBUG2122##"<<std::endl; delete[] szBuf; // std::cout<<"##DEBUG2722##"<<std::endl; return 0; }
bool OutputFile::getIt(ParamQt * p) { int deb=0; currentIteration++; p->setRho(0); p->setTheta(0); p->setLL(0); TiXmlHandle root(&mDoc); TiXmlHandle h = root.FirstChild("outputFile"); TiXmlHandle hIter = h.Child("Iteration", currentIteration); TiXmlElement* t; // <Tree> t = hIter.FirstChild("Tree").ToElement(); if (t == NULL) // Can I use hIter to return false? return false; string s(t->GetText()); while (s.at(0)==10 || s.at(0)==13) s=s.substr(1,s.length()-1); while (s.at(s.size()-1)==10 || s.at(s.size()-1)==13) s=s.substr(0,s.length()-1); p->setTreeData(new RecTree(getL(),s,false,false),blocks); // <number>, <theta>, <delta>, <rho>, <ll>. t = hIter.FirstChild("number").ToElement(); p->setNumber(atol(t->GetText())); t = hIter.FirstChild("theta").ToElement(); p->setTheta(p->getTheta() + atof(t->GetText())); t = hIter.FirstChild("delta").ToElement(); p->setDelta(atof(t->GetText())); t = hIter.FirstChild("rho").ToElement(); p->setRho(p->getRho() + atof(t->GetText())); t = hIter.FirstChild("ll").ToElement(); p->setLL(p->getLL() + atof(t->GetText())); // <recedge> TiXmlElement* parent = hIter.ToElement(); TiXmlElement* child = 0; while (child = (TiXmlElement*) parent->IterateChildren("recedge", child)) { int start=0,end=0,efrom=0,eto=0; double ato=0,afrom=0; t = child->FirstChildElement("start"); start = deb + atoi(t->GetText()); t = child->FirstChildElement("end"); end = deb + atoi(t->GetText()); t = child->FirstChildElement("efrom"); efrom = atoi(t->GetText()); t = child->FirstChildElement("eto"); eto = atoi(t->GetText()); t = child->FirstChildElement("afrom"); afrom = atof(t->GetText()); t = child->FirstChildElement("ato"); ato = atof(t->GetText()); p->getTree()->addRecEdge(afrom,ato,start,end,efrom,eto); } return true; }
Precision Stencil::apply( const DiscreteFunction& u, const Position pos, const Index sx, const Index sy) const { const Index nx = u.getNx(); const Index ny = u.getNy(); const Precision hx = u.getHx(); const Precision hy = u.getHy(); const Point origin = u.getOrigin(); NumericArray opL = getL(pos,sx,sy,nx,ny,hx,hy,origin); PositionArray jX = getJx(pos,nx,ny); PositionArray jY = getJy(pos,nx,ny); Precision result = 0.0; for (Index i = 0; i<opL.size(); ++i) result+=opL[i]*u(sx+jX[i],sy+jY[i]); return result; }
void opt(void){// Find MLE int i,end; double x,del,L,L1[np]; for(i=0;i<np;i++)pa[i]=0; del=1e-3; it=0;end=0; while(1){ L=getL(L1); for(i=0,x=0;i<np;i++)x+=L1[i]*L1[i];x=sqrt(x/np); if(end||it%1000==0){ printf("\nit %d of MLE-finding\nL %10g bits L/nr %10g bits\n",it,L/log(2),L/log(2)/nr); for(i=0;i<nt;i++)printf("%-*s %12g %12g %12g %12g\n",maxtl,tm[i],al[i],be[i],L1[i],L1[nt+i]); printf("%12g %12g\n%12g %12g\n",hh[0],L1[2*nt],hh[1],L1[2*nt+1]); } if(end)break; if(x<1e-9||it==50000)end=1; for(i=0;i<np;i++)pa[i]+=del*L1[i];// pa+=delta*L' = crude gradient descent it++; } }
const IR::Node* DoRemoveLeftSlices::postorder(IR::AssignmentStatement* stat) { if (!stat->left->is<IR::Slice>()) return stat; auto ls = stat->left->to<IR::Slice>(); int h = ls->getH(); int l = ls->getL(); mpz_class m = Util::maskFromSlice(h, l); auto type = typeMap->getType(ls->e0, true); auto mask = new IR::Constant(ls->srcInfo, type, m, 16); auto right = stat->right; // Handle a[m:l] = e; -> a = (a & ~mask) | (((cast)e << l) & mask); auto cmpl = new IR::Cmpl(ls->srcInfo, mask); auto and1 = new IR::BAnd(ls->srcInfo, ls->e0, cmpl); auto cast = new IR::Cast(right->srcInfo, type, right); auto sh = new IR::Shl(right->srcInfo, cast, new IR::Constant(l)); auto and2 = new IR::BAnd(right->srcInfo, sh, mask); auto rhs = new IR::BOr(right->srcInfo, and1, and2); auto result = new IR::AssignmentStatement(stat->srcInfo, ls->e0, rhs); LOG1("Replaced " << stat << " with " << result); return result; }
NumericArray Stencil::getLInSize( const Position pos, const Index sx, const Index sy, const Index nx, const Index ny, const Precision hx, const Precision hy, const Point origin, const Index size ) const { ASSERT( size == 1 || size == 2 ); NumericArray result( 0.0, size == 1 ? 9 : 25 ); NumericArray operatorL = getL( pos, sx, sy, nx, ny, hx, hy, origin ); PositionArray jX = getJx( pos, nx, ny ); PositionArray jY = getJy( pos, nx, ny ); for ( Index i = 0; i < operatorL.size(); i++ ) { if( jX[ i ] == -1 ) { if( jY[ i ] == -1 ) result[ SW ] = operatorL[ i ]; else if( jY[ i ] == 0 ) result[ W ] = operatorL[ i ]; else if( jY[ i ] == 1) result[ NW ] = operatorL[ i ]; if ( size > 1 ) { if ( jY[ i ] == -2 ) result[ SSW ] = operatorL[ i ]; else if( jY[ i ] == 2 ) result[ NNW ] = operatorL[ i ]; } else if ( jY[i] == -2 || jY[i] == 2 ) { result[ C ] += operatorL[ i ]; } } else if( jX[ i ] == 0 ) { if( jY[ i ] == -1 ) result[ S ] = operatorL[ i ]; else if( jY[ i ] == 0 ) result[ C ] += operatorL[ i ]; else if( jY[ i ] == 1 ) result[ N ] = operatorL[ i ]; if ( size > 1 ) { if ( jY[ i ] == -2 ) result[ SS ] = operatorL[ i ]; else if( jY[ i ] == 2 ) result[ NN ] = operatorL[ i ]; } else if ( jY[ i ] == -2 || jY[ i ] == 2 ) { result[ C ] += operatorL[ i ]; } } else if( jX[ i ] == 1 ) { if( jY[ i ] == -1 ) result[ SE ] = operatorL[ i ]; else if( jY[ i ] == 0 ) result[ E ] = operatorL[ i ]; else if( jY[ i ] == 1 ) result[ NE ] = operatorL[ i ]; if ( size > 1 ) { if ( jY[ i ] == -2 ) result[ SSE ] = operatorL[ i ]; else if( jY[ i ] == 2 ) result[ NNE ] = operatorL[ i ]; } else if ( jY[ i ] == -2 || jY[ i ] == 2 ) { result[ C ] += operatorL[ i ]; } } if ( size > 1 ) { if ( jX[ i ] == -2 ) { if ( jY[ i ] == -2 ) result[ SSWW ] = operatorL[ i ]; else if ( jY[ i ] == -1 ) result[ SWW ] = operatorL[ i ]; else if ( jY[ i ] == 0 ) result[ WW ] = operatorL[ i ]; else if ( jY[ i ] == 1 ) result[ NWW ] = operatorL[ i ]; else if ( jY[ i ] == 2 ) result[ NNWW ] = operatorL[ i ]; } else if ( jX[ i ] == 2 ) { if ( jY[ i ] == -2 ) result[ SSEE ] = operatorL[ i ]; else if ( jY[ i ] == -1 ) result[ SEE ] = operatorL[ i ]; else if ( jY[ i ] == 0 ) result[ EE ] = operatorL[ i ]; else if ( jY[ i ] == 1 ) result[ NEE ] = operatorL[ i ]; else if ( jY[ i ] == 2 ) result[ NNEE ] = operatorL[ i ]; } } else if ( jX[ i ] == -2 || jX[ i ] == 2 ) { result[ C ] += operatorL[ i ]; } } return result; }
//! Returns the number of nonzero entries in the global graph. int getGlobalNumEntries() const {return(getL().getGlobalNumEntries()+getU().getGlobalNumEntries());}