[m-rev.] trivial diff: fix failure of tests/valid/mert
Julien Fischer
juliensf at csse.unimelb.edu.au
Wed Dec 20 16:07:20 AEDT 2006
Estimated hours taken: 0
Branches: main
tests/valid/mert.m:
Delete the bodies of the foreign_procs in this module so
that we can compile it into a .o file (as the standard
runtest target in this directory requires).
Julien.
Index: mert.m
===================================================================
RCS file: /home/mercury1/repository/tests/valid/mert.m,v
retrieving revision 1.1
diff -u -r1.1 mert.m
--- mert.m 19 Dec 2006 03:01:49 -0000 1.1
+++ mert.m 20 Dec 2006 05:04:51 -0000
@@ -36,23 +36,14 @@
:- import_module string, int.
-:- pragma foreign_decl("C", "
-#include ""mert.koehn.h""
-").
-
-:- pragma foreign_code("C", "
-#include ""mert.koehn.c""
- /* all the C functions */
-").
-
%% Creating data for MERTing:
:- type c_candidate. % C-implemented, represents one sentence
-:- pragma foreign_type("C", c_candidate, "candidate_t *",
+:- pragma foreign_type("C", c_candidate, "void *",
[stable, can_pass_as_mercury_type]).
:- type data. % C-implemented, represents the whole nbestlist
-:- pragma foreign_type("C", data, "data_t *",
+:- pragma foreign_type("C", data, "void *",
[stable, can_pass_as_mercury_type]).
:- type feats == list(float). % score breakdown
@@ -67,25 +58,7 @@
:- pragma foreign_proc("C",
new_c_candidate(NFeats::in, Feats::in, NComps::in, Comps::in) = (C::uo),
[promise_pure, will_not_call_mercury, thread_safe], "
- C = MR_GC_malloc(sizeof(candidate_t));
- C->features = MR_GC_malloc(NFeats*sizeof(float));
- C->comps = MR_GC_malloc(NComps*sizeof(int));
- C->m = 0.0;
- C->b = 0.0;
- /* copy list to array */
- float *p = C->features;
- while (!MR_list_is_empty(Feats)) {
- *p = MR_list_head(Feats);
- p++;
- Feats = MR_list_tail(Feats);
- }
- /* copy list to array */
- int *q = C->comps;
- while (!MR_list_is_empty(Comps)) {
- *q = MR_list_head(Comps);
- q++;
- Comps = MR_list_tail(Feats);
- }
+ /* NFeats, Feats, NComps, Comps, C */
").
:- func nbestlist_to_data(scorednbestlist) = data.
@@ -106,44 +79,11 @@
:- pragma foreign_proc("C",
new_c_data(NSents::in, CandsPerSent::in, TotNCands::in, AllCands::in) = (D::uo),
[promise_pure, will_not_call_mercury, thread_safe], "
- D = MR_GC_malloc(sizeof(data_t));
- D->sents_max = NSents;
- D->sents_n = NSents;
- D->cands_n = MR_GC_malloc(sizeof(int)*D->sents_max);
- /* copy list to array: CandsPerSent */
- int *q = D->cands_n;
- while (!MR_list_is_empty(CandsPerSent)) {
- *q = MR_list_head(CandsPerSent);
- q++;
- CandsPerSent = MR_list_tail(CandsPerSent);
- }
-
- /* create master array for candidates and then set data->sents
- to point into it */
- candidate_t *MasterCands;
- MasterCands = MR_GC_malloc(TotNCands * sizeof(candidate_t));
- /* copy list to array: MasterCands */
- candidate_t *p = MasterCands;
- while (!MR_list_is_empty(AllCands)) {
- candidate_t *thisC = (candidate_t*) MR_list_head(AllCands);
- *p = *thisC; /* copy the contents */
- p++;
- AllCands = MR_list_tail(AllCands);
- }
-
- D->sents = MR_GC_malloc(D->sents_n * sizeof(candidate_t *));
- int CandsSoFar = 0;
- int sent_i;
- for (sent_i=0; sent_i<D->sents_n; sent_i++) {
- D->sents[sent_i] = MasterCands+CandsSoFar;
- CandsSoFar += D->cands_n[sent_i];
- }
-
- /* GC will collect the masterarray 'MasterCands' */
+ /* NSents, CandsPerSent, TotNCands, AllCands */
").
:- type point. % C-implemented, represents the whole nbestlist
-:- pragma foreign_type("C", point, "point_t *",
+:- pragma foreign_type("C", point, "void *",
[stable, can_pass_as_mercury_type]).
optimize(NBL, Rand, InW) = OutW :-
@@ -170,16 +110,7 @@
:- pragma foreign_proc("C",
optimize_random(Data::in, BestSoFar::in, Min::in, Max::in, Iter::in) = (Out::out),
[promise_pure, will_not_call_mercury, thread_safe], "
- int i;
- point_t *newpoint;
- for (i=0; i<Iter; i++) {
- newpoint = random_point(Min, Max);
- newpoint = optimize_koehn(Data, newpoint);
- if (newpoint->score > BestSoFar->score)
- point_copy_contents(newpoint, BestSoFar);
- point_delete(newpoint);
- }
- Out = BestSoFar;
+ /* Data, BestSoFar, Min, Max, Iter */
").
:- func optimize_koehn(data, point) = point.
@@ -188,7 +119,7 @@
:- pragma foreign_proc("C",
optimize_koehn(Data::in, In::in) = (Out::out),
[promise_pure, will_not_call_mercury, thread_safe], "
- Out = optimize_koehn(Data, In);
+ /* Data, In, Out */
").
:- func construct_point(list(float)) = point.
@@ -200,32 +131,13 @@
:- pragma foreign_proc("C",
construct_point(List::in) = (Point::out),
[promise_pure, will_not_call_mercury, thread_safe], "
- int i;
-
- Point = new_point();
- for(i=0; i<dim; i++) {
- if (MR_list_is_empty(List)) {
- fprintf(stderr, ""Failed to construct point, expected %i dimensions!\\n"", dim);
- exit(1);
- }
- Point->weights[i] = MR_list_head(List);
- List = MR_list_tail(List);
- }
+ /* List, Point */
").
:- pragma foreign_proc("C",
deconstruct_point(Point::in) = (List::out),
[promise_pure, will_not_call_mercury, thread_safe], "
- MR_Word Tail;
- float v;
- int i;
- Tail = MR_list_empty();
- for(i=dim; i<=0; i--) {
- v = Point->weights[i];
- Tail = MR_list_cons(v, Tail);
- }
- point_delete(Point);
- List = Tail;
+ /* Point, List */
").
:- type bleucomps == list(int).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list