Skip to content

Commit

Permalink
hash map.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 20, 2025
1 parent be1234b commit 8792ec8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
package ml.dmlc.xgboost4j.java;

import java.util.Iterator;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* QuantileDMatrix will only be used to train
Expand Down Expand Up @@ -116,8 +120,16 @@ public void setGroup(int[] group) throws XGBoostError {
}

private String getConfig(float missing, int maxBin, int nthread, boolean useExternalMemory) {
return String.format("{\"missing\":%f,\"max_bin\":%d,\"nthread\":%d," +
"\"use_ext_mem\":%b}", missing, maxBin, nthread, useExternalMemory);
Map<String, Object> conf = new java.util.HashMap<>();
conf.put("missing", missing);
conf.put("max_bin", maxBin);
conf.put("nthread", nthread);
conf.put("use_ext_mem", useExternalMemory);
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(conf);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to serialize configuration", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
7 changes: 7 additions & 0 deletions src/c_api/c_api_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
LOG(CONSOLE) << "[XGBoost C API invocation] " << __PRETTY_FUNCTION__; \
try { \
auto __guard = ::xgboost::XGBoostAPIGuard();

#define API_BEGIN_UNGUARD() \
LOG(CONSOLE) << "[XGBoost C API invocation] " << __PRETTY_FUNCTION__; \
try {

#else // LOG_CAPI_INVOCATION

#define API_BEGIN() \
try { \
auto __guard = ::xgboost::XGBoostAPIGuard();

#define API_BEGIN_UNGUARD() try {

#endif // LOG_CAPI_INVOCATION

/*! \brief every function starts with API_BEGIN();
Expand Down

0 comments on commit 8792ec8

Please sign in to comment.