void DataGenerator::_gen_dist_normal(GUINT32 N, double mean, double sigma, bool discrete, const QString &fn) { bool success = false; char buf[2*SMALL_BUFFER_SIZE]; GUINT32 progress_increment = N / 100; GUINT32 progress_mem = progress_increment; try{ CREATE_AND_OPEN_OUTPUT_FILE(fn); GUINT32 i; int len; for(i = 0; i < N; i+=2){ if(i >= progress_mem){ emit ProgressUpdated((double)i/N * 100); progress_mem += progress_increment; } if(m_cancel) throw CancelledOperationException<>(); if(discrete){ GUtil::Pair<int> X = m_rng.N_Discrete2(mean, sigma); len = sprintf(buf, "%d\n", X.First); if(i != N-1) len += sprintf(buf + len, "%d\n", X.Second); } else{ GUtil::Pair<GFLOAT64> X = m_rng.N2(mean, sigma); len = sprintf(buf, "%.100f\n", X.First); if(i != N-1) len += sprintf(buf + len, "%.100f\n", X.Second); } outfile.Write(buf, len); } emit ProgressUpdated(100); success = true; } catch(const Exception<> &ex){ emit NotifyError(std::shared_ptr<std::exception>( static_cast<std::exception*>((Exception<> *)ex.Clone())) ); } if(success) emit NotifyInfo(tr("Normal distribution generated")); }
STDMETHODIMP CProgressInfo7Zip::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) { ProgressUpdated ( (m_bDoIn) ? *inSize : *outSize, m_lMaxSize ); /* if (*inSize >= ApprovedStart && InSize == 0) { InSize = *inSize; }*/ return S_OK; }
void DataGenerator::_gen_dist_uniform(GUINT32 N, double min, double max, bool discrete, const QString &fn) { bool success = false; char buf[SMALL_BUFFER_SIZE]; GUINT32 progress_increment = N / 100; try{ CREATE_AND_OPEN_OUTPUT_FILE(fn); for(GUINT32 i = 0; i < N; i++){ if(0 == i % progress_increment) emit ProgressUpdated((double)i/N * 100); if(m_cancel) throw CancelledOperationException<>(); int len; if(discrete){ const int X = m_rng.U_Discrete(min, max); len = sprintf(buf, "%d\n", X); } else{ const double X = m_rng.U(min, max); len = sprintf(buf, "%f\n", X); } outfile.Write(buf, len); } emit ProgressUpdated(100); success = true; } catch(const Exception<> &ex){ emit NotifyError(std::shared_ptr<std::exception>( static_cast<std::exception*>((Exception<> *)ex.Clone())) ); } if(success) emit NotifyInfo(tr("Uniform distribution generated")); }