/** \brief Returns the minimum value of all values. \param a_pArg Pointer to an array of Values \param a_iArgc Number of values stored in a_pArg */ void FunMin::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc) { if (a_iArgc < 1) throw ParserError(ErrorContext(ecTOO_FEW_PARAMS, GetExprPos(), GetIdent())); float_type smin(1e30), sval(smin); for (int i=0; i<a_iArgc; ++i) { switch(a_pArg[i]->GetType()) { case 'f': case 'i': sval = a_pArg[i]->GetFloat(); break; default: { ErrorContext err; err.Errc = ecTYPE_CONFLICT_FUN; err.Arg = i+1; err.Type1 = a_pArg[i]->GetType(); err.Type2 = 'f'; throw ParserError(err); } } smin = min(smin, sval); } *ret = smin; }
cl_int2 ObjectClusterer::SearchValidPixelOnLine(const ImLine& border, const cl_int2& centerPixel, const int firstID, const int secondID) { int majorAxis=0, minorAxis=1; if(border.IsXAxisMajor()==false) { majorAxis=1; minorAxis=0; } cl_int2 linePixel = centerPixel; int pxidx, move=1; int rangeMin = smin(border.endPixels[0].s[majorAxis], border.endPixels[1].s[majorAxis]); int rangeMax = smax(border.endPixels[0].s[majorAxis], border.endPixels[1].s[majorAxis]); cl_float4 coef = (cl_float4){border.a, border.b, border.c, 0.f}; while(linePixel.s[majorAxis] >= rangeMin && linePixel.s[majorAxis] <= rangeMax) { linePixel.s[majorAxis] = centerPixel.s[majorAxis]-move; linePixel.s[minorAxis] = (int)(-coef.s[majorAxis]/coef.s[minorAxis]*linePixel.s[majorAxis] + coef.s[2]/coef.s[minorAxis]); pxidx = PIXIDX(linePixel); if(nullityMap[pxidx] < NullID::PointNull && (objectMap[pxidx]==firstID || objectMap[pxidx]==secondID)) return linePixel; linePixel.s[majorAxis] = centerPixel.s[majorAxis]+move; linePixel.s[minorAxis] = (int)(-coef.s[majorAxis]/coef.s[minorAxis]*linePixel.s[majorAxis] + coef.s[2]/coef.s[minorAxis]); pxidx = PIXIDX(linePixel); if(nullityMap[pxidx] < NullID::PointNull && (objectMap[pxidx]==firstID || objectMap[pxidx]==secondID)) return linePixel; move++; } throw 1; return centerPixel; }
int test_macros(void) { ASSERT_EQ(bits(256), 32); ASSERT_EQ(bytes(32), 256); ASSERT_EQ(smin(1, 2), 1); ASSERT_EQ(smax(1, 2), 2); return 1; }
int argmax(double *arrayin, uint32_t *arrayout, size_t nx, size_t ny, int nparallel){ size_t ix, iy, ix_offset, imax[NBLOCK]; double vmax[NBLOCK]; (void) nparallel; Py_BEGIN_ALLOW_THREADS #if defined(_OPENMP) #pragma omp parallel private(iy, ix_offset, imax, vmax) num_threads(nparallel) #endif { #if defined(_OPENMP) #pragma omp for schedule(dynamic, 1) nowait #endif for (ix=0; ix<nx; ix+=NBLOCK){ for (ix_offset=0; ix_offset<smin(NBLOCK, nx-ix); ix_offset++) { imax[ix_offset] = 0; vmax[ix_offset] = DBL_MIN; } for (iy=0; iy<ny; iy++){ for (ix_offset=0; ix_offset<smin(NBLOCK, nx-ix); ix_offset++) { if (arrayin[iy*nx + ix + ix_offset] > vmax[ix_offset]){ vmax[ix_offset] = arrayin[iy*nx + ix + ix_offset]; imax[ix_offset] = iy; } } } for (ix_offset=0; ix_offset<smin(NBLOCK, nx-ix); ix_offset++) { arrayout[ix+ix_offset] = (uint32_t)imax[ix_offset]; } } } Py_END_ALLOW_THREADS return SUCCESS; }
/// Set the first saturation to either its min or max value in /// the indicated cells. The second saturation value s2 is set /// to (1.0 - s1) for each cell. Any further saturation values /// are unchanged. void setFirstSat(const std::vector<int>& cells, const Opm::BlackoilPropertiesInterface& props, ExtremalSat es) { const int n = cells.size(); std::vector<double> smin(num_phases_*n); std::vector<double> smax(num_phases_*n); props.satRange(n, &cells[0], &smin[0], &smax[0]); const double* svals = (es == MinSat) ? &smin[0] : &smax[0]; for (int ci = 0; ci < n; ++ci) { const int cell = cells[ci]; sat_[num_phases_*cell] = svals[num_phases_*ci]; sat_[num_phases_*cell + 1] = 1.0 - sat_[num_phases_*cell]; } }
void IntervalFilter::add(uint16 from, uint16 to) { if (from > MAX_ID) { from = MAX_ID; } if (to > MAX_ID) { to = MAX_ID; } //assert order if (from > to) { sswap(from, to); } //adjust lower bound fFrom = smin(fFrom, from); //adjust upper bound fTo = smax(fTo, to); }
// Write up to nMax characters of the prepared (by DoSrv) response lines. // Returns the number of characters sent, including null. // Zero returned if and only if there's nothing else to send. int DoSrvMore(char *pOut, size_t nMax) { wxASSERT(currentLine >= 0); wxASSERT(currentPosition >= 0); size_t totalLines = aStr.GetCount(); while (currentLine < totalLines) { wxString lineString = aStr[currentLine]; size_t lineLength = lineString.Length(); size_t charsLeftInLine = lineLength - currentPosition; wxASSERT(charsLeftInLine >= 0); if (charsLeftInLine == 0) { // Move to next line ++currentLine; currentPosition = 0; } else { // Write as much of the rest of the line as will fit in the buffer size_t charsToWrite = smin(charsLeftInLine, nMax - 1); memcpy(pOut, lineString.Mid(currentPosition, currentPosition + charsToWrite).mb_str(), charsToWrite); pOut[charsToWrite] = '\0'; currentPosition += charsToWrite; // Need to cast to prevent compiler warnings int charsWritten = static_cast<int>(charsToWrite + 1); // (Check cast was safe) wxASSERT(static_cast<size_t>(charsWritten) == charsToWrite + 1); return charsWritten; } } return 0; }
float distance(vec4 point) { assert(sdf_args.num_edits <= 0 || sdf_args.edits != NULL); float dist = FLT_MAX; for (int i = 0; i < sdf_args.num_edits; ++i) { Primative *primative = sdf_args.edits[i]; switch (primative->operation) { case ADDITIVE: dist = primative->blend > 0 ? smin(dist, primative_distance(primative, point), primative->blend) : min(dist, primative_distance(primative, point)); break; case SUBTRACTIVE: dist = max(dist, -primative_distance(primative, point)); break; } } return dist; }