Skip to content

Commit

Permalink
Merge pull request #4196 from syashakash/replace-cmath-ceil
Browse files Browse the repository at this point in the history
Replace CMath::ceil with std::ceil
  • Loading branch information
karlnapf committed Mar 23, 2018
2 parents 3495985 + cbdef6e commit 7605741
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/shogun/features/DataGenerator.cpp
Expand Up @@ -32,7 +32,7 @@ SGMatrix<float64_t> CDataGenerator::generate_checkboard_data(int32_t num_classes
{
int32_t points_per_class = num_points / num_classes;

int32_t grid_size = (int32_t ) CMath::ceil(CMath::sqrt((float64_t ) num_classes));
int32_t grid_size = (int32_t)std::ceil(CMath::sqrt((float64_t)num_classes));
float64_t cell_size = (float64_t ) 1 / grid_size;
SGVector<float64_t> grid_idx(dim);
for (index_t i=0; i<dim; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/features/StringFeatures.cpp
Expand Up @@ -1143,7 +1143,7 @@ template<class ST> bool CStringFeatures<ST>::load_compressed(char* src, bool dec
}
else
{
int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST));
int32_t offs = std::ceil(2.0 * sizeof(int32_t) / sizeof(ST));
features[i].string=SG_MALLOC(ST, len_compressed+offs);
features[i].slen=len_compressed+offs;
int32_t* feat32ptr=((int32_t*) (features[i].string));
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/lib/JLCoverTree.h
Expand Up @@ -98,7 +98,7 @@ inline float dist_of_scale (int s)

inline int get_scale(float d)
{
return (int) CMath::ceil(il2 * log(d));
return (int)std::ceil(il2 * log(d));
}

template<class P>
Expand Down
9 changes: 0 additions & 9 deletions src/shogun/mathematics/Math.h
Expand Up @@ -374,15 +374,6 @@ class CMath : public CSGObject
return std::floor(d);
}

/** The value of x rounded upward (as a floating-point value)
* @param d input decimal value
* @return rounded off value
*/
static inline float64_t ceil(float64_t d)
{
return std::ceil(d);
}

/** Signum of input value
* @param a input value
* @return 1 if a>0, -1 if a<0
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/mathematics/ajd/FFDiag.cpp
Expand Up @@ -45,7 +45,7 @@ SGMatrix<float64_t> CFFDiag::diagonalize(SGNDArray<float64_t> C0, SGMatrix<float
W.data());

W.transposeInPlace();
int e = CMath::ceil(log2(W.array().abs().rowwise().sum().maxCoeff()));
int e = std::ceil(log2(W.array().abs().rowwise().sum().maxCoeff()));
int s = std::max(0,e-1);
W /= pow(2,s);

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/preprocessor/DecompressString.cpp
Expand Up @@ -82,7 +82,7 @@ ST* CDecompressString<ST>::apply_to_string(ST* f, int32_t &len)
uint64_t compressed_size=((int32_t*) f)[0];
uint64_t uncompressed_size=((int32_t*) f)[1];

int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST));
int32_t offs = std::ceil(2.0 * sizeof(int32_t) / sizeof(ST));
ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size)

len=uncompressed_size;
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/regression/KRRNystrom.cpp
Expand Up @@ -81,7 +81,7 @@ bool CKRRNystrom::solve_krr_system()

if (m_num_rkhs_basis == 0)
{
set_num_rkhs_basis((int32_t)CMath::ceil(n/2.0));
set_num_rkhs_basis((int32_t)std::ceil(n / 2.0));
SG_SWARNING("Number of sampled rows not set, default is half (%d) "
"of the number of data points (%d)\n", m_num_rkhs_basis, n);
}
Expand Down
22 changes: 14 additions & 8 deletions src/shogun/structure/DynProg.cpp
Expand Up @@ -1176,18 +1176,24 @@ void CDynProg::compute_nbest_paths(int32_t max_num_signals, bool use_orf,
/* if the transition is an ORF or we do computation with loss, we have to disable long transitions */
if ((m_orf_info.element(ii,0)!=-1) || (m_orf_info.element(j,1)!=-1) || (!long_transitions))
{
look_back.set_element(CMath::ceil(penij->get_max_value()), j, ii) ;
//look_back_orig.set_element(CMath::ceil(penij->get_max_value()), j, ii) ;
if (CMath::ceil(penij->get_max_value()) > max_look_back)
{
look_back.set_element(
std::ceil(penij->get_max_value()), j, ii);
//look_back_orig.set_element(CMath::ceil(penij->get_max_value()), j, ii) ;
if (std::ceil(penij->get_max_value()) > max_look_back)
{
SG_DEBUG("%d %d -> value: %f\n", ii,j,penij->get_max_value())
max_look_back = (int32_t) (CMath::ceil(penij->get_max_value()));
}
max_look_back =
(int32_t)(std::ceil(penij->get_max_value()));
}
}
else
{
look_back.set_element(CMath::min( (int32_t)CMath::ceil(penij->get_max_value()), m_long_transition_threshold ), j, ii) ;
//look_back_orig.set_element( (int32_t)CMath::ceil(penij->get_max_value()), j, ii) ;
look_back.set_element(
CMath::min(
(int32_t)std::ceil(penij->get_max_value()),
m_long_transition_threshold),
j, ii);
//look_back_orig.set_element( (int32_t)CMath::ceil(penij->get_max_value()), j, ii) ;
}

if (penij->uses_svm_values())
Expand Down
14 changes: 9 additions & 5 deletions src/shogun/structure/TwoStateModel.cpp
Expand Up @@ -270,14 +270,18 @@ CHMSVMModel* CTwoStateModel::simulate_data(int32_t num_exm, int32_t exm_len,
{
SGVector< int32_t > lab(exm_len);
lab.zero();
rnb = num_blocks[0] + CMath::ceil((num_blocks[1]-num_blocks[0])*
CMath::random(0.0, 1.0)) - 1;
rnb = num_blocks[0] +
std::ceil(
(num_blocks[1] - num_blocks[0]) * CMath::random(0.0, 1.0)) -
1;

for ( int32_t j = 0 ; j < rnb ; ++j )
{
rl = block_len[0] + CMath::ceil((block_len[1]-block_len[0])*
CMath::random(0.0, 1.0)) - 1;
rp = CMath::ceil((exm_len-rl)*CMath::random(0.0, 1.0));
rl = block_len[0] +
std::ceil(
(block_len[1] - block_len[0]) * CMath::random(0.0, 1.0)) -
1;
rp = std::ceil((exm_len - rl) * CMath::random(0.0, 1.0));

for ( int32_t idx = rp-1 ; idx < rp+rl ; ++idx )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mathematics/Math_unittest.cc
Expand Up @@ -84,7 +84,7 @@ TEST(CMath, float64_tests)
EXPECT_NEAR(CMath::round(7.5), 8.0, 1E-15);
EXPECT_NEAR(CMath::round(7.5-1E-15), 7.0, 1E-15);
EXPECT_NEAR(CMath::floor(8-1E-15), 7.0, 1E-15);
EXPECT_NEAR(CMath::ceil(7+1E-15), 8.0, 1E-15);
EXPECT_NEAR(std::ceil(7 + 1E-15), 8.0, 1E-15);

float64_t a=5.78123516567856743364;
// x^2, x^(1/2)
Expand Down

0 comments on commit 7605741

Please sign in to comment.