float discordance(Values &val0, Values &val1) { int i, j, num0=val0.size(), num1=val1.size(); int su; sort(val0.begin(), val0.end()); sort(val1.begin(), val1.end()); #if 0 FOR (i, num0) cout << val0[i] << " "; cout << endl; FOR (i, num1) cout << val1[i] << " "; cout << endl; #endif // count pairs with val1 >= val2 but cl1=loss and cl2 = win su = 0; i = 0; FOR (j, num0) { while (i < num1 && val0[j] >= val1[i]) i++; su += i; } // cout << "s=" << su << " d=" << double(su) / (num0*num1) << endl; return double(su) / ((num0+num1)*(num0+num1-1)/2); }
ReturnCode computeMeanSigma(Result &mean, Result &sigma, const Values &values, const Weights &weights) { MSS_BEGIN(ReturnCode); MSS(!values.empty()); MSS(values.size() == weights.size()); //Compute mean and the sum of the weights mean = 0.0; Result sumW = 0.0; typename Values::const_iterator value = values.begin(); for (auto weight: weights) { mean += *(value++)*weight; sumW += weight; } mean /= sumW; //Compute sigma sigma = 0.0; typename Weights::const_iterator weight = weights.begin(); for (auto value: values) sigma += *(weight++)*(value-mean)*(value-mean); sigma = ::sqrt(sigma/sumW); MSS_END(); }
/* ************************************************************************* */ VectorValues Values::localCoordinates(const Values& cp) const { if(this->size() != cp.size()) throw DynamicValuesMismatched(); VectorValues result; for(const_iterator it1=this->begin(), it2=cp.begin(); it1!=this->end(); ++it1, ++it2) { if(it1->key != it2->key) throw DynamicValuesMismatched(); // If keys do not match // Will throw a dynamic_cast exception if types do not match // NOTE: this is separate from localCoordinates(cp, ordering, result) due to at() vs. insert result.insert(it1->key, it1->value.localCoordinates_(it2->value)); } return result; }
/* ************************************************************************* */ bool Values::equals(const Values& other, double tol) const { if (this->size() != other.size()) return false; for (const_iterator it1 = this->begin(), it2 = other.begin(); it1 != this->end(); ++it1, ++it2) { const Value& value1 = it1->value; const Value& value2 = it2->value; if (typeid(value1) != typeid(value2) || it1->key != it2->key || !value1.equals_(value2, tol)) { return false; } } return true; // We return false earlier if we find anything that does not match }
ReturnCode computeMean(Mean &mean, const Values &values, const Weights &weights) { MSS_BEGIN(ReturnCode); MSS(!values.empty()); MSS(values.size() == weights.size()); mean = 0.0; Mean sumW = 0.0; typename Values::const_iterator value = values.begin(); for (auto weight: weights) { mean += *(value++)*weight; sumW += weight; } mean /= sumW; MSS_END(); }
StringsView::Items StringsView::items() const { Items options; if ( 0x0 != _model ) { typedef OptionsItemModel::Values Values; Values values ( _model->values() ); for ( Values::const_iterator iter = values.begin(); iter != values.end(); ++iter ) { options.push_back ( *iter ); } } return options; }
void process_properties(Feature & feature, Headers const& headers, Values const& values, Locator const& locator, Transcoder const& tr) { auto val_beg = values.begin(); auto val_end = values.end(); auto num_headers = headers.size(); for (std::size_t i = 0; i < num_headers; ++i) { std::string const& fld_name = headers.at(i); if (val_beg == val_end) { feature.put(fld_name,tr.transcode("")); continue; } std::string value = mapnik::util::trim_copy(*val_beg++); int value_length = value.length(); if (locator.index == i && (locator.type == geometry_column_locator::WKT || locator.type == geometry_column_locator::GEOJSON) ) continue; bool matched = false; bool has_dot = value.find(".") != std::string::npos; if (value.empty() || (value_length > 20) || (value_length > 1 && !has_dot && value[0] == '0')) { matched = true; feature.put(fld_name,std::move(tr.transcode(value.c_str()))); } else if (csv_utils::is_likely_number(value)) { bool has_e = value.find("e") != std::string::npos; if (has_dot || has_e) { double float_val = 0.0; if (mapnik::util::string2double(value,float_val)) { matched = true; feature.put(fld_name,float_val); } } else { mapnik::value_integer int_val = 0; if (mapnik::util::string2int(value,int_val)) { matched = true; feature.put(fld_name,int_val); } } } if (!matched) { if (csv_utils::ignore_case_equal(value, "true")) { feature.put(fld_name, true); } else if (csv_utils::ignore_case_equal(value, "false")) { feature.put(fld_name, false); } else // fallback to string { feature.put(fld_name,std::move(tr.transcode(value.c_str()))); } } } }
void GuiMedia::render() { if (ImGui::CollapsingHeader(_name.c_str())) { auto mediaList = getSceneMedia(); for (auto& media : mediaList) { auto mediaName = media->getName(); if (ImGui::TreeNode(mediaName.c_str())) { ImGui::Text("Change media type: "); ImGui::SameLine(); if (_mediaTypeIndex.find(mediaName) == _mediaTypeIndex.end()) _mediaTypeIndex[mediaName] = 0; vector<const char*> mediaTypes; for (auto& type : _mediaTypes) mediaTypes.push_back(type.first.c_str()); if (ImGui::Combo("", &_mediaTypeIndex[mediaName], mediaTypes.data(), mediaTypes.size())) replaceMedia(mediaName, mediaTypes[_mediaTypeIndex[mediaName]]); ImGui::Text(("Current media type: " + _mediaTypesReversed[media->getRemoteType()]).c_str()); ImGui::Text("Parameters:"); auto attributes = media->getAttributes(true); drawAttributes(mediaName, attributes); // TODO: specific part for Queues. Need better Attributes definition to remove this // Display the playlist if this is a queue if (dynamic_pointer_cast<QueueSurrogate>(media)) { if (ImGui::TreeNode("Playlist")) { auto updated = false; Values playlist; auto playlistIt = attributes.find("playlist"); if (playlistIt != attributes.end()) { playlist = playlistIt->second; // Current sources int index = 0; int deleteIndex = -1; for (auto& source : playlist) { auto values = source.as<Values>(); auto idStack = to_string(index) + values[0].as<string>(); ImGui::PushID((idStack + "delete").c_str()); if (ImGui::Button("-")) deleteIndex = index; ImGui::PopID(); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Delete this media"); ImGui::SameLine(); ImGui::PushItemWidth(96); ImGui::PushID((idStack + "media_type").c_str()); ImGui::Text(_mediaTypesReversed[values[0].as<string>()].c_str()); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Media type"); ImGui::PopID(); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::PushItemWidth(96); float tmp = values[2].as<float>(); ImGui::PushID((idStack + "start").c_str()); if (ImGui::InputFloat("", &tmp, 1.0f, 1.0f, 2, ImGuiInputTextFlags_EnterReturnsTrue)) { source[2] = tmp; updated = true; } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Start time (s)"); ImGui::PopID(); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::PushItemWidth(96); tmp = values[3].as<float>(); ImGui::PushID((idStack + "stop").c_str()); if (ImGui::InputFloat("", &tmp, 1.0f, 1.0f, 2, ImGuiInputTextFlags_EnterReturnsTrue)) { source[3] = tmp; updated = true; } if (ImGui::IsItemHovered()) ImGui::SetTooltip("Stop time (s)"); ImGui::PopID(); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::PushItemWidth(-0.01f); ImGui::PushID((idStack + "path").c_str()); ImGui::Text(values[1].as<string>().c_str()); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Media path"); ImGui::PopID(); ImGui::PopItemWidth(); ++index; } if (deleteIndex >= 0) { playlist.erase(playlist.begin() + deleteIndex); updated = true; } } // Adding a source ImGui::Text("Add a media:"); ImGui::PushID("addNewMedia"); if (ImGui::Button("+")) { playlist.push_back(_newMedia); updated = true; } ImGui::PopID(); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Add this media"); int typeIndex; ImGui::SameLine(); ImGui::PushItemWidth(96); ImGui::PushID("newMediaType"); if (ImGui::Combo("", &_newMediaTypeIndex, mediaTypes.data(), mediaTypes.size())) _newMedia[0] = _mediaTypes[mediaTypes[_newMediaTypeIndex]]; if (ImGui::IsItemHovered()) ImGui::SetTooltip("Media type"); ImGui::PopID(); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::PushItemWidth(96); ImGui::PushID("newMediaStart"); if (ImGui::InputFloat("", &_newMediaStart, 0.1f, 1.0f, 2, ImGuiInputTextFlags_EnterReturnsTrue)) _newMedia[2] = _newMediaStart; if (ImGui::IsItemHovered()) ImGui::SetTooltip("Start time (s)"); ImGui::PopID(); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::PushItemWidth(96); ImGui::PushID("newMediaStop"); if (ImGui::InputFloat("", &_newMediaStop, 0.1f, 1.0f, 2, ImGuiInputTextFlags_EnterReturnsTrue)) _newMedia[3] = _newMediaStop; if (ImGui::IsItemHovered()) ImGui::SetTooltip("Stop time (s)"); ImGui::PopID(); ImGui::PopItemWidth(); string filepath = _newMedia[1].as<string>(); filepath.resize(512); ImGui::SameLine(); ImGui::PushItemWidth(-32.f); ImGui::PushID("newMediaFile"); if (ImGui::InputText("", const_cast<char*>(filepath.c_str()), filepath.size(), ImGuiInputTextFlags_EnterReturnsTrue)) _newMedia[1] = filepath; if (ImGui::IsItemHovered()) ImGui::SetTooltip("Media path"); ImGui::PopItemWidth(); ImGui::SameLine(); if (ImGui::Button("...")) { _fileSelectorTarget = mediaName; } if (_fileSelectorTarget == mediaName) { static string path = _root.lock()->getMediaPath(); bool cancelled; vector<string> extensions{{"bmp"}, {"jpg"}, {"png"}, {"tga"}, {"tif"}, {"avi"}, {"mov"}, {"mp4"}}; if (SplashImGui::FileSelector(mediaName, path, cancelled, extensions)) { if (!cancelled) { _newMedia[1] = path; path = Utils::getPathFromFilePath("./"); } _fileSelectorTarget = ""; } } ImGui::PopID(); if (updated) { setObject(mediaName, "playlist", playlist); } ImGui::TreePop(); } // Display the filters associated with this queue auto filter = dynamic_pointer_cast<QueueSurrogate>(media)->getFilter(); auto filterName = filter->getName(); if (ImGui::TreeNode(("Filter: " + filterName).c_str())) { auto filterAttributes = filter->getAttributes(true); drawAttributes(filterName, filterAttributes); ImGui::TreePop(); } } else { // Display the filters associated with this media auto filters = getFiltersForImage(media); for (auto& filter : filters) { auto filterName = filter->getName(); if (ImGui::TreeNode(("Filter: " + filterName).c_str())) { auto filterAttributes = filter->getAttributes(true); drawAttributes(filterName, filterAttributes); ImGui::TreePop(); } } } ImGui::TreePop(); } } } }
Values::iterator begin(){ return values.begin(); }
void TypeNodeCodeGen::emitCall(MemberFctCall* call, Place* self) { Values args; MemberFct* fct = call->getMemberFct(); call->exprList_->accept(this); TypeList& out = fct->sig_.outTypes_; /* * prepare arguments */ if (self) args.push_back( self->getAddr(builder_) ); Values perRefRetValues; // append return-value arguments for (size_t i = 0; i < out.size(); ++i) { const Type* type = out[i]; if ( type->perRef() ) { int simdLength = call->simd_ ? 4 : 0; // HACK const llvm::Type* llvmType = type->getRawLLVMType(ctxt_->module_, simdLength); // do return value optimization or create temporary Place* place = 0; if ( call->initPlaces_ && (*call->initPlaces_)[i] ) place = (*call->initPlaces_)[i]; Value* arg = place ? place->getAddr(builder_) : createEntryAlloca(builder_, llvmType); args.push_back(arg); perRefRetValues.push_back(arg); } } // append regular arguments call->exprList_->getArgs(builder_, args); llvm::Function* llvmFct = call->simd_ ? fct->simdFct_ : fct->llvmFct_; swiftAssert(llvmFct, "must exist"); // create actual call llvm::CallInst* callInst = llvm::CallInst::Create( llvmFct, args.begin(), args.end() ); callInst->setCallingConv(llvm::CallingConv::Fast); Value* retValue = builder_.Insert(callInst); /* * write results back */ swiftAssert( call->numResults() == out.size(), "sizes must match" ); size_t idxRetType = 0; size_t idxPerRef = 0; for (size_t i = 0; i < out.size(); ++i) { call->set(i).place_ = out[i]->perRef() ? (Place*) new Addr( perRefRetValues[idxPerRef++] ) : (Place*) new Scalar( builder_.CreateExtractValue(retValue, idxRetType++) ); } }
/* ************************************************************************* */ void Values::update(const Values& values) { for(const_iterator key_value = values.begin(); key_value != values.end(); ++key_value) { this->update(key_value->key, key_value->value); } }
/* ************************************************************************* */ void Values::insert(const Values& values) { for(const_iterator key_value = values.begin(); key_value != values.end(); ++key_value) { Key key = key_value->key; // Non-const duplicate to deal with non-const insert argument insert(key, key_value->value); } }