PocketSphinx  5prealpha
vector.h
1 /* ====================================================================
2  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * This work was supported in part by funding from the Defense Advanced
18  * Research Projects Agency and the National Science Foundation of the
19  * United States of America, and the CMU Sphinx Speech Consortium.
20  *
21  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
22  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * ====================================================================
34  *
35  */
36 
37 /*
38  * vector.h -- vector routines.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1997 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  */
47 
48 
49 #ifndef __VECTOR_H__
50 #define __VECTOR_H__
51 
52 /* System headers. */
53 #include <stdio.h>
54 
55 /* SphinxBase headers. */
56 #include <sphinxbase/prim_type.h>
57 
58 typedef float32 *vector_t;
59 
60 /*
61  * The reason for some of the "trivial" routines below is that they could be OPTIMIZED for SPEED
62  * at some point.
63  */
64 
65 
66 /* Floor all elements of v[0..dim-1] to min value of f */
67 void vector_floor(vector_t v, int32 dim, float64 f);
68 
69 
70 /* Floor all non-0 elements of v[0..dim-1] to min value of f */
71 void vector_nz_floor(vector_t v, int32 dim, float64 f);
72 
73 
74 /*
75  * Normalize the elements of the given vector so that they sum to 1.0. If the sum is 0.0
76  * to begin with, the vector is left untouched. Return value: The normalization factor.
77  */
78 float64 vector_sum_norm(vector_t v, int32 dim);
79 
80 
81 /* Print vector in one line, in %11.4e format, terminated by newline */
82 void vector_print(FILE *fp, vector_t v, int32 dim);
83 
84 
85 /* Return TRUE iff given vector is all 0.0 */
86 int32 vector_is_zero (float32 *vec, /* In: Vector to be checked */
87  int32 len); /* In: Length of above vector */
88 
89 #endif /* VECTOR_H */