int main() { int racer_num = 5; Racer rcs[] = { { 1, 100 }, { 2, 10 }, { 3, 4 }, { 5, 6 }, }; vector<Racer> racers(rcs, rcs+ArraySize(rcs)); // for (int i=0; i<racer_num; ++i) { // racers[i].beg = rand(); // racers[i].end = racers[i].beg + rand(); // } vector<int> scores = ScoreHelper(racers).GetScores(); return 0; }
// Note: ignore parallel paramter, only applies to other IScorers ScoreResult Tree::Score(const bkp::MaskedVector<const HiggsCsvRow>& data, bool parallel) { int data_size = static_cast<int>(data.size()); std::vector<double> s_scores(data_size, std::numeric_limits<double>::quiet_NaN()); std::vector<double> b_scores(data_size, std::numeric_limits<double>::quiet_NaN()); bkp::MaskedVector<int> return_indices( std::vector<int>( boost::counting_iterator<int>(0), boost::counting_iterator<int>(data_size) ) ); // construct filter such that filter[i] is true iff data has no NaN values in any of // our target_feature columns (don't care about NaNs in other columns) std::vector<bool> filter = HasNan(data, *target_features_); filter.flip(); // use local std::vectors as backing stores for some MaskingVectors. ScoreHelper // will then populate our vectors by populating the MaskingVector and their // MaskingVector::Slices (implicitly ignoring rows with NaN's, which will be // handled by other trees). // // Normally it would be dangerous to create a shared_ptr to a local variable like // this. Either the shared_ptr will go out of scope and try to delete the // local variable (crash and/or UB) or the local variable will go out of scope with the // shared_ptr still pointing to it (dangling ptr). In this case we can see that // the local variable will outlive the shared_ptrs (they will both live until the // end of this method, although the contents of the local vectors will be std::moved // to a value-returned Score object at the end of the method). So, all we need to do // is remove the shared_ptr's deleter (done in ShareLocal) and we're good to go. auto filtered_return_indices = return_indices.Filter(filter); ScoreHelper(data, filtered_return_indices.MakeSlice(), s_scores, b_scores); return hrf::ScoreResult(std::move(s_scores), std::move(b_scores)); }