? src/data/.deps
? src/data/.dirstamp
? src/language/.deps
? src/language/.dirstamp
? src/language/control/.deps
? src/language/control/.dirstamp
? src/language/data-io/.deps
? src/language/data-io/.dirstamp
? src/language/dictionary/.deps
? src/language/dictionary/.dirstamp
? src/language/expressions/.deps
? src/language/expressions/.dirstamp
? src/language/lexer/.deps
? src/language/lexer/.dirstamp
? src/language/stats/.deps
? src/language/stats/.dirstamp
? src/language/tests/.deps
? src/language/tests/.dirstamp
? src/language/utilities/.deps
? src/language/utilities/.dirstamp
? src/language/xforms/.deps
? src/language/xforms/.dirstamp
? src/libpspp/.deps
? src/libpspp/.dirstamp
? src/math/.deps
? src/math/.dirstamp
? src/math/linreg/.deps
? src/math/linreg/.dirstamp
? src/math/ts/.deps
? src/math/ts/.dirstamp
? src/output/.deps
? src/output/.dirstamp
? src/output/charts/.deps
? src/output/charts/.dirstamp
? src/ui/.deps
? src/ui/.dirstamp
? src/ui/gui/.deps
? src/ui/gui/.dirstamp
? src/ui/terminal/.deps
? src/ui/terminal/.dirstamp
Index: src/data/automake.mk
===================================================================
RCS file: /sources/pspp/pspp/src/data/automake.mk,v
retrieving revision 1.16
diff -c -r1.16 automake.mk
*** src/data/automake.mk	22 Apr 2007 00:48:50 -0000	1.16
--- src/data/automake.mk	25 May 2007 02:52:41 -0000
***************
*** 42,47 ****
--- 42,49 ----
  	src/data/format.def \
  	src/data/identifier.c \
  	src/data/identifier.h \
+ 	src/data/interaction.c \
+ 	src/data/interaction.h \
  	src/data/missing-values.c \
  	src/data/missing-values.h \
  	src/data/make-file.c \
Index: src/data/interaction.c
===================================================================
RCS file: src/data/interaction.c
diff -N src/data/interaction.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- src/data/interaction.c	25 May 2007 02:52:41 -0000
***************
*** 0 ****
--- 1,103 ----
+ /* PSPP - Creates data structures to store interactions for
+    statistical routines.  
+ 
+    Copyright (C) 2007 Free Software Foundation, Inc.
+ 
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+ 
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+ 
+    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., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA. */
+ 
+ /*
+   An interaction is a gsl_vector containing a "product" of other
+   variables. The variables can be either categorical or numeric.
+   If the variables are all numeric, the interaction is just the
+   scalar product. If any of the variables are categorical, their
+   product is a vector containing 0's in all but one entry. This entry
+   is found by combining the vectors corresponding to the variables'
+   OBS_VALS member. If there are K categorical variables, each with
+   N_1, N_2, ..., N_K categories, then the interaction will have
+   N_1 * N_2 * N_3 *...* N_K - 1 entries.
+  */
+ #include <assert.h>
+ #include <libpspp/alloc.h>
+ #include <gsl/gsl_math.h>
+ #include <gsl/gsl_vector.h>
+ #include <data/category.h>
+ #include <data/variable.h>
+ 
+ /*
+   Convert a list of values to a binary vector. The order of VALS must
+   correspond to the order of V.
+  */
+ gsl_vector *
+ get_interaction (union value **vals, const struct variable **v, size_t n_vars)
+ {
+   gsl_vector *result = NULL;
+   size_t *subs = NULL;
+   size_t length = 1;
+   size_t i;
+   size_t j;
+   double tmp = 0.0;
+ 
+   for (i = 0; i < n_vars; i++)
+     {
+       if (var_get_type (v[i]) == VAR_STRING)
+ 	{
+ 	  length *= cat_get_n_categories (v[i]);
+ 	}
+       else
+ 	{
+ 	  length = (length > 0) ? length : 1;
+ 	}
+     }
+   if (length > 0)
+     {
+       length--;
+     }
+ 
+   result = gsl_vector_calloc (length);
+   subs = xnmalloc (n_vars, sizeof (*subs));
+   for (j = 0; j < n_vars; j++)
+     {
+       if (var_get_type (v[j]) == VAR_STRING)
+ 	{
+ 	  subs[j] = cat_value_find (v[j], vals[j]);
+ 	}
+     }
+   j = subs[0];
+   for (i = 1; i < n_vars; i++)
+     {
+       j = j * cat_get_n_categories (v[i]) + subs[i];
+     }
+   gsl_vector_set (result, j, 1.0);
+   /*
+      If any of the variables are numeric, the interaction of that
+      variable with another is just a scalar product.
+    */
+   for (i = 1; i < n_vars; i++)
+     {
+       tmp = 0.0;
+       if (var_get_type (v[i]) == VAR_NUMERIC)
+ 	{
+ 	  tmp *= vals[i]->f;
+ 	}
+     }
+   if (fabs (tmp) > GSL_DBL_EPSILON)
+     {
+       gsl_vector_set (result, j, tmp);
+     }
+   free (subs);
+ 
+   return result;
+ }
Index: src/data/interaction.h
===================================================================
RCS file: src/data/interaction.h
diff -N src/data/interaction.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- src/data/interaction.h	25 May 2007 02:52:41 -0000
***************
*** 0 ****
--- 1,21 ----
+ /* PSPP - Creates data structures to store interactions for
+    statistical routines.  
+ 
+    Copyright (C) 2007 Free Software Foundation, Inc.
+ 
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+ 
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+ 
+    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., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA. */
+ gsl_vector *
+ get_interaction (union value **, const struct variable **, size_t);
