arma::mat Vespucci::Math::Transform::cwtPeakAnalysis(const arma::mat &X, std::string wavelet, arma::uword qscale, double threshold, std::string threshold_method, arma::mat &transform) { transform.set_size(X.n_rows, X.n_cols); arma::uvec scales(1); scales(0) = qscale; arma::uword i; arma::umat peak_positions; arma::mat peak_extrema(X.n_rows, X.n_cols); arma::vec spectrum, current_transform, dtransform, peak_magnitudes; try{ for (i = 0; i < X.n_cols; ++i){ spectrum = X.col(i); current_transform = Vespucci::Math::Transform::cwt(spectrum, wavelet, scales); transform.col(i) = current_transform; dtransform = Vespucci::Math::diff(transform, 1); dtransform.insert_rows(0, 1, true); //dtransform(i) is derivative at transform(i) peak_positions = Vespucci::Math::PeakFinding::FindPeakPositions(transform, dtransform, threshold, threshold_method, peak_magnitudes); peak_extrema.col(i) = Vespucci::Math::PeakFinding::PeakExtrema(X.n_elem, peak_positions); } } catch(std::exception e){ std::cerr << "CWTPeakAnalysis" << std::endl; std::cerr << "i = " << i << std::endl; throw(e); } return peak_extrema; }
arma::vec Vespucci::Math::Transform::cwt_spdbc(const arma::vec &X, std::string wavelet, arma::uword qscale, double threshold, std::string threshold_method, arma::uword window_size, arma::umat &peak_extrema, arma::vec &baseline) { arma::umat peaks; arma::vec peak_magnitudes; arma::uvec scales(1); scales(0) = qscale; try{ arma::vec X_transform = Vespucci::Math::Transform::cwt(X, wavelet, scales); arma::vec dX_transform = Vespucci::Math::diff(X, 1); dX_transform.insert_rows(0, 1, true); //buffer so that X and dX have same //number of elements and dX(i) is the derivative of X at i. peak_extrema = Vespucci::Math::PeakFinding::FindPeakPositions(X_transform, dX_transform, threshold, threshold_method, peak_magnitudes); baseline = Vespucci::Math::PeakFinding::EstimateBaseline(X, peak_extrema, window_size); }catch(std::exception e){ std::cerr << std::endl << "exception! cwt_spdbc" << std::endl; std::cerr << e.what(); throw(e); } return X - baseline; }
const scale_type& smaller(const scale_type& scale) const { const auto found = std::find_if(scales().rbegin(), scales().rend(), [&scale](const scale_type& candidate) { return candidate < scale; }); return found != scales().rend() ? *found : scales().front(); }
const scale_type& at(const size_type index) const { if (index >= scales().size()) BOOST_THROW_EXCEPTION(std::out_of_range("index is out of range.")); return scales()[index]; }
tetengo2::stdalt::optional<size_type> index_of(const scale_type& scale) const { for (size_type i = 0; i < scales().size(); ++i) { if (scales()[i] == scale) return tetengo2::stdalt::make_optional(std::move(i)); } return TETENGO2_STDALT_NULLOPT; }
void StackedRuizEquil ( SparseMatrix<Field>& A, SparseMatrix<Field>& B, Matrix<Base<Field>>& dRowA, Matrix<Base<Field>>& dRowB, Matrix<Base<Field>>& dCol, bool progress ) { EL_DEBUG_CSE typedef Base<Field> Real; const Int mA = A.Height(); const Int mB = B.Height(); const Int n = A.Width(); Ones( dRowA, mA, 1 ); Ones( dRowB, mB, 1 ); Ones( dCol, n, 1 ); // TODO(poulson): Expose these as control parameters // For now, simply hard-code the number of iterations const Int maxIter = 4; Matrix<Real> scales, maxAbsValsB; const Int indent = PushIndent(); for( Int iter=0; iter<maxIter; ++iter ) { // Rescale the columns // ------------------- ColumnMaxNorms( A, scales ); ColumnMaxNorms( B, maxAbsValsB ); for( Int j=0; j<n; ++j ) scales(j) = Max(scales(j),maxAbsValsB(j)); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dCol ); DiagonalSolve( RIGHT, NORMAL, scales, A ); DiagonalSolve( RIGHT, NORMAL, scales, B ); // Rescale the rows // ---------------- RowMaxNorms( A, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dRowA ); DiagonalSolve( LEFT, NORMAL, scales, A ); RowMaxNorms( B, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dRowB ); DiagonalSolve( LEFT, NORMAL, scales, B ); } SetIndent( indent ); }
void MKLDNNAddtoLayer::resetBwd(std::vector<primitive>& pipeline, std::vector<MKLDNNMatrixPtr>& inputs, MKLDNNMatrixPtr& out) { resetBwdBuffers(inputs, biasGrad_, out); // backward only need share output grad to input grad for (size_t i = 0; i < inputs.size(); i++) { if (inputs[i] != nullptr) { inputs[i] = out; inputLayers_[i]->getOutputGrad()->setData(inputs[i]->getData()); } } // backward bias bwdBias_ = nullptr; if (biasGrad_) { std::vector<float> scales(bs_, 1.0); std::vector<memory::primitive_desc> srcPDs(bs_, biasGrad_->getPrimitiveDesc()); auto biasPD = sum::primitive_desc(biasGrad_->getMemoryDesc(), scales, srcPDs); std::vector<primitive::at> srcs; for (size_t i = 0; i < grads_.size(); ++i) { srcs.push_back(*(grads_[i])); } bwdBias_.reset(new sum(biasPD, srcs, *biasGrad_)); pipeline.push_back(*bwdBias_); } }
static int m_test_scaletypes() { int i,scale_error; scales(&d); if (weight_variable>=0) { if (!scale_ok(&d,weight_variable,RATIO_SCALE)) { sprintf(sbuf,"\nWeight variable %.8s must have ratio scale!", d.varname[weight_variable]); sur_print(sbuf); WAIT; if (scale_check==SCALE_INTERRUPT) return(-1); } } scale_error=0; for (i=0; i<d.m_act; ++i) { if (!scale_ok(&d,d.v[i],SCORE_SCALE)) { if (!scale_error) sur_print("\nInvalid scale in variables: "); scale_error=1; sprintf(sbuf,"%.8s ",d.varname[d.v[i]]); sur_print(sbuf); } } if (scale_error) { sur_print("\nIn MEAN score scale at least is expected!"); WAIT; if (scale_check==SCALE_INTERRUPT) return(-1); } return(1); }
static void cwt(const vector<type>& intensities, double& fwhm, vector<double>& result) { if (intensities.empty()) { //printf("Empty spectrum no chance !"); //exit(0); LOG(FATAL) << "Empty spectrum no chance !"; exit(EXIT_FAILURE); } //make a copy of size power of 2 vector<double> ints(intensities.begin(), intensities.end()); makePowerOf2(ints); //double scale = MAGIC * fwhm; mz_uint N = ints.size(); cwtlib::WTransform *wt; try { cwtlib::Signal s( N, &ints[0] ); cwtlib::LinearRangeFunctor scales( fwhm, 3 * fwhm, 2 * fwhm); //perform only at one scale ? ->to test wt = cwtlib::CWTalgorithm::cwtft(s, scales, cwtlib::MexicanHat(), "Youpi"); } catch(exception& e) { //printf("%s\n", e.what()); LOG(ERROR) << e.what(); } //fill result //result.reserve( intensities.size() ); for (mz_uint i = 0, l=intensities.size(); i < l; ++i) { result.push_back(wt->re(0, i)); } delete wt; }
bool task1(const cv::Mat& image) { cv::Mat manual, buildIn, diff, tmp; std::vector<cv::Mat> channels; scaleImage(image, manual, 2, 100); image.convertTo(buildIn, -1, 2, 100); cv::absdiff(manual, buildIn, diff); cv::split(diff, channels); std::cout << "Max difference element: "; for (VMit it = channels.begin(); it != channels.end(); ++it) { int max = *(std::max_element((*it).begin<uchar>(), (*it).end<uchar>())); std::cout << max << " "; } std::cout << std::endl; std::vector<cv::Mat> scales(5, cv::Mat()); std::vector<cv::Mat> dst(2, cv::Mat()); for (int i = 0; i < task1c; ++i) { scaleImage(image, scales[i], task1v[2 * i], task1v[2 * i + 1]); } concatImages(scales[0], scales[1], dst[0]); concatChannels(dst[0], dst[0]); concatImages(scales[2], scales[3], dst[1]); concatImages(dst[1], scales[4], dst[1]); concatChannels(dst[1], dst[1]); return cv::imwrite(PATH + "Task1Lena01.jpg", dst[0]) && cv::imwrite(PATH + "Task1Lena345.jpg", dst[1]); }
void SymmetricRuizEquil ( DistSparseMatrix<F>& A, DistMultiVec<Base<F>>& d, Int maxIter, bool progress ) { DEBUG_CSE typedef Base<F> Real; const Int n = A.Height(); mpi::Comm comm = A.Comm(); d.SetComm( comm ); Ones( d, n, 1 ); DistMultiVec<Real> scales(comm); const Int indent = PushIndent(); for( Int iter=0; iter<maxIter; ++iter ) { // Rescale the columns (and rows) // ------------------------------ ColumnMaxNorms( A, scales ); EntrywiseMap( scales, function<Real(Real)>(DampScaling<Real>) ); EntrywiseMap( scales, function<Real(Real)>(SquareRootScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, d ); SymmetricDiagonalSolve( scales, A ); } SetIndent( indent ); }
template <typename PointInT, typename PointOutT> void pcl::SIFTKeypoint<PointInT, PointOutT>::detectKeypointsForOctave ( const PointCloudIn &input, KdTree &tree, float base_scale, int nr_scales_per_octave, PointCloudOut &output) { // Compute the difference of Gaussians (DoG) scale space std::vector<float> scales (nr_scales_per_octave + 3); for (int i_scale = 0; i_scale <= nr_scales_per_octave + 2; ++i_scale) { scales[i_scale] = base_scale * pow (2.0, (1.0 * i_scale - 1) / nr_scales_per_octave); } Eigen::MatrixXf diff_of_gauss; computeScaleSpace (input, tree, scales, diff_of_gauss); // Find extrema in the DoG scale space std::vector<int> extrema_indices, extrema_scales; findScaleSpaceExtrema (input, tree, diff_of_gauss, extrema_indices, extrema_scales); // Add keypoints to output for (size_t i_keypoint = 0; i_keypoint < extrema_indices.size (); ++i_keypoint) { PointOutT keypoint; const int &keypoint_index = extrema_indices[i_keypoint]; keypoint.x = input.points[keypoint_index].x; keypoint.y = input.points[keypoint_index].y; keypoint.z = input.points[keypoint_index].z; keypoint.scale = scales[extrema_scales[i_keypoint]]; output.points.push_back (keypoint); } }
/// This method rescales each statistic and combines all the results void MultiGrid2D::reduceStatistics(){ std::vector<BlockStatistics*> levelStatistics(this->getNumLevels()); std::vector<int> dimensionsX, dimensionsT; dimensionsX = statsSubscriber.getDimensionsX(); dimensionsT = statsSubscriber.getDimensionsT(); for (plint iLevel=0; iLevel<this->getNumLevels(); ++iLevel) { int dxScale = this->getReferenceLevel() - iLevel; int dtScale = dxScale; // TODO: here, we assume convective scaling; general case should be considered. std::vector<double> scales(dimensionsX.size()); for (pluint iScale=0; iScale<scales.size(); ++iScale) { scales[iScale] = scaleToReference(dxScale, dimensionsX[iScale], dtScale, dimensionsT[iScale]); } // copy the statistics levelStatistics[iLevel] = new BlockStatistics(getComponent(iLevel).getInternalStatistics()); // rescale the statistics to the reference level levelStatistics[iLevel]->rescale(scales); } combine(levelStatistics, getInternalStatistics() ); internalStatistics.incrementStats(); for (plint iLevel=0; iLevel<this->getNumLevels(); ++iLevel){ delete levelStatistics[iLevel]; } }
void executeDataProcessor( ReductiveDataProcessorGenerator3D& generator, std::vector<MultiGrid3D*> multiGrids, plint referenceLevel ) { if(multiGrids.empty()) return; plint numLevels = (plint)multiGrids[0]->getNumLevels(); std::vector<int> dimensionsX, dimensionsT; generator.getDimensionsX(dimensionsX); generator.getDimensionsT(dimensionsT); std::vector<ReductiveDataProcessorGenerator3D*> localGenerators(numLevels); std::vector<BlockStatistics*> localStatistics(numLevels); for (plint iLevel=0; iLevel<numLevels; ++iLevel) { int dxScale = (int)referenceLevel - (int)iLevel; int dtScale = dxScale; // TODO: here, we assume convective scaling; general case could be considered. localGenerators[iLevel] = generator.clone(); plint boxRescaleFactor = util::roundToInt(util::twoToThePowerPlint(std::abs(referenceLevel-iLevel))); if (dxScale < 0) generator.divide(boxRescaleFactor); else generator.multiply(boxRescaleFactor); std::vector<MultiBlock3D*> localBlocks(multiGrids.size()); for (plint iBlock=0; iBlock<(plint)localBlocks.size(); ++iBlock) { localBlocks[iBlock] = &multiGrids[iBlock]->getComponent(iLevel); } executeDataProcessor(*localGenerators[iLevel], localBlocks); std::vector<double> scales(dimensionsX.size()); for (pluint iScale=0; iScale<scales.size(); ++iScale) { scales[iScale] = scaleToReference(dxScale, dimensionsX[iScale], dtScale, dimensionsT[iScale]); } localGenerators[iLevel]->getStatistics().rescale(scales); localStatistics[iLevel] = &(localGenerators[iLevel]->getStatistics()); } combine(localStatistics, generator.getStatistics()); }
void SymmetricRuizEquil ( DistSparseMatrix<Field>& A, DistMultiVec<Base<Field>>& d, Int maxIter, bool progress ) { EL_DEBUG_CSE typedef Base<Field> Real; const Int n = A.Height(); const Grid& grid = A.Grid(); d.SetGrid( grid ); Ones( d, n, 1 ); DistMultiVec<Real> scales(grid); const Int indent = PushIndent(); for( Int iter=0; iter<maxIter; ++iter ) { // Rescale the columns (and rows) // ------------------------------ ColumnMaxNorms( A, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); EntrywiseMap( scales, MakeFunction(SquareRootScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, d ); SymmetricDiagonalSolve( scales, A ); } SetIndent( indent ); }
void EntityModel::setEntityScale(float value) { Lumix::StackAllocator<256> allocator; Lumix::Array<Lumix::Entity> entities(allocator); Lumix::Array<float> scales(allocator); entities.push(m_entity); scales.push(value); m_editor.setEntitiesScales(entities, scales); }
void StackedRuizEquil ( DistSparseMatrix<Field>& A, DistSparseMatrix<Field>& B, DistMultiVec<Base<Field>>& dRowA, DistMultiVec<Base<Field>>& dRowB, DistMultiVec<Base<Field>>& dCol, bool progress ) { EL_DEBUG_CSE typedef Base<Field> Real; const Int mA = A.Height(); const Int mB = B.Height(); const Int n = A.Width(); mpi::Comm comm = A.Comm(); dRowA.SetComm( comm ); dRowB.SetComm( comm ); dCol.SetComm( comm ); Ones( dRowA, mA, 1 ); Ones( dRowB, mB, 1 ); Ones( dCol, n, 1 ); // TODO(poulson): Expose to control structure // For, simply hard-code a small number of iterations const Int maxIter = 4; DistMultiVec<Real> scales(comm), maxAbsValsB(comm); auto& scalesLoc = scales.Matrix(); auto& maxAbsValsBLoc = maxAbsValsB.Matrix(); const Int localHeight = scalesLoc.Height(); const Int indent = PushIndent(); for( Int iter=0; iter<maxIter; ++iter ) { // Rescale the columns // ------------------- ColumnMaxNorms( A, scales ); ColumnMaxNorms( B, maxAbsValsB ); for( Int jLoc=0; jLoc<localHeight; ++jLoc ) scalesLoc(jLoc) = Max(scalesLoc(jLoc),maxAbsValsBLoc(jLoc)); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dCol ); DiagonalSolve( RIGHT, NORMAL, scales, A ); DiagonalSolve( RIGHT, NORMAL, scales, B ); // Rescale the rows // ---------------- RowMaxNorms( A, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dRowA ); DiagonalSolve( LEFT, NORMAL, scales, A ); RowMaxNorms( B, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dRowB ); DiagonalSolve( LEFT, NORMAL, scales, B ); } SetIndent( indent ); }
template <typename PointInT, typename PointOutT> void pcl::SIFTKeypoint<PointInT, PointOutT>::detectKeypointsForOctave ( const PointCloudIn &input, KdTree &tree, float base_scale, int nr_scales_per_octave, PointCloudOut &output, pcl::PointIndices &indices) { // Compute the difference of Gaussians (DoG) scale space std::vector<float> scales (nr_scales_per_octave + 3); for (int i_scale = 0; i_scale <= nr_scales_per_octave + 2; ++i_scale) { scales[i_scale] = base_scale * powf (2.0f, (1.0f * static_cast<float> (i_scale) - 1.0f) / static_cast<float> (nr_scales_per_octave)); } Eigen::MatrixXf diff_of_gauss; computeScaleSpace (input, tree, scales, diff_of_gauss); // Find extrema in the DoG scale space std::vector<int> extrema_indices, extrema_scales; findScaleSpaceExtrema (input, tree, diff_of_gauss, extrema_indices, extrema_scales); output.points.reserve (output.points.size () + extrema_indices.size ()); indices.indices.reserve (indices.indices.size () + extrema_indices.size ()); // Save scale? if (scale_idx_ != -1) { // Add keypoints to output for (size_t i_keypoint = 0; i_keypoint < extrema_indices.size (); ++i_keypoint) { PointOutT keypoint; const int &keypoint_index = extrema_indices[i_keypoint]; keypoint.x = input.points[keypoint_index].x; keypoint.y = input.points[keypoint_index].y; keypoint.z = input.points[keypoint_index].z; memcpy (reinterpret_cast<char*> (&keypoint) + out_fields_[scale_idx_].offset, &scales[extrema_scales[i_keypoint]], sizeof (float)); output.points.push_back (keypoint); indices.indices.push_back (keypoint_index); } } else { // Add keypoints to output for (size_t i_keypoint = 0; i_keypoint < extrema_indices.size (); ++i_keypoint) { PointOutT keypoint; const int &keypoint_index = extrema_indices[i_keypoint]; keypoint.x = input.points[keypoint_index].x; keypoint.y = input.points[keypoint_index].y; keypoint.z = input.points[keypoint_index].z; output.points.push_back (keypoint); indices.indices.push_back (keypoint_index); } } }
bool Transform3D::loadXMLSettings(XMLElement *element) { if (!isSuitable(element)) return false; XMLElement *child; if (child = element->getChildByName("Row")) { XMLElement *subChild; Tuple4f xyzw; int offset = 0; for (size_t i = 0; i < element->getChildrenCount(); i++) { if (offset >= 16) return true; if (!(subChild = element->getChild(i))) continue; xyzw.set(0.0f, 0.0f, 0.0f, 0.0f); if (subChild->getName() == "Row") { XMLElement::loadRX_GY_BZ_AWf(*subChild, xyzw); updated = true; matrix[offset + 0] = xyzw.x; matrix[offset + 1] = xyzw.y; matrix[offset + 2] = xyzw.z; matrix[offset + 3] = xyzw.w; offset += 4; } } return true; } Tuple3f translations, rotations, scales(1.0f, 1.0f, 1.0f); if (child = element->getChildByName("Scales")) XMLElement::loadRX_GY_BZf(*child, scales); if (child = element->getChildByName("Rotations")) XMLElement::loadRX_GY_BZf(*child, rotations); if (child = element->getChildByName("Translations")) XMLElement::loadRX_GY_BZf(*child, translations); this->translations.setTranslations(translations); this->rotations.rotateXYZ(rotations); this->scales.setScales(scales); forceUpdate(); return true; }
static std::vector<string_type> make_labels() { std::vector<string_type> labels{ { string_type{ TETENGO2_TEXT("10%") } }, { string_type{ TETENGO2_TEXT("25%") } }, { string_type{ TETENGO2_TEXT("50%") } }, { string_type{ TETENGO2_TEXT("75%") } }, { string_type{ TETENGO2_TEXT("100%") } }, { string_type{ TETENGO2_TEXT("150%") } }, { string_type{ TETENGO2_TEXT("200%") } }, { string_type{ TETENGO2_TEXT("400%") } }, }; assert(labels.size() == scales().size()); return labels; }
Vector<FloatSize> NinePieceImage::computeIntrinsicTileScales(const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, ENinePieceImageRule hRule, ENinePieceImageRule vRule) { Vector<FloatSize> scales(MaxPiece, FloatSize(1, 1)); scales[TopPiece] = computeIntrinsicSideTileScale(TopPiece, destinationRects, sourceRects); scales[RightPiece] = computeIntrinsicSideTileScale(RightPiece, destinationRects, sourceRects); scales[BottomPiece] = computeIntrinsicSideTileScale(BottomPiece, destinationRects, sourceRects); scales[LeftPiece] = computeIntrinsicSideTileScale(LeftPiece, destinationRects, sourceRects); scales[MiddlePiece] = computeIntrinsicMiddleTileScale(scales, destinationRects, sourceRects, hRule, vRule); return scales; }
int main() { input(); if ((save % 2) == 1) { printf("impossible"); return; } else { save = save / 2; } scales(0, 0,0); printf("%d", count); }
void createSomeModel(int numTiles) { std::vector<MoTile> tiles(numTiles, MoTile(QImage(20, 30, QImage::Format_RGBA8888))); model.constructInitialState(targetImage, tiles); std::vector<float> x(numTiles); model.setXCoords(&x[0], &x[0] + numTiles); std::vector<float> y(numTiles); model.setXCoords(&y[0], &y[0] + numTiles); std::vector<float> rotations(numTiles, 0.0f); model.setRotations(&rotations[0], &rotations[0] + numTiles); std::vector<float> scales(numTiles, 0.0f); model.setRotations(&scales[0], &scales[0] + numTiles); }
void MKLDNNAddtoLayer::resetFwdPD(std::shared_ptr<sum::primitive_desc>& pd, std::shared_ptr<sum::primitive_desc>& biasPD, std::vector<MKLDNNMatrixPtr>& inputs, MKLDNNMatrixPtr bias, MKLDNNMatrixPtr out) { std::vector<float> scales(inputs.size(), 1.0); std::vector<memory::primitive_desc> srcPDs; for (size_t i = 0; i < inputs.size(); i++) { srcPDs.push_back(inputs[i]->getPrimitiveDesc()); } CHECK(out); pd.reset(new sum::primitive_desc(out->getMemoryDesc(), scales, srcPDs)); CHECK_PRIMITIVE_DESC_EQ(out, pd->dst_primitive_desc()); biasPD = nullptr; if (bias) { std::vector<float> scales(2, 1.0); std::vector<memory::primitive_desc> srcPDs(2, bias->getPrimitiveDesc()); biasPD.reset( new sum::primitive_desc(bias->getMemoryDesc(), scales, srcPDs)); CHECK_PRIMITIVE_DESC_EQ(bias, biasPD->dst_primitive_desc()); } }
void NormsFromScaledSquares ( const Matrix<Real>& localScales, Matrix<Real>& localScaledSquares, Matrix<Real>& normsLoc, mpi::Comm comm ) { DEBUG_CSE const Int nLocal = localScales.Height(); // Find the maximum relative scales Matrix<Real> scales( nLocal, 1 ); mpi::AllReduce ( localScales.LockedBuffer(), scales.Buffer(), nLocal, mpi::MAX, comm ); // Equilibrate the local scaled sums for( Int jLoc=0; jLoc<nLocal; ++jLoc ) { const Real scale = scales(jLoc); if( scale != Real(0) ) { // Equilibrate our local scaled sum to the maximum scale Real relScale = localScales(jLoc)/scale; localScaledSquares(jLoc) *= relScale*relScale; } else localScaledSquares(jLoc) = 0; } // Combine the local contributions Matrix<Real> scaledSquares( nLocal, 1 ); mpi::AllReduce ( localScaledSquares.Buffer(), scaledSquares.Buffer(), nLocal, mpi::SUM, comm ); for( Int jLoc=0; jLoc<nLocal; ++jLoc ) normsLoc(jLoc) = scales(jLoc)*Sqrt(scaledSquares(jLoc)); }
bool QgsComposerMapGridWidget::hasPredefinedScales() const { // first look at project's scales QStringList scales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) ); bool hasProjectScales( QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" ) ); if ( !hasProjectScales || scales.isEmpty() ) { // default to global map tool scales QSettings settings; QString scalesStr( settings.value( "Map/scales", PROJECT_SCALES ).toString() ); QStringList myScalesList = scalesStr.split( ',' ); return !myScalesList.isEmpty() && myScalesList[0] != ""; } return true; }
//------------------------------------------------------------------------------ // draw() -- //------------------------------------------------------------------------------ void Eadi3DPage::draw() { BasicGL::Display* dsp = getDisplay(); if (dsp != 0) { eadiObjs.makeObjects(); GLsizei vpWidth; GLsizei vpHeight; dsp->getViewportSize(&vpWidth, &vpHeight); LCreal ratio = static_cast<LCreal>(vpWidth) / static_cast<LCreal>(vpHeight); bool depthTest = false; if (glIsEnabled(GL_DEPTH_TEST)) depthTest = true; if (depthTest) glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-2.635 * ratio, 2.635 * ratio, -2.635, 2.635, -3.51, 0.01); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); globeBall(pitchDEG, rollDEG, pitchSteeringCmd, rollSteeringCmd, pitchSteeringValid, rollSteeringValid, landingMode); background(); const char* airSpeedType = "C"; scales(glideslopeDevDOTS, localizerDevDOTS, turnRateDOTS, slipIndDOTS, glideslopeDevValid, localizerDevValid, landingMode); windows(airspeedKTS, altitudeFT, aoaDEG, machNo, vviFPM, airSpeedType, Gload); LCreal hdgCmd = 0.0; heading(headingDEG, hdgCmd); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); if (depthTest) glEnable(GL_DEPTH_TEST); // now draw our components BaseClass::draw(); } }
void scales(int sum,int depth,int index) { int i; //printf("%d\n", sum); if (depth >= num) { return; } if (sum == save) { count++; } for (i = index; i < num; i++) { if (visited[i] == 0) { visited[i] = 1; scales(sum + arr[i], depth + 1,i); visited[i] = 0; } } }
CustomImage::Image Resize(const CustomImage::Image &image) { // Computation of the paramter of the scaling Point lo = image.domain().lowerBound(); Point hi = image.domain().upperBound(); uint64_t width = (hi-lo)[0]+1; uint64_t height = (hi-lo)[1]+1; double lambda = ((double)500)/(double)std::max(width, height); // Scaling stuff std::vector<double> scales(2, 1.0/lambda); typedef functors::BasicDomainSubSampler<Domain, Integer, double> ReSampler; functors::Identity idD; ReSampler reSampler(image.domain(), scales, Point(0,0)); typedef ConstImageAdapter<CustomImage::Image, Domain, ReSampler, CustomImage::Image::Value, functors::Identity> SamplerImageAdapter; SamplerImageAdapter sampledImage(image, reSampler.getSubSampledDomain(), reSampler, idD); // Construction of the result image CustomImage::Image new_image(reSampler.getSubSampledDomain()); for (const auto &p : reSampler.getSubSampledDomain()) { new_image.setValue(p, sampledImage(p)); } return new_image; }
void RuizEquil ( DistSparseMatrix<Field>& A, DistMultiVec<Base<Field>>& dRow, DistMultiVec<Base<Field>>& dCol, bool progress ) { EL_DEBUG_CSE typedef Base<Field> Real; const Int m = A.Height(); const Int n = A.Width(); mpi::Comm comm = A.Comm(); dRow.SetComm( comm ); dCol.SetComm( comm ); Ones( dRow, m, 1 ); Ones( dCol, n, 1 ); // TODO(poulson): Expose to control structure // For, simply hard-code a small number of iterations const Int maxIter = 4; DistMultiVec<Real> scales(comm); const Int indent = PushIndent(); for( Int iter=0; iter<maxIter; ++iter ) { // Rescale the columns // ------------------- ColumnMaxNorms( A, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dCol ); DiagonalSolve( RIGHT, NORMAL, scales, A ); // Rescale the rows // ---------------- RowMaxNorms( A, scales ); EntrywiseMap( scales, MakeFunction(DampScaling<Real>) ); DiagonalScale( LEFT, NORMAL, scales, dRow ); DiagonalSolve( LEFT, NORMAL, scales, A ); } SetIndent( indent ); }