Skip to content

Commit

Permalink
remove BH dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Oct 24, 2023
1 parent 95bfa2b commit 9fc5b31
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cyclops.Rproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Imports:
survival,
bit64
LinkingTo: Rcpp,
BH (>= 1.51.0),
RcppEigen (>= 0.3.2)
Suggests:
testthat,
Expand Down
14 changes: 8 additions & 6 deletions src/cyclops/CcdInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "CyclicCoordinateDescent.h"
#include "ModelData.h"

#include "boost/iterator/counting_iterator.hpp"
//#include "boost/iterator/counting_iterator.hpp"
#include "Thread.h"

// #include "io/InputReader.h"
Expand Down Expand Up @@ -370,9 +370,9 @@ double CcdInterface::profileModel(CyclicCoordinateDescent *ccd, AbstractModelDat
}
);
} else {
auto scheduler = TaskScheduler<boost::counting_iterator<int> >(
boost::make_counting_iterator(0),
boost::make_counting_iterator(static_cast<int>(bounds.size())),
auto scheduler = TaskScheduler<IncrementableIterator<size_t>>(
IncrementableIterator<size_t>(0), // boost::make_counting_iterator(0),
IncrementableIterator<size_t>(bounds.size()), //boost::make_counting_iterator(static_cast<int>(bounds.size())),
nThreads);

auto oneTask = [&getBound, &scheduler, &ccdPool, &bounds](unsigned long task) {
Expand Down Expand Up @@ -583,8 +583,10 @@ double CcdInterface::evaluateProfileModel(CyclicCoordinateDescent *ccd, Abstract
values[i] = evaluate(points[i], ccd);
}
} else {
auto scheduler = TaskScheduler<boost::counting_iterator<int>>(
boost::make_counting_iterator(0), boost::make_counting_iterator(static_cast<int>(points.size())), nThreads);
auto scheduler = TaskScheduler<IncrementableIterator<size_t>>(
IncrementableIterator<size_t>(0), //boost::make_counting_iterator(0),
IncrementableIterator<size_t>(points.size()), //boost::make_counting_iterator(static_cast<int>(points.size())),
nThreads);

auto oneTask = [&evaluate, &scheduler, &ccdPool, &points, &values](unsigned long task) {
values[task] = evaluate(points[task], ccdPool[scheduler.getThreadIndex(task)]);
Expand Down
8 changes: 4 additions & 4 deletions src/cyclops/CyclicCoordinateDescent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ void CyclicCoordinateDescent::init(bool offset) {

// initialize starting betas to default value 0.0
startingBeta.resize(J, static_cast<double>(0.0));

// hXBeta.resize(K, static_cast<double>(0.0));
// hXBetaSave.resize(K, static_cast<double>(0.0));

fixBeta.resize(J, false);

hWeights.resize(0);
cWeights.resize(0); // ESK: For censor weights

Expand Down Expand Up @@ -695,7 +695,7 @@ void CyclicCoordinateDescent::kktSwindle(const ModeFindingArguments& arguments)
int swindleIterationCount = 1;

// int initialActiveSize = activeSet.size();
int perPassSize = arguments.swindleMultipler;
// int perPassSize = arguments.swindleMultipler;

while (!done) {

Expand Down Expand Up @@ -823,7 +823,7 @@ void CyclicCoordinateDescent::kktSwindle(const ModeFindingArguments& arguments)
}
}
++swindleIterationCount;
perPassSize *= 2;
// perPassSize *= 2;

logger->yield(); // This is not re-entrant safe
}
Expand Down
48 changes: 43 additions & 5 deletions src/cyclops/Iterators.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef ITERATORS_H
#define ITERATORS_H

#include <boost/tuple/tuple.hpp>
//#include <boost/tuple/tuple.hpp>
#include <tuple>

#include "CompressedDataMatrix.h"

Expand All @@ -14,6 +15,40 @@ namespace bsccs {
* single run-time determined iterator
*/

template <typename T>
class IncrementableIterator : public std::iterator<std::input_iterator_tag, T> {
public:
IncrementableIterator(T value) : value(value) { }

IncrementableIterator& operator++() {
++value;
return *this;
}

T operator*() const { return value; }

bool operator==(const IncrementableIterator& rhs) const {
return value == rhs.value;
}

bool operator!=(const IncrementableIterator& rhs) const {
return !(*this == rhs);
}

template <typename V>
IncrementableIterator operator+(V n) const {
IncrementableIterator copy = *this;
copy.value += n;
return copy;
}

bool operator<(const IncrementableIterator& rhs) const {
return value < rhs.value;
}

private:
T value;
};

struct IndicatorTag {};
struct SparseTag {};
Expand All @@ -31,7 +66,7 @@ class IndicatorIterator {
typedef IndicatorTag tag;
typedef int Index;
typedef Scalar ValueType;
typedef boost::tuples::tuple<Index> XTuple;
typedef std::tuple<Index> XTuple;

const static std::string name;

Expand Down Expand Up @@ -123,7 +158,8 @@ class SparseIterator {
typedef SparseTag tag;
typedef int Index;
typedef Scalar ValueType;
typedef boost::tuples::tuple<Index, Scalar> XTuple;
// typedef boost::tuples::tuple<Index, Scalar> XTuple;
typedef std::tuple<Index, Scalar> XTuple;

const static std::string name;

Expand Down Expand Up @@ -300,7 +336,8 @@ class DenseIterator {
typedef DenseTag tag;
typedef int Index;
typedef Scalar ValueType;
typedef boost::tuples::tuple<Index, Scalar> XTuple;
// typedef boost::tuples::tuple<Index, Scalar> XTuple;
typedef std::tuple<Index, Scalar> XTuple;

const static std::string name;

Expand Down Expand Up @@ -392,7 +429,8 @@ class InterceptIterator {
typedef InterceptTag tag; // TODO Fix!!!
typedef int Index;
typedef Scalar ValueType;
typedef boost::tuples::tuple<Index> XTuple;
// typedef boost::tuples::tuple<Index> XTuple;
typedef std::tuple<Index> XTuple;

const static std::string name;

Expand Down
4 changes: 2 additions & 2 deletions src/cyclops/ModelData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <list>
#include <functional>

#include <boost/iterator/permutation_iterator.hpp>
#include <boost/iterator/transform_iterator.hpp>
// #include <boost/iterator/permutation_iterator.hpp>
// #include <boost/iterator/transform_iterator.hpp>

#include "ModelData.h"

Expand Down
15 changes: 10 additions & 5 deletions src/cyclops/drivers/AbstractCrossValidationDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <numeric>
#include <cmath>

#include "boost/iterator/counting_iterator.hpp"
// #include "boost/iterator/counting_iterator.hpp"

#include "Types.h"
#include "Thread.h"
Expand Down Expand Up @@ -146,10 +146,15 @@ double AbstractCrossValidationDriver::doCrossValidationStep(
auto& weightsExclude = this->weightsExclude;
auto& logger = this->logger;

auto scheduler = TaskScheduler<decltype(boost::make_counting_iterator(0))>(
boost::make_counting_iterator(0),
boost::make_counting_iterator(arguments.foldToCompute),
nThreads);
// auto scheduler = TaskScheduler<decltype(boost::make_counting_iterator(0))>(
// boost::make_counting_iterator(0),
// boost::make_counting_iterator(arguments.foldToCompute),
// nThreads);

auto scheduler = TaskScheduler<IncrementableIterator<size_t>>(
IncrementableIterator<size_t>(0),
IncrementableIterator<size_t>(arguments.foldToCompute),
nThreads);

auto oneTask =
[step, coldStart, nThreads, &ccdPool, &selectorPool,
Expand Down
4 changes: 2 additions & 2 deletions src/cyclops/drivers/AutoSearchCrossValidationDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "AbstractSelector.h"
#include "../utils/HParSearch.h"

#include "boost/iterator/counting_iterator.hpp"
// #include "boost/iterator/counting_iterator.hpp"

namespace bsccs {

Expand Down Expand Up @@ -115,7 +115,7 @@ MaxPoint AutoSearchCrossValidationDriver::doCrossValidationLoop(
// Newly re-located code
double pointEstimate = doCrossValidationStep(ccd, selector, allArguments, step,
nThreads, ccdPool, selectorPool,
predLogLikelihood);
predLogLikelihood);

double stdDevEstimate = computeStDev(predLogLikelihood, pointEstimate);

Expand Down
8 changes: 4 additions & 4 deletions src/cyclops/engine/ModelSpecifics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ struct TupleXGetterNew {

template <class TupleType>
inline ReturnType operator()(TupleType& tuple) const {
return boost::get<index>(tuple);
return std::get<index>(tuple);
}
};

Expand Down Expand Up @@ -1728,7 +1728,7 @@ struct TestNumeratorKernel {
template <class NumeratorType, class TupleType>
NumeratorType operator()(const NumeratorType lhs, const TupleType tuple) {

const auto expXBeta = boost::get<0>(tuple);
const auto expXBeta = std::get<0>(tuple);
const auto x = getX(tuple); //boost::get<1>(tuple);

return {
Expand All @@ -1752,8 +1752,8 @@ struct TestGradientKernel {

template <class GradientType, class NumeratorType, class TupleType>
GradientType operator()(const GradientType lhs, const NumeratorType numerator, const TupleType tuple) {
const auto denominator = boost::get<0>(tuple);
const auto weight = boost::get<1>(tuple);
const auto denominator = std::get<0>(tuple);
const auto weight = std::get<1>(tuple);

return BaseModel::template incrementGradientAndHessian<IteratorType,
WeightType>(
Expand Down
2 changes: 1 addition & 1 deletion src/cyclops/engine/ModelSpecifics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "Recursions.hpp"
#include "ParallelLoops.h"
#include "Ranges.h"
// #include "Ranges.h"

#ifdef USE_RCPP_PARALLEL
#include <tbb/combinable.h>
Expand Down
2 changes: 1 addition & 1 deletion src/cyclops/engine/ParallelLoops.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include <numeric>
#include <thread>
#include <boost/iterator/counting_iterator.hpp>
// #include <boost/iterator/counting_iterator.hpp>

// #define USE_RCPP_PARALLEL
#undef USE_RCPP_PARALLEL
Expand Down

0 comments on commit 9fc5b31

Please sign in to comment.