2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseFloatMatrix.h
19 * @brief This is the header file for the %FloatMatrix class.
21 * This header file contains the declarations of the %FloatMatrix class.
25 #ifndef _FBASE_FLOAT_MATRIX_H_
26 #define _FBASE_FLOAT_MATRIX_H_
29 #include <FBaseTypes.h>
30 #include <FBaseObject.h>
32 namespace Tizen { namespace Base
36 * @brief This class encapsulates a two-dimensional matrix.
40 * The %FloatMatrix class provides a @c float precision, two-dimensional matrix class.
43 class _OSP_EXPORT_ FloatMatrix
44 : public Tizen::Base::Object
48 * Copying of objects using this copy constructor is allowed.
52 * @param[in] rhs An instance of %FloatMatrix
54 FloatMatrix(const FloatMatrix& rhs);
57 * Constructs a row by column null matrix in which all elements are zero.
61 * @param[in] rowCount The number of rows in the current instance
62 * @param[in] columnCount The number of columns in the current instance
64 FloatMatrix(int rowCount, int columnCount);
67 * Constructs a row by column matrix initialized to the values in the specified array.
71 * @param[in] rowCount The number of rows in the current instance
72 * @param[in] columnCount The number of columns in the current instance
73 * @param[in] pArray A one-dimensional array @n The array must be at least row * column in length.
74 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
75 * else @c copy in column-major order
77 FloatMatrix(int rowCount, int columnCount, const float* pArray, bool rowMajor = true);
80 * Constructs a row by column matrix initialized to the values in the specified array.
84 * @param[in] rowCount The number of rows in the current instance
85 * @param[in] columnCount The number of columns in the current instance
86 * @param[in] pArray[] A two-dimensional array @n The array must be at least row * column in length.
88 FloatMatrix(int rowCount, int columnCount, const float* pArray[]);
91 * This destructor overrides Tizen::Base::Object::~Object().
95 virtual ~FloatMatrix(void);
98 * Checks whether the current instance and the specified instance of %FloatMatrix are equal.
102 * @return @c true if all matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
104 * @param[in] rhs An instance of %FloatMatrix
106 bool operator ==(const FloatMatrix& rhs) const;
109 * Checks whether the current instance and the specified instance of %FloatMatrix are not equal.
113 * @return @c true if all matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
115 * @param[in] rhs An instance of %FloatMatrix
117 bool operator !=(const FloatMatrix& rhs) const;
120 * Copying of objects using this copy assignment operator is allowed.
124 * @return The reference to this instance
125 * @param[in] rhs An instance of %FloatMatrix
126 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
127 * @remarks The specific error code can be accessed using the GetLastResult() method.
128 * @remarks If either row or column count of the current instance is not same with that of the specified instance,
129 * return the reference to this instance without assigning.
131 FloatMatrix& operator =(const FloatMatrix& rhs);
134 * Checks whether the current instance of %FloatMatrix equals the specified instance of %FloatMatrix.
138 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
140 * @param[in] obj An instance of %FloatMatrix
141 * @remarks This method overrides Tizen::Base::Object::Equals(). This method uses the values of the Matrix components to compare the two instances.
143 virtual bool Equals(const Tizen::Base::Object& obj) const;
146 * Gets the hash value of the current instance of %FloatMatrix.
150 * @return The hash value of the current instance
151 * @remarks Two equal instances must return the same hash value. For better performance,
152 * the used hash function must generate a random distribution for all inputs.
154 virtual int GetHashCode(void) const;
157 * Adds the value of the specified instance to the current instance of %FloatMatrix.
161 * @return An error code
162 * @param[in] matrix An instance of %FloatMatrix
163 * @exception E_SUCCESS The method is successful.
164 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
166 result Add(const FloatMatrix& matrix);
169 * Adds the value to each matrix members of current instance of %FloatMatrix.
173 * @param[in] value A @c float value to add
175 void AddToEachElement(float value);
178 * Gets the number of column in the current instance of %FloatMatrix.
182 * @return The number of column in the current instance
184 int GetColumnCount(void) const;
187 * Gets a new array that includes the values of the specified column in the current instance of %FloatMatrix.
191 * @return A pointer to float array
192 * @param[in] columnIndex The target column number in the current instance
193 * @exception E_INVALID_ARG The @c columnIndex is larger than the column count of the current instance.
194 * @remarks The specific error code can be accessed using the GetLastResult() method.
196 float* GetColumnN(int columnIndex) const;
199 * Gets the determinant of the current instance of %FloatMatrix.
203 * @return The determinant value of the current instance
204 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
205 * @remarks The specific error code can be accessed using the GetLastResult() method.
206 * @remarks If the current instance is not a square matrix, return zero.
208 float GetDeterminant(void) const;
211 * Gets the value at the specified row and column of the current instance of %FloatMatrix.
215 * @return The value at the specified row and column of the current instance
216 * @param[in] rowIndex The target row number in the current instance
217 * @param[in] columnIndex The target column number in the current instance
218 * @exception E_INVALID_ARG The @c columnIndex or @c rowIndex is larger than that of the current instance.
219 * @remarks The specific error code can be accessed using the GetLastResult() method.
221 float GetElement(int rowIndex, int columnIndex) const;
224 * Gets the inverse matrix of the current instance of %FloatMatrix.
228 * @return A pointer to the instance of %FloatMatrix containing the resulting value of the operation
229 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
230 * @remarks The specific error code can be accessed using the GetLastResult() method.
232 FloatMatrix* GetInverseN(void) const;
235 * Gets the number of row in the current instance of %FloatMatrix.
239 * @return The number of row in the current instance
241 int GetRowCount(void) const;
244 * Gets a new array that includes the values of the specified row in the current instance of %FloatMatrix.
248 * @return A pointer to @c float array
249 * @param[in] rowIndex The target row number in the current instance
250 * @exception E_INVALID_ARG The @c rowIndex is larger than the row count of the current instance.
251 * @remarks The specific error code can be accessed using the GetLastResult() method.
253 float* GetRowN(int rowIndex) const;
256 * Gets the trace of the current instance of %FloatMatrix.
260 * @return An error code
261 * @param[out] value A @c float value
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
265 result GetTrace(float& value) const;
268 * Gets the transpose matrix of the current instance of %FloatMatrix.
272 * @return A pointer to the instance of %FloatMatrix containing the resulting value of the operation
273 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
274 * @remarks The specific error code can be accessed using the GetLastResult() method.
276 FloatMatrix* GetTransposeN(void) const;
279 * Checks whether the current instance is an identity matrix.
283 * @return @c true if the matrix is an identity matrix, @n
286 bool IsIdentity(void) const;
289 * Checks whether the current matrix is invertible.
293 * @return @c true if the matrix is invertible, @n
296 bool IsInvertible(void) const;
299 * Multiplies the value of the specified instance with the current instance of %FloatMatrix.
303 * @return An error code
304 * @param[in] matrix An instance of %FloatMatrix
305 * @exception E_SUCCESS The method is successful.
306 * @exception E_INVALID_ARG The column count of the current instance is not same with the row count of the specified instance.
308 result Multiply(const FloatMatrix& matrix);
311 * Multiplies the value to each matrix members of current instance of %FloatMatrix.
315 * @param[in] value A @c float value to multiply
317 void Multiply(float value);
320 * Negates the matrix members of current instance of %FloatMatrix.
327 * Sets the value of the current instance of %FloatMatrix to its identity.
331 * @return An error code
332 * @exception E_SUCCESS The method is successful.
333 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
335 result SetAsIdentity(void);
338 * Sets the value of the current instance of %FloatMatrix to its inverse.
342 * @return An error code
343 * @exception E_SUCCESS The method is successful.
344 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
349 * Sets the value of the current instance of %FloatMatrix to its transpose.
353 * @return An error code
354 * @exception E_SUCCESS The method is successful.
355 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
357 result Transpose(void);
360 * Sets the values of the specified array to the specified column of the current instance of %FloatMatrix.
364 * @return An error code
365 * @param[in] columnIndex The target column number in the current instance
366 * @param[in] pArray An array which includes the values @n The array must be at least row in length.
367 * @exception E_SUCCESS The method is successful.
368 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c columnIndex is larger than the column count of the current instance.
370 result SetColumn(int columnIndex, const float* pArray);
373 * Sets the values of the specified array to the specified row of the current instance of %FloatMatrix.
377 * @return An error code
378 * @param[in] rowIndex The target row number in the current instance
379 * @param[in] pArray An array which includes the values @n The array must be at least column in length.
380 * @exception E_SUCCESS The method is successful.
381 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c rowIndex is larger than the row count of the current instance.
383 result SetRow(int rowIndex, const float* pArray);
386 * Sets the value to the specified row and column of the current instance of %FloatMatrix.
390 * @return An error code
391 * @param[in] rowIndex The target row number in the current instance
392 * @param[in] columnIndex The target column number in the current instance
393 * @param[in] value A @c float value
394 * @exception E_SUCCESS The method is successful.
395 * @exception E_INVALID_ARG The pArray is @c null, or the @c rowIndex is larger than the row count of the current instance,
396 * or the @c columnIndex is larger than the column count of the current instance.
398 result SetElement(int rowIndex, int columnIndex, float value);
401 * Sets the values to the current instance of %FloatMatrix in either the row-major or column-major order.
405 * @return An error code
406 * @param[in] pArray A one-dimensional array @n The array must be at least row * column in length.
407 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
408 * else @c false to copy in column-major order
409 * @exception E_SUCCESS The method is successful.
410 * @exception E_INVALID_ARG The pArray is @c null.
412 result SetValue(const float* pArray, bool rowMajor = true);
415 * Sets the matrix members of current instance of %FloatMatrix to zero.
419 void SetAsNull(void);
422 * Subtracts the value of the specified instance from the current instance of %FloatMatrix.
426 * @return An error code
427 * @param[in] matrix An instance of %FloatMatrix
428 * @exception E_SUCCESS The method is successful.
429 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
431 result Subtract(const FloatMatrix& matrix);
434 * Subtracts the value from each matrix members of current instance of %FloatMatrix.
438 * @param[in] value A @c float value to subtract
440 void SubtractToEachElement(float value);
444 * This default constructor is intentionally declared as private so that only the platform can create an instance.
450 bool AllocateCapacity(int rowCount, int columnCount);
451 void GetMinor(float** pSrc, float** pDest, int rowIndex, int columnIndex, int order) const;
452 float CalculateDeterminant(float** pMatrix, int order) const;
454 friend class _FloatMatrixImpl;
455 class _FloatMatrixImpl* __pImpl;
465 #endif //_FBASE_FLOAT_MATRIX_H_