Skip to content

Commit

Permalink
Remove copy constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jul 22, 2019
1 parent c0496ad commit cc28f33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
4 changes: 4 additions & 0 deletions include/xgboost/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class JsonArray : public Value {
Value(ValueKind::Array), vec_{std::move(arr)} {}
JsonArray(std::vector<Json> const& arr) : // NOLINT
Value(ValueKind::Array), vec_{arr} {}
JsonArray(JsonArray const& that) = delete;
JsonArray(JsonArray && that);

void Save(JsonWriter* writer) override;

Expand Down Expand Up @@ -153,6 +155,8 @@ class JsonObject : public Value {
public:
JsonObject() : Value(ValueKind::Object) {}
JsonObject(std::map<std::string, Json>&& object); // NOLINT
JsonObject(JsonObject const& that) = delete;
JsonObject(JsonObject && that);

void Save(JsonWriter* writer) override;

Expand Down
30 changes: 7 additions & 23 deletions src/common/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Json& DummyJsonObject() {
}

// Json Object
JsonObject::JsonObject(JsonObject && that) :
Value(ValueKind::Object), object_{std::move(that.object_)} {}

JsonObject::JsonObject(std::map<std::string, Json>&& object)
: Value(ValueKind::Object), object_{std::move(object)} {}

Expand Down Expand Up @@ -188,6 +191,9 @@ void JsonString::Save(JsonWriter* writer) {
}

// Json Array
JsonArray::JsonArray(JsonArray && that) :
Value(ValueKind::Array), vec_{std::move(that.vec_)} {}

Json& JsonArray::operator[](std::string const & key) {
LOG(FATAL) << "Object of type "
<< Value::TypeStr() << " can not be indexed by string.";
Expand Down Expand Up @@ -562,29 +568,7 @@ void Json::Dump(Json json, std::ostream *stream, bool pretty) {
}

Json& Json::operator=(Json const &other) {
auto type = other.GetValue().Type();
switch (type) {
case Value::ValueKind::Array:
ptr_.reset(new JsonArray(*Cast<JsonArray const>(&other.GetValue())));
break;
case Value::ValueKind::Boolean:
ptr_.reset(new JsonBoolean(*Cast<JsonBoolean const>(&other.GetValue())));
break;
case Value::ValueKind::Null:
ptr_.reset(new JsonNull(*Cast<JsonNull const>(&other.GetValue())));
break;
case Value::ValueKind::Number:
ptr_.reset(new JsonNumber(*Cast<JsonNumber const>(&other.GetValue())));
break;
case Value::ValueKind::Object:
ptr_.reset(new JsonObject(*Cast<JsonObject const>(&other.GetValue())));
break;
case Value::ValueKind::String:
ptr_.reset(new JsonString(*Cast<JsonString const>(&other.GetValue())));
break;
default:
LOG(FATAL) << "Unknown value kind.";
}
this->ptr_ = other.ptr_;
return *this;
}
} // namespace xgboost
8 changes: 4 additions & 4 deletions src/gbm/gblinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class GBLinear : public GradientBooster {
for (const auto &batch : p_fmat->GetRowBatches()) {
// parallel over local batch
const auto nsize = static_cast<bst_omp_uint>(batch.Size());
#pragma omp parallel for schedule(static)
#pragma omp parallel for schedule(static)
for (bst_omp_uint i = 0; i < nsize; ++i) {
auto inst = batch[i];
auto row_idx = static_cast<size_t>(batch.base_rowid + i);
Expand Down Expand Up @@ -220,7 +220,7 @@ class GBLinear : public GradientBooster {
// k is number of group
// parallel over local batch
const auto nsize = static_cast<omp_ulong>(batch.Size());
#pragma omp parallel for schedule(static)
#pragma omp parallel for schedule(static)
for (omp_ulong i = 0; i < nsize; ++i) {
const size_t ridx = batch.base_rowid + i;
// loop over output groups
Expand Down Expand Up @@ -273,8 +273,8 @@ class GBLinear : public GradientBooster {
}
}

inline void Pred(const SparsePage::Inst &inst, bst_float *preds, int gid,
bst_float base) {
void Pred(const SparsePage::Inst &inst, bst_float *preds, int gid,
bst_float base) {
bst_float psum = model_.bias()[gid] + base;
for (const auto& ins : inst) {
if (ins.index >= model_.param.num_feature) continue;
Expand Down

0 comments on commit cc28f33

Please sign in to comment.