From f4c07cacab73e6f4b72e6393f394e990501b5916 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 6 Nov 2021 20:09:24 -0700 Subject: [PATCH] MATRIX GET positive test --- doc/matrices.texi | 7 +- src/language/stats/matrix.c | 33 ++++++-- tests/language/stats/matrix.at | 139 +++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 8 deletions(-) diff --git a/doc/matrices.texi b/doc/matrices.texi index 4ecf0360e7..74e17c15ad 100644 --- a/doc/matrices.texi +++ b/doc/matrices.texi @@ -2401,9 +2401,10 @@ values, specify one of the following settings on @code{MISSING}: @table @asis @item @code{ACCEPT} -Accept user-missing values with no change. By default, system-missing -values still yield an error. Use the @code{SYSMIS} subcommand to -change this treatment: +Accept user-missing values with no change. + +By default, system-missing values still yield an error. Use the +@code{SYSMIS} subcommand to change this treatment: @table @asis @item @code{OMIT} diff --git a/src/language/stats/matrix.c b/src/language/stats/matrix.c index 088870d358..bcae199717 100644 --- a/src/language/stats/matrix.c +++ b/src/language/stats/matrix.c @@ -4911,8 +4911,11 @@ matrix_read (struct read_command *read, struct dfm_reader *reader, { ss_ltrim (&line, ss_cstr (" ,")); if (!ss_is_empty (line)) - msg (SW, _("Trailing garbage on line \"%.*s\""), - (int) line.length, line.string); + { + /* XXX */ + msg (SW, _("Trailing garbage on line \"%.*s\""), + (int) line.length, line.string); + } } } } @@ -5467,11 +5470,11 @@ matrix_parse_get (struct matrix_state *s) { lex_match (s->lexer, T_EQUALS); if (lex_match_id (s->lexer, "OMIT")) - get->user.treatment = MGET_OMIT; + get->system.treatment = MGET_OMIT; else if (lex_is_number (s->lexer)) { - get->user.treatment = MGET_RECODE; - get->user.substitute = lex_number (s->lexer); + get->system.treatment = MGET_RECODE; + get->system.substitute = lex_number (s->lexer); lex_get (s->lexer); } else @@ -5487,6 +5490,10 @@ matrix_parse_get (struct matrix_state *s) goto error; } } + + if (get->user.treatment != MGET_ACCEPT) + get->system.treatment = MGET_ERROR; + return cmd; error: @@ -5551,6 +5558,22 @@ matrix_cmd_execute_get (struct get_command *get) } } + if (get->names) + { + gsl_matrix *names = gsl_matrix_alloc (n_vars, 1); + for (size_t i = 0; i < n_vars; i++) + { + char s[sizeof (double)]; + double f; + buf_copy_str_rpad (s, sizeof s, var_get_name (vars[i]), ' '); + memcpy (&f, s, sizeof f); + gsl_matrix_set (names, i, 0, f); + } + + gsl_matrix_free (get->names->value); + get->names->value = names; + } + size_t n_rows = 0; gsl_matrix *m = gsl_matrix_alloc (4, n_vars); long long int casenum = 1; diff --git a/tests/language/stats/matrix.at b/tests/language/stats/matrix.at index 395c578795..f5e76d0b0a 100644 --- a/tests/language/stats/matrix.at +++ b/tests/language/stats/matrix.at @@ -2884,4 +2884,143 @@ matrix.sps:20: error: WRITE: Format A9 is too wide for 8-byte matrix eleemnts. matrix.sps:21: error: MATRIX: WRITE with MODE=TRIANGULAR requires a square matrix but the matrix to be written has dimensions 1×2. ]) +AT_CLEANUP + +AT_SETUP([MATRIX - GET]) +AT_DATA([matrix.sps], [dnl +DATA LIST LIST NOTABLE /a b c. +MISSING VALUES a(1) b(5). +BEGIN DATA. +0 0 0 +1 2 3 +4 5 6 +7 8 . +END DATA. +SAVE OUTFILE='matrix.sav'. + +MATRIX. +GET x0 /FILE='matrix.sav' /NAMES=names0. +PRINT x0. +PRINT names0/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x1 /FILE='matrix.sav' /VARIABLES=a b c /NAMES=names1 /MISSING=OMIT. +PRINT x1. +PRINT names1/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x2 /FILE='matrix.sav' /VARIABLES=a b /NAMES=names2 /MISSING=OMIT. +PRINT x2. +PRINT names2/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x3 /FILE='matrix.sav' /VARIABLES=a b c /NAMES=names3 /MISSING=5. +PRINT x3. +PRINT names3/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x4 /FILE='matrix.sav' /VARIABLES=a b /NAMES=names4 /MISSING=5. +PRINT x4. +PRINT names4/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x5 /FILE='matrix.sav' /VARIABLES=a b c /NAMES=names5 /MISSING=ACCEPT. +PRINT x5. +PRINT names5/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x6 /FILE='matrix.sav' /VARIABLES=a b c /NAMES=names6 /MISSING=ACCEPT /SYSMIS=9. +PRINT x6. +PRINT names6/FORMAT=A8. +END MATRIX. + +MATRIX. +GET x7 /FILE='matrix.sav' /VARIABLES=a b c /NAMES=names7 /MISSING=ACCEPT /SYSMIS=OMIT. +PRINT x7. +PRINT names7/FORMAT=A8. +END MATRIX. +]) +AT_CHECK([pspp matrix.sps], [1], [dnl +matrix.sps:12: error: MATRIX: GET: Variable a in case 2 has user-missing value +1. + +matrix.sps:13: error: MATRIX: Uninitialized variable x0 used in expression. + +names0 + a + b + c + +matrix.sps:18: error: MATRIX: GET: Variable c in case 4 is system-missing. + +matrix.sps:19: error: MATRIX: Uninitialized variable x1 used in expression. + +names1 + a + b + c + +x2 + 0 0 + 7 8 + +names2 + a + b + +matrix.sps:30: error: MATRIX: GET: Variable c in case 4 is system-missing. + +matrix.sps:31: error: MATRIX: Uninitialized variable x3 used in expression. + +names3 + a + b + c + +x4 + 0 0 + 5 2 + 4 5 + 7 8 + +names4 + a + b + +matrix.sps:42: error: MATRIX: GET: Variable c in case 4 is system-missing. + +matrix.sps:43: error: MATRIX: Uninitialized variable x5 used in expression. + +names5 + a + b + c + +x6 + 0 0 0 + 1 2 3 + 4 5 6 + 7 8 9 + +names6 + a + b + c + +x7 + 0 0 0 + 1 2 3 + 4 5 6 + +names7 + a + b + c +]) AT_CLEANUP \ No newline at end of file -- 2.30.2