C++ Code Examples for normalize
60 C++ code examples are found related to "normalize".
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Project: electron-edge-js Author: agracio File: monoembedding.cpp License: Apache License 2.0 | 6 votes |
void MonoEmbedding::NormalizeException(MonoException** e) { static MonoMethod* method; if (!method) { method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "NormalizeException", -1); } void *params[] = { *e }; MonoException *exc = NULL; MonoException *en = (MonoException*)mono_runtime_invoke(method, NULL, params, (MonoObject**)exc); if (NULL == exc) { *e = en; } }
Example 2
Project: NiuTensor Author: NiuTrans File: Normalize.cpp License: Apache License 2.0 | 6 votes |
void _Normalize(const XTensor * input, XTensor * output, int dim, const XTensor * mean, const XTensor * var, const XTensor * a, const XTensor * b, DTYPE epsilon) { CheckNTErrors((_IsSameShaped(input, output)), "Unmatched input tensors!"); CheckNTErrors((_IsSameShaped(a, b)), "Unmatched input tensors"); CheckNTErrors((_IsSameShaped(mean, var)), "Unmatched input tensors"); CheckNTErrors((input && output && mean && var && a && b), "Empty input tensors!"); CheckNTErrors((dim >= 0 && dim < input->order), "Incorrect reduction dimension!"); CheckNTErrors((input->order == mean->order + 1), "Incorrect reduction dimension!"); int stride = 1; int strideNum = input->dimSize[dim]; int blockSize = 1; int blockNum = 1; for (int i = 0; i < input->order; i++) { if (i < dim) { CheckNTErrors((input->dimSize[i] == mean->dimSize[i]), "Wrong size!"); blockNum *= input->dimSize[i]; } else if (i > dim) { CheckNTErrors((input->dimSize[i] == mean->dimSize[i - 1]), "Wrong size!"); stride *= input->dimSize[i]; } }
Example 3
Project: rosbots_driver Author: ROSbots File: duration.cpp License: GNU General Public License v3.0 | 6 votes |
void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec) { int32_t nsec_part = nsec; int32_t sec_part = sec; while (nsec_part > 1000000000L) { nsec_part -= 1000000000L; ++sec_part; } while (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } sec = sec_part; nsec = nsec_part; }
Example 4
Project: apfs-fuse Author: sgan81 File: Unicode.cpp License: GNU General Public License v2.0 | 6 votes |
int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t *ccc) { char32_t ch_idx; uint16_t hi_res; uint16_t mi_res; uint16_t lo_res; const uint16_t *seq_u16 = 0; const uint32_t *seq_u32 = 0; uint32_t seq_len = 0; uint32_t cnt; char32_t c; ccc[0] = 0; if (ch >= 0xF0000) { if ((ch & 0xFFFE) == 0xFFFE) return -1; else { nfd[0] = ch; return 1; } }
Example 5
Project: supra Author: IFL-CAMP File: duration.cpp License: GNU Lesser General Public License v2.1 | 6 votes |
void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec) { int32_t nsec_part = nsec; int32_t sec_part = sec; while (nsec_part > 1000000000L) { nsec_part -= 1000000000L; ++sec_part; } while (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } sec = sec_part; nsec = nsec_part; }
Example 6
Project: edge-js Author: agracio File: monoembedding.cpp License: Apache License 2.0 | 6 votes |
void MonoEmbedding::NormalizeException(MonoException** e) { static MonoMethod* method; if (!method) { method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "NormalizeException", -1); } void *params[] = { *e }; MonoException *exc = NULL; MonoException *en = (MonoException*)mono_runtime_invoke(method, NULL, params, (MonoObject**)exc); if (NULL == exc) { *e = en; } }
Example 7
Project: PerfectShow Author: KAlO2 File: opencv_utility.cpp License: Apache License 2.0 | 6 votes |
cv::Mat normalize(const cv::Mat& mat, double* max/* = nullptr */) { double x = 1.0; Mat mat2; switch(mat.depth()) { case CV_8U: x = std::numeric_limits<uint8_t>::max(); mat.convertTo(mat2, CV_32F, 1/x); break; case CV_8S: x = std::numeric_limits<int8_t>::max(); mat.convertTo(mat2, CV_32F, 1/x); break; case CV_16U: x = std::numeric_limits<uint16_t>::max(); mat.convertTo(mat2, CV_32F, 1/x); break; case CV_16S: x = std::numeric_limits<int16_t>::max(); mat.convertTo(mat2, CV_32F, 1/x); break; case CV_32S: x = std::numeric_limits<int32_t>::max(); mat.convertTo(mat2, CV_32F, 1/x); break; case CV_32F: mat.copyTo(mat2); break; case CV_64F: mat.convertTo(mat2, CV_32F, 1.0); break; default: assert(false); break; } if(max != nullptr) *max = x; return mat2; }
Example 8
Project: O-CNN Author: microsoft File: octree.cpp License: MIT License | 6 votes |
void Octree::normalize_pts(vector<float>& pts_scaled, const Points& point_cloud) { const float* bbmin = oct_info_.bbmin(); const float* pts = point_cloud.ptr(PointsInfo::kPoint); const int npt = point_cloud.info().pt_num(); const float mul = float(1 << oct_info_.depth()) / oct_info_.bbox_max_width(); pts_scaled.resize(3 * npt); // normalize the points into the range [0, 1 << depth_) using bbox_width #pragma omp parallel for for (int i = 0; i < npt; i++) { int i3 = i * 3; for (int j = 0; j < 3; j++) { pts_scaled[i3 + j] = (pts[i3 + j] - bbmin[j]) * mul; } } }
Example 9
Project: YACCLAB Author: prittt File: yacclab_tensor.cc License: BSD 3-Clause "New" or "Revised" License | 6 votes |
void YacclabTensorOutput3D::NormalizeLabels() { std::map<int, int> map_new_labels; int i_max_new_label = 0; if (mat_.dims == 3) { for (int z = 0; z < mat_.size[0]; z++) { for (int y = 0; y < mat_.size[1]; y++) { unsigned int * img_labels_row = reinterpret_cast<unsigned int *>(mat_.data + z * mat_.step[0] + y * mat_.step[1]); for (int x = 0; x < mat_.size[2]; x++) { int iCurLabel = img_labels_row[x]; if (iCurLabel > 0) { if (map_new_labels.find(iCurLabel) == map_new_labels.end()) { map_new_labels[iCurLabel] = ++i_max_new_label; } img_labels_row[x] = map_new_labels.at(iCurLabel); } } } } } }
Example 10
Project: ZUI Author: zero-rp File: SkMatrix.cpp License: MIT License | 6 votes |
static void normalize_perspective(SkScalar mat[9]) { // If it was interesting to never store the last element, we could divide all 8 other // elements here by the 9th, making it 1.0... // // When SkScalar was SkFixed, we would sometimes rescale the entire matrix to keep its // component values from getting too large. This is not a concern when using floats/doubles, // so we do nothing now. // Disable this for now, but it could be enabled. #if 0 if (0 == mat[SkMatrix::kMPersp0] && 0 == mat[SkMatrix::kMPersp1]) { SkScalar p2 = mat[SkMatrix::kMPersp2]; if (p2 != 0 && p2 != 1) { double inv = 1.0 / p2; for (int i = 0; i < 6; ++i) { mat[i] = SkDoubleToScalar(mat[i] * inv); } mat[SkMatrix::kMPersp2] = 1; } } #endif }
Example 11
Project: RosettaStone Author: utilForever File: InputDataConverter.cpp License: GNU Affero General Public License v3.0 | 6 votes |
float InputDataConverter::NormalizeFromUniformDist(double v, double min, double max) const { // Normalize to mean = 0, var = 1.0 // Uniform dist is with variance = (max-min)^2 / 12 // -> So we should have (max-min)^2 / 12 = 1.0 // -> (max-min)^2 = 12.0 // -> (max-min) = sqrt(12.0) static double sqrt_12 = std::sqrt(12.0); const double mean = (min + max) / 2; const double range = (max - min); const double scale = sqrt_12 / range; const double ret = (v - mean) * scale; return static_cast<float>(ret); }
Example 12
Project: deepin-calculator Author: linuxdeepin File: rational.cpp License: GNU General Public License v3.0 | 6 votes |
void Rational::normalize() { if (m_denom == 0) { m_valid = false; return; } if (m_num == 0) { m_denom = 1; return; } int g = gcd(abs(m_num), abs(m_denom)); m_num /= g; m_denom /= g; if (m_denom < 0) { m_num = -m_num; m_denom = -m_denom; } }
Example 13
Project: deepmd-kit Author: deepmodeling File: driver.cc License: GNU Lesser General Public License v3.0 | 6 votes |
void normalize_coord (vector<double > & coord, const SimulationRegion<double > & region) { int natoms = coord.size() / 3; for (int ii = 0; ii < natoms; ++ii){ double inter[3]; region.phys2Inter (inter, &coord[3*ii]); for (int dd = 0; dd < 3; ++dd){ inter[dd] -= int(floor(inter[dd])); if (inter[dd] < 0 ) inter[dd] += 1.; else if (inter[dd] >= 1) inter[dd] -= 1.; } region.inter2Phys (&coord[3*ii], inter); }
Example 14
Project: BattleServer Author: tsymiar File: json_writer.cpp License: The Unlicense | 6 votes |
std::string StyledWriter::normalizeEOL( const std::string &text ) { std::string normalized; normalized.reserve( text.length() ); const char *begin = text.c_str(); const char *end = begin + text.length(); const char *current = begin; while ( current != end ) { char c = *current++; if ( c == '\r' ) // mac or dos EOL { if ( *current == '\n' ) // convert dos EOL ++current; normalized += '\n'; } else // handle unix EOL & other char normalized += c; } return normalized; }
Example 15
Project: YACCLAB Author: prittt File: yacclab_tensor.cc License: BSD 3-Clause "New" or "Revised" License | 6 votes |
void YacclabTensorOutput2D::NormalizeLabels() { std::map<int, int> map_new_labels; int i_max_new_label = 0; for (int r = 0; r < mat_.rows; ++r) { unsigned * const mat_row = mat_.ptr<unsigned>(r); for (int c = 0; c < mat_.cols; ++c) { int iCurLabel = mat_row[c]; if (iCurLabel > 0) { if (map_new_labels.find(iCurLabel) == map_new_labels.end()) { map_new_labels[iCurLabel] = ++i_max_new_label; } mat_row[c] = map_new_labels.at(iCurLabel); } } } }
Example 16
Project: awtk Author: zlgopen File: SDL_x11xinput2.c License: GNU Lesser General Public License v2.1 | 6 votes |
static void xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window, double in_x, double in_y, float *out_x, float *out_y) { int i; for (i = 0; i < videodata->numwindows; i++) { SDL_WindowData *d = videodata->windowlist[i]; if (d->xwindow == window) { if (d->window->w == 1) { *out_x = 0.5f; } else { *out_x = in_x / (d->window->w - 1); } if (d->window->h == 1) { *out_y = 0.5f; } else { *out_y = in_y / (d->window->h - 1); } return; }
Example 17
Project: linorobot Author: linorobot File: duration.cpp License: BSD 2-Clause "Simplified" License | 6 votes |
void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec) { int32_t nsec_part = nsec; int32_t sec_part = sec; while (nsec_part > 1000000000L) { nsec_part -= 1000000000L; ++sec_part; } while (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } sec = sec_part; nsec = nsec_part; }
Example 18
Project: ZUI Author: zero-rp File: SkGaussFilter.cpp License: MIT License | 6 votes |
static void normalize(int n, double* gauss) { // Carefully add from smallest to largest to calculate the normalizing sum. double sum = 0; for (int i = n-1; i >= 1; i--) { sum += 2 * gauss[i]; } sum += gauss[0]; // Normalize gauss. for (int i = 0; i < n; i++) { gauss[i] /= sum; } // The factors should sum to 1. Take any remaining slop, and add it to gauss[0]. Add the // values in such a way to maintain the most accuracy. sum = 0; for (int i = n - 1; i >= 1; i--) { sum += 2 * gauss[i]; } gauss[0] = 1 - sum; }
Example 19
Project: face-recognition-caffe2 Author: tpys File: normalize_op.cc License: Apache License 2.0 | 6 votes |
::DoNormalize( const T* xData, T* yData, const int m, const int n, const int sf) { using InnerStride = Eigen::InnerStride<Eigen::Dynamic>; using StridedVec = Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic>, 0, InnerStride>; using ConstStridedVec = Eigen::Map<const Eigen::Matrix<T, 1, Eigen::Dynamic>, 0, InnerStride>; for (int i = 0; i < n; ++i) { auto base = (i / sf) * sf * m + (i % sf); ConstStridedVec xVec(xData + base, 1, m, InnerStride(sf)); auto norm = xVec.template lpNorm<2>(); if (norm != 0) { StridedVec yVec(yData + base, 1, m, InnerStride(sf)); yVec = xVec / norm; } } }
Example 20
Project: ros_lecture Author: project-srs File: duration.cpp License: MIT License | 6 votes |
void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec) { int32_t nsec_part = nsec; int32_t sec_part = sec; while (nsec_part > 1000000000L) { nsec_part -= 1000000000L; ++sec_part; } while (nsec_part < 0) { nsec_part += 1000000000L; --sec_part; } sec = sec_part; nsec = nsec_part; }
Example 21
Project: inviwo Author: inviwo File: eigennormalize.cpp License: BSD 2-Clause "Simplified" License | 6 votes |
void EigenNormalize::process() { auto m = in_.getData(); switch (method_.get()) { case Method::MaxElement: { auto maxV = m->maxCoeff(); out_.setData(std::make_shared<Eigen::MatrixXf>((*m) / maxV)); break; } case Method::MinMaxElement: { auto minV = m->minCoeff(); auto maxV = m->maxCoeff(); auto m2 = std::make_shared<Eigen::MatrixXf>(*m); m2->array() -= minV; m2->array() /= maxV - minV; out_.setData(m2); break; } case Method::Normalize: out_.setData(std::make_shared<Eigen::MatrixXf>(m->normalized())); break; } }
Example 22
Project: echo Author: timi-liuliang File: maximal_inputs.cpp License: MIT License | 6 votes |
void NormalizeColByMax(const arma::mat &input, arma::mat &output) { output.set_size(input.n_rows, input.n_cols); for (arma::uword i = 0; i != input.n_cols; ++i) { const double max = arma::max(arma::abs(input.col(i))); if (max != 0.0) { output.col(i) = input.col(i) / max; } else { output.col(i) = input.col(i); } }
Example 23
Project: BattleServer Author: tsymiar File: json_writer.cpp License: The Unlicense | 6 votes |
std::string StyledStreamWriter::normalizeEOL( const std::string &text ) { std::string normalized; normalized.reserve( text.length() ); const char *begin = text.c_str(); const char *end = begin + text.length(); const char *current = begin; while ( current != end ) { char c = *current++; if ( c == '\r' ) // mac or dos EOL { if ( *current == '\n' ) // convert dos EOL ++current; normalized += '\n'; } else // handle unix EOL & other char normalized += c; } return normalized; }
Example 24
Project: datatable Author: h2oai File: const.cc License: Mozilla Public License 2.0 | 6 votes |
static SType normalize_stype(SType stype0, double x) { constexpr double MAXF32 = double(std::numeric_limits<float>::max()); switch (stype0) { case SType::FLOAT32: if (std::abs(x) <= MAXF32) return SType::FLOAT32; FALLTHROUGH; case SType::FLOAT64: case SType::VOID: return SType::FLOAT64; default: throw RuntimeError() << "Wrong `stype0` in `normalize_stype()`: " << stype0; // LCOV_EXCL_LINE } }
Example 25
Project: Marlin-2.0.x-FYSETC Author: FYSETC File: mixing.cpp License: GNU General Public License v3.0 | 6 votes |
void Mixer::normalize(const uint8_t tool_index) { float cmax = 0; #ifdef MIXER_NORMALIZER_DEBUG float csum = 0; #endif MIXER_STEPPER_LOOP(i) { const float v = collector[i]; NOLESS(cmax, v); #ifdef MIXER_NORMALIZER_DEBUG csum += v; #endif } #ifdef MIXER_NORMALIZER_DEBUG SERIAL_ECHOPGM("Mixer: Old relation : [ "); MIXER_STEPPER_LOOP(i) { SERIAL_ECHO_F(collector[i] / csum, 3); SERIAL_CHAR(' '); }
Example 26
Project: ion Author: google File: hb-ot-var.cc License: Apache License 2.0 | 6 votes |
void hb_ot_var_normalize_variations (hb_face_t *face, const hb_variation_t *variations, /* IN */ unsigned int variations_length, int *coords, /* OUT */ unsigned int coords_length) { for (unsigned int i = 0; i < coords_length; i++) coords[i] = 0; const OT::fvar &fvar = _get_fvar (face); for (unsigned int i = 0; i < variations_length; i++) { unsigned int axis_index; if (hb_ot_var_find_axis (face, variations[i].tag, &axis_index, nullptr) && axis_index < coords_length) coords[axis_index] = fvar.normalize_axis_value (axis_index, variations[i].value); } const OT::avar &avar = _get_avar (face); avar.map_coords (coords, coords_length); }
Example 27
Project: Rustla2 Author: MemeLabs File: Channel.cpp License: MIT License | 6 votes |
Status Channel::NormalizeAdvancedChannel(std::string *channel) { try { auto channel_uri = folly::Uri(*channel); if (channel_uri.scheme() != "http" && channel_uri.scheme() != "https") { return Status(StatusCode::VALIDATION_ERROR, "invalid advanced url schema. must be http or https"); } *channel = channel_uri.str(); } catch (const std::invalid_argument &e) { return Status(StatusCode::VALIDATION_ERROR, "invalid advanced url"); } return Status::OK; }
Example 28
Project: rom-properties Author: GerbilSoft File: lz_encoder_mf.c License: GNU General Public License v2.0 | 6 votes |
static void normalize(lzma_mf *mf) { assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS); uint32_t i = 0; // In future we may not want to touch the lowest bits, because there // may be match finders that use larger resolution than one byte. const uint32_t subvalue = (MUST_NORMALIZE_POS - mf->cyclic_size); // & (~(UINT32_C(1) << 10) - 1); for (i = 0; i < mf->hash_count; ++i) { // If the distance is greater than the dictionary size, // we can simply mark the hash element as empty. if (mf->hash[i] <= subvalue) mf->hash[i] = EMPTY_HASH_VALUE; else mf->hash[i] -= subvalue; }
Example 29
Project: SLib Author: SLIBIO File: math.cpp License: MIT License | 6 votes |
SLIB_INLINE static T normalizeDegree(T v) noexcept { if (Math::isNaN(v)) { return 0; } sl_int32 n = (sl_int32)v; T f = v - n; if (f < 0) { f = 1 + f; n--; } n = n % 360; if (n < 0) { n += 360; } v = (T)(n) + f; return v; }
Example 30
Project: programming-abstractions Author: heavy3 File: WorldGenerator.cpp License: MIT License | 6 votes |
static void normalizeTerrain(Grid<double>& heights) { /* Compute the maximum and minimum heights. */ double maxHeight = -numeric_limits<double>::infinity(); double minHeight = numeric_limits<double>::infinity(); for (int row = 0; row < heights.numRows(); row++) { for (int col = 0; col < heights.numCols(); col++) { maxHeight = max(maxHeight, heights[row][col]); minHeight = min(minHeight, heights[row][col]); } } /* Remap everything from the range [minHeight, maxHeight] to [0, 1]. */ double range = maxHeight - minHeight; for (int row = 0; row < heights.numRows(); row++) { for (int col = 0; col < heights.numCols(); col++) { heights[row][col] -= minHeight; heights[row][col] /= range; } } }
Example 31
Project: zerospeech2017 Author: bootphon File: MixBiNormal.cc License: GNU General Public License v3.0 | 6 votes |
void MixBiNormal::normalizeAlphasWithNoise() { // Normalize alphas. int l; double tmp = 0.0; for (l=0;l<NumMixComps;l++) { tmp += cur_alphas[l]; } // added to each one. double noise = tmp/NumMixComps; tmp += tmp; const double inv_tmp = 1.0/tmp; for (l=0;l<NumMixComps;l++) { cur_alphas[l] += noise; cur_alphas[l] *= inv_tmp; } }
Example 32
Project: Marlin_2.0.X_Beta_Alfawise_Ux0 Author: hobiseven File: mixing.cpp License: GNU General Public License v3.0 | 6 votes |
void Mixer::normalize(const uint8_t tool_index) { float cmax = 0; #ifdef MIXER_NORMALIZER_DEBUG float csum = 0; #endif MIXER_STEPPER_LOOP(i) { const float v = collector[i]; NOLESS(cmax, v); #ifdef MIXER_NORMALIZER_DEBUG csum += v; #endif } #ifdef MIXER_NORMALIZER_DEBUG SERIAL_ECHOPGM("Mixer: Old relation : [ "); MIXER_STEPPER_LOOP(i) { SERIAL_ECHO_F(collector[i] / csum, 3); SERIAL_CHAR(' '); }
Example 33
Project: OpenPapyrus Author: papyrussolution File: 7z-ppmd.cpp License: GNU Affero General Public License v3.0 | 6 votes |
void CEncProps::Normalize(int level) { if(level < 0) level = 5; if(level > 9) level = 9; if(MemSize == (uint32)(int32)-1) MemSize = (level >= 9) ? ((uint32)192 << 20) : ((uint32)1 << (level + 19)); const uint kMult = 16; if(MemSize / kMult > ReduceSize) { for(uint i = 16; i <= 31; i++) { uint32 m = (uint32)1 << i; if(ReduceSize <= m / kMult) { SETMIN(MemSize, m); break; } } } if(Order == -1) Order = kOrders[(uint)level]; }
Example 34
Project: datatable Author: h2oai File: const.cc License: Mozilla Public License 2.0 | 6 votes |
static SType normalize_stype(SType stype0, int64_t x) { switch (stype0) { case SType::INT8: if (x == static_cast<int8_t>(x)) return SType::INT8; FALLTHROUGH; case SType::INT16: if (x == static_cast<int16_t>(x)) return SType::INT16; FALLTHROUGH; case SType::INT32: case SType::VOID: if (x == static_cast<int32_t>(x)) return SType::INT32; return SType::INT64; default: return stype0; } }
Example 35
Project: grpc-nebula-c Author: grpc-nebula File: channel_args.cc License: Apache License 2.0 | 6 votes |
grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { grpc_arg** args = static_cast<grpc_arg**>(gpr_malloc(sizeof(grpc_arg*) * a->num_args)); for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } if (a->num_args > 1) qsort(args, a->num_args, sizeof(grpc_arg*), cmp_key_stable); grpc_channel_args* b = static_cast<grpc_channel_args*>(gpr_malloc(sizeof(grpc_channel_args))); b->num_args = a->num_args; b->args = static_cast<grpc_arg*>(gpr_malloc(sizeof(grpc_arg) * b->num_args)); for (size_t i = 0; i < a->num_args; i++) { b->args[i] = copy_arg(args[i]); } gpr_free(args); return b; }
Example 36
Project: OrionUO Author: Hotride File: GLVector.cpp License: MIT License | 6 votes |
void CVector::Normalize() { WISPFUN_DEBUG("c38_f1"); if (!X && !Y && !Z) return; double result = X * X + Y * Y + Z * Z; //if (result) { result = sqrtl(result); X /= result; Y /= result; Z /= result; } }
Example 37
Project: variational-surface-cutting Author: nmwsharp File: geometry.cpp License: GNU General Public License v2.0 | 6 votes |
::normalize() { // compute center of mass Vector3 cm; for (VertexPtr v: mesh.vertices()) { cm += position(v); } cm /= mesh.nVertices(); // translate to origin and determine radius double rMax = 0; for (VertexPtr v: mesh.vertices()) { Vector3& p = position(v); p -= cm; rMax = std::max(rMax, norm(p)); } // rescale to unit sphere for (VertexPtr v: mesh.vertices()) { position(v) /= rMax; } }
Example 38
Project: scantailor-advanced Author: 4lex4 File: RelinkablePath.cpp License: GNU General Public License v3.0 | 6 votes |
QString RelinkablePath::normalize(const QString& path) { QString frontSlashes(path); frontSlashes.replace(QChar('\\'), QLatin1String("/")); QStringList newComponents; for (const QString& comp : frontSlashes.split(QChar('/'), QString::KeepEmptyParts)) { if (comp.isEmpty()) { if (newComponents.isEmpty() #if _WIN32 || (newComponents.size() == 1 && newComponents.front().isEmpty()) #endif ) { newComponents.push_back(comp); } else { // This will get rid of redundant slashes, including the trailing slash. continue; } } else if
Example 39
Project: vise Author: ox-vgg File: ESiftDescriptor.cpp License: BSD 2-Clause "Simplified" License | 6 votes |
void NormalizeEVect(float *vec, int len, float norm) { int i; float val, fac, sqlen = 0.0; for (i = 0; i < len; i++) { val = vec[i]; //sqlen += val * val; sqlen += fabs(val); } // fac = norm / sqrt(sqlen); fac=sqlen/len; for (i = 0; i < len; i++) vec[i] = vec[i]/fac *100; }
Example 40
Project: lullaby Author: google File: debug_render_impl.cc License: Apache License 2.0 | 6 votes |
static NormalizedCoordinates NormalizeScreenCoordinates( const mathfu::vec2& pixel_pos0, const mathfu::vec2& pixel_pos1, const mathfu::vec2i& dimensions) { // Flip Y axis from Y-down to Y-up, preserving quad winding. const float sx = 2.0f / dimensions.x; const float sy = 2.0f / dimensions.y; const float x0 = sx * pixel_pos0.x - 1.0f; const float y0 = 1.0f - sy * pixel_pos0.y; const float x1 = sx * pixel_pos1.x - 1.0f; const float y1 = 1.0f - sy * pixel_pos1.y; const float z = -1.0f; const NormalizedCoordinates coords = { mathfu::vec3(x0, y1, z), mathfu::vec3(x1, y0, z) }; return coords; }
Example 41
Project: zetasql Author: google File: civil_time.cc License: Apache License 2.0 | 6 votes |
void NormalizeDatetime(int64_t* y, int32_t* mo, int32_t* d, int32_t* h, int32_t* m, int32_t* s, int64_t* ns) { int64_t carry_seconds = zetasql_base::MathUtil::FloorOfRatio(*ns, kNanosPerSecond); absl::CivilSecond cs(*y, *mo, *d, *h, *m, *s); cs += carry_seconds; *y = cs.year(); *mo = cs.month(); *d = cs.day(); *h = cs.hour(); *m = cs.minute(); *s = cs.second(); *ns -= (carry_seconds * kNanosPerSecond); // The CivilTime constructor should have coerced all the time values to the // appropriate range. DCHECK(IsValidTimeFields(*h, *m, *s, *ns)); }
Example 42
Project: TANK Author: phaistos-networks File: service_wait.cpp License: Apache License 2.0 | 6 votes |
static inline uint64_t normalize_wakeup_time(const uint64_t when) noexcept { // This is important // // We don't want to wake up the reactor every millisecond, which can happen easily // if we have too many consumers and each e.g consumes with a max wait time 256 // and they all happen to consume 1 ms apart from each other. // // To mitigate this thundering herd problem, we 'll just align the wake up time // to 128ms. We can experiment with 256ms or 64ms, though 128ms seems fine static constexpr const uint64_t alignment = 128; static_assert(std::is_same<decltype(alignment), const uint64_t>::value); const uint64_t n = when + alignment - 1; const auto res = n & -alignment; return res; }
Example 43
Project: EventEntityExtractor Author: bishanyang File: Sentence.cpp License: GNU Lesser General Public License v3.0 | 6 votes |
void Sentence::NormalizeWords() { for (int s = 0; s < words.size(); ++s) { string word = words[s]; // normalize digits bool is_number = true; for (int i = 0; i < word.size(); ++i) { if (!(word[i] >= '0' && word[i] <= '9')) { is_number = false; break; } } if (is_number) { lemmas[s] = "NUMNUM"; } else if (word.find('@') != string::npos && word.find(".com") != string::npos) { lemmas[s] = "@EMAIL"; } else {
Example 44
Project: TH3D-Unified-U2.R1 Author: houseofbugs File: mixing.cpp License: GNU General Public License v3.0 | 6 votes |
void Mixer::normalize(const uint8_t tool_index) { float cmax = 0; #ifdef MIXER_NORMALIZER_DEBUG float csum = 0; #endif MIXER_STEPPER_LOOP(i) { const float v = collector[i]; NOLESS(cmax, v); #ifdef MIXER_NORMALIZER_DEBUG csum += v; #endif } #ifdef MIXER_NORMALIZER_DEBUG SERIAL_ECHOPGM("Mixer: Old relation : [ "); MIXER_STEPPER_LOOP(i) { SERIAL_ECHO_F(collector[i] / csum, 3); SERIAL_CHAR(' '); }
Example 45
Project: sling Author: google File: unicode.cc License: Apache License 2.0 | 6 votes |
int Unicode::Normalize(int c, int flags) { if (c & unicode_tab_mask) return c; if (flags & NORMALIZE_CASE) { c = unicode_lower_tab[c]; } if (flags & NORMALIZE_LETTERS) { c = unicode_normalize_tab[c]; } if (flags & NORMALIZE_DIGITS) { if (IsDigit(c)) c = '9'; } if (flags & NORMALIZE_PUNCTUATION) { if (IsPunctuation(c)) c = 0; } if (flags & NORMALIZE_NAME) { if (IsNamePunctuation(c)) c = 0; } if (flags & NORMALIZE_WHITESPACE) { if (IsWhitespace(c)) c = 0; } return c; }
Example 46
Project: btrf Author: lood339 File: matrix.c License: BSD 2-Clause "Simplified" License | 6 votes |
void normalizeMatrix(Matrix *mat) { cellValueT lowest = minMatrix(mat, NULL, NULL); cellValueT highest = maxMatrix(mat, NULL, NULL); cellValueT *ptr = mat->cellValues; cellValueT val; double interval; matrixSizeT i = matSize(mat); interval = highest - lowest; // normalize ptr = mat->cellValues; i = matSize(mat); while (i--) { val = abs(*ptr); *(ptr++) = (cellValueT)(((double)(val - lowest) / interval) * 255.0); } }
Example 47
Project: neoGFX Author: i42output File: hb-ot-var.cc License: GNU General Public License v3.0 | 6 votes |
void hb_ot_var_normalize_variations (hb_face_t *face, const hb_variation_t *variations, /* IN */ unsigned int variations_length, int *coords, /* OUT */ unsigned int coords_length) { for (unsigned int i = 0; i < coords_length; i++) coords[i] = 0; const OT::fvar &fvar = *face->table.fvar; for (unsigned int i = 0; i < variations_length; i++) { hb_ot_var_axis_info_t info; if (hb_ot_var_find_axis_info (face, variations[i].tag, &info) && info.axis_index < coords_length) coords[info.axis_index] = fvar.normalize_axis_value (info.axis_index, variations[i].value); } face->table.avar->map_coords (coords, coords_length); }
Example 48
Project: SGEN_L Author: makerbase-mks File: mixing.cpp License: GNU General Public License v3.0 | 6 votes |
void Mixer::normalize(const uint8_t tool_index) { float cmax = 0; #ifdef MIXER_NORMALIZER_DEBUG float csum = 0; #endif MIXER_STEPPER_LOOP(i) { const float v = collector[i]; NOLESS(cmax, v); #ifdef MIXER_NORMALIZER_DEBUG csum += v; #endif } #ifdef MIXER_NORMALIZER_DEBUG SERIAL_ECHOPGM("Mixer: Old relation : [ "); MIXER_STEPPER_LOOP(i) { SERIAL_ECHO_F(collector[i] / csum, 3); SERIAL_CHAR(' '); }
Example 49
Project: VulkanDemos Author: BobLChen File: Q3BSPFileImporter.cpp License: MIT License | 6 votes |
static void normalizePathName( const std::string &rPath, std::string &normalizedPath ) { normalizedPath = ""; if (rPath.empty()) { return; } #ifdef _WIN32 std::string sep = "\\"; #else std::string sep = "/"; #endif static const unsigned int numDelimiters = 2; const char delimiters[ numDelimiters ] = { '/', '\\' }; normalizedPath = rPath; for (const char delimiter : delimiters) { for ( size_t j=0; j<normalizedPath.size(); ++j ) { if ( normalizedPath[j] == delimiter ) { normalizedPath[ j ] = sep[ 0 ]; } } } }
Example 50
Project: w2rap-contigger Author: bioinfologics File: IntDistribution.cc License: MIT License | 6 votes |
void IntDistribution::_normalize() { const int x0 = _prob.x_min(); const int x1 = _prob.x_max(); ForceAssertGe(_prob[x0], 0.0); _prob_le[x0] = _prob[x0]; for (int x = x0 + 1; x <= x1; x++) { const real_t p = _prob[x]; ForceAssertGe(p, 0.0); _prob_le[x] = _prob_le[x - 1] + p; } const real_t sum = _prob_le[x1]; if (sum == 0.0) { _prob = IntFunction<real_t>(); // this signals an invalid distribution } else {
Example 51
Project: cvkit Author: roboception File: mesh.cc License: BSD 3-Clause "New" or "Revised" License | 6 votes |
void Mesh::normalizeNormals() { for (int i=3*(getVertexCount()-1); i>=0; i-=3) { float len=(float) sqrt(normal[i]*normal[i]+ normal[i+1]*normal[i+1]+ normal[i+2]*normal[i+2]); if (len > 0) { normal[i]/=len; normal[i+1]/=len; normal[i+2]/=len; } } }
Example 52
Project: TrafficMonitorSkinEditor Author: zhongyang219 File: Common.cpp License: GNU General Public License v3.0 | 6 votes |
void CCommon::NormalizeFont(LOGFONT & font) { wstring name; wstring style; name = font.lfFaceName; if (name.empty()) return; if (name.back() == L' ') name.pop_back(); size_t index = name.rfind(L' '); if (index == wstring::npos) return; style = name.substr(index + 1); bool style_acquired = false; if (style == L"Light") { font.lfWeight = FW_LIGHT; style_acquired = true; } else if
Example 53
Project: face-recognizer-android Author: pillarpond File: prewhiten.cc License: Apache License 2.0 | 6 votes |
void NormalizeNeon(const float* const input, const float mean, const float std_adj, const int num_vals, float* const output) { const float32x4_t mean_vec = vdupq_n_f32(-mean); const float32x4_t std_vec = vdupq_n_f32(1/std_adj); float32x4_t result; int offset = 0; for (; offset <= num_vals - 4; offset += 4) { const float32x4_t deltas = vaddq_f32(mean_vec, vld1q_f32(&input[offset])); result = vmulq_f32(deltas, std_vec); vst1q_f32(&output[offset], result); } // Get the remaining 1 to 3 values. for (; offset < num_vals; ++offset) { output[offset] = (input[offset] - mean) / std_adj; } }
Example 54
Project: beefweb Author: hyperblast File: playlists_controller.cpp License: MIT License | 5 votes |
std::string PlaylistsController::validateAndNormalizeItem(const SettingsData& settings, const std::string& item) { std::string path; if (isUrl(item)) { if (auto fileUrlPath = stripFileScheme(item)) path = *fileUrlPath; else return item; }
Example 55
Project: ChromaTag Author: CogChameleon File: JMD_Math_Common.cpp License: MIT License | 5 votes |
void JMD::JMD_Utils_Math::Vector_Normalize(float *vector_param, unsigned int size_param) { //get length float length = Vector_Length(vector_param, size_param); //normalize elements for( int i=0; i < size_param; i++ ) { vector_param[i] /= length; } }
Example 56
Project: ChromaTag Author: CogChameleon File: JMD_Math_Common.cpp License: MIT License | 5 votes |
void JMD::JMD_Utils_Math::Vector_Normalize(vector<double> *vector_param) { //get length float length = Vector_Length(vector_param); //normalize elements for(vector<double>::iterator iter=vector_param->begin(); iter != vector_param->end(); ++iter) { *iter /= length; } }
Example 57
Project: apfs-fuse Author: sgan81 File: Unicode.cpp License: GNU General Public License v2.0 | 5 votes |
int normalizeJimdo(char32_t ch, char32_t *nfd, uint8_t *ccc) { constexpr int SBase = 0xAC00; constexpr int LBase = 0x1100; constexpr int VBase = 0x1161; constexpr int TBase = 0x11A7; // constexpr int LCount = 19; constexpr int VCount = 21; constexpr int TCount = 28; constexpr int NCount = VCount * TCount; // constexpr int SCount = LCount * NCount; int SIndex = ch - SBase; int LIndex = SIndex / NCount; int VIndex = (SIndex % NCount) / TCount; int TIndex = SIndex % TCount; nfd[0] = LBase + LIndex; ccc[0] = 0; nfd[1] = VBase + VIndex; ccc[1] = 0; if (TIndex > 0) { nfd[2] = TBase + TIndex; ccc[2] = 0; return 3; } return 2; }
Example 58
Project: EGSfM Author: AIBluefisher File: domset.cc License: BSD 3-Clause "New" or "Revised" License | 5 votes |
void Domset::deNormalizePointCloud() { const size_t numPoints( points.size() ); // denormalizing points #if OPENMVG_USE_OPENMP #pragma omp parallel for #endif for_parallel( i, numPoints ) { points[ i ].pos = ( points[ i ].pos / normScale ) + pcCentre.pos; } const size_t numOldPoints( origPoints.size() ); #if OPENMVG_USE_OPENMP #pragma omp parallel for #endif for_parallel( i, numOldPoints ) { origPoints[ i ].pos = ( origPoints[ i ].pos / normScale ) + pcCentre.pos; } // denormalizing camera centers const size_t numViews( views.size() ); #if OPENMVG_USE_OPENMP #pragma omp parallel for #endif for_parallel( i, numViews ) { views[ i ].trans = ( views[ i ].trans / normScale ) + pcCentre.pos; } }
Example 59
Project: cirrus Author: ucbrise File: SparseDataset.cpp License: Apache License 2.0 | 5 votes |
void SparseDataset::normalize(uint64_t hash_size) { std::vector<FEATURE_TYPE> max_val_feature(hash_size); std::vector<FEATURE_TYPE> min_val_feature(hash_size, std::numeric_limits<FEATURE_TYPE>::max()); for (const auto& w : data_) { for (const auto& v : w) { uint64_t index = v.first; FEATURE_TYPE value = v.second; #ifdef DEBUG if (index >= hash_size) throw std::runtime_error("Index bigger than capacity"); #endif max_val_feature[index] = std::max(value, max_val_feature[index]); min_val_feature[index] = std::min(value, min_val_feature[index]); } } for (auto& w : data_) { for (auto& v : w) { int index = v.first; // only normalize if there are different values // in the same column if (max_val_feature[index] != min_val_feature[index]) { v.second = (v.second - min_val_feature[index]) / (max_val_feature[index] - min_val_feature[index]); } } } }
Example 60
Project: xmrig-amd Author: xmrig File: ApiRouter.cpp License: GNU General Public License v3.0 | 5 votes |
static inline rapidjson::Value normalize(double d) { using namespace rapidjson; if (!isnormal(d)) { return Value(kNullType); } return Value(floor(d * 100.0) / 100.0); }