Changeset: 6756eee98160 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6756eee98160
Modified Files:
        monetdb5/modules/mal/Tests/array03.mal
        monetdb5/modules/mal/Tests/array03.stable.err
        monetdb5/modules/mal/Tests/array03.stable.out
        monetdb5/modules/mal/array.mx
Branch: sciql
Log Message:

Handle the array cell replacement
Replacement of cell values is driven by a cell id list and
a list of replacement values or a scalar.


diffs (truncated from 349 to 300 lines):

diff --git a/monetdb5/modules/mal/Tests/array03.mal 
b/monetdb5/modules/mal/Tests/array03.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/Tests/array03.mal
@@ -0,0 +1,41 @@
+#modification of an array
+
+#create array v(i int dimension[0:1:4], payload:int)
+v:= array.series(0,1,4,1,1);
+vv:= array.series(0,3,12,1,1);
+io.print(v,vv);
+
+#create array M(x int dimension[0:2:6], y int dimension[0:1:4], int default 
333);
+mx:= array.series(0,2,6,4,1);
+my:= array.series(0,1,4,1,3);
+mv:= array.series(0,1,12,1,1);
+io.print(mx,my,mv);
+
+#create a cell identifier vector
+#do a point select
+x:= bat.new(:oid,:oid);
+bat.insert(x, 2@0,1@0);
+bat.insert(x, 1@0,0@0);
+io.print(x);
+xv:= bat.new(:oid,:int);
+bat.insert(xv,0@0,999);
+io.print(xv);
+y:= bat.new(:oid,:oid);
+bat.insert(y, 2@0,0@0);
+bat.insert(y, 3@0,1@0);
+bat.insert(y, 7@0,2@0);
+yv:= bat.new(:oid,:int);
+bat.insert(yv,0@0,123);
+bat.insert(yv,3@0,234);
+bat.insert(yv,4@0,345);
+io.print(yv);
+
+#fetch the index column
+xz:= array.replace(vv,x,xv);
+io.print(v,xz);
+
+yz:= array.replace(mv,y,yv);
+io.print(x);
+yz:= array.replace(yz,x,-1);
+io.print(mx,my,yz);
+
diff --git a/monetdb5/modules/mal/Tests/array03.stable.err 
b/monetdb5/modules/mal/Tests/array03.stable.err
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/Tests/array03.stable.err
@@ -0,0 +1,31 @@
+stderr of test 'array03` in directory 'modules/mal` itself:
+
+
+# 22:31:10 >  
+# 22:31:10 >   mserver5  --debug=10 --set gdk_nr_threads=0  --set 
"gdk_dbfarm=/ufs/mk/sciql//Linux/var/MonetDB" --set mapi_open=true --set 
mapi_port=33451 --set monet_prompt= --trace --forcemito --set mal_listing=2  
--dbname=mTests_modules_mal  array03.mal
+# 22:31:10 >  
+
+# builtin opt  gdk_dbname = demo
+# builtin opt  gdk_dbfarm = /ufs/mk/sciql//Linux/var/monetdb5/dbfarm
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_alloc_map = no
+# builtin opt  gdk_vmtrim = yes
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  gdk_dbfarm = /ufs/mk/sciql//Linux/var/MonetDB
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 33451
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbname = mTests_modules_mal
+
+# 22:31:10 >  
+# 22:31:10 >  Done.
+# 22:31:10 >  
+
diff --git a/monetdb5/modules/mal/Tests/array03.stable.out 
b/monetdb5/modules/mal/Tests/array03.stable.out
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/mal/Tests/array03.stable.out
@@ -0,0 +1,103 @@
+stdout of test 'array03` in directory 'modules/mal` itself:
+
+
+# 22:31:10 >  
+# 22:31:10 >   mserver5  --debug=10 --set gdk_nr_threads=0  --set 
"gdk_dbfarm=/ufs/mk/sciql//Linux/var/MonetDB" --set mapi_open=true --set 
mapi_port=33451 --set monet_prompt= --trace --forcemito --set mal_listing=2  
--dbname=mTests_modules_mal  array03.mal
+# 22:31:10 >  
+
+# MonetDB 5 server v11.4.0
+# This is an unreleased version
+# Serving database 'mTests_modules_mal', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
+# Found 7.749 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2011 MonetDB B.V., all rights reserved
+# Visit http://monetdb.cwi.nl/ for further information
+# Listening for connection requests on mapi:monetdb://eir.ins.cwi.nl:33451/
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+function user.main():void;
+#modification of an array 
+#create array v(i int dimension[0:1:4], payload:int) 
+    v := array.series(0,1,4,1,1);
+    vv := array.series(0,3,12,1,1);
+    io.print(v,vv);
+#create array M(x int dimension[0:2:6], y int dimension[0:1:4], int default 
333); 
+    mx := array.series(0,2,6,4,1);
+    my := array.series(0,1,4,1,3);
+    mv := array.series(0,1,12,1,1);
+    io.print(mx,my,mv);
+#create a cell identifier vector 
+#do a point select 
+    x := bat.new(:oid,:oid);
+    bat.insert(x,2@0,1@0);
+    bat.insert(x,1@0,0@0);
+    io.print(x);
+    xv := bat.new(:oid,:int);
+    bat.insert(xv,0@0,999);
+    io.print(xv);
+    y := bat.new(:oid,:oid);
+    bat.insert(y,2@0,0@0);
+    bat.insert(y,3@0,1@0);
+    bat.insert(y,7@0,2@0);
+    yv := bat.new(:oid,:int);
+    bat.insert(yv,0@0,123);
+    bat.insert(yv,3@0,234);
+    bat.insert(yv,4@0,345);
+    io.print(yv);
+#fetch the index column 
+    xz := array.replace(vv,x,xv);
+    io.print(v,xz);
+    yz := array.replace(mv,y,yv);
+    io.print(x);
+    yz := array.replace(yz,x,-1);
+    io.print(mx,my,yz);
+end main;
+#-------------------------#
+# h    t       t         # name
+# void int     int       # type
+#-------------------------#
+[ 0@0,   0,      0       ]
+[ 1@0,   1,      3       ]
+[ 2@0,   2,      6       ]
+[ 3@0,   3,      9       ]
+#---------------------------------#
+# h    t       t       t         # name
+# void int     int     int       # type
+#---------------------------------#
+[ 0@0,   0,      0,      0       ]
+[ 1@0,   0,      1,      1       ]
+[ 2@0,   0,      2,      2       ]
+[ 3@0,   0,      3,      3       ]
+[ 4@0,   2,      0,      4       ]
+[ 5@0,   2,      1,      5       ]
+[ 6@0,   2,      2,      6       ]
+[ 7@0,   2,      3,      7       ]
+[ 8@0,   4,      0,      8       ]
+[ 9@0,   4,      1,      9       ]
+[ 10@0,          4,      2,      10      ]
+[ 11@0,          4,      3,      11      ]
+#-----------------#
+# h    t         # name
+# oid  oid       # type
+#-----------------#
+[ 2@0,   1@0     ]
+[ 1@0,   0@0     ]
+#-----------------#
+# h    t         # name
+# void int       # type
+#-----------------#
+[ 0@0,   999     ]
+#-----------------#
+# h    t         # name
+# void int       # type
+#-----------------#
+[ 0@0,   123     ]
+[ 3@0,   234     ]
+[ 4@0,   345     ]
+!MALException:array.replace:unbalanced array arguments
+
+# 22:31:10 >  
+# 22:31:10 >  Done.
+# 22:31:10 >  
+
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
@@ -77,27 +77,14 @@
 address ARRAYgetDimensions
 comment "Extract the series sizes";
 
-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 
dimension
-one with the structure of A and the other with the portion required.";
-
-pattern index(shape:any...):bat[:oid,:any]...
-address ARRAYindex
-comment "Extract a dimension portion of an array representation described by 
two shapes";
-
-pattern getoid(a:bat[:oid, :any_1], shape:any...):bat[:oid,:oid]
-address ARRAYgetoid
-comment "Extract indices of array cells in their BAT storage.";
+pattern replace(v1:bat[:oid, :any_1], idx:bat[:oid, :oid], 
v2:any_1):bat[:oid,:any_1]
+address ARRAYreplaceScalar
+comment "Replace values in v1 at the positions determined by idx with v2, 
return the modified v1.";
 
 pattern replace(v1:bat[:oid, :any_1], idx:bat[:oid, :oid], v2:bat[:oid, 
:any_1]):bat[:oid,:any_1]
 address ARRAYreplace
 comment "Replace values in v1 at the positions determined by idx with values 
in v2, return the modified v1.";
 
-pattern replace(v1:bat[:oid, :any_1], idx:bat[:oid, :oid], 
v2:any_1):bat[:oid,:any_1]
-address ARRAYreplaceDefault
-comment "Replace values in v1 at the positions determined by idx with v2, 
return the modified v1.";
-
 command product(b:bat[:any_3,:any_1],c:bat[:any_4,:any_2]):bat[:any_1,:any_2]
 address ARRAYproduct
 comment "Produce an array product";
@@ -130,12 +117,10 @@
 array_export str ARRAYgetDimensions(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 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 ARRAYmapReverse(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);
+array_export str ARRAYreplaceScalar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 
 @= array_defs
 array_export str ARRAYseries_@1(int *ret, @1 *start, @1 *step, @1 *stop, int 
*grp, int *series);
@@ -467,43 +452,82 @@
 }
 
 str
-ARRAYselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+ARRAYreplace(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
+       BAT *b, *bo, *bc, *bv,*bn;
+       int *ret = (int*) getArgReference(stk,pci,0);
+
        (void) cntxt;
        (void) mb;
-       (void) stk;
-       (void) p;
-       throw(MAL,"array.select", PROGRAM_NYI);
+       if ((b = BATdescriptor(*(int*)getArgReference(stk,pci,1))) == NULL) 
+               throw(MAL, "array.replace", RUNTIME_OBJECT_MISSING);
+       if ((bc = BATdescriptor(*(int*)getArgReference(stk,pci,2))) == NULL) {
+               BBPreleaseref(b->batCacheid);
+               throw(MAL, "array.replace", RUNTIME_OBJECT_MISSING);
+       }
+       if ((bv = BATdescriptor(*(int*)getArgReference(stk,pci,3))) == NULL) {
+               BBPreleaseref(b->batCacheid);
+               BBPreleaseref(bc->batCacheid);
+               throw(MAL, "array.replace", RUNTIME_OBJECT_MISSING);
+       }
+       if ( BATcount(bc) != BATcount(bv)){
+               BBPreleaseref(b->batCacheid);
+               BBPreleaseref(bc->batCacheid);
+               BBPreleaseref(bv->batCacheid);
+               throw(MAL, "array.replace", "unbalanced array arguments");
+       }
+       bn = BATcopy(b, b->htype, b->ttype, TRUE);
+       bo = BATjoin(bc,bv,0);
+       if ( bo )
+               bn = BATreplace(bn,bo, TRUE);
+       if ( bn == NULL || bo == NULL){
+               BBPreleaseref(b->batCacheid);
+               BBPreleaseref(bc->batCacheid);
+               BBPreleaseref(bv->batCacheid);
+               if ( bo == NULL) BBPreleaseref(bo->batCacheid);
+               throw(MAL, "array.replace", RUNTIME_OBJECT_MISSING);
+       }
+       BBPkeepref(*ret = bn->batCacheid);
+       BBPreleaseref(b->batCacheid);
+       BBPreleaseref(bc->batCacheid);
+       BBPreleaseref(bv->batCacheid);
+       BBPreleaseref(bo->batCacheid);
+       return MAL_SUCCEED;
 }
 
 str
-ARRAYindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+ARRAYreplaceScalar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
+       BAT *b, *bc, *bn, *bo;
+       int *ret = (int*) getArgReference(stk,pci,0);
+       void *val = (void*) getArgReference(stk,pci,3);
+       BATiter bi;
+       BUN p,q;
+
        (void) cntxt;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to