Example #1
0
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);
}
Example #2
0
 /* ************************************************************************* */
 Constraint::shared_ptr AllDiff::partiallyApply(const Values& values) const {
   DiscreteKeys newKeys;
   // loop over keys and add them only if they do not appear in values
   for(Key k: keys_)
     if (values.find(k) == values.end()) {
       newKeys.push_back(DiscreteKey(k,cardinalities_.at(k)));
     }
   return boost::make_shared<AllDiff>(newKeys);
 }
Example #3
0
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;
}
Example #4
0
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())));
            }
        }
    }
}
 Values::iterator end(){
     return values.end();
 }
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++) );
    }
}
Example #7
0
 /* ************************************************************************* */
 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);
   }
 }
Example #8
0
 /* ************************************************************************* */
 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);
   }
 }