Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw IOException when failing to load svm_model #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions java/libsvm/svm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,18 @@ public void print(String s)
System.out.flush();
}
};

private static svm_print_interface svm_print_stderr = new svm_print_interface() {

public void print(String s)
{
System.err.print(s);
System.err.flush();
}
};

private static svm_print_interface svm_print_string = svm_print_stdout;
private static svm_print_interface svm_print_err_string = svm_print_stderr;

static void info(String s)
{
Expand Down Expand Up @@ -2015,7 +2025,7 @@ public static svm_model svm_train(svm_problem prob, svm_parameter param)
if(param.weight_label[i] == label[j])
break;
if(j == nr_class)
System.err.print("WARNING: class label "+param.weight_label[i]+" specified in weight is not found\n");
svm_print_err_string.print("WARNING: class label "+param.weight_label[i]+" specified in weight is not found\n");
else
weighted_C[j] *= param.weight[i];
}
Expand Down Expand Up @@ -2315,7 +2325,7 @@ public static double svm_get_svr_probability(svm_model model)
return model.probA[0];
else
{
System.err.print("Model doesn't contain information for SVR probability inference\n");
svm_print_err_string.print("Model doesn't contain information for SVR probability inference\n");
return 0;
}
}
Expand Down Expand Up @@ -2569,7 +2579,7 @@ private static boolean read_model_header(BufferedReader fp, svm_model model)
}
if(i == svm_type_table.length)
{
System.err.print("unknown svm type.\n");
svm_print_err_string.print("unknown svm type.\n");
return false;
}
}
Expand All @@ -2586,7 +2596,7 @@ else if(cmd.startsWith("kernel_type"))
}
if(i == kernel_type_table.length)
{
System.err.print("unknown kernel function.\n");
svm_print_err_string.print("unknown kernel function.\n");
return false;
}
}
Expand Down Expand Up @@ -2646,7 +2656,7 @@ else if(cmd.startsWith("SV"))
}
else
{
System.err.print("unknown text in model file: ["+cmd+"]\n");
svm_print_err_string.print("unknown text in model file: ["+cmd+"]\n");
return false;
}
}
Expand Down Expand Up @@ -2676,8 +2686,7 @@ public static svm_model svm_load_model(BufferedReader fp) throws IOException

if (read_model_header(fp, model) == false)
{
System.err.print("ERROR: failed to read model\n");
return null;
throw new IOException("ERROR: failed to read model");
}

// read sv_coef and SV
Expand Down Expand Up @@ -2846,4 +2855,10 @@ public static void svm_set_print_string_function(svm_print_interface print_func)
else
svm_print_string = print_func;
}

public static void svm_set_print_err_string_function(svm_print_interface print_func)
{
if (print_func != null)
svm_print_err_string = print_func;
}
}