Edinburgh Speech Tools  2.1-release
EST_matrix_support.cc
Go to the documentation of this file.
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 using namespace std;
47 
48 const int EST_CURRENT=-1;
49 const int EST_ALL=-1;
50 
52  int c,
53  int num_rows,
54  int num_columns,
55  bool set)
56 {
57  const char *what = set?"set":"access";
58 
59  if ((r < 0) || (r >= num_rows))
60  {
61  cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
62  return FALSE;
63  }
64  if ((c < 0) || (c >= num_columns))
65  {
66  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
67  return FALSE;
68  }
69 
70  return TRUE;
71 }
72 
73 bool EST_matrix_bounds_check(int r, int nr,
74  int c, int nc,
75  int num_rows,
76  int num_columns,
77  bool set)
78 {
79  const char *what = set?"set":"access";
80 
81  if (nr>0)
82  {
83  if ((r < 0) || (r >= num_rows))
84  {
85  cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
86  return FALSE;
87  }
88  if (r+nr-1 >= num_rows)
89  {
90  cerr << "Tried to " << what << " row " << r+nr-1 << " of " << num_rows << " row matrix\n";
91  return FALSE;
92  }
93  }
94  if (nc>0)
95  {
96  if ((c < 0) || (c >= num_columns))
97  {
98  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
99  return FALSE;
100  }
101  if (c+nc-1 >= num_columns)
102  {
103  cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column matrix\n";
104  return FALSE;
105  }
106  }
107 
108  return TRUE;
109 }
110 
112  int num_columns,
113  bool set)
114 {
115  const char *what = set?"set":"access";
116 
117  if ((c < 0) || (c >= num_columns))
118  {
119  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
120  return FALSE;
121  }
122 
123  return TRUE;
124 }
125 
126 bool EST_vector_bounds_check(int c, int nc,
127  int num_columns,
128  bool set)
129 {
130  const char *what = set?"set":"access";
131 
132  if (nc>0)
133  {
134  if ((c < 0) || (c >= num_columns))
135  {
136  cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
137  return FALSE;
138  }
139  if (c+nc-1 >= num_columns)
140  {
141  cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column vector\n";
142  return FALSE;
143  }
144  }
145  return TRUE;
146 }
147 
bool EST_matrix_bounds_check(int r, int c, int num_rows, int num_columns, bool set)
bool EST_vector_bounds_check(int c, int num_columns, bool set)
const int EST_CURRENT
const int EST_ALL
#define FALSE
Definition: EST_bool.h:119
#define TRUE
Definition: EST_bool.h:118