Re: MonetDB: default - use new sub sample function (cleans up some m...
Why the mix of ptr/BUN/wrd in SAMPLEsubuniform? The function is only called from MAL for a command whose last parameter is declared as s:wrd, so SAMPLEsubuniform can be declared as having a last argument as wrd *s and the cast inside then becomes correct too: (BUN) *s. Remember, wrd and BUN are not *necessarily* the same size. On 2012-12-06 10:25, Niels Nes wrote:
Changeset: 7c832c8b1a70 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7c832c8b1a70 Modified Files: monetdb5/modules/kernel/algebra.mx monetdb5/modules/mal/sample.c monetdb5/modules/mal/sample.h monetdb5/modules/mal/sample.mal sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_gencode.c Branch: default Log Message:
use new sub sample function (cleans up some more reverses and marks)
diffs (112 lines):
diff --git a/monetdb5/modules/kernel/algebra.mx b/monetdb5/modules/kernel/algebra.mx --- a/monetdb5/modules/kernel/algebra.mx +++ b/monetdb5/modules/kernel/algebra.mx @@ -282,6 +282,11 @@ comment "Selects all elements that have command sample ( b:bat[:oid,:any_2], num:int ) :bat[:oid,:any_2] address ALGsample comment "Produce a random selection of size 'num' from the input BAT."; + +command subsample(b:bat[:oid,:any_1], num:int ) :bat[:oid,:oid] +address ALGsubsample +comment "Return the oids of a random selection of size 'num' from the input BAT."; + # @+ BAT copying command copy( b:bat[:any_1,:any_2]) :bat[:any_1,:any_2] address ALGcopy @@ -1076,6 +1081,7 @@ algebra_export str ALG@1(int *result, in @:ALGbinaryExport(tdifference)@ @:ALGbinaryExport(tdiff)@ @:ALGbinaryintExport(sample)@ +@:ALGbinaryintExport(subsample)@
algebra_export str ALGtunique(int *result, int *bid); algebra_export str ALGtsort(int *result, int *bid); @@ -2765,6 +2771,11 @@ ALGsample(bat *result, bat *bid, int *pa return ALGbinaryint(result, bid, param, BATsample, "algebra.sample"); }
+str +ALGsubsample(bat *result, bat *bid, int *param) +{ + return ALGbinaryint(result, bid, param, BATsample_, "algebra.subsample"); +}
/* add items missing in the kernel */ str diff --git a/monetdb5/modules/mal/sample.c b/monetdb5/modules/mal/sample.c --- a/monetdb5/modules/mal/sample.c +++ b/monetdb5/modules/mal/sample.c @@ -96,6 +96,23 @@ SAMPLEuniform(bat *r, bat *b, ptr s) { }
sample_export str +SAMPLEsubuniform(bat *r, bat *b, ptr s) { + BAT *br, *bb; + + if ((bb = BATdescriptor(*b)) == NULL) { + throw(MAL, "sample.subuniform", INTERNAL_BAT_ACCESS); + } + br = BATsample_(bb,*(BUN *)s); + if (br == NULL) + throw(MAL, "sample.subuniform", OPERATION_FAILED); + + BBPunfix(bb->batCacheid); + BBPkeepref(*r = br->batCacheid); + return MAL_SUCCEED; + +} + +sample_export str SAMPLEuniform_dbl(bat *r, bat *b, ptr p) { BAT *bb; double pr = *(double *)p; diff --git a/monetdb5/modules/mal/sample.h b/monetdb5/modules/mal/sample.h --- a/monetdb5/modules/mal/sample.h +++ b/monetdb5/modules/mal/sample.h @@ -42,6 +42,9 @@ sample_export str SAMPLEuniform(bat *r, bat *b, ptr s);
sample_export str +SAMPLEsubuniform(bat *r, bat *b, ptr s); + +sample_export str SAMPLEuniform_dbl(bat *r, bat *b, ptr p);
#endif diff --git a/monetdb5/modules/mal/sample.mal b/monetdb5/modules/mal/sample.mal --- a/monetdb5/modules/mal/sample.mal +++ b/monetdb5/modules/mal/sample.mal @@ -27,6 +27,10 @@ command uniform(b:bat[:oid,:any],s:wrd): address SAMPLEuniform comment "Returns a uniform sample of size s"
+command subuniform(b:bat[:oid,:any],s:wrd):bat[:oid,:oid] +address SAMPLEsubuniform +comment "Returns the oids of a uniform sample of size s" + command uniform(b:bat[:oid,:any],p:dbl):bat[:oid,:any] address SAMPLEuniform_dbl comment "Returns a uniform sample of size = (p x count(b)), where 0 <= p <= 1.0" diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -2677,7 +2677,6 @@ rel2bin_sample( mvc *sql, sql_rel *rel, sc = column(sql->sa, sc); sample = stmt_sample(sql->sa, stmt_alias(sql->sa, sc, tname, cname),s);
- sample = stmt_reverse(sql->sa, stmt_mark_tail(sql->sa, sample, 0)); for ( ; n; n = n->next) { stmt *sc = n->data; char *cname = column_name(sql->sa, sc); diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c --- a/sql/backends/monet5/sql_gencode.c +++ b/sql/backends/monet5/sql_gencode.c @@ -983,7 +983,7 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st case st_sample:{ int l = _dumpstmt(sql, mb, s->op1); int r = _dumpstmt(sql, mb, s->op2); - q = newStmt(mb, "sample", "uniform"); + q = newStmt(mb, "sample", "subuniform"); q = pushArgument(mb, q, l); q = pushArgument(mb, q, r); s->nr = getDestVar(q); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list
-- Sjoerd Mullender _______________________________________________ developers-list mailing list developers-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/developers-list
participants (1)
-
Sjoerd Mullender