projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added src/ui/terminal/automake.mk and src/ui/gui/automake.mk
[pspp]
/
src
/
sample.c
diff --git
a/src/sample.c
b/src/sample.c
index 67523b3d80ff62e65cd5185de4ce70ce26df7777..0255ae79ee21a210411a64c7100a8973acb48a15 100644
(file)
--- a/
src/sample.c
+++ b/
src/sample.c
@@
-14,10
+14,11
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include <config.h>
+#include <gsl/gsl_rng.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
@@
-29,6
+30,9
@@
#include "str.h"
#include "var.h"
#include "str.h"
#include "var.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
#include "debug-print.h"
/* The two different types of samples. */
#include "debug-print.h"
/* The two different types of samples. */
@@
-41,7
+45,6
@@
enum
/* SAMPLE transformation. */
struct sample_trns
{
/* SAMPLE transformation. */
struct sample_trns
{
- struct trns_header h;
int type; /* One of TYPE_*. */
int n, N; /* TYPE_A_FROM_B: n from N. */
int m, t; /* TYPE_A_FROM_B: # picked so far; # so far. */
int type; /* One of TYPE_*. */
int n, N; /* TYPE_A_FROM_B: n from N. */
int m, t; /* TYPE_A_FROM_B: # picked so far; # so far. */
@@
-49,6
+52,7
@@
struct sample_trns
};
static trns_proc_func sample_trns_proc;
};
static trns_proc_func sample_trns_proc;
+static trns_free_func sample_trns_free;
int
cmd_sample (void)
int
cmd_sample (void)
@@
-61,8
+65,11
@@
cmd_sample (void)
if (!lex_force_num ())
return CMD_FAILURE;
if (!lex_force_num ())
return CMD_FAILURE;
- if (!lex_i
nteger_p
())
+ if (!lex_i
s_integer
())
{
{
+ unsigned long min = gsl_rng_min (get_rng ());
+ unsigned long max = gsl_rng_max (get_rng ());
+
type = TYPE_FRACTION;
if (tokval <= 0 || tokval >= 1)
{
type = TYPE_FRACTION;
if (tokval <= 0 || tokval >= 1)
{
@@
-71,7
+78,7
@@
cmd_sample (void)
return CMD_FAILURE;
}
return CMD_FAILURE;
}
- frac = tokval *
UINT_MAX
;
+ frac = tokval *
(max - min) + min
;
a = b = 0;
}
else
a = b = 0;
}
else
@@
-96,37
+103,28
@@
cmd_sample (void)
}
lex_get ();
}
lex_get ();
-#if DEBUGGING
- if (type == TYPE_FRACTION)
- printf ("SAMPLE %g.\n", frac / (double) UINT_MAX);
- else
- printf ("SAMPLE %d FROM %d.\n", a, b);
-#endif
-
trns = xmalloc (sizeof *trns);
trns = xmalloc (sizeof *trns);
- trns->h.proc = sample_trns_proc;
- trns->h.free = NULL;
trns->type = type;
trns->n = a;
trns->N = b;
trns->m = trns->t = 0;
trns->frac = frac;
trns->type = type;
trns->n = a;
trns->N = b;
trns->m = trns->t = 0;
trns->frac = frac;
- add_transformation (
(struct trns_header *)
trns);
+ add_transformation (
sample_trns_proc, sample_trns_free,
trns);
return lex_end_of_command ();
}
/* Executes a SAMPLE transformation. */
static int
return lex_end_of_command ();
}
/* Executes a SAMPLE transformation. */
static int
-sample_trns_proc (
struct trns_header * trns
, struct ccase *c UNUSED,
+sample_trns_proc (
void *t_
, struct ccase *c UNUSED,
int case_num UNUSED)
{
int case_num UNUSED)
{
- struct sample_trns *t =
(struct sample_trns *) trns
;
+ struct sample_trns *t =
t_
;
double U;
if (t->type == TYPE_FRACTION)
{
double U;
if (t->type == TYPE_FRACTION)
{
- if (
rng_get_unsigned (pspp
_rng ()) <= t->frac)
+ if (
gsl_rng_get (get
_rng ()) <= t->frac)
return -1;
else
return -2;
return -1;
else
return -2;
@@
-135,7
+133,7
@@
sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED,
if (t->m >= t->n)
return -2;
if (t->m >= t->n)
return -2;
- U =
rng_get_double (pspp
_rng ());
+ U =
gsl_rng_uniform (get
_rng ());
if ((t->N - t->t) * U >= t->n - t->m)
{
t->t++;
if ((t->N - t->t) * U >= t->n - t->m)
{
t->t++;
@@
-148,3
+146,10
@@
sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED,
return -1;
}
}
return -1;
}
}
+
+static void
+sample_trns_free (void *t_)
+{
+ struct sample_trns *t = t_;
+ free (t);
+}