Changeset: 0f9ee294c503 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0f9ee294c503
Modified Files:
monetdb5/modules/mal/Tests/array00.mal
monetdb5/modules/mal/Tests/array01.mal
monetdb5/modules/mal/array.mx
Branch: sciql
Log Message:
Skeleton for index mapping
The oids for the cells can be extracted using a shape pair.
diffs (171 lines):
diff --git a/monetdb5/modules/mal/Tests/array00.mal
b/monetdb5/modules/mal/Tests/array00.mal
--- a/monetdb5/modules/mal/Tests/array00.mal
+++ b/monetdb5/modules/mal/Tests/array00.mal
@@ -11,5 +11,6 @@
io.print(mx,my,mv);
#create array u(x int dimension[0:*:1]);
+#any * implies this one
ux:= array.dimension(0,0,0,0);
io.print(ux);
diff --git a/monetdb5/modules/mal/Tests/array01.mal
b/monetdb5/modules/mal/Tests/array01.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/Tests/array01.mal
@@ -0,0 +1,32 @@
+#extraction of cell positions from arrays
+
+#create array v(i int dimension[1:3:1])
+vi:= array.dimension(1,2,1,1);
+io.print(vi);
+
+#create array m(x int dimension[0:4:1], y int dimension[0:4:1], int 333);
+mx:= array.dimension(1,4,4,0);
+my:= array.dimension(4,4,1,0);
+mv:= array.filler(mx,333);
+io.print(mx,my,mv);
+
+#extract the indices from both
+
+x1:= array.map(vi,vi);
+io.print(x1);
+
+x2:= array.map(mx,my,mx,my);
+io.print(x2);
+
+x3:= array.map(mx,my,vi,vi);
+io.print(x3);
+
+x4:= array.map(vi,mx);
+io.print(x4);
+
+x5:= array.map(vi,vi,mx,my);
+io.print(x5);
+
+# try out some errors
+
+e0:= array.map(vi,vi,vi);
diff --git a/monetdb5/modules/mal/array.mx b/monetdb5/modules/mal/array.mx
--- a/monetdb5/modules/mal/array.mx
+++ b/monetdb5/modules/mal/array.mx
@@ -59,9 +59,15 @@
address ARRAYfiller
comment "Create an array value representation described by a dimension column
and fill it with V";
-pattern select(a:bat[:oid,:any_1], shape:any...):bat[:oid,:any_1]
+pattern map(dims:bat[:oid,:any]...):bat[:oid,:oid]
+address ARRAYmap
+comment "The argument is a double set of dimension columns. The first set
describes the shape
+of the target array and the second one holds the index values of interest. The
result is a column
+with the oid positions of the elements in target. ";
+
+pattern select(a:bat[:oid,:any_1], dim:any...):bat[:oid,:any_1]
address ARRAYselect
-comment "Extract a value portion of an array representation described by two
shapes,
+comment "Extract a value portion of an array representation described by
dimension
one with the structure of A and the other with the portion required.";
pattern index(shape:any...):bat[:oid,:any]...
@@ -143,6 +149,7 @@
array_export str ARRAYproduct(int *ret, int *bid, int *rid);
array_export str ARRAYfiller(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
array_export str ARRAYselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
+array_export str ARRAYmap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
p);
array_export str ARRAYindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
array_export str ARRAYgetoid(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
array_export str ARRAYreplace(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
@@ -396,6 +403,77 @@
}
str
+ARRAYmap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ BAT **b, *bn;
+ int i,n = 0, error = 0;
+ BATiter *bi;
+ BUN p,q,s;
+ void *val;
+
+ (void) cntxt;
+ (void) mb;
+ if ( (pci->argc-pci->retc-1) % 2 != 0)
+ throw(MAL, "array.map", "Unbalanced index arguments");
+
+ b= (BAT**) GDKzalloc(sizeof(BAT*) * pci->argc-pci->retc);
+ if( b == NULL)
+ throw(MAL, "array.map", MAL_MALLOC_FAIL);
+ bi= (BATiter*) GDKzalloc(sizeof(BATiter) * pci->argc-pci->retc);
+ if( bi == NULL){
+ GDKfree(b);
+ throw(MAL, "array.map", MAL_MALLOC_FAIL);
+ }
+
+ for ( i=pci->retc; i< pci->argc; i++){
+ if ((b[n++] = BATdescriptor(*(int*)getArgReference(stk,pci,i)))
== NULL) {
+ GDKfree(b);
+ GDKfree(bi);
+ for ( n--; n>= 0; n--)
+ BBPreleaseref(b[n]->batCacheid);
+ throw(MAL, "array.map", MAL_MALLOC_FAIL);
+ }
+ }
+ /* type check the shapes and prepare iterators */
+ for ( i= 0; i< n/2; i++) {
+ error |= b[i]->ttype != b[i+n/2]->ttype;
+ bi[i] = bat_iterator(b[i]);
+ bi[i+n/2] = bat_iterator(b[i+n/2]);
+ }
+
+ if ( error ){
+ GDKfree(b);
+ GDKfree(bi);
+ for ( n--; n>= 0; n--)
+ BBPreleaseref(b[n]->batCacheid);
+ throw(MAL, "array.map", "Incompatible index types");
+ }
+
+ bn = BATnew(TYPE_void,TYPE_oid, BATcount(b[0]));
+ if (bn == NULL){
+ GDKfree(b);
+ GDKfree(bi);
+ for ( n--; n>= 0; n--)
+ BBPreleaseref(b[n]->batCacheid);
+ throw(MAL, "array.map", MAL_MALLOC_FAIL);
+ }
+
+ /* select the oids we need by searching all matching index vectors */
+ BATloop(b[n/2],p,q){
+ (void) val;
+ (void) s;
+ }
+
+ *(int*) getArgReference(stk,pci,0) = bn->batCacheid;
+ BBPkeepref(bn->batCacheid);
+ for ( n--; n>= 0; n--)
+ BBPreleaseref(b[n]->batCacheid);
+ GDKfree(b);
+ GDKfree(bi);
+ return MAL_SUCCEED;
+}
+
+str
ARRAYselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
{
(void) cntxt;
@@ -435,16 +513,6 @@
throw(MAL,"array.replace", PROGRAM_NYI);
}
-str
-ARRAYmap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
-{
- (void) cntxt;
- (void) mb;
- (void) stk;
- (void) p;
- throw(MAL,"array.map", PROGRAM_NYI);
-}
-
@-
The printing stuff is postponed to the future. Then it also needs
a solution to the GDKout issues.
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list