Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_matrix_support.cc
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* Date: Tue Mar 10 1998 */
36  /* -------------------------------------------------------------------- */
37  /* Support functions for all matrix types. */
38  /* */
39  /*************************************************************************/
40 
41 #include <iostream>
42 #include "EST_TVector.h"
43 #include "EST_matrix_support.h"
44 #include "EST_bool.h"
45 
46 const int EST_CURRENT=-1;
47 const int EST_ALL=-1;
48 
49 bool EST_matrix_bounds_check(int r,
50  int c,
51  int num_rows,
52  int num_columns,
53  bool set)
54 {
55  const char *what = set?"set":"access";
56 
57  if ((r < 0) || (r >= num_rows))
58  {
59  cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
60  return FALSE;
61  }
62  if ((c < 0) || (c >= num_columns))
63  {
64  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
65  return FALSE;
66  }
67 
68  return TRUE;
69 }
70 
71 bool EST_matrix_bounds_check(int r, int nr,
72  int c, int nc,
73  int num_rows,
74  int num_columns,
75  bool set)
76 {
77  const char *what = set?"set":"access";
78 
79  if (nr>0)
80  {
81  if ((r < 0) || (r >= num_rows))
82  {
83  cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
84  return FALSE;
85  }
86  if (r+nr-1 >= num_rows)
87  {
88  cerr << "Tried to " << what << " row " << r+nr-1 << " of " << num_rows << " row matrix\n";
89  return FALSE;
90  }
91  }
92  if (nc>0)
93  {
94  if ((c < 0) || (c >= num_columns))
95  {
96  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
97  return FALSE;
98  }
99  if (c+nc-1 >= num_columns)
100  {
101  cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column matrix\n";
102  return FALSE;
103  }
104  }
105 
106  return TRUE;
107 }
108 
109 bool EST_vector_bounds_check(int c,
110  int num_columns,
111  bool set)
112 {
113  const char *what = set?"set":"access";
114 
115  if ((c < 0) || (c >= num_columns))
116  {
117  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
118  return FALSE;
119  }
120 
121  return TRUE;
122 }
123 
124 bool EST_vector_bounds_check(int c, int nc,
125  int num_columns,
126  bool set)
127 {
128  const char *what = set?"set":"access";
129 
130  if (nc>0)
131  {
132  if ((c < 0) || (c >= num_columns))
133  {
134  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
135  return FALSE;
136  }
137  if (c+nc-1 >= num_columns)
138  {
139  cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column vector\n";
140  return FALSE;
141  }
142  }
143  return TRUE;
144 }
145