OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 // Accessors and mutators. | 117 // Accessors and mutators. |
118 int num_rows() const { return num_rows_; } | 118 int num_rows() const { return num_rows_; } |
119 int num_columns() const { return num_columns_; } | 119 int num_columns() const { return num_columns_; } |
120 T* const* elements() { return &elements_[0]; } | 120 T* const* elements() { return &elements_[0]; } |
121 const T* const* elements() const { return &elements_[0]; } | 121 const T* const* elements() const { return &elements_[0]; } |
122 | 122 |
123 T Trace() { | 123 T Trace() { |
124 CHECK_EQ(num_rows_, num_columns_); | 124 RTC_CHECK_EQ(num_rows_, num_columns_); |
125 | 125 |
126 T trace = 0; | 126 T trace = 0; |
127 for (int i = 0; i < num_rows_; ++i) { | 127 for (int i = 0; i < num_rows_; ++i) { |
128 trace += elements_[i][i]; | 128 trace += elements_[i][i]; |
129 } | 129 } |
130 return trace; | 130 return trace; |
131 } | 131 } |
132 | 132 |
133 // Matrix Operations. Returns *this to support method chaining. | 133 // Matrix Operations. Returns *this to support method chaining. |
134 Matrix& Transpose() { | 134 Matrix& Transpose() { |
135 CopyDataToScratch(); | 135 CopyDataToScratch(); |
136 Resize(num_columns_, num_rows_); | 136 Resize(num_columns_, num_rows_); |
137 return Transpose(scratch_elements()); | 137 return Transpose(scratch_elements()); |
138 } | 138 } |
139 | 139 |
140 Matrix& Transpose(const Matrix& operand) { | 140 Matrix& Transpose(const Matrix& operand) { |
141 CHECK_EQ(operand.num_rows_, num_columns_); | 141 RTC_CHECK_EQ(operand.num_rows_, num_columns_); |
142 CHECK_EQ(operand.num_columns_, num_rows_); | 142 RTC_CHECK_EQ(operand.num_columns_, num_rows_); |
143 | 143 |
144 return Transpose(operand.elements()); | 144 return Transpose(operand.elements()); |
145 } | 145 } |
146 | 146 |
147 template <typename S> | 147 template <typename S> |
148 Matrix& Scale(const S& scalar) { | 148 Matrix& Scale(const S& scalar) { |
149 for (size_t i = 0; i < data_.size(); ++i) { | 149 for (size_t i = 0; i < data_.size(); ++i) { |
150 data_[i] *= scalar; | 150 data_[i] *= scalar; |
151 } | 151 } |
152 | 152 |
153 return *this; | 153 return *this; |
154 } | 154 } |
155 | 155 |
156 template <typename S> | 156 template <typename S> |
157 Matrix& Scale(const Matrix& operand, const S& scalar) { | 157 Matrix& Scale(const Matrix& operand, const S& scalar) { |
158 CopyFrom(operand); | 158 CopyFrom(operand); |
159 return Scale(scalar); | 159 return Scale(scalar); |
160 } | 160 } |
161 | 161 |
162 Matrix& Add(const Matrix& operand) { | 162 Matrix& Add(const Matrix& operand) { |
163 CHECK_EQ(num_rows_, operand.num_rows_); | 163 RTC_CHECK_EQ(num_rows_, operand.num_rows_); |
164 CHECK_EQ(num_columns_, operand.num_columns_); | 164 RTC_CHECK_EQ(num_columns_, operand.num_columns_); |
165 | 165 |
166 for (size_t i = 0; i < data_.size(); ++i) { | 166 for (size_t i = 0; i < data_.size(); ++i) { |
167 data_[i] += operand.data_[i]; | 167 data_[i] += operand.data_[i]; |
168 } | 168 } |
169 | 169 |
170 return *this; | 170 return *this; |
171 } | 171 } |
172 | 172 |
173 Matrix& Add(const Matrix& lhs, const Matrix& rhs) { | 173 Matrix& Add(const Matrix& lhs, const Matrix& rhs) { |
174 CopyFrom(lhs); | 174 CopyFrom(lhs); |
175 return Add(rhs); | 175 return Add(rhs); |
176 } | 176 } |
177 | 177 |
178 Matrix& Subtract(const Matrix& operand) { | 178 Matrix& Subtract(const Matrix& operand) { |
179 CHECK_EQ(num_rows_, operand.num_rows_); | 179 RTC_CHECK_EQ(num_rows_, operand.num_rows_); |
180 CHECK_EQ(num_columns_, operand.num_columns_); | 180 RTC_CHECK_EQ(num_columns_, operand.num_columns_); |
181 | 181 |
182 for (size_t i = 0; i < data_.size(); ++i) { | 182 for (size_t i = 0; i < data_.size(); ++i) { |
183 data_[i] -= operand.data_[i]; | 183 data_[i] -= operand.data_[i]; |
184 } | 184 } |
185 | 185 |
186 return *this; | 186 return *this; |
187 } | 187 } |
188 | 188 |
189 Matrix& Subtract(const Matrix& lhs, const Matrix& rhs) { | 189 Matrix& Subtract(const Matrix& lhs, const Matrix& rhs) { |
190 CopyFrom(lhs); | 190 CopyFrom(lhs); |
191 return Subtract(rhs); | 191 return Subtract(rhs); |
192 } | 192 } |
193 | 193 |
194 Matrix& PointwiseMultiply(const Matrix& operand) { | 194 Matrix& PointwiseMultiply(const Matrix& operand) { |
195 CHECK_EQ(num_rows_, operand.num_rows_); | 195 RTC_CHECK_EQ(num_rows_, operand.num_rows_); |
196 CHECK_EQ(num_columns_, operand.num_columns_); | 196 RTC_CHECK_EQ(num_columns_, operand.num_columns_); |
197 | 197 |
198 for (size_t i = 0; i < data_.size(); ++i) { | 198 for (size_t i = 0; i < data_.size(); ++i) { |
199 data_[i] *= operand.data_[i]; | 199 data_[i] *= operand.data_[i]; |
200 } | 200 } |
201 | 201 |
202 return *this; | 202 return *this; |
203 } | 203 } |
204 | 204 |
205 Matrix& PointwiseMultiply(const Matrix& lhs, const Matrix& rhs) { | 205 Matrix& PointwiseMultiply(const Matrix& lhs, const Matrix& rhs) { |
206 CopyFrom(lhs); | 206 CopyFrom(lhs); |
207 return PointwiseMultiply(rhs); | 207 return PointwiseMultiply(rhs); |
208 } | 208 } |
209 | 209 |
210 Matrix& PointwiseDivide(const Matrix& operand) { | 210 Matrix& PointwiseDivide(const Matrix& operand) { |
211 CHECK_EQ(num_rows_, operand.num_rows_); | 211 RTC_CHECK_EQ(num_rows_, operand.num_rows_); |
212 CHECK_EQ(num_columns_, operand.num_columns_); | 212 RTC_CHECK_EQ(num_columns_, operand.num_columns_); |
213 | 213 |
214 for (size_t i = 0; i < data_.size(); ++i) { | 214 for (size_t i = 0; i < data_.size(); ++i) { |
215 data_[i] /= operand.data_[i]; | 215 data_[i] /= operand.data_[i]; |
216 } | 216 } |
217 | 217 |
218 return *this; | 218 return *this; |
219 } | 219 } |
220 | 220 |
221 Matrix& PointwiseDivide(const Matrix& lhs, const Matrix& rhs) { | 221 Matrix& PointwiseDivide(const Matrix& lhs, const Matrix& rhs) { |
222 CopyFrom(lhs); | 222 CopyFrom(lhs); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 return *this; | 257 return *this; |
258 } | 258 } |
259 | 259 |
260 Matrix& PointwiseSquare(const Matrix& operand) { | 260 Matrix& PointwiseSquare(const Matrix& operand) { |
261 CopyFrom(operand); | 261 CopyFrom(operand); |
262 return PointwiseSquare(); | 262 return PointwiseSquare(); |
263 } | 263 } |
264 | 264 |
265 Matrix& Multiply(const Matrix& lhs, const Matrix& rhs) { | 265 Matrix& Multiply(const Matrix& lhs, const Matrix& rhs) { |
266 CHECK_EQ(lhs.num_columns_, rhs.num_rows_); | 266 RTC_CHECK_EQ(lhs.num_columns_, rhs.num_rows_); |
267 CHECK_EQ(num_rows_, lhs.num_rows_); | 267 RTC_CHECK_EQ(num_rows_, lhs.num_rows_); |
268 CHECK_EQ(num_columns_, rhs.num_columns_); | 268 RTC_CHECK_EQ(num_columns_, rhs.num_columns_); |
269 | 269 |
270 return Multiply(lhs.elements(), rhs.num_rows_, rhs.elements()); | 270 return Multiply(lhs.elements(), rhs.num_rows_, rhs.elements()); |
271 } | 271 } |
272 | 272 |
273 Matrix& Multiply(const Matrix& rhs) { | 273 Matrix& Multiply(const Matrix& rhs) { |
274 CHECK_EQ(num_columns_, rhs.num_rows_); | 274 RTC_CHECK_EQ(num_columns_, rhs.num_rows_); |
275 | 275 |
276 CopyDataToScratch(); | 276 CopyDataToScratch(); |
277 Resize(num_rows_, rhs.num_columns_); | 277 Resize(num_rows_, rhs.num_columns_); |
278 return Multiply(scratch_elements(), rhs.num_rows_, rhs.elements()); | 278 return Multiply(scratch_elements(), rhs.num_rows_, rhs.elements()); |
279 } | 279 } |
280 | 280 |
281 std::string ToString() const { | 281 std::string ToString() const { |
282 std::ostringstream ss; | 282 std::ostringstream ss; |
283 ss << std::endl << "Matrix" << std::endl; | 283 ss << std::endl << "Matrix" << std::endl; |
284 | 284 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 359 |
360 return *this; | 360 return *this; |
361 } | 361 } |
362 | 362 |
363 RTC_DISALLOW_COPY_AND_ASSIGN(Matrix); | 363 RTC_DISALLOW_COPY_AND_ASSIGN(Matrix); |
364 }; | 364 }; |
365 | 365 |
366 } // namespace webrtc | 366 } // namespace webrtc |
367 | 367 |
368 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_MATRIX_H_ | 368 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_MATRIX_H_ |
OLD | NEW |