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 FBaseDoubleMatrix.h
19 * @brief This is the header file for the %DoubleMatrix class.
21 * This header file contains the declarations of the %DoubleMatrix class.
24 #ifndef _FBASE_DOUBLE_MATRIX_H_
25 #define _FBASE_DOUBLE_MATRIX_H_
28 #include <FBaseTypes.h>
29 #include <FBaseObject.h>
31 namespace Tizen { namespace Base
35 * @brief This class encapsulates a two-dimensional matrix.
39 * The %DoubleMatrix class provides a @c double precision, two-dimensional matrix.
42 class _OSP_EXPORT_ DoubleMatrix
43 : public Tizen::Base::Object
47 * Copying of objects using this copy constructor is allowed.
51 * @param[in] rhs An instance of %DoubleMatrix to copy
53 DoubleMatrix(const DoubleMatrix& rhs);
56 * Constructs a row by column null matrix in which all the elements are zero.
60 * @param[in] rowCount The number of rows in the current instance
61 * @param[in] columnCount The number of columns in the current instance
63 DoubleMatrix(int rowCount, int columnCount);
66 * Constructs a row by column matrix initialized to the values in the specified array.
70 * @param[in] rowCount The number of rows in the current instance
71 * @param[in] columnCount The number of columns in the current instance
72 * @param[in] pArray The one-dimensional array @n
73 * 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 DoubleMatrix(int rowCount, int columnCount, const double* 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[] The two-dimensional array @n
87 * The array must be at least row * column in length.
89 DoubleMatrix(int rowCount, int columnCount, const double* pArray[]);
92 * This destructor overrides Tizen::Base::Object::~Object().
97 virtual ~DoubleMatrix(void);
100 * Checks whether the current instance and the specified instance of %DoubleMatrix are equal.
104 * @return @c true if all the matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
106 * @param[in] rhs An instance of %DoubleMatrix
108 bool operator ==(const DoubleMatrix& rhs) const;
111 * Checks whether the current instance and the specified instance of %DoubleMatrix are not equal.
115 * @return @c true if all matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
117 * @param[in] rhs An instance of %DoubleMatrix
119 bool operator !=(const DoubleMatrix& rhs) const;
122 * Copying of objects using this copy assignment operator is allowed.
126 * @return A reference to this instance
127 * @param[in] rhs An instance of %DoubleMatrix
128 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
130 * - The specific error code can be accessed using the GetLastResult() method.
131 * - If either the row or the column count of the current instance is not same as that of the specified instance,
132 * this method returns the reference to this instance without assigning.
134 DoubleMatrix& operator =(const DoubleMatrix& rhs);
137 * Checks whether the current instance of %DoubleMatrix equals the specified instance of %DoubleMatrix.
141 * @return @c true if the values of the current instance are equal to the values of the specified instance, @n
143 * @param[in] obj An instance of %DoubleMatrix
145 * - This method overrides Tizen::Base::Object::Equals().
146 * - This method uses the values of the Matrix components to compare the two instances.
148 virtual bool Equals(const Tizen::Base::Object& obj) const;
151 * Gets the hash value of the current instance of %DoubleMatrix.
155 * @return The hash value of the current instance
156 * @remarks Two equal instances must return the same hash value. @n
157 * For better performance, the used hash function must generate a random distribution for all the inputs.
159 virtual int GetHashCode(void) const;
162 * Adds the value of the specified instance to the current instance of %DoubleMatrix.
166 * @return An error code
167 * @param[in] matrix An instance of %DoubleMatrix
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
171 result Add(const DoubleMatrix& matrix);
174 * Adds the value to each matrix member of the current instance of %DoubleMatrix.
178 * @param[in] value The @c double value to add
180 void AddToEachElement(double value);
183 * Gets the number of columns in the current instance of %DoubleMatrix.
187 * @return The number of columns in the current instance
189 int GetColumnCount(void) const;
192 * Gets a new array that includes the values of the specified column in the current instance of %DoubleMatrix.
196 * @return A pointer to the @c double array
197 * @param[in] columnIndex The target column number in the current instance
198 * @exception E_INVALID_ARG The @c columnIndex is larger than the column count of the current instance.
199 * @remarks The specific error code can be accessed using the GetLastResult() method.
201 double* GetColumnN(int columnIndex) const;
204 * Gets the determinant of the current instance of %DoubleMatrix.
208 * @return The determinant value of the current instance
209 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
211 * - The specific error code can be accessed using the GetLastResult() method.
212 * - If the current instance is not a square matrix, this method returns zero.
214 double GetDeterminant(void) const;
217 * Gets the value at the specified row and column of the current instance of %DoubleMatrix.
221 * @return The value at the specified row and column of the current instance
222 * @param[in] rowIndex The target row number in the current instance
223 * @param[in] columnIndex The target column number in the current instance
224 * @exception E_INVALID_ARG The @c columnIndex or @c rowIndex is larger than that of the current instance.
225 * @remarks The specific error code can be accessed using the GetLastResult() method.
227 double GetElement(int rowIndex, int columnIndex) const;
230 * Gets the inverse matrix of the current instance of %DoubleMatrix.
234 * @return A pointer to the instance of %DoubleMatrix that contains the resulting value of the operation
235 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
236 * @remarks The specific error code can be accessed using the GetLastResult() method.
238 DoubleMatrix* GetInverseN(void) const;
241 * Gets the number of rows in the current instance of %DoubleMatrix.
245 * @return The number of rows in the current instance
247 int GetRowCount(void) const;
250 * Gets a new array that includes the values of the specified row in the current instance of %DoubleMatrix.
254 * @return A pointer to the @c double array
255 * @param[in] rowIndex The target row number in the current instance
256 * @exception E_INVALID_ARG The @c rowIndex is larger than the row count of the current instance.
257 * @remarks The specific error code can be accessed using the GetLastResult() method.
259 double* GetRowN(int rowIndex) const;
262 * Gets the trace of the current instance of %DoubleMatrix.
266 * @return An error code
267 * @param[out] value The @c double value
268 * @exception E_SUCCESS The method is successful.
269 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
271 result GetTrace(double& value) const;
274 * Gets the transpose matrix of the current instance of %DoubleMatrix.
278 * @return A pointer to the %DoubleMatrix instance that contains the resulting value of the operation
279 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
280 * @remarks The specific error code can be accessed using the GetLastResult() method.
282 DoubleMatrix* GetTransposeN(void) const;
285 * Checks whether the current instance is an identity matrix.
289 * @return @c true if the matrix is an identity matrix, @n
292 bool IsIdentity(void) const;
295 * Checks whether the current matrix is invertible.
299 * @return @c true if the matrix is invertible, @n
302 bool IsInvertible(void) const;
305 * Multiplies the value of the specified instance with the current instance of %DoubleMatrix.
309 * @return An error code
310 * @param[in] matrix An instance of %DoubleMatrix
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_INVALID_ARG The column count of the current instance is not same as the row count of the specified instance.
314 result Multiply(const DoubleMatrix& matrix);
317 * Multiplies the value with each matrix member of the current instance of %DoubleMatrix.
321 * @param[in] value The @c double value to multiply
323 void Multiply(double value);
326 * Negates the matrix members of the current instance of %DoubleMatrix.
333 * Sets the value of the current instance of %DoubleMatrix to its identity.
337 * @return An error code
338 * @exception E_SUCCESS The method is successful.
339 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
341 result SetAsIdentity(void);
344 * Sets the value of the current instance of %DoubleMatrix to its inverse.
348 * @return An error code
349 * @exception E_SUCCESS The method is successful.
350 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
355 * Sets the value of the current instance of %DoubleMatrix to its transpose.
359 * @return An error code
360 * @exception E_SUCCESS The method is successful.
361 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
363 result Transpose(void);
366 * Sets the values of the specified array to the specified column of the current instance of %DoubleMatrix.
370 * @return An error code
371 * @param[in] columnIndex The target column number in the current instance
372 * @param[in] pArray The array which includes the values @n
373 * The array must be at least row in length.
374 * @exception E_SUCCESS The method is successful.
375 * @exception E_INVALID_ARG Either of the following conditions has occurred:
376 * - The specified @c pArray is @c null.
377 * - The specified @c columnIndex is larger than the column count of the current instance.
379 result SetColumn(int columnIndex, const double* pArray);
382 * Sets the values of the specified array to the specified row of the current instance of %DoubleMatrix.
386 * @return An error code
387 * @param[in] rowIndex The target row number in the current instance
388 * @param[in] pArray The array which includes the values @n
389 * The array must be at least column in length.
390 * @exception E_SUCCESS The method is successful.
391 * @exception E_INVALID_ARG Either of the following conditions has occurred:
392 * - The specified @c pArray is @c null.
393 * - The specified @c rowIndex is larger than the row count of the current instance.
395 result SetRow(int rowIndex, const double* pArray);
398 * Sets the value to the specified row and column of the current instance of %DoubleMatrix.
402 * @return An error code
403 * @param[in] rowIndex The target row number in the current instance
404 * @param[in] columnIndex The target column number in the current instance
405 * @param[in] value The @c double value
406 * @exception E_SUCCESS The method is successful.
407 * @exception E_INVALID_ARG Either of the following conditions has occurred:
408 * - The specified @c pArray is @c null.
409 * - The specified @c rowIndex is larger than the row count of the current instance.
410 * - The specified @c columnIndex is larger than the column count of the current instance.
412 result SetElement(int rowIndex, int columnIndex, double value);
415 * Sets the values to the current instance of %DoubleMatrix in either the row-major or the column-major order.
419 * @return An error code
420 * @param[in] pArray The one-dimensional array @n
421 * The array must be at least row * column in length.
422 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
423 * else @c copy in column-major order
424 * @exception E_SUCCESS The method is successful.
425 * @exception E_INVALID_ARG The specified @c pArray is @c null.
427 result SetValue(const double* pArray, bool rowMajor = true);
430 * Sets the matrix members of the current instance of %DoubleMatrix to zero.
434 void SetAsNull(void);
437 * Subtracts the value of the specified instance from the current instance of %DoubleMatrix.
441 * @return An error code
442 * @param[in] matrix An instance of %DoubleMatrix
443 * @exception E_SUCCESS The method is successful.
444 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
446 result Subtract(const DoubleMatrix& matrix);
449 * Subtracts the value from each matrix member of the current instance of %DoubleMatrix.
453 * @param[in] value The @c double value to subtract
455 void SubtractToEachElement(double value);
459 * This default constructor is intentionally declared as private so that only the platform can create an instance.
465 bool AllocateCapacity(int rowCount, int columnCount);
466 void GetMinor(double** pSrc, double** pDest, int rowIndex, int columnIndex, int order) const;
467 double CalculateDeterminant(double** pMatrix, int order) const;
469 friend class _DoubleMatrixImpl;
470 class _DoubleMatrixImpl* __pImpl;
478 #endif //_FBASE_DOUBLE_MATRIX_H_