Skip to content

Commit

Permalink
Fix cpplint. (#4157)
Browse files Browse the repository at this point in the history
* Add comment after #endif.
* Add missing headers.
  • Loading branch information
trivialfis authored Feb 17, 2019
1 parent 71a604f commit 2e618af
Show file tree
Hide file tree
Showing 46 changed files with 97 additions and 72 deletions.
6 changes: 3 additions & 3 deletions R-package/src/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2015 by Contributors
*
*
* This file was initially generated using the following R command:
* tools::package_native_routine_registration_skeleton('.', con = 'src/init.c', character_only = F)
* and edited to conform to xgboost C linter requirements. For details, see
Expand All @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <R_ext/Rdynload.h>

/* FIXME:
/* FIXME:
Check these declarations against the C/Fortran source code.
*/

Expand Down Expand Up @@ -70,7 +70,7 @@ static const R_CallMethodDef CallEntries[] = {

#if defined(_WIN32)
__declspec(dllexport)
#endif
#endif // defined(_WIN32)
void R_init_xgboost(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
Expand Down
2 changes: 1 addition & 1 deletion R-package/src/xgboost_custom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool CheckNAN(double v) {
double LogGamma(double v) {
return lgammafn(v);
}
#endif
#endif // !defined(XGBOOST_USE_CUDA)
// customize random engine.
void CustomGlobalRandomEngine::seed(CustomGlobalRandomEngine::result_type val) {
// ignore the seed
Expand Down
4 changes: 4 additions & 0 deletions cmake/build_config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*!
* Copyright 2019 by Contributors
* \file build_config.h
*/
#ifndef XGBOOST_BUILD_CONFIG_H_
#define XGBOOST_BUILD_CONFIG_H_

Expand Down
18 changes: 9 additions & 9 deletions include/xgboost/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#ifndef XGBOOST_STRICT_R_MODE
#define XGBOOST_STRICT_R_MODE 0
#endif
#endif // XGBOOST_STRICT_R_MODE

/*!
* \brief Whether always log console message with time.
Expand All @@ -26,21 +26,21 @@
*/
#ifndef XGBOOST_LOG_WITH_TIME
#define XGBOOST_LOG_WITH_TIME 1
#endif
#endif // XGBOOST_LOG_WITH_TIME

/*!
* \brief Whether customize the logger outputs.
*/
#ifndef XGBOOST_CUSTOMIZE_LOGGER
#define XGBOOST_CUSTOMIZE_LOGGER XGBOOST_STRICT_R_MODE
#endif
#endif // XGBOOST_CUSTOMIZE_LOGGER

/*!
* \brief Whether to customize global PRNG.
*/
#ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG
#define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE
#endif
#endif // XGBOOST_CUSTOMIZE_GLOBAL_PRNG

/*!
* \brief Check if alignas(*) keyword is supported. (g++ 4.8 or higher)
Expand All @@ -49,7 +49,7 @@
#define XGBOOST_ALIGNAS(X) alignas(X)
#else
#define XGBOOST_ALIGNAS(X)
#endif
#endif // defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)

#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4) && \
!defined(__CUDACC__)
Expand All @@ -64,7 +64,7 @@
#else
#define XGBOOST_PARALLEL_SORT(X, Y, Z) std::sort((X), (Y), (Z))
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) std::stable_sort((X), (Y), (Z))
#endif
#endif // GLIBC VERSION

/*!
* \brief Tag function as usable by device
Expand All @@ -73,7 +73,7 @@
#define XGBOOST_DEVICE __host__ __device__
#else
#define XGBOOST_DEVICE
#endif
#endif // defined (__CUDA__) || defined(__NVCC__)

/*! \brief namespace of xgboost*/
namespace xgboost {
Expand Down Expand Up @@ -215,8 +215,8 @@ using bst_omp_uint = dmlc::omp_uint; // NOLINT
#if __GNUC__ == 4 && __GNUC_MINOR__ < 8
#define override
#define final
#endif
#endif
#endif // __GNUC__ == 4 && __GNUC_MINOR__ < 8
#endif // DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
} // namespace xgboost

/* Always keep this #include at the bottom of xgboost/base.h */
Expand Down
2 changes: 1 addition & 1 deletion include/xgboost/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#elif defined(__GNUC__)
// Enable __builtin_prefetch for GCC
#define XGBOOST_BUILTIN_PREFETCH_PRESENT
#endif
#endif // GUARDS

#endif // XGBOOST_BUILD_CONFIG_H_
9 changes: 5 additions & 4 deletions include/xgboost/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#ifdef __cplusplus
#define XGB_EXTERN_C extern "C"
#include <cstdio>
#include <cstdint>
#else
#define XGB_EXTERN_C
#include <stdio.h>
#include <stdint.h>
#endif
#endif // __cplusplus

// XGBoost C API will include APIs in Rabit C API
#include <rabit/c_api.h>
Expand All @@ -23,7 +24,7 @@
#define XGB_DLL XGB_EXTERN_C __declspec(dllexport)
#else
#define XGB_DLL XGB_EXTERN_C
#endif
#endif // defined(_MSC_VER) || defined(_WIN32)

// manually define unsigned long
typedef uint64_t bst_ulong; // NOLINT(*)
Expand All @@ -49,7 +50,7 @@ typedef struct { // NOLINT(*)
long* offset; // NOLINT(*)
#else
int64_t* offset; // NOLINT(*)
#endif
#endif // __APPLE__
/*! \brief labels of each instance */
float* label;
/*! \brief weight of each instance, can be NULL */
Expand Down Expand Up @@ -562,7 +563,7 @@ XGB_DLL int XGBoosterGetAttr(BoosterHandle handle,
*
* \param handle handle
* \param key The key of the attribute.
* \param value The value to be saved.
* \param value The value to be saved.
* If nullptr, the attribute would be deleted.
* \return 0 when success, -1 when failure happens
*/
Expand Down
1 change: 1 addition & 0 deletions include/xgboost/learner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <rabit/rabit.h>
#include <utility>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "./base.h"
Expand Down
12 changes: 6 additions & 6 deletions include/xgboost/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseLogger {
BaseLogger() {
#if XGBOOST_LOG_WITH_TIME
log_stream_ << "[" << dmlc::DateLogger().HumanDate() << "] ";
#endif
#endif // XGBOOST_LOG_WITH_TIME
}
std::ostream& stream() { return log_stream_; } // NOLINT

Expand Down Expand Up @@ -116,14 +116,14 @@ class LogCallbackRegistry {
return nullptr;
}
};
#endif
#endif // !defined(XGBOOST_STRICT_R_MODE) || XGBOOST_STRICT_R_MODE == 0

using LogCallbackRegistryStore = dmlc::ThreadLocalStore<LogCallbackRegistry>;

// Redefines LOG_WARNING for controling verbosity
#if defined(LOG_WARNING)
#undef LOG_WARNING
#endif
#endif // defined(LOG_WARNING)
#define LOG_WARNING \
if (::xgboost::ConsoleLogger::ShouldLog( \
::xgboost::ConsoleLogger::LV::kWarning)) \
Expand All @@ -133,7 +133,7 @@ using LogCallbackRegistryStore = dmlc::ThreadLocalStore<LogCallbackRegistry>;
// Redefines LOG_INFO for controling verbosity
#if defined(LOG_INFO)
#undef LOG_INFO
#endif
#endif // defined(LOG_INFO)
#define LOG_INFO \
if (::xgboost::ConsoleLogger::ShouldLog( \
::xgboost::ConsoleLogger::LV::kInfo)) \
Expand All @@ -142,7 +142,7 @@ using LogCallbackRegistryStore = dmlc::ThreadLocalStore<LogCallbackRegistry>;

#if defined(LOG_DEBUG)
#undef LOG_DEBUG
#endif
#endif // defined(LOG_DEBUG)
#define LOG_DEBUG \
if (::xgboost::ConsoleLogger::ShouldLog( \
::xgboost::ConsoleLogger::LV::kDebug)) \
Expand All @@ -152,7 +152,7 @@ using LogCallbackRegistryStore = dmlc::ThreadLocalStore<LogCallbackRegistry>;
// redefines the logging macro if not existed
#ifndef LOG
#define LOG(severity) LOG_##severity.stream()
#endif
#endif // LOG

// Enable LOG(CONSOLE) for print messages to console.
#define LOG_CONSOLE ::xgboost::ConsoleLogger( \
Expand Down
3 changes: 3 additions & 0 deletions include/xgboost/predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#pragma once
#include <xgboost/base.h>
#include <xgboost/data.h>

#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "../../src/gbm/gbtree_model.h"
#include "../../src/common/host_device_vector.h"

Expand Down
2 changes: 1 addition & 1 deletion src/common/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ GlobalRandomEngine& GlobalRandom() {
int AllVisibleImpl::AllVisible() {
return 0;
}
#endif
#endif // !defined(XGBOOST_USE_CUDA)

} // namespace xgboost
4 changes: 2 additions & 2 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define WITH_CUDA() false

#endif
#endif // defined(__CUDACC__)

namespace dh {
#if defined(__CUDACC__)
Expand All @@ -44,7 +44,7 @@ inline cudaError_t ThrowOnCudaError(cudaError_t code, const char *file,
}
return code;
}
#endif
#endif // defined(__CUDACC__)
} // namespace dh

namespace xgboost {
Expand Down
4 changes: 2 additions & 2 deletions src/common/compressed_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#ifdef __CUDACC__
#include "device_helpers.cuh"
#endif
#endif // __CUDACC__

namespace xgboost {
namespace common {
Expand Down Expand Up @@ -115,7 +115,7 @@ class CompressedBufferWriter {
symbol >>= 8;
}
}
#endif
#endif // __CUDACC__

template <typename IterT>
void Write(CompressedByteT *buffer, IterT input_begin, IterT input_end) {
Expand Down
6 changes: 3 additions & 3 deletions src/common/hist_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define PREFETCH_READ_T0(addr) __builtin_prefetch(reinterpret_cast<const char*>(addr), 0, 3)
#else // no SW pre-fetching available; PREFETCH_READ_T0 is no-op
#define PREFETCH_READ_T0(addr) do {} while (0)
#endif
#endif // defined(XGBOOST_MM_PREFETCH_PRESENT)

namespace xgboost {
namespace common {
Expand Down Expand Up @@ -544,7 +544,7 @@ void GHistBuilder::BuildBlockHist(const std::vector<GradientPair>& gpair,

#if defined(_OPENMP)
const auto nthread = static_cast<bst_omp_uint>(this->nthread_);
#endif
#endif // defined(_OPENMP)
tree::GradStats* p_hist = hist.data();

#pragma omp parallel for num_threads(nthread) schedule(guided)
Expand Down Expand Up @@ -590,7 +590,7 @@ void GHistBuilder::SubtractionTrick(GHistRow self, GHistRow sibling, GHistRow pa

#if defined(_OPENMP)
const auto nthread = static_cast<bst_omp_uint>(this->nthread_);
#endif
#endif // defined(_OPENMP)
tree::GradStats* p_self = self.data();
tree::GradStats* p_sibling = sibling.data();
tree::GradStats* p_parent = parent.data();
Expand Down
2 changes: 1 addition & 1 deletion src/common/host_device_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ template class HostDeviceVector<size_t>;

} // namespace xgboost

#endif
#endif // XGBOOST_USE_CUDA
7 changes: 4 additions & 3 deletions src/common/host_device_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <algorithm>
#include <cstdlib>
#include <initializer_list>
#include <utility>
#include <vector>

#include "common.h"
Expand All @@ -66,15 +67,15 @@
// is included from a .cu file
#ifdef __CUDACC__
#include <thrust/device_ptr.h>
#endif
#endif // __CUDACC__

namespace xgboost {

#ifdef __CUDACC__
// Sets a function to call instead of cudaSetDevice();
// only added for testing
void SetCudaSetDeviceHandler(void (*handler)(int));
#endif
#endif // __CUDACC__

template <typename T> struct HostDeviceVectorImpl;

Expand Down Expand Up @@ -233,7 +234,7 @@ class HostDeviceVector {

void ScatterFrom(thrust::device_ptr<const T> begin, thrust::device_ptr<const T> end);
void GatherTo(thrust::device_ptr<T> begin, thrust::device_ptr<T> end) const;
#endif
#endif // __CUDACC__

void Fill(T v);
void Copy(const HostDeviceVector<T>& other);
Expand Down
4 changes: 2 additions & 2 deletions src/common/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ inline bool CheckNAN(T v) {
return (_isnan(v) != 0);
#else
return std::isnan(v);
#endif
#endif // _MSC_VER
}
#endif // XGBOOST_STRICT_R_MODE_

Expand All @@ -149,7 +149,7 @@ XGBOOST_DEVICE inline T LogGamma(T v) {

#else
return lgamma(v);
#endif
#endif // _MSC_VER
}

#endif // XGBOOST_STRICT_R_MODE && !defined(XGBOOST_USE_CUDA)
Expand Down
2 changes: 1 addition & 1 deletion src/common/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef CustomGlobalRandomEngine GlobalRandomEngine;
* \brief global random engine
*/
using GlobalRandomEngine = RandomEngine;
#endif
#endif // XGBOOST_CUSTOMIZE_GLOBAL_PRNG

/*!
* \brief global singleton of a random engine.
Expand Down
Loading

0 comments on commit 2e618af

Please sign in to comment.