void DrivenCavity<Dim>::Jacobian(const vector_ptrtype& X, sparse_matrix_ptrtype& J) { auto U = Vh->element( "(u,p)" ); auto V = Vh->element( "(v,q)" ); auto u = U.template element<0>( "u" ); auto v = V.template element<0>( "u" ); auto p = U.template element<1>( "p" ); auto q = V.template element<1>( "p" ); //#if defined( FEELPP_USE_LM ) auto lambda = U.template element<2>(); auto nu = V.template element<2>(); //#endif if (!J) J = backend(_name="newtonns")->newMatrix( Vh, Vh ); auto a = form2( _test=Vh, _trial=Vh, _matrix=J ); a = integrate( elements( mesh ), inner(gradt( u ),grad( v ))/Re ); a += integrate( elements( mesh ), id(q)*divt(u) -idt(p)*div(v) ); // Convective terms a += integrate( elements( mesh ), trans(id(v))*gradv(u)*idt(u)); a += integrate( elements( mesh ), trans(id(v))*gradt(u)*idv(u)); //#if defined( FEELPP_USE_LM ) a += integrate(elements(mesh), id(q)*idt(lambda)+idt(p)*id(nu)); //#elif //a += integrate(elements(mesh), idt(p)*id(nu)); //Weak Dirichlet conditions a += integrate( boundaryfaces( mesh ),-trans( -idt(p)*N()+gradt(u)*N()/Re )*id( v ));// a += integrate( boundaryfaces( mesh ),-trans( -id(p)*N()+grad(u)*N()/Re )*idt( u ));// a += integrate( boundaryfaces( mesh ), +penalbc*inner( idt( u ),id( v ) )/hFace() ); }
int middle (int x) { if (x == 0) return inner (5); else return inner (6); }
/// This is supposed to clear the scopes up to the specified ID, without /// checking for conflicts. This can't be implemented by RSTM yet. inline void _ITM_transaction::commitToId(_ITM_transactionId_t id) { assert(false && "commitToId not yet implemented."); for (Node* scope = inner(); scope->getId() > id; scope = inner()) { // rstm_merge_scopes_without_aborting scope->commit(); leave(); } }
sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(const AsFPArgs& args) const { SkASSERT(args.fContext); SkMatrix localMatrix = this->getLocalMatrix(); if (args.fLocalMatrix) { localMatrix.preConcat(*args.fLocalMatrix); } SkMatrix matrix = *args.fViewMatrix; matrix.preConcat(localMatrix); if (0 == fNumOctaves) { if (kFractalNoise_Type == fType) { // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) // TODO: Either treat the output of this shader as sRGB or allow client to specify a // color space of the noise. Either way, this case (and the GLSL) need to convert to // the destination. sk_sp<GrFragmentProcessor> inner( GrConstColorProcessor::Make(GrColor4f::FromGrColor(0x80404040), GrConstColorProcessor::kModulateRGBA_InputMode)); return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); } // Emit zero. return GrConstColorProcessor::Make(GrColor4f::TransparentBlack(), GrConstColorProcessor::kIgnore_InputMode); } // Either we don't stitch tiles, either we have a valid tile size SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); SkPerlinNoiseShader::PaintingData* paintingData = new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); sk_sp<GrTextureProxy> permutationsProxy(GrMakeCachedBitmapProxy( args.fContext->resourceProvider(), paintingData->getPermutationsBitmap())); sk_sp<GrTextureProxy> noiseProxy(GrMakeCachedBitmapProxy(args.fContext->resourceProvider(), paintingData->getNoiseBitmap())); SkMatrix m = *args.fViewMatrix; m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); if (permutationsProxy && noiseProxy) { sk_sp<GrFragmentProcessor> inner( GrPerlinNoiseEffect::Make(args.fContext->resourceProvider(), fType, fNumOctaves, fStitchTiles, paintingData, std::move(permutationsProxy), std::move(noiseProxy), m)); return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); } delete paintingData; return nullptr; }
const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( GrContext* context, const SkMatrix& viewM, const SkMatrix* externalLocalMatrix, SkFilterQuality) const { SkASSERT(context); SkMatrix localMatrix = this->getLocalMatrix(); if (externalLocalMatrix) { localMatrix.preConcat(*externalLocalMatrix); } SkMatrix matrix = viewM; matrix.preConcat(localMatrix); if (0 == fNumOctaves) { if (kFractalNoise_Type == fType) { // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) SkAutoTUnref<const GrFragmentProcessor> inner( GrConstColorProcessor::Create(0x80404040, GrConstColorProcessor::kModulateRGBA_InputMode)); return GrFragmentProcessor::MulOutputByInputAlpha(inner); } // Emit zero. return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode); } // Either we don't stitch tiles, either we have a valid tile size SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); SkPerlinNoiseShader::PaintingData* paintingData = new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); SkAutoTUnref<GrTexture> permutationsTexture( GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), GrTextureParams::ClampNoFilter())); SkAutoTUnref<GrTexture> noiseTexture( GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), GrTextureParams::ClampNoFilter())); SkMatrix m = viewM; m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); if ((permutationsTexture) && (noiseTexture)) { SkAutoTUnref<GrFragmentProcessor> inner( GrPerlinNoiseEffect::Create(fType, fNumOctaves, fStitchTiles, paintingData, permutationsTexture, noiseTexture, m)); return GrFragmentProcessor::MulOutputByInputAlpha(inner); } delete paintingData; return nullptr; }
float iaf_dist(int len, float *list1, float *list2){ float af11 = 0; float af22 = 0; float af12 = 0; float dist = 0; af11 = inner(len,list1,list1); af22 = inner(len,list2,list2); af12 = inner(len,list1,list2); dist = af11 * af22 / af12 / af12; return(dist); }
inline void _ITM_transaction::registerOnCommit(_ITM_userCommitFunction f, _ITM_transactionId_t tid, void* arg) { Node* scope = inner(); while (scope->getId() > tid) { scope = inner(); } assert(scope->getId() == tid && "asked for a scope that doesn't exist"); scope->registerOnCommit(f, arg); }
void proj(double *dest, double *projected, double* vout, int dim) { double destnorm = inner(dest, dest, dim); double scale = inner(dest, projected, dim); int i; if (destnorm==0) scale = 0; else scale /= destnorm; for (i=0; i<dim; i++) vout[i] = dest[i] * scale; }
float naf_dist(int len, float *list1, float *list2){ float af11 = 0; float af22 = 0; float af12 = 0; float dist = 0; af11 = inner(len,list1,list1); af22 = inner(len,list2,list2); af12 = inner(len,list1,list2); //dist = af11 * af22 / af12 / af12; dist = af12 * af12 / af11 / af22; dist = 1-dist; return(dist); }
int main( int argc, char *argv[] ) { int i, j; int size = 8; float x[8], y[8], z; printf("Please enter the 8 floating point numbers of the first of the two vectors you wish to multiply:\n"); /* prompts the user for the elements of the first vector */ for (i=0; i<size; i++){ /* runs loop once for every element in the array */ scanf("%f", &x[i]); /* enters the data into the corresponding element */ } printf("Please enter the 8 floating point values of the second of the two vectors you wish to multiply:\n"); /* prompts the user for the elements of the second vector */ for (j=0; j<size; j++){ /* runs loop once for every element in the array */ scanf("%f", &y[j]); /* enters the data into the corresponding element */ } z = inner (x, y, 8); /* calls the inner function and stores the return value into the variable z */ printf("The inner product of the two vectors is %f.\n", z); /* prints the inner product of the two vectors */ return 0 ; }
BaseIF* makeVane(const Real& thick, const RealVect& normal, const Real& innerRadius, const Real& outerRadius, const Real& offset, const Real& height) { RealVect zero(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> vaneParts; // Each side of the vane (infinite) RealVect normal1(normal); RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0)); PlaneIF plane1(normal1,point1,inside); vaneParts.push_back(&plane1); RealVect normal2(-normal); RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0)); PlaneIF plane2(normal2,point2,inside); vaneParts.push_back(&plane2); // Make sure we only get something to the right of the origin RealVect normal3(D_DECL(0.0,0.0,1.0)); RealVect point3(D_DECL(0.0,0.0,0.0)); PlaneIF plane3(normal3,point3,inside); vaneParts.push_back(&plane3); // Cut off the top and bottom RealVect normal4(D_DECL(1.0,0.0,0.0)); RealVect point4(D_DECL(offset,0.0,0.0)); PlaneIF plane4(normal4,point4,inside); vaneParts.push_back(&plane4); RealVect normal5(D_DECL(-1.0,0.0,0.0)); RealVect point5(D_DECL(offset+height,0.0,0.0)); PlaneIF plane5(normal5,point5,inside); vaneParts.push_back(&plane5); // The outside of the inner cylinder TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside); vaneParts.push_back(&inner); // The inside of the outer cylinder TiltedCylinderIF outer(outerRadius,xAxis,zero,inside); vaneParts.push_back(&outer); IntersectionIF* vane = new IntersectionIF(vaneParts); return vane; }
sk_sp<SkSpecialImage> SkComposeImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx, SkIPoint* offset) const { // The bounds passed to the inner filter must be filtered by the outer // filter, so that the inner filter produces the pixels that the outer // filter requires as input. This matters if the outer filter moves pixels. SkIRect innerClipBounds; innerClipBounds = this->getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); SkIPoint innerOffset = SkIPoint::Make(0, 0); sk_sp<SkSpecialImage> inner(this->filterInput(1, source, innerContext, &innerOffset)); if (!inner) { return nullptr; } SkMatrix outerMatrix(ctx.ctm()); outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y())); SkIRect clipBounds = ctx.clipBounds(); clipBounds.offset(-innerOffset.x(), -innerOffset.y()); Context outerContext(outerMatrix, clipBounds, ctx.cache()); SkIPoint outerOffset = SkIPoint::Make(0, 0); sk_sp<SkSpecialImage> outer(this->filterInput(0, inner.get(), outerContext, &outerOffset)); if (!outer) { return nullptr; } *offset = innerOffset + outerOffset; return outer; }
/// Handles the _ITM_commitTransaction call. Simply asks the library to /// commit. If the library commit call actually returns, then there weren't any /// conflicts. If it didn't return then everything was handled by tmabort. inline void _ITM_transaction::commit(void** protected_stack_lower_bound) { // This code was pilfered from <stm/api/library.hpp>. // Don't commit anything if we're nested... just exit this scope, this // hopefully respects libstm's lack of closed nesting for the moment. // // Don't pre-decerement the nesting depth, because the tmcommit call can // fail due to a conflict. This calls tmabort, and tmabort will fail if the // nesting depth is 0. if (thread_handle_.nesting_depth == 1) { // dispatch to the appropriate end function thread_handle_.tmcommit(&thread_handle_, protected_stack_lower_bound); // // zero scope (to indicate "not in tx") CFENCE; thread_handle_.scope = NULL; // record start of nontransactional time, this misses the itm2stm commit // and leave time for the outermost scope, but I think we're ok. thread_handle_.end_txn_time = tick(); } // Decrement the nesting depth unconditionally here. It's needed on a nested // commit, as well as after the tmcommit succeeds for the outermost scope. --thread_handle_.nesting_depth; inner()->commit(); leave(); // don't care about the returned node during a commit }
int main(int argc, char *argv[]){ float x[8], y[8]; float product; int i, j; int size = 8; printf("Type eight floating point numbers: "); for(i = 0; i < 8; i++){ scanf("%f", &x[i]); } printf("Type eight floating point numbers: "); for(j = 0; j < 8; j++){ scanf("%f", &y[j]); } product = inner(x, y, size); printf("%f\n", product); return 0; }
sf::ConvexShape star(unsigned int nbStarPoints, float innerRadius, float outerRadius, const sf::Color& fillColor, float outlineThickness, const sf::Color& outlineColor) { assert(innerRadius > 0.f); assert(outerRadius > innerRadius); assert(outlineThickness >= 0.f); // Calculate points of the inner, regular polygon and the outer star points PolarVector2f inner(innerRadius, 0.f); PolarVector2f outer(outerRadius, 0.f); sf::ConvexShape shape; shape.setFillColor(fillColor); shape.setOutlineThickness(outlineThickness); shape.setOutlineColor(outlineColor); // Step around and alternately add inner and outer points for (unsigned int points = 0; points < nbStarPoints; ++points) { inner.phi = 360.f * points / nbStarPoints; outer.phi = inner.phi + 180.f / nbStarPoints; addPoint(shape, inner); addPoint(shape, outer); } return shape; }
void EmojiButton::paintEvent(QPaintEvent *e) { Painter p(this); uint64 ms = getms(); float64 loading = a_loading.current(ms, _loading ? 1 : 0); p.setOpacity(_opacity * (1 - loading)); p.fillRect(e->rect(), a_bg.current()); p.setOpacity(a_opacity.current() * _opacity * (1 - loading)); const style::sprite &i((_state & StateDown) ? _st.downIcon : _st.icon); if (!i.isEmpty()) { const QPoint &t((_state & StateDown) ? _st.downIconPos : _st.iconPos); p.drawSprite(t, i); } p.setOpacity(a_opacity.current() * _opacity); p.setPen(QPen(st::emojiCircleFg, st::emojiCircleLine)); p.setBrush(Qt::NoBrush); p.setRenderHint(QPainter::HighQualityAntialiasing); QRect inner(QPoint((width() - st::emojiCircle.width()) / 2, st::emojiCircleTop), st::emojiCircle); if (loading > 0) { int32 full = 5760; int32 start = qRound(full * float64(ms % uint64(st::emojiCirclePeriod)) / st::emojiCirclePeriod), part = qRound(loading * full / st::emojiCirclePart); p.drawArc(inner, start, full - part); } else { p.drawEllipse(inner); } p.setRenderHint(QPainter::HighQualityAntialiasing, false); }
int main( int argc, char* argv[] ) { float u[8], v[8]; int size, i; /* printf( "\nEnter the number of elements the vectors will contain: " ); scanf( "%d", &size ); */ size = 8; if( (size >= 0) && (size <= 8) ){ printf( "\nEnter %d floating point value(s) for each vector to obtain their dot product:\n\nVector 1: ", size ); for( i = 0; i < size; i++ ) scanf( "%f", &u[i] ); printf( "\nVector 2: " ); for( i = 0; i < size; i++ ) scanf( "%f", &v[i] ); printf( "\nThe dot product of the two vectors is: %f\n\n", inner( u, v, size ) ); } else printf( "\nThe number of elements each vector can contain must be from 0 to 8 inclusively.\n\n" ); return 0; }
void GenerateFullMatrices(double values[], double scale, boost::shared_ptr<NekMatrix<NekDouble, StandardMatrixTag> >& m1, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag> >& m2, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag> >& m3) { m1 = MakePtr(new NekMatrix<NekDouble, StandardMatrixTag>(4, 4, values)); double inner_values[16]; std::transform(values, values+16, inner_values, boost::bind(std::divides<NekDouble>(), _1, scale)); boost::shared_ptr<NekMatrix<NekDouble> > inner( new NekMatrix<NekDouble>(4, 4, inner_values)); m2 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag>(scale, inner)); double block_1_values[] = {values[0], values[1], values[4], values[5]}; double block_2_values[] = {values[2], values[3], values[6], values[7]}; double block_3_values[] = {values[8], values[9], values[12], values[13]}; double block_4_values[] = {values[10], values[11], values[14], values[15]}; boost::shared_ptr<NekMatrix<NekDouble> > block1(new NekMatrix<NekDouble>(2, 2, block_1_values)); boost::shared_ptr<NekMatrix<NekDouble> > block2(new NekMatrix<NekDouble>(2, 2, block_2_values)); boost::shared_ptr<NekMatrix<NekDouble> > block3(new NekMatrix<NekDouble>(2, 2, block_3_values)); boost::shared_ptr<NekMatrix<NekDouble> > block4(new NekMatrix<NekDouble>(2, 2, block_4_values)); m3 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag>(2, 2, 2, 2)); m3->SetBlock(0,0, block1); m3->SetBlock(1,0, block2); m3->SetBlock(0,1, block3); m3->SetBlock(1,1, block4); }
void GenerateUpperTriangularMatrices(NekDouble values[], NekDouble scale, boost::shared_ptr<NekMatrix<NekDouble, StandardMatrixTag> >& m1, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag> >& m2, boost::shared_ptr<NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag> >& m3) { m1 = MakePtr(new NekMatrix<NekDouble, StandardMatrixTag>(4, 4, values, eUPPER_TRIANGULAR)); double inner_values[10]; std::transform(values, values+10, inner_values, boost::bind(std::divides<NekDouble>(), _1, scale)); boost::shared_ptr<NekMatrix<NekDouble> > inner( new NekMatrix<NekDouble>(4, 4, inner_values, eUPPER_TRIANGULAR)); m2 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, ScaledMatrixTag>(scale, inner)); double block_1_values[] = {values[0], 0.0, values[1], values[2]}; double block_2_values[] = {values[3], values[4], values[6], values[7]}; double block_4_values[] = {values[5], 0.0, values[8], values[9]}; boost::shared_ptr<NekMatrix<NekDouble> > block1(new NekMatrix<NekDouble>(2, 2, block_1_values)); boost::shared_ptr<NekMatrix<NekDouble> > block2(new NekMatrix<NekDouble>(2, 2, block_2_values)); boost::shared_ptr<NekMatrix<NekDouble> > block4(new NekMatrix<NekDouble>(2, 2, block_4_values)); m3 = MakePtr(new NekMatrix<NekMatrix<NekDouble>, BlockMatrixTag>(2, 2, 2, 2)); m3->SetBlock(0,0, block1); m3->SetBlock(0,1, block2); m3->SetBlock(1,1, block4); }
/* * Check if the current predicted type for the location in ii is specific * enough for what the current opcode wants. If not, return false. */ bool RegionFormer::consumeInput(int i, const InputInfo& ii) { if (ii.dontGuard) return true; auto const type = irgen::predictedTypeFromLocation(m_irgs, ii.loc); if (m_profiling && type <= TBoxedCell && (m_region->blocks().size() > 1 || !m_region->entry()->empty())) { // We don't want side exits when profiling, so only allow instructions that // consume refs at the beginning of the region. return false; } if (!ii.dontBreak && !type.isKnownDataType()) { // Trying to consume a value without a precise enough type. FTRACE(1, "selectTracelet: {} tried to consume {}\n", m_inst.toString(), m_inst.inputs[i].pretty()); return false; } if (!(type <= TBoxedCell) || m_inst.ignoreInnerType || ii.dontGuardInner) { return true; } if (!type.inner().isKnownDataType()) { // Trying to consume a boxed value without a guess for the inner type. FTRACE(1, "selectTracelet: {} tried to consume ref {}\n", m_inst.toString(), m_inst.inputs[i].pretty()); return false; } return true; }
void CalcDensity(particle_t *SPH){ #pragma omp parallel for for(int i = 0 ; i < N_SPHP ; ++ i){ SPH[i].div_v = 0; SPH[i].omega = 0; SPH[i].rot_v = vec3<double>(0, 0, 0); SPH[i].rho = 0; SPH[i].q = 0; for(int k = 0 ; k < SPH[i].n_ngb ; ++ k){ int j = SPH[i].ngb_hash[k]; SPH[i].rho += SPH[j].m * kernel.W(SPH[i].r - SPH[j].r, SPH[i].h); SPH[i].q += SPH[j].m * SPH[j].u * kernel.W(SPH[i].r - SPH[j].r, SPH[i].h); } //Pressure SPH[i].p = Pressure (SPH[i].q / SPH[i].u, SPH[i].u); SPH[i].c = SoundSpeed(SPH[i].q / SPH[i].u, SPH[i].u); //div v and rot v for(int k = 0 ; k < SPH[i].n_ngb ; ++ k){ int j = SPH[i].ngb_hash[k]; if(i == j) continue; vec3<double> dr = SPH[i].r - SPH[j].r; vec3<double> dv = SPH[i].v - SPH[j].v; vec3<double> grad_kernel = kernel.gradW(dr, SPH[i].h); SPH[i].omega += - SPH[j].m * SPH[j].u * (N_DIM / SPH[i].h * kernel.W(dr, SPH[i].h) - abs(dr) / SPH[i].h * abs(grad_kernel)); double volume = SPH[j].m * SPH[i].u / SPH[i].q; SPH[i].div_v += - volume * inner(dv, grad_kernel); SPH[i].rot_v += - volume * outer(dv, grad_kernel); } //Balsara 1989 SPH[i].f = abs(SPH[i].div_v) / (abs(SPH[i].div_v) + abs(SPH[i].rot_v) + 1.0e-4 * SPH[i].c / SPH[i].h); //Hopkins 2012 SPH[i].omega = 1.0 + SPH[i].h / (N_DIM * SPH[i].q) * SPH[i].omega; } }
void CalcDensity(particle_t *SPH){ #pragma omp parallel for for(int i = 0 ; i < N_SPHP ; ++ i){ SPH[i].div_v = 0; SPH[i].omega = 0; SPH[i].rot_v = vec3<double>(0, 0, 0); SPH[i].p_smth = 0; for(int k = 0 ; k < SPH[i].n_ngb ; ++ k){ int j = SPH[i].ngb_hash[k]; SPH[i].p_smth += SPH[j].Y * kernel.W(SPH[i].r - SPH[j].r, SPH[i].h); } //Pressure SPH[i].p = Pressure (SPH[i].m * SPH[i].p_smth / SPH[i].Y, SPH[i].u); SPH[i].c = SoundSpeed(SPH[i].m * SPH[i].p_smth / SPH[i].Y, SPH[i].u); SPH[i].rho = SPH[i].m * SPH[i].p_smth / SPH[i].Y; //div v and rot v for(int k = 0 ; k < SPH[i].n_ngb ; ++ k){ int j = SPH[i].ngb_hash[k]; if(i == j) continue; vec3<double> dr = SPH[i].r - SPH[j].r; vec3<double> dv = SPH[i].v - SPH[j].v; vec3<double> grad_kernel = kernel.gradW(dr, SPH[i].h); SPH[i].omega += - SPH[j].Y * (N_DIM / SPH[i].h * kernel.W(dr, SPH[i].h) - abs(dr) / SPH[i].h * abs(grad_kernel)); double volume = SPH[j].Y / SPH[i].p_smth; SPH[i].div_v += - volume * inner(dv, grad_kernel); SPH[i].rot_v += - volume * outer(dv, grad_kernel); } //DEBUG SPH[i].er = (SPH[i].p_smth + 7.15 * 3309.0) / (SPH[i].rho * 6.15) / SPH[i].u - 1.0; //Balsara 1989 SPH[i].f = abs(SPH[i].div_v) / (abs(SPH[i].div_v) + abs(SPH[i].rot_v) + 1.0e-4 * SPH[i].c / SPH[i].h); //Hosono+ (?) SPH[i].omega = 1.0 + SPH[i].h / (N_DIM * SPH[i].p_smth) * SPH[i].omega; } }
void NormalizedPointsSpace<T>::loadPointsSpace(const char* fileName) { std::ifstream in(fileName); if(!in.is_open()) return; in >> this->num_points__ >> this->num_dimensions__ >> this->quant; this->lines__ = this->num_points__; int counter = 0, coordId=0, pointId=0; Coord tmp; in >> pointId; char separator; while(!in.eof()) { T* point = new T(counter); std::string line; std::getline(in, line); std::stringstream inner(std::ios::in); inner.str(line); inner.seekg(0, std::ios_base::beg); while(!inner.eof()) { inner >> coordId >> separator >> tmp; point->insert(coordId, tmp); } points__.insert({counter, dynamic_cast<AbstractPoint*>(point)}); } in.close(); }
void test_model() { cout << "Running test_model" << endl; number_t nCells = 3000; real c = 0.5; real a = 0.1; Topology W(nCells, c); Pattern Z(nCells, a); Matrix J(nCells, nCells); J = clipped_Hebbian(Z,W); // iterate 5 x more vector<Matrix::data_t> I; // Stores the inner product // Create X=Z0 vector for inner product vector<Matrix::data_t> X=Z.AsVector(0); for (int i=0; i<5; ++i) { I = inner(J.transpose(), X); vector<real> V(I.size()); // Calculate Average 'spk_avg' real spk_avg=0; for (register size_t x=0; x<I.size(); ++x) { V[x]=static_cast<real>(I[x]) / nCells; spk_avg += V[x]; } spk_avg /= V.size(); // cout << "Average: " << spk_avg << endl; // Send some debug info to stdout // cout << "Before V=: " << endl; // for (vector<real>::iterator it=V.begin(); it!=V.end(); ++it) // cout << *it << " "; // cout << endl; // cout << " spk_avg=" << spk_avg << " * 0.433 = " << 0.433*spk_avg << endl; // Compute threshold real threshold = 0.433*spk_avg; size_t count=0; for (register size_t x=0; x<I.size(); ++x) if (V[x]>threshold) { X[x] = 1; ++count; } else X[x]=0; cout << "Iteration " << i << "-> number of neurons over threshold: " << count << endl; // Print Result // cout << "After X=:" << endl; // for (vector<Matrix::data_t>::iterator it=X.begin(); it!=X.end(); ++it) // cout << (int)(*it) << " "; // cout << endl; } cout << "Done" << endl; }
void TriangulationCDTWindow::OneNestedPolygon() { int numPoints = 7; mPoints.resize(numPoints); mPoints[0] = { 128.0f, 256.0f }; mPoints[1] = { 256.0f, 128.0f }; mPoints[2] = { 384.0f, 256.0f }; mPoints[3] = { 256.0f, 384.0f }; mPoints[4] = { 320.0f, 256.0f }; mPoints[5] = { 256.0f, 192.0f }; mPoints[6] = { 256.0f, 320.0f }; std::vector<int> outer(4); outer[0] = 0; outer[1] = 1; outer[2] = 2; outer[3] = 3; std::vector<int> inner(3); inner[0] = 4; inner[1] = 5; inner[2] = 6; Triangulator::Polygon outerPoly = { (int)outer.size(), &outer[0] }; Triangulator::Polygon innerPoly = { (int)inner.size(), &inner[0] }; mTriangulator = std::make_unique<Triangulator>(numPoints, &mPoints[0]); (*mTriangulator)(outerPoly, innerPoly); auto const& triangles = mTriangulator->GetAllTriangles(); int numTriangles = (int)triangles.size(); mPMesher = std::make_unique<PlanarMesher>(numPoints, &mPoints[0], numTriangles, (int const*)&triangles[0]); DrawTriangulation(); }
int main(int argc, char* argv[]) { float u[8], v[8]; int i, j ; float ans ; for( i = 0 ; i < 8 ; i++) { printf("Print first 8 values for the first vector:"); scanf("%f", &u[i]); } for( j = 0 ; j < 8 ; j++ ) { printf("Print next 8 values for the second vector:"); scanf("%f", &v[j]); } ans = inner( u, v, 8 ); printf("The answer is: %f", ans); printf( "\n"); return 0; }
void CountrySelect::paintEvent(QPaintEvent *e) { bool trivial = (rect() == e->rect()); QPainter p(this); if (!trivial) { p.setClipRect(e->rect()); } p.setOpacity(st::layerAlpha * a_bgAlpha.current()); p.fillRect(rect(), st::layerBG->b); if (animating()) { p.setOpacity(a_alpha.current()); p.drawPixmap(a_coord.current() + _innerLeft, _innerTop, _cache); } else { p.setOpacity(1); QRect inner(_innerLeft, _innerTop, _innerWidth, _innerHeight); _shadow.paint(p, inner); if (trivial || e->rect().intersects(inner)) { // fill bg p.fillRect(inner, st::white->b); // paint shadows p.fillRect(_innerLeft, _innerTop + st::participantFilter.height, _innerWidth, st::scrollDef.topsh, st::scrollDef.shColor->b); // paint button sep p.fillRect(_innerLeft + st::btnSelectCancel.width, _innerTop + _innerHeight - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b); // draw box title / text p.setPen(st::black->p); p.setFont(st::addContactTitleFont->f); p.drawText(_innerLeft + st::addContactTitlePos.x(), _innerTop + st::addContactTitlePos.y() + st::addContactTitleFont->ascent, lang(lng_country_select)); } } }
void EmojiButton::paintEvent(QPaintEvent *e) { Painter p(this); auto ms = getms(); p.fillRect(e->rect(), st::historyComposeAreaBg); paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms); auto loading = a_loading.current(ms, _loading ? 1 : 0); p.setOpacity(1 - loading); auto over = isOver(); auto icon = &(over ? _st.iconOver : _st.icon); icon->paint(p, _st.iconPosition, width()); p.setOpacity(1.); auto pen = (over ? st::historyEmojiCircleFgOver : st::historyEmojiCircleFg)->p; pen.setWidth(st::historyEmojiCircleLine); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setBrush(Qt::NoBrush); PainterHighQualityEnabler hq(p); QRect inner(QPoint((width() - st::historyEmojiCircle.width()) / 2, st::historyEmojiCircleTop), st::historyEmojiCircle); if (loading > 0) { int32 full = FullArcLength; int32 start = qRound(full * float64(ms % st::historyEmojiCirclePeriod) / st::historyEmojiCirclePeriod), part = qRound(loading * full / st::historyEmojiCirclePart); p.drawArc(inner, start, full - part); } else { p.drawEllipse(inner); } }
static inline void assemble(boost::shared_ptr<Mesh<Simplex<Dim>>>& mesh, double* vec) { boost::timer time; auto Vh = FunctionSpace<Mesh<Simplex<Dim>>, bases<Lagrange<Order, Type>>>::New(_mesh = mesh); vec[2] = time.elapsed(); vec[1] = Vh->nDof(); Environment::logMemoryUsage( "Assemble Laplacian Memory Usage: FunctionSpace" ); time.restart(); auto v = Vh->element(); auto f = backend()->newVector(Vh); auto l = form1(_test = Vh, _vector = f); l = integrate(_range = elements(mesh), _expr = id(v)); vec[4] = time.elapsed(); Environment::logMemoryUsage( "Assemble Laplacian Memory Usage: Form1" ); time.restart(); auto u = Vh->element(); auto A = backend()->newMatrix(Vh, Vh); vec[5] = time.elapsed(); Environment::logMemoryUsage( "Assemble Laplacian Memory Usage: Matrix" ); time.restart(); auto a = form2(_trial = Vh, _test = Vh, _matrix = A); a = integrate(_range = elements(mesh), _expr = inner(gradt(u),grad(v))); a += on(_range = markedfaces(mesh, "Dirichlet"), _rhs = l, _element = u, _expr = cst(0.0)); vec[3] = time.elapsed(); auto mem = Environment::logMemoryUsage( "Assemble Laplacian Memory Usage: form2" ); v[6] = mem.memory_usage/1e9; LOG(INFO) << "v[6] = " << v[6]; cleanup(); }
const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality) const { SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(fDeviceMatrix)); return GrFragmentProcessor::MulOutputByInputAlpha(inner); }