2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseFloatMatrix.h
20 * @brief This is the header file for the %FloatMatrix class.
22 * This header file contains the declarations of the %FloatMatrix class.
26 #ifndef _FBASE_FLOAT_MATRIX_H_
27 #define _FBASE_FLOAT_MATRIX_H_
30 #include <FBaseTypes.h>
31 #include <FBaseObject.h>
33 namespace Tizen { namespace Base
37 * @brief This class encapsulates a two-dimensional matrix.
41 * The %FloatMatrix class provides a @c float precision, two-dimensional matrix class.
44 class _OSP_EXPORT_ FloatMatrix
45 : public Tizen::Base::Object
49 * Copying of objects using this copy constructor is allowed.
53 * @param[in] rhs An instance of %FloatMatrix
55 FloatMatrix(const FloatMatrix& rhs);
58 * Constructs a row by column null matrix in which all elements are zero.
62 * @param[in] rowCount The number of rows in the current instance
63 * @param[in] columnCount The number of columns in the current instance
65 FloatMatrix(int rowCount, int columnCount);
68 * Constructs a row by column matrix initialized to the values in the specified array.
72 * @param[in] rowCount The number of rows in the current instance
73 * @param[in] columnCount The number of columns in the current instance
74 * @param[in] pArray A one-dimensional array @n The array must be at least row * column in length.
75 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
76 * else @c copy in column-major order
78 FloatMatrix(int rowCount, int columnCount, const float* pArray, bool rowMajor = true);
81 * Constructs a row by column matrix initialized to the values in the specified array.
85 * @param[in] rowCount The number of rows in the current instance
86 * @param[in] columnCount The number of columns in the current instance
87 * @param[in] pArray[] A two-dimensional array @n The array must be at least row * column in length.
89 FloatMatrix(int rowCount, int columnCount, const float* pArray[]);
92 * This destructor overrides Tizen::Base::Object::~Object().
96 virtual ~FloatMatrix(void);
99 * Checks whether the current instance and the specified instance of %FloatMatrix are equal.
103 * @return @c true if all matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
105 * @param[in] rhs An instance of %FloatMatrix
107 bool operator ==(const FloatMatrix& rhs) const;
110 * Checks whether the current instance and the specified instance of %FloatMatrix are not equal.
114 * @return @c true if all matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
116 * @param[in] rhs An instance of %FloatMatrix
118 bool operator !=(const FloatMatrix& rhs) const;
121 * Copying of objects using this copy assignment operator is allowed.
125 * @return The reference to this instance
126 * @param[in] rhs An instance of %FloatMatrix
127 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
128 * @remarks The specific error code can be accessed using the GetLastResult() method.
129 * @remarks If either row or column count of the current instance is not same with that of the specified instance,
130 * return the reference to this instance without assigning.
132 FloatMatrix& operator =(const FloatMatrix& rhs);
135 * Checks whether the current instance of %FloatMatrix equals the specified instance of %FloatMatrix.
139 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
141 * @param[in] obj An instance of %FloatMatrix
142 * @remarks This method overrides Tizen::Base::Object::Equals(). This method uses the values of the Matrix components to compare the two instances.
144 virtual bool Equals(const Tizen::Base::Object& obj) const;
147 * Gets the hash value of the current instance of %FloatMatrix.
151 * @return The hash value of the current instance
152 * @remarks Two equal instances must return the same hash value. For better performance,
153 * the used hash function must generate a random distribution for all inputs.
155 virtual int GetHashCode(void) const;
158 * Adds the value of the specified instance to the current instance of %FloatMatrix.
162 * @return An error code
163 * @param[in] matrix An instance of %FloatMatrix
164 * @exception E_SUCCESS The method is successful.
165 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
167 result Add(const FloatMatrix& matrix);
170 * Adds the value to each matrix members of current instance of %FloatMatrix.
174 * @param[in] value A @c float value to add
176 void AddToEachElement(float value);
179 * Gets the number of column in the current instance of %FloatMatrix.
183 * @return The number of column in the current instance
185 int GetColumnCount(void) const;
188 * Gets a new array that includes the values of the specified column in the current instance of %FloatMatrix.
192 * @return A pointer to float array
193 * @param[in] columnIndex The target column number in the current instance
194 * @exception E_INVALID_ARG The @c columnIndex is larger than the column count of the current instance.
195 * @remarks The specific error code can be accessed using the GetLastResult() method.
197 float* GetColumnN(int columnIndex) const;
200 * Gets the determinant of the current instance of %FloatMatrix.
204 * @return The determinant value of the current instance
205 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
206 * @remarks The specific error code can be accessed using the GetLastResult() method.
207 * @remarks If the current instance is not a square matrix, return zero.
209 float GetDeterminant(void) const;
212 * Gets the value at the specified row and column of the current instance of %FloatMatrix.
216 * @return The value at the specified row and column of the current instance
217 * @param[in] rowIndex The target row number in the current instance
218 * @param[in] columnIndex The target column number in the current instance
219 * @exception E_INVALID_ARG The @c columnIndex or @c rowIndex is larger than that of the current instance.
220 * @remarks The specific error code can be accessed using the GetLastResult() method.
222 float GetElement(int rowIndex, int columnIndex) const;
225 * Gets the inverse matrix of the current instance of %FloatMatrix.
229 * @return A pointer to the instance of %FloatMatrix containing the resulting value of the operation
230 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
231 * @remarks The specific error code can be accessed using the GetLastResult() method.
233 FloatMatrix* GetInverseN(void) const;
236 * Gets the number of row in the current instance of %FloatMatrix.
240 * @return The number of row in the current instance
242 int GetRowCount(void) const;
245 * Gets a new array that includes the values of the specified row in the current instance of %FloatMatrix.
249 * @return A pointer to @c float array
250 * @param[in] rowIndex The target row number in the current instance
251 * @exception E_INVALID_ARG The @c rowIndex is larger than the row count of the current instance.
252 * @remarks The specific error code can be accessed using the GetLastResult() method.
254 float* GetRowN(int rowIndex) const;
257 * Gets the trace of the current instance of %FloatMatrix.
261 * @return An error code
262 * @param[out] value A @c float value
263 * @exception E_SUCCESS The method is successful.
264 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
266 result GetTrace(float& value) const;
269 * Gets the transpose matrix of the current instance of %FloatMatrix.
273 * @return A pointer to the instance of %FloatMatrix containing the resulting value of the operation
274 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
275 * @remarks The specific error code can be accessed using the GetLastResult() method.
277 FloatMatrix* GetTransposeN(void) const;
280 * Checks whether the current instance is an identity matrix.
284 * @return @c true if the matrix is an identity matrix, @n
287 bool IsIdentity(void) const;
290 * Checks whether the current matrix is invertible.
294 * @return @c true if the matrix is invertible, @n
297 bool IsInvertible(void) const;
300 * Multiplies the value of the specified instance with the current instance of %FloatMatrix.
304 * @return An error code
305 * @param[in] matrix An instance of %FloatMatrix
306 * @exception E_SUCCESS The method is successful.
307 * @exception E_INVALID_ARG The column count of the current instance is not same with the row count of the specified instance.
309 result Multiply(const FloatMatrix& matrix);
312 * Multiplies the value to each matrix members of current instance of %FloatMatrix.
316 * @param[in] value A @c float value to multiply
318 void Multiply(float value);
321 * Negates the matrix members of current instance of %FloatMatrix.
328 * Sets the value of the current instance of %FloatMatrix to its identity.
332 * @return An error code
333 * @exception E_SUCCESS The method is successful.
334 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
336 result SetAsIdentity(void);
339 * Sets the value of the current instance of %FloatMatrix to its inverse.
343 * @return An error code
344 * @exception E_SUCCESS The method is successful.
345 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
350 * Sets the value of the current instance of %FloatMatrix to its transpose.
354 * @return An error code
355 * @exception E_SUCCESS The method is successful.
356 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
358 result Transpose(void);
361 * Sets the values of the specified array to the specified column of the current instance of %FloatMatrix.
365 * @return An error code
366 * @param[in] columnIndex The target column number in the current instance
367 * @param[in] pArray An array which includes the values @n The array must be at least row in length.
368 * @exception E_SUCCESS The method is successful.
369 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c columnIndex is larger than the column count of the current instance.
371 result SetColumn(int columnIndex, const float* pArray);
374 * Sets the values of the specified array to the specified row of the current instance of %FloatMatrix.
378 * @return An error code
379 * @param[in] rowIndex The target row number in the current instance
380 * @param[in] pArray An array which includes the values @n The array must be at least column in length.
381 * @exception E_SUCCESS The method is successful.
382 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c rowIndex is larger than the row count of the current instance.
384 result SetRow(int rowIndex, const float* pArray);
387 * Sets the value to the specified row and column of the current instance of %FloatMatrix.
391 * @return An error code
392 * @param[in] rowIndex The target row number in the current instance
393 * @param[in] columnIndex The target column number in the current instance
394 * @param[in] value A @c float value
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_INVALID_ARG The pArray is @c null, or the @c rowIndex is larger than the row count of the current instance,
397 * or the @c columnIndex is larger than the column count of the current instance.
399 result SetElement(int rowIndex, int columnIndex, float value);
402 * Sets the values to the current instance of %FloatMatrix in either the row-major or column-major order.
406 * @return An error code
407 * @param[in] pArray A one-dimensional array @n The array must be at least row * column in length.
408 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
409 * else @c false to copy in column-major order
410 * @exception E_SUCCESS The method is successful.
411 * @exception E_INVALID_ARG The pArray is @c null.
413 result SetValue(const float* pArray, bool rowMajor = true);
416 * Sets the matrix members of current instance of %FloatMatrix to zero.
420 void SetAsNull(void);
423 * Subtracts the value of the specified instance from the current instance of %FloatMatrix.
427 * @return An error code
428 * @param[in] matrix An instance of %FloatMatrix
429 * @exception E_SUCCESS The method is successful.
430 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
432 result Subtract(const FloatMatrix& matrix);
435 * Subtracts the value from each matrix members of current instance of %FloatMatrix.
439 * @param[in] value A @c float value to subtract
441 void SubtractToEachElement(float value);
445 * This default constructor is intentionally declared as private so that only the platform can create an instance.
451 bool AllocateCapacity(int rowCount, int columnCount);
452 void GetMinor(float** pSrc, float** pDest, int rowIndex, int columnIndex, int order) const;
453 float CalculateDeterminant(float** pMatrix, int order) const;
455 friend class _FloatMatrixImpl;
456 class _FloatMatrixImpl* __pImpl;
466 #endif //_FBASE_FLOAT_MATRIX_H_