projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Used pow2(x) instead of x * x where appropriate.
[pspp-builds.git]
/
src
/
language
/
stats
/
crosstabs.q
diff --git
a/src/language/stats/crosstabs.q
b/src/language/stats/crosstabs.q
index 8adf044c95129abbd2126f38e6a68b8aa602d9cf..d49e3006d9614aed22955aede20dfe3d76b5708a 100644
(file)
--- a/
src/language/stats/crosstabs.q
+++ b/
src/language/stats/crosstabs.q
@@
-46,13
+46,10
@@
#include <language/dictionary/split-file.h>
#include <language/lexer/lexer.h>
#include <language/lexer/variable-parser.h>
#include <language/dictionary/split-file.h>
#include <language/lexer/lexer.h>
#include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
#include <libpspp/array.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/hash.h>
#include <libpspp/array.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/hash.h>
-#include <libpspp/magic.h>
-#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
@@
-61,6
+58,8
@@
#include <output/table.h>
#include "minmax.h"
#include <output/table.h>
#include "minmax.h"
+#include "xalloc.h"
+#include "xmalloca.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-361,7
+360,7
@@
crs_custom_tables (struct lexer *lexer, struct dataset *ds, struct cmd_crosstabs
goto done;
if (xalloc_oversized (nx, by_nvar[n_by]))
{
goto done;
if (xalloc_oversized (nx, by_nvar[n_by]))
{
- msg (SE, _("Too many crosstabulation variables or dimensions."));
+ msg (SE, _("Too many cross
-
tabulation variables or dimensions."));
goto done;
}
nx *= by_nvar[n_by];
goto done;
}
nx *= by_nvar[n_by];
@@
-521,10
+520,11
@@
precalc (struct casereader *input, const struct dataset *ds)
{
struct ccase c;
{
struct ccase c;
- if (!casereader_peek (input, 0, &c))
- return;
- output_split_file_values (ds, &c);
- case_destroy (&c);
+ if (casereader_peek (input, 0, &c))
+ {
+ output_split_file_values (ds, &c);
+ case_destroy (&c);
+ }
if (mode == GENERAL)
{
if (mode == GENERAL)
{
@@
-552,7
+552,7
@@
precalc (struct casereader *input, const struct dataset *ds)
sorted_tab = xnrealloc (sorted_tab,
n_sorted_tab + count, sizeof *sorted_tab);
sorted_tab = xnrealloc (sorted_tab,
n_sorted_tab + count, sizeof *sorted_tab);
- v =
local_alloc
(sizeof *v * x->nvar);
+ v =
xmalloca
(sizeof *v * x->nvar);
for (j = 2; j < x->nvar; j++)
v[j] = get_var_range (x->vars[j])->min;
for (j = 0; j < count; j++)
for (j = 2; j < x->nvar; j++)
v[j] = get_var_range (x->vars[j])->min;
for (j = 0; j < count; j++)
@@
-586,7
+586,7
@@
precalc (struct casereader *input, const struct dataset *ds)
break;
}
}
break;
}
}
-
local_free
(v);
+
freea
(v);
}
sorted_tab = xnrealloc (sorted_tab,
}
sorted_tab = xnrealloc (sorted_tab,
@@
-616,7
+616,7
@@
calc_general (struct ccase *c, const struct dataset *ds)
struct crosstab *x = xtab[t];
const size_t entry_size = (sizeof (struct table_entry)
+ sizeof (union value) * (x->nvar - 1));
struct crosstab *x = xtab[t];
const size_t entry_size = (sizeof (struct table_entry)
+ sizeof (union value) * (x->nvar - 1));
- struct table_entry *te =
local_alloc
(entry_size);
+ struct table_entry *te =
xmalloca
(entry_size);
/* Construct table entry for the current record and table. */
te->table = t;
/* Construct table entry for the current record and table. */
te->table = t;
@@
-637,12
+637,14
@@
calc_general (struct ccase *c, const struct dataset *ds)
te->values[j].f = case_num (c, x->vars[j]);
else
{
te->values[j].f = case_num (c, x->vars[j]);
else
{
- memcpy (te->values[j].s, case_str (c, x->vars[j]),
- var_get_width (x->vars[j]));
+ size_t n = var_get_width (x->vars[j]);
+ if (n > MAX_SHORT_STRING)
+ n = MAX_SHORT_STRING;
+ memcpy (te->values[j].s, case_str (c, x->vars[j]), n);
/* Necessary in order to simplify comparisons. */
memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
/* Necessary in order to simplify comparisons. */
memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
- sizeof (union value) -
var_get_width (x->vars[j])
);
+ sizeof (union value) -
n
);
}
}
}
}
}
}
@@
-665,7
+667,7
@@
calc_general (struct ccase *c, const struct dataset *ds)
}
next_crosstab:
}
next_crosstab:
-
local_free
(te);
+
freea
(te);
}
}
}
}
@@
-827,6
+829,16
@@
postcalc (void)
}
hsh_destroy (gen_tab);
}
hsh_destroy (gen_tab);
+ if (mode == INTEGER)
+ {
+ int i;
+ for (i = 0; i < n_sorted_tab; i++)
+ {
+ free (sorted_tab[i]->u.data);
+ free (sorted_tab[i]);
+ }
+ free (sorted_tab);
+ }
}
static void insert_summary (struct tab_table *, int tab_index, double valid);
}
static void insert_summary (struct tab_table *, int tab_index, double valid);
@@
-915,7
+927,7
@@
insert_summary (struct tab_table *t, int tab_index, double valid)
/* Crosstabulation name. */
{
/* Crosstabulation name. */
{
- char *buf =
local_alloc
(128 * x->nvar);
+ char *buf =
xmalloca
(128 * x->nvar);
char *cp = buf;
int i;
char *cp = buf;
int i;
@@
-928,7
+940,7
@@
insert_summary (struct tab_table *t, int tab_index, double valid)
}
tab_text (t, 0, 0, TAB_LEFT, buf);
}
tab_text (t, 0, 0, TAB_LEFT, buf);
-
local_free
(buf);
+
freea
(buf);
}
/* Counts and percentages. */
}
/* Counts and percentages. */
@@
-1055,7
+1067,7
@@
output_pivot_table (struct table_entry **pb, struct table_entry **pe,
/* Title. */
{
/* Title. */
{
- char *title =
local_alloc
(x->nvar * 64 + 128);
+ char *title =
xmalloca
(x->nvar * 64 + 128);
char *cp = title;
int i;
char *cp = title;
int i;
@@
-1121,7
+1133,7
@@
output_pivot_table (struct table_entry **pb, struct table_entry **pe,
strcpy (cp, "].");
tab_title (table, "%s", title);
strcpy (cp, "].");
tab_title (table, "%s", title);
-
local_free
(title);
+
freea
(title);
}
tab_offset (table, 0, 2);
}
tab_offset (table, 0, 2);
@@
-2444,7
+2456,7
@@
calc_r (double *X, double *Y, double *r, double *ase_0, double *ase_1)
for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++)
{
sum_Xr += X[i] * row_tot[i];
for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++)
{
sum_Xr += X[i] * row_tot[i];
- sum_X2r +=
X[i] * X[i]
* row_tot[i];
+ sum_X2r +=
pow2 (X[i])
* row_tot[i];
}
Xbar = sum_Xr / W;
}
Xbar = sum_Xr / W;
@@
-2456,11
+2468,11
@@
calc_r (double *X, double *Y, double *r, double *ase_0, double *ase_1)
Ybar = sum_Yc / W;
S = sum_XYf - sum_Xr * sum_Yc / W;
Ybar = sum_Yc / W;
S = sum_XYf - sum_Xr * sum_Yc / W;
- SX = sum_X2r -
sum_Xr * sum_Xr
/ W;
- SY = sum_Y2c -
sum_Yc * sum_Yc
/ W;
+ SX = sum_X2r -
pow2 (sum_Xr)
/ W;
+ SY = sum_Y2c -
pow2 (sum_Yc)
/ W;
T = sqrt (SX * SY);
*r = S / T;
T = sqrt (SX * SY);
*r = S / T;
- *ase_0 = sqrt ((sum_X2Y2f -
(sum_XYf *
sum_XYf) / W) / (sum_X2r * sum_Y2c));
+ *ase_0 = sqrt ((sum_X2Y2f -
pow2 (
sum_XYf) / W) / (sum_X2r * sum_Y2c));
{
double s, c, y, t;
{
double s, c, y, t;
@@
-2550,9
+2562,9
@@
calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC],
Dr = Dc = W * W;
for (r = 0; r < n_rows; r++)
Dr = Dc = W * W;
for (r = 0; r < n_rows; r++)
- Dr -=
row_tot[r] * row_tot[r]
;
+ Dr -=
pow2 (row_tot[r])
;
for (c = 0; c < n_cols; c++)
for (c = 0; c < n_cols; c++)
- Dc -=
col_tot[c] * col_tot[c]
;
+ Dc -=
pow2 (col_tot[c])
;
}
{
}
{
@@
-2725,8
+2737,8
@@
calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC],
/* Spearman correlation, Pearson's r. */
if (cmd.a_statistics[CRS_ST_CORR])
{
/* Spearman correlation, Pearson's r. */
if (cmd.a_statistics[CRS_ST_CORR])
{
- double *R =
local_alloc
(sizeof *R * n_rows);
- double *C =
local_alloc
(sizeof *C * n_cols);
+ double *R =
xmalloca
(sizeof *R * n_rows);
+ double *C =
xmalloca
(sizeof *C * n_cols);
{
double y, t, c = 0., s = 0.;
{
double y, t, c = 0., s = 0.;
@@
-2765,8
+2777,8
@@
calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC],
calc_r (R, C, &v[6], &t[6], &ase[6]);
t[6] = v[6] / t[6];
calc_r (R, C, &v[6], &t[6], &ase[6]);
t[6] = v[6] / t[6];
-
local_free
(R);
-
local_free
(C);
+
freea
(R);
+
freea
(C);
calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]);
t[7] = v[7] / t[7];
calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]);
t[7] = v[7] / t[7];
@@
-3061,10
+3073,10
@@
calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL],
}
for (sum_ri2 = 0., i = 0; i < n_rows; i++)
}
for (sum_ri2 = 0., i = 0; i < n_rows; i++)
- sum_ri2 +=
row_tot[i] * row_tot[i]
;
+ sum_ri2 +=
pow2 (row_tot[i])
;
for (sum_cj2 = 0., j = 0; j < n_cols; j++)
for (sum_cj2 = 0., j = 0; j < n_cols; j++)
- sum_cj2 +=
col_tot[j] * col_tot[j]
;
+ sum_cj2 +=
pow2 (col_tot[j])
;
v[3] = (W * sum_fij2_ci - sum_ri2) / (W * W - sum_ri2);
v[4] = (W * sum_fij2_ri - sum_cj2) / (W * W - sum_cj2);
v[3] = (W * sum_fij2_ci - sum_ri2) / (W * W - sum_ri2);
v[4] = (W * sum_fij2_ri - sum_cj2) / (W * W - sum_cj2);
@@
-3154,9
+3166,9
@@
calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL],
for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++)
{
sum_Xr += rows[i].f * row_tot[i];
for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++)
{
sum_Xr += rows[i].f * row_tot[i];
- sum_X2r +=
rows[i].f * rows[i].f
* row_tot[i];
+ sum_X2r +=
pow2 (rows[i].f)
* row_tot[i];
}
}
- SX = sum_X2r -
sum_Xr * sum_Xr
/ W;
+ SX = sum_X2r -
pow2 (sum_Xr)
/ W;
for (SXW = 0., j = 0; j < n_cols; j++)
{
for (SXW = 0., j = 0; j < n_cols; j++)
{
@@
-3164,7
+3176,7
@@
calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL],
for (cum = 0., i = 0; i < n_rows; i++)
{
for (cum = 0., i = 0; i < n_rows; i++)
{
- SXW +=
rows[i].f * rows[i].f
* mat[j + i * n_cols];
+ SXW +=
pow2 (rows[i].f)
* mat[j + i * n_cols];
cum += rows[i].f * mat[j + i * n_cols];
}
cum += rows[i].f * mat[j + i * n_cols];
}
@@
-3181,7
+3193,7
@@
calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL],
for (sum_Yc = sum_Y2c = 0., i = 0; i < n_cols; i++)
{
sum_Yc += cols[i].f * col_tot[i];
for (sum_Yc = sum_Y2c = 0., i = 0; i < n_cols; i++)
{
sum_Yc += cols[i].f * col_tot[i];
- sum_Y2c +=
cols[i].f * cols[i].f
* col_tot[i];
+ sum_Y2c +=
pow2 (cols[i].f)
* col_tot[i];
}
SY = sum_Y2c - sum_Yc * sum_Yc / W;
}
SY = sum_Y2c - sum_Yc * sum_Yc / W;
@@
-3191,7
+3203,7
@@
calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL],
for (cum = 0., j = 0; j < n_cols; j++)
{
for (cum = 0., j = 0; j < n_cols; j++)
{
- SYW +=
cols[j].f * cols[j].f
* mat[j + i * n_cols];
+ SYW +=
pow2 (cols[j].f)
* mat[j + i * n_cols];
cum += cols[j].f * mat[j + i * n_cols];
}
cum += cols[j].f * mat[j + i * n_cols];
}