[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: var->index versus var in linreg code
From: |
Jason Stover |
Subject: |
Re: var->index versus var in linreg code |
Date: |
Wed, 6 Dec 2006 10:12:09 -0500 |
User-agent: |
Mutt/1.4.2.1i |
I can't think of any problems this would cause.
On Tue, Dec 05, 2006 at 08:01:58PM -0800, Ben Pfaff wrote:
> Hi Jason. While looking over code, I noticed a number of
> comparisons in linreg.c, coefficient.c, and design-matrix.c of
> the form "var1->index == var2->index". I think that in each case
> this could be replaced by "var1 == var2".
>
> With your permission, I'd like to check in the following change
> that takes advantage of this. It still passes "make check", so
> unless you're aware of some kind of subtlety, I think it is
> correct:
>
> Index: src/math/coefficient.c
> ===================================================================
> RCS file: /cvsroot/pspp/pspp/src/math/coefficient.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 coefficient.c
> --- src/math/coefficient.c 5 Dec 2006 15:10:21 -0000 1.5
> +++ src/math/coefficient.c 6 Dec 2006 03:59:26 -0000
> @@ -169,7 +169,7 @@ pspp_coeff_get_value (struct pspp_coeff
> while (i < c->n_vars)
> {
> candidate = pspp_coeff_get_var (c, i);
> - if (v->index == candidate->index)
> + if (v == candidate)
> {
> return (c->v_info + i)->val;
> }
> @@ -201,7 +201,7 @@ pspp_linreg_get_coeff (const pspp_linreg
>
> result = c->coeff[i];
> tmp = pspp_coeff_get_var (result, 0);
> - while (tmp->index != v->index && i < c->n_coeffs)
> + while (tmp != v && i < c->n_coeffs)
> {
> result = c->coeff[i];
> tmp = pspp_coeff_get_var (result, 0);
> @@ -221,7 +221,7 @@ pspp_linreg_get_coeff (const pspp_linreg
> If v is categorical, we need to ensure the coefficient
> matches the VAL.
> */
> - while (tmp->index != v->index && i < c->n_coeffs
> + while (tmp != v && i < c->n_coeffs
> && compare_values (pspp_coeff_get_value (result, tmp),
> val, var_get_width (v)))
> { /* FIX THIS */
> Index: src/math/design-matrix.c
> ===================================================================
> RCS file: /cvsroot/pspp/pspp/src/math/design-matrix.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 design-matrix.c
> --- src/math/design-matrix.c 5 Dec 2006 15:10:21 -0000 1.4
> +++ src/math/design-matrix.c 6 Dec 2006 03:59:26 -0000
> @@ -146,8 +146,8 @@ design_matrix_destroy (struct design_mat
> Return the index of the variable for the
> given column.
> */
> -static size_t
> -design_matrix_col_to_var_index (const struct design_matrix *dm, size_t col)
> +struct variable *
> +design_matrix_col_to_var (const struct design_matrix *dm, size_t col)
> {
> size_t i;
> struct design_matrix_var v;
> @@ -156,42 +156,11 @@ design_matrix_col_to_var_index (const st
> {
> v = dm->vars[i];
> if (v.first_column <= col && col <= v.last_column)
> - return (v.v)->index;
> - }
> - return DM_INDEX_NOT_FOUND;
> -}
> -
> -/*
> - Return a pointer to the variable whose values
> - are stored in column col.
> - */
> -struct variable *
> -design_matrix_col_to_var (const struct design_matrix *dm, size_t col)
> -{
> - size_t index;
> - size_t i;
> - struct design_matrix_var dmv;
> -
> - index = design_matrix_col_to_var_index (dm, col);
> - for (i = 0; i < dm->n_vars; i++)
> - {
> - dmv = dm->vars[i];
> - if ((dmv.v)->index == index)
> - {
> - return (struct variable *) dmv.v;
> - }
> + return (struct variable *) v.v;
> }
> return NULL;
> }
>
> -static size_t
> -cmp_dm_var_index (const struct design_matrix_var *dmv, size_t index)
> -{
> - if (dmv->v->index == index)
> - return 1;
> - return 0;
> -}
> -
> /*
> Return the number of the first column which holds the
> values for variable v.
> @@ -206,7 +175,7 @@ design_matrix_var_to_column (const struc
> for (i = 0; i < dm->n_vars; i++)
> {
> tmp = dm->vars[i];
> - if (cmp_dm_var_index (&tmp, v->index))
> + if (tmp.v == v)
> {
> return tmp.first_column;
> }
> @@ -225,7 +194,7 @@ dm_var_to_last_column (const struct desi
> for (i = 0; i < dm->n_vars; i++)
> {
> tmp = dm->vars[i];
> - if (cmp_dm_var_index (&tmp, v->index))
> + if (tmp.v == v)
> {
> return tmp.last_column;
> }
> Index: src/math/linreg/linreg.c
> ===================================================================
> RCS file: /cvsroot/pspp/pspp/src/math/linreg/linreg.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 linreg.c
> --- src/math/linreg/linreg.c 19 May 2006 21:08:20 -0000 1.15
> +++ src/math/linreg/linreg.c 6 Dec 2006 03:59:27 -0000
> @@ -123,7 +123,7 @@ pspp_linreg_get_vars (const void *c_, st
> /* Repeated variables are likely to bunch together, at the end
> of the array. */
> i = result - 1;
> - while (i >= 0 && (v[i]->index != tmp->index))
> + while (i >= 0 && v[i] != tmp)
> {
> i--;
> }
>
>
> --
> "I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz
>
>
>
> _______________________________________________
> pspp-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/pspp-dev
--
Jason H. Stover
Assistant Professor
Mathematics Department
Georgia College & State University