Skip to content

Commit

Permalink
work on scala.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 22, 2025
1 parent 73c95c7 commit fa380e0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions jvm-packages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build.sh
xgboost4j-tester/pom.xml
xgboost4j-tester/iris.csv
dependency-reduced-pom.xml
.factorypath
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;


public class ExtMemQuantileDMatrix extends QuantileDMatrix {
// on_host is set to true by default as we only support GPU at the moment
// cache_prefix is not used yet since we have on_host=true.
Expand All @@ -29,22 +28,45 @@ public ExtMemQuantileDMatrix(Iterator<ColumnBatch> iter,
ref_handle[0] = ref.getHandle();
}
String conf = this.getConfig(missing, maxBin, nthread, max_num_device_pages,
max_quantile_batches, min_cache_page_bytes);
max_quantile_batches, min_cache_page_bytes);
XGBoostJNI.checkCall(XGBoostJNI.XGExtMemQuantileDMatrixCreateFromCallback(
iter, ref_handle, conf, out));
handle = out[0];
}

public ExtMemQuantileDMatrix(
Iterator<ColumnBatch> iter,
float missing,
int maxBin,
DMatrix ref) throws XGBoostError {
this(iter, missing, maxBin, ref, 1, -1, -1, -1);
}

public ExtMemQuantileDMatrix(
Iterator<ColumnBatch> iter,
float missing,
int maxBin) throws XGBoostError {
this(iter, missing, maxBin, null);
}

private String getConfig(float missing, int maxBin, int nthread, int max_num_device_pages,
int max_quantile_batches,
int min_cache_page_bytes) {
Map<String, Object> conf = new java.util.HashMap<>();
conf.put("missing", missing);
conf.put("max_bin", maxBin);
conf.put("nthread", nthread);
conf.put("max_num_device_pages", max_num_device_pages);
conf.put("max_quantile_batches", max_quantile_batches);
conf.put("min_cache_page_bytes", min_cache_page_bytes);

if (max_num_device_pages > 0) {
conf.put("max_num_device_pages", max_num_device_pages);
}
if (max_quantile_batches > 0) {
conf.put("max_quantile_batches", max_quantile_batches);
}
if (min_cache_page_bytes > 0) {
conf.put("min_cache_page_bytes", min_cache_page_bytes);
}

conf.put("on_host", true);
conf.put("cache_prefix", ".");
ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (c) 2025 by Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ml.dmlc.xgboost4j.scala

import scala.collection.JavaConverters._

import ml.dmlc.xgboost4j.java.{Column, ColumnBatch, ExtMemQuantileDMatrix => jExtMemQuantileDMatrix, XGBoostError}

class ExtMemQuantileDMatrix private[scala](
private[scala] override val jDMatrix: jExtMemQuantileDMatrix) extends QuantileDMatrix(jDMatrix) {

def this(iter: Iterator[ColumnBatch], missing: Float, maxBin: Int) {
this(new jExtMemQuantileDMatrix(iter.asJava, missing, maxBin))
}

def this(
iter: Iterator[ColumnBatch],
ref: ExtMemQuantileDMatrix,
missing: Float,
maxBin: Int
) {
this(new jExtMemQuantileDMatrix(iter.asJava, missing, maxBin, ref.jDMatrix))
}
}

0 comments on commit fa380e0

Please sign in to comment.