public Predictor()

in runtime/java/treelite4j/src/main/java/ml/dmlc/treelite4j/Predictor.java [37:89]


  public Predictor(
    String libpath, int nthread, boolean verbose) throws TreeliteError {
    File f = new File(libpath);
    String path = "";
    if (f.isDirectory()) {  // libpath is a diectory
      // directory is given; locate shared library inside it
      String basename = f.getName();
      boolean lib_found = false;
      for (String ext : new String[]{".so", ".dll", ".dylib"}) {
        path = Paths.get(libpath, basename + ext).toString();
        File f2 = new File(path);
        if (f2.exists()) {
          lib_found = true;
          break;
        }
      }
      if (!lib_found) {
        throw new TreeliteError(String.format(
          "Directory %s doesn't appear to have any dynamic " +
          "shared library (.so/.dll/.dylib).", libpath));
      }
    } else {  // libpath is actually the name of shared library file
      String fileext = libpath.substring(libpath.lastIndexOf('.'));
      if (fileext.equals(".dll")
          || fileext.equals(".so") || fileext.equals(".dylib")) {
        path = libpath;
      } else {
        throw new TreeliteError(String.format(
          "Specified path %s has wrong file extension (%s); the shared " +
          "library must have one of the following extensions: " +
          ".so / .dll / .dylib", libpath, fileext));
      }
    }

    long[] out = new long[1];
    TreeliteJNI.checkCall(TreeliteJNI.TreelitePredictorLoad(
      path, nthread, out));
    handle = out[0];

    // Save # of output groups and # of features
    TreeliteJNI.checkCall(TreeliteJNI.TreelitePredictorQueryNumOutputGroup(
      handle, out));
    num_output_group = (int)out[0];
    TreeliteJNI.checkCall(TreeliteJNI.TreelitePredictorQueryNumFeature(
      handle, out));
    num_feature = (int)out[0];

    if (verbose) {
      logger.info(String.format(
        "Dynamic shared library %s has been successfully loaded into memory",
        path));
    }
  }