Skip to content

Commit

Permalink
[jvm-packages] Deprecate constructors with implicit missing value. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Sep 16, 2021
1 parent 0ed979b commit 9f63d6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Expand Up @@ -124,7 +124,11 @@ public DMatrix(long[] headers, int[] indices, float[] data, DMatrix.SparseType s
* @param nrow number of rows
* @param ncol number of columns
* @throws XGBoostError native error
*
* @deprecated Please specify the missing value explicitly using
* {@link DMatrix(float[], int, int, float)}
*/
@Deprecated
public DMatrix(float[] data, int nrow, int ncol) throws XGBoostError {
long[] out = new long[1];
XGBoostJNI.checkCall(XGBoostJNI.XGDMatrixCreateFromMat(data, nrow, ncol, 0.0f, out));
Expand Down
Expand Up @@ -79,6 +79,7 @@ class DMatrix private[scala](private[scala] val jDMatrix: JDMatrix) {
* @param nrow number of rows
* @param ncol number of columns
*/
@deprecated("Please specify the missing value explicitly", "XGBoost 1.5")
@throws(classOf[XGBoostError])
def this(data: Array[Float], nrow: Int, ncol: Int) {
this(new JDMatrix(data, nrow, ncol))
Expand Down
Expand Up @@ -212,7 +212,7 @@ public void testCreateFromDenseMatrix() throws XGBoostError {
label0[i] = random.nextFloat();
}

DMatrix dmat0 = new DMatrix(data0, nrow, ncol);
DMatrix dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN);
dmat0.setLabel(label0);

//check
Expand Down Expand Up @@ -281,7 +281,7 @@ public void testCreateFromDenseMatrixRef() throws XGBoostError {
label0[i] = random.nextFloat();
}

dmat0 = new DMatrix(data0);
dmat0 = new DMatrix(data0, Float.NaN);
dmat0.setLabel(label0);

//check
Expand Down Expand Up @@ -318,7 +318,7 @@ public void testTrainWithDenseMatrixRef() throws XGBoostError {
for (int j = 0; j < data0.ncol; j++)
data0.set(i, j, data[i][j]);

trainMat = new DMatrix(data0);
trainMat = new DMatrix(data0, Float.NaN);
trainMat.setLabel(new float[]{1f, 2f, 3f});

HashMap<String, Object> params = new HashMap<>();
Expand All @@ -338,7 +338,7 @@ public void testTrainWithDenseMatrixRef() throws XGBoostError {
// (3,1) -> 2
// (2,3) -> 3
for (int i = 0; i < 3; i++) {
float[][] preds = booster.predict(new DMatrix(data[i], 1, 2));
float[][] preds = booster.predict(new DMatrix(data[i], 1, 2, Float.NaN));
assertEquals(1, preds.length);
assertArrayEquals(new float[]{(float) (i + 1)}, preds[0], 1e-2f);
}
Expand Down
Expand Up @@ -130,7 +130,7 @@ class DMatrixSuite extends FunSuite {
for (i <- label0.indices) {
label0(i) = Random.nextFloat()
}
val dmat0 = new DMatrix(data0, nrow, ncol)
val dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN)
dmat0.setLabel(label0)
// check
assert(dmat0.rowNum === 10)
Expand Down

0 comments on commit 9f63d6f

Please sign in to comment.