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 class.
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
53 DoubleMatrix(const DoubleMatrix& rhs);
56 * Constructs a row by column null matrix in which all 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 A one-dimensional array @n The array must be at least row * column in length.
73 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
74 * else @c copy in column-major order
76 DoubleMatrix(int rowCount, int columnCount, const double* pArray, bool rowMajor = true);
79 * Constructs a row by column matrix initialized to the values in the specified array.
83 * @param[in] rowCount The number of rows in the current instance
84 * @param[in] columnCount The number of columns in the current instance
85 * @param[in] pArray[] A two-dimensional array @n The array must be at least row * column in length.
87 DoubleMatrix(int rowCount, int columnCount, const double* pArray[]);
90 * This destructor overrides Tizen::Base::Object::~Object().
95 virtual ~DoubleMatrix(void);
98 * Checks whether the current instance and the specified instance of %DoubleMatrix 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 %DoubleMatrix
106 bool operator ==(const DoubleMatrix& rhs) const;
109 * Checks whether the current instance and the specified instance of %DoubleMatrix 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 %DoubleMatrix
117 bool operator !=(const DoubleMatrix& 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 %DoubleMatrix
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 DoubleMatrix& operator =(const DoubleMatrix& rhs);
134 * Checks whether the current instance of %DoubleMatrix equals the specified instance of %DoubleMatrix.
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 %DoubleMatrix
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 %DoubleMatrix.
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 %DoubleMatrix.
161 * @return An error code
162 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
169 * Adds the value to each matrix members of the current instance of %DoubleMatrix.
173 * @param[in] value A @c double value to add
175 void AddToEachElement(double value);
178 * Gets the number of column in the current instance of %DoubleMatrix.
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 %DoubleMatrix.
191 * @return A pointer to @c double 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 double* GetColumnN(int columnIndex) const;
199 * Gets the determinant of the current instance of %DoubleMatrix.
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 double GetDeterminant(void) const;
211 * Gets the value at the specified row and column of the current instance of %DoubleMatrix.
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 double GetElement(int rowIndex, int columnIndex) const;
224 * Gets the inverse matrix of the current instance of %DoubleMatrix.
228 * @return A pointer to the instance of %DoubleMatrix 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 DoubleMatrix* GetInverseN(void) const;
235 * Gets the number of row in the current instance of %DoubleMatrix.
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 %DoubleMatrix.
248 * @return A pointer to @c double 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 double* GetRowN(int rowIndex) const;
256 * Gets the trace of the current instance of %DoubleMatrix.
260 * @return An error code
261 * @param[out] value A @c double 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(double& value) const;
268 * Gets the transpose matrix of the current instance of %DoubleMatrix.
272 * @return A pointer to the instance of %DoubleMatrix 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 DoubleMatrix* 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 %DoubleMatrix.
303 * @return An error code
304 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
311 * Multiplies the value with each matrix members of the current instance of %DoubleMatrix.
315 * @param[in] value A @c double value to multiply
317 void Multiply(double value);
320 * Negates the matrix members of the current instance of %DoubleMatrix.
327 * Sets the value of the current instance of %DoubleMatrix 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 %DoubleMatrix 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 %DoubleMatrix 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 %DoubleMatrix.
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 double* pArray);
373 * Sets the values of the specified array to the specified row of the current instance of %DoubleMatrix.
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 double* pArray);
386 * Sets the value to the specified row and column of the current instance of %DoubleMatrix.
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 double 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, double value);
401 * Sets the values to the current instance of %DoubleMatrix 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 copy in column-major order
409 * @exception E_SUCCESS The method is successful.
410 * @exception E_INVALID_ARG The @c pArray is @c null.
412 result SetValue(const double* pArray, bool rowMajor = true);
415 * Sets the matrix members of current instance of %DoubleMatrix to zero.
419 void SetAsNull(void);
422 * Subtracts the value of the specified instance from the current instance of %DoubleMatrix.
426 * @return An error code
427 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
434 * Subtracts the value from each matrix members of the current instance of %DoubleMatrix.
438 * @param[in] value A @c double value to subtract
440 void SubtractToEachElement(double 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(double** pSrc, double** pDest, int rowIndex, int columnIndex, int order) const;
452 double CalculateDeterminant(double** pMatrix, int order) const;
454 friend class _DoubleMatrixImpl;
455 class _DoubleMatrixImpl* __pImpl;
463 #endif //_FBASE_DOUBLE_MATRIX_H_