Changeset: 90c0e44b0072 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=90c0e44b0072
Modified Files:
monetdb5/modules/mal/Tests/rapi00.mal
monetdb5/modules/mal/rapi.c
monetdb5/modules/mal/rapi.mal
Branch: RIntegration
Log Message:
Addition of initialization and DBL inputs
diffs (241 lines):
diff --git a/monetdb5/modules/mal/Tests/rapi00.mal
b/monetdb5/modules/mal/Tests/rapi00.mal
--- a/monetdb5/modules/mal/Tests/rapi00.mal
+++ b/monetdb5/modules/mal/Tests/rapi00.mal
@@ -17,6 +17,6 @@ r:bat[:oid,:dbl] := rapi.eval("print(arg
io.print(r);
-(r:bat[:oid,:dbl], s:bat[:oid,:dbl]) := rapi.eval("someval <- Re(fft(arg1));
print(someval); return(data.frame(someval,someval));",b);
-io.print(r,s);
+(t:bat[:oid,:dbl], s:bat[:oid,:dbl]) := rapi.eval("someval2 <- Re(fft(arg2));
print(someval2); return(data.frame(someval2,someval2));",b);
+io.print(t,s);
diff --git a/monetdb5/modules/mal/rapi.c b/monetdb5/modules/mal/rapi.c
--- a/monetdb5/modules/mal/rapi.c
+++ b/monetdb5/modules/mal/rapi.c
@@ -26,6 +26,7 @@
// The R-environment should be single threaded, calling for some protective
measures.
static MT_Lock rapiLock;
+static int rapiInitialized;
char* R_HomeDir(void) {
// FIXME this won't work in general
@@ -42,14 +43,10 @@ void writeConsoleEx(const char * buf, in
THRprintf(GDKout, "%s", buf);
}
-str RAPIprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
+static void RAPIinitialize(void)
+{
char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
- (void) cntxt;
- (void) mb;
- (void) stk;
- (void) pci;
-
MT_lock_init(&rapiLock, "rapi_lock");
Rf_initEmbeddedR(4, rargv);
// these globals are indicative for non-thread safe R settings.
@@ -57,6 +54,18 @@ str RAPIprelude(Client cntxt, MalBlkPtr
ptr_R_WriteConsoleEx = writeConsoleEx;
R_Outputfile = NULL;
R_Consolefile = NULL;
+ rapiInitialized++;
+}
+
+str RAPIprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
+ (void) cntxt;
+ (void) mb;
+ (void) stk;
+ (void) pci;
+
+ if ( rapiInitialized)
+ return MAL_SUCCEED;
+ RAPIinitialize();
return MAL_SUCCEED;
}
@@ -84,9 +93,8 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
char *msg = createException(MAL, "rapi.eval", "NYI");
BAT *b;
BUN cnt;
- char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
- Rf_initEmbeddedR(4, rargv);
- (void) mb;
+
+ RAPIinitialize();
rcall = malloc(strlen(exprStr) + sizeof(argnames) + 100);
if (rcall==NULL) {
@@ -130,13 +138,29 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
switch (ATOMstorage(getTailType(getArgType(mb,pci,i))))
{
case TYPE_int:
+ { int v;
varvalue = NEW_INTEGER(BATcount(b));
for (j = 0; j < BATcount(b); j++) {
- // TODO: check for NULLs
- INTEGER_POINTER(varvalue)[j] = ((int*)
Tloc(b, BUNfirst(b)))[j];
+ v = ((int*) Tloc(b, BUNfirst(b)))[j];
+ if ( v == int_nil)
+ ; // TOBEFIXED
INTEGER_POINTER(varvalue)[j] = (int) NULL_USER_OBJECT;
+ else
+ INTEGER_POINTER(varvalue)[j] =
v;
}
break;
-
+ }
+ case TYPE_dbl:
+ { dbl v;
+ varvalue = NEW_NUMERIC(BATcount(b));
+ for (j = 0; j < BATcount(b); j++) {
+ v = ((int*) Tloc(b, BUNfirst(b)))[j];
+ if ( v == dbl_nil)
+ ; // TOBEFIXED
NUMERIC_POINTER(varvalue)[j] = (flt) NULL_USER_OBJECT;
+ else
+ NUMERIC_POINTER(varvalue)[j] =
v;
+ }
+ break;
+ }
case TYPE_str:
//varvalue = NEW_CHARACTER( strlen(*(str*)
getArgReference(stk,pci,i)));
break;
@@ -202,7 +226,6 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
cnt = (BUN)ret_rows;
-
//do something with it
if (isaBatType(getArgType(mb,pci,i))) {
// hand over the vector into a BAT
@@ -217,12 +240,11 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
b->tsorted = 1;
b->trevsorted = 1;
b->tdense = 1;
- BATsetcount(b,cnt);
if (ret_type != INTSXP) {
msg = createException(MAL, "rapi.eval",
-
"wrong R column type for column %d, expected %d, got
%d",i,INTSXP,ret_type);
- goto
wrapup;
+ "wrong R column type
for column %d, expected %d, got %d",i,INTSXP,ret_type);
+ goto wrapup;
}
p = (int*) Tloc(b, BUNfirst(b));
@@ -247,60 +269,57 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
}
prev = *p;
}
- *ret = b->batCacheid;
break;
}
case TYPE_dbl:
{ double *p, prev;
- b = BATnew(TYPE_void,
TYPE_dbl, cnt);
+ b = BATnew(TYPE_void, TYPE_dbl, cnt);
- BATseqbase(b, 0);
- b->T->nil = 0;
- b->T->nonil = 1;
- b->tkey = 1;
- b->tsorted = 1;
- b->trevsorted = 1;
- b->tdense = 1;
- BATsetcount(b,cnt);
+ BATseqbase(b, 0);
+ b->T->nil = 0;
+ b->T->nonil = 1;
+ b->tkey = 1;
+ b->tsorted = 1;
+ b->trevsorted = 1;
+ b->tdense = 1;
+ if (ret_type != REALSXP) {
+ msg = createException(MAL, "rapi.eval",
+ "wrong R column type
for column %d, expected %d, got %d",i,INTSXP,ret_type);
+ goto wrapup;
+ }
- if (ret_type !=
REALSXP) {
- msg =
createException(MAL, "rapi.eval",
-
"wrong R column type for column %d, expected
%d, got %d",i,INTSXP,ret_type);
-
goto wrapup;
- }
-
- p = (double*) Tloc(b,
BUNfirst(b));
- for( i =0; i< (int)
cnt; i++, p++){
- *p =
NUMERIC_POINTER(ret_col)[i];
- if ( *p ==
NA_REAL){
-
b->T->nil = 1;
-
b->T->nonil = 0;
- *p=
int_nil;
- }
- // also update
the sortedness properties
- if (prev){
- if ( *p
> prev && b->trevsorted){
-
b->trevsorted = 0;
-
if (*p != prev +1)
-
b->tdense = 0;
- } else
- if ( *p
< prev && b->tsorted){
-
b->tsorted = 0;
-
b->tdense = 0;
- }
- }
- prev = *p;
- }
-
- *ret = b->batCacheid;
- break;
+ p = (double*) Tloc(b, BUNfirst(b));
+ for( i =0; i< (int) cnt; i++, p++){
+ *p = NUMERIC_POINTER(ret_col)[i];
+ if ( *p == NA_REAL){
+ b->T->nil = 1;
+ b->T->nonil = 0;
+ *p= int_nil;
+ }
+ // also update the sortedness properties
+ if (prev){
+ if ( *p > prev &&
b->trevsorted){
+ b->trevsorted = 0;
+ if (*p != prev +1)
+ b->tdense = 0;
+ } else
+ if ( *p < prev && b->tsorted){
+ b->tsorted = 0;
+ b->tdense = 0;
}
+ }
+ prev = *p;
+ }
+ break;
+ }
default:
// no clue what type to consider
msg = createException(MAL, "rapi.eval",
"unknown argument type");
goto wrapup;
}
+ BATsetcount(b,cnt);
+ *ret = b->batCacheid;
BBPkeepref(b->batCacheid);
}
msg = MAL_SUCCEED;
diff --git a/monetdb5/modules/mal/rapi.mal b/monetdb5/modules/mal/rapi.mal
--- a/monetdb5/modules/mal/rapi.mal
+++ b/monetdb5/modules/mal/rapi.mal
@@ -26,9 +26,9 @@ pattern eval(expr:str,arg:any...):any...
address RAPIeval
comment "Execute a simple R script value";
-pattern prelude()
+pattern rapi.prelude()
address RAPIprelude;
-pattern postlude()
+pattern rapi.postlude()
address RAPIpostlude;
rapi.prelude();
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list