Skip to content

Commit

Permalink
Updated JPMML-R dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 15, 2024
1 parent 23a3db3 commit 0c46da4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 51 deletions.
2 changes: 1 addition & 1 deletion inst/java/classpath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pmml-evaluator-1.6.8.jar
pmml-evaluator-metro-1.6.8.jar
pmml-model-1.6.8.jar
pmml-model-metro-1.6.8.jar
pmml-rexp-1.6.2-minified.jar
pmml-rexp-1.6.3-minified.jar
Binary file modified inst/java/jpmml-evaluator-r-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-rexp</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down
65 changes: 16 additions & 49 deletions src/main/java/org/jpmml/evaluator/rexp/RExpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.primitives.Doubles;
import com.google.common.primitives.Ints;
import org.jpmml.evaluator.Evaluator;
import org.jpmml.evaluator.EvaluatorUtil;
import org.jpmml.evaluator.Table;
Expand All @@ -42,8 +39,6 @@
import org.jpmml.rexp.RExpWriter;
import org.jpmml.rexp.RGenericVector;
import org.jpmml.rexp.RIntegerVector;
import org.jpmml.rexp.RPair;
import org.jpmml.rexp.RString;
import org.jpmml.rexp.RStringVector;
import org.jpmml.rexp.RVector;

Expand Down Expand Up @@ -154,9 +149,10 @@ private RGenericVector formatNamedList(Map<String, ?> map){
values.add(vector);
}

RPair attributes = new RPair(new RString("names"), new RStringVector(names, null), null);
RGenericVector result = new RGenericVector(values, null);
result.addAttribute("names", new RStringVector(names, null));

return new RGenericVector(values, attributes);
return result;
}

static
Expand Down Expand Up @@ -190,42 +186,29 @@ private RGenericVector formatDataFrame(Table table){
vectors.add(vector);
}

RPair attributes = new RPair(new RString("names"), new RStringVector(names, null), null);
RGenericVector result = new RGenericVector(vectors, null);
result.addAttribute("names", new RStringVector(names, null));

return new RGenericVector(vectors, attributes);
return result;
}

static
private RVector<?> createScalar(Object value){

if(value instanceof Double){
Double doubleValue = (Double)value;

return new RDoubleVector(new double[]{doubleValue.doubleValue()}, null);
} else

if(value instanceof Float){
Float floatValue = (Float)value;

return new RDoubleVector(new double[]{floatValue.floatValue()}, null);
if(value instanceof Double || value instanceof Float){
return new RDoubleVector((Number)value, null);
} else

if(value instanceof Integer){
Integer integerValue = (Integer)value;

return new RIntegerVector(new int[]{integerValue.intValue()}, null);
return new RIntegerVector((Integer)value, null);
} else

if(value instanceof Boolean){
Boolean booleanValue = (Boolean)value;

return new RBooleanVector(new int[]{booleanValue.booleanValue() ? 1 : 0}, null);
return new RBooleanVector((Boolean)value, null);
} else

if(value instanceof String){
String stringValue = (String)value;

return new RStringVector(Collections.singletonList(stringValue), null);
return new RStringVector((String)value, null);
} else

{
Expand All @@ -235,34 +218,18 @@ private RVector<?> createScalar(Object value){

static
private RVector<?> createVector(List<?> values){
Object value = values.get(0);
Object value = (values.iterator()).next();

if(value instanceof Double){
return new RDoubleVector(Doubles.toArray((List)values), null);
} else

if(value instanceof Float){
double[] floatValues = new double[values.size()];

for(int i = 0; i < values.size(); i++){
floatValues[i] = ((Float)values.get(i)).floatValue();
}

return new RDoubleVector(floatValues, null);
if(value instanceof Double || value instanceof Float){
return new RDoubleVector((List)values, null);
} else

if(value instanceof Integer){
return new RIntegerVector(Ints.toArray((List)values), null);
return new RIntegerVector((List)values, null);
} else

if(value instanceof Boolean){
int[] booleanValues = new int[values.size()];

for(int i = 0; i < values.size(); i++){
booleanValues[i] = ((Boolean)values.get(i)).booleanValue() ? 1 : 0;
}

return new RBooleanVector(booleanValues, null);
return new RBooleanVector((List)values, null);
} else

if(value instanceof String){
Expand Down

0 comments on commit 0c46da4

Please sign in to comment.