1 /*************************************************************************/
2 /*                                                                       */
3 /*                Centre for Speech Technology Research                  */
4 /*                 (University of Edinburgh, UK) and                     */
5 /*                           Korin Richmond                              */
6 /*                         Copyright (c) 2003                            */
7 /*                         All Rights Reserved.                          */
8 /*                                                                       */
9 /*  Permission is hereby granted, free of charge, to use and distribute  */
10 /*  this software and its documentation without restriction, including   */
11 /*  without limitation the rights to use, copy, modify, merge, publish,  */
12 /*  distribute, sublicense, and/or sell copies of this work, and to      */
13 /*  permit persons to whom this work is furnished to do so, subject to   */
14 /*  the following conditions:                                            */
15 /*                                                                       */
16 /*   1. The code must retain the above copyright notice, this list of    */
17 /*      conditions and the following disclaimer.                         */
18 /*   2. Any modifications must be clearly marked as such.                */
19 /*   3. Original authors' names are not deleted.                         */
20 /*   4. The authors' names are not used to endorse or promote products   */
21 /*      derived from this software without specific prior written        */
22 /*      permission.                                                      */
23 /*                                                                       */
24 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
25 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
26 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT   */
27 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
28 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
29 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
30 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
31 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
32 /*  THIS SOFTWARE.                                                       */
33 /*                                                                       */
34 /*************************************************************************/
35 /*                                                                       */
36 /*                   Author :  Korin Richmond                            */
37 /*                     Date :  28 August 2003                            */
38 /* -------------------------------------------------------------------   */
39 /* SWIG interface file for EST_FVector class                             */
40 /*                                                                       */
41 /*************************************************************************/
42 
43 %module EST_FVector
44 
45 %{
46 #include "EST_FMatrix.h"
47 %}
48 
49 
50 %include "EST_rw_status.i"
51 %include "EST_typemaps.i"
52 
53 %include "EST_TSimpleVector.i"
54 %template(floatvector) EST_TVector<float>;
55 %template(floatsimplevector) EST_TSimpleVector<float>;
56 
57 class EST_FVector: public EST_TSimpleVector<float> {
58 public:
EST_FVector()59   EST_FVector(): EST_TSimpleVector<float>() {}
EST_FVector(const EST_FVector & a)60   EST_FVector(const EST_FVector &a): EST_TSimpleVector<float>(a) {}
61   // Size constructor.
EST_FVector(int n)62   EST_FVector(int n): EST_TSimpleVector<float>(n) {}
63 
64   // elementwise multiply
65   EST_FVector &operator*=(const EST_FVector &s);
66 
67   // elementwise add
68   EST_FVector &operator+=(const EST_FVector &s);
69 
70   // elementwise multiply by scalar
71   EST_FVector &operator*=(float f);
72 
73   // elementwise divide by scalar
74   EST_FVector &operator/=(float f);
75 
76   // save vector to file
77   EST_write_status est_save(const EST_String &filename,
78 			    const EST_String &type);
79 
80   EST_write_status save(const EST_String &filename,
81 			const EST_String &type);
82 
83   // load vector from file
84   EST_read_status load(const EST_String &filename);
85 
86   // Load from file in EST format
87   EST_read_status est_load(const EST_String &filename);
88 
89   %extend {
90     //    float max() const {
91     //      return vector_max( *self );
92     //    }
93 
randomise(float scale)94     void randomise( float scale ) {
95       make_random_vector( *self, scale );
96     }
97 
sum()98     float sum() const {
99       float sum = 0.0;
100       int a_len = self->length();
101 
102       for( int i=0; i<a_len; ++i )
103 	sum += self->a_no_check(i);
104 
105       return sum;
106     }
107   }
108 };
109 
110 // elementwise add
111 EST_FVector add(const EST_FVector &a,const EST_FVector &b);
112 // elementwise subtract
113 EST_FVector subtract(const EST_FVector &a,const EST_FVector &b);
114 
115 %newobject sqrt;
116 %inline %{
sqrt(const EST_FVector & a)117   EST_FVector* sqrt( const EST_FVector &a ){
118     int a_len = a.length();
119 
120     EST_FVector *ans = new EST_FVector(a_len);
121 
122     for( int i=0; i<a_len; ++i )
123       ans->a_no_check(i) = sqrt( a.a_no_check(i) );
124 
125     return ans;
126   }
127 %}
128 
129 %newobject topower;
130 %inline %{
topower(const EST_FVector & a,float f)131   EST_FVector* topower( const EST_FVector &a, float f ){
132     int a_len = a.length();
133 
134     EST_FVector *ans = new EST_FVector(a_len);
135 
136     for( int i=0; i<a_len; ++i )
137       ans->a_no_check(i) = pow( a.a_no_check(i), f );
138 
139     return ans;
140   }
141 %}
142 
143 EST_FVector operator-(const EST_FVector &a, const EST_FVector &b);
144 EST_FVector operator+(const EST_FVector &a, const EST_FVector &b);
145 // vector dot product
146 float operator*(const EST_FVector &v1, const EST_FVector &v2);
147 
148 
149 
150 // least squares fit
151 bool polynomial_fit(EST_FVector &x, EST_FVector &y,
152 		    EST_FVector &coefs, int order);
153 
154 // weighted least squares fit
155 bool polynomial_fit(EST_FVector &x, EST_FVector &y,
156 		    EST_FVector &coefs,
157 		    EST_FVector &weights, int order);
158 
159 float polynomial_value(const EST_FVector &coefs, const float x);
160 
161