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.
25 #ifndef _FBASE_DOUBLE_MATRIX_H_
26 #define _FBASE_DOUBLE_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 %DoubleMatrix class provides a @c double precision, two-dimensional matrix class.
43 class _OSP_EXPORT_ DoubleMatrix
44 : public Tizen::Base::Object
48 * Copying of objects using this copy constructor is allowed.
52 * @param[in] rhs An instance of %DoubleMatrix
54 DoubleMatrix(const DoubleMatrix& 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 DoubleMatrix(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 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[] A two-dimensional array @n The array must be at least row * column in length.
88 DoubleMatrix(int rowCount, int columnCount, const double* pArray[]);
91 * This destructor overrides Tizen::Base::Object::~Object().
96 virtual ~DoubleMatrix(void);
99 * Checks whether the current instance and the specified instance of %DoubleMatrix 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 %DoubleMatrix
107 bool operator ==(const DoubleMatrix& rhs) const;
110 * Checks whether the current instance and the specified instance of %DoubleMatrix 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 %DoubleMatrix
118 bool operator !=(const DoubleMatrix& 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 %DoubleMatrix
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 DoubleMatrix& operator =(const DoubleMatrix& rhs);
135 * Checks whether the current instance of %DoubleMatrix equals the specified instance of %DoubleMatrix.
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 %DoubleMatrix
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 %DoubleMatrix.
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 %DoubleMatrix.
162 * @return An error code
163 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
170 * Adds the value to each matrix members of the current instance of %DoubleMatrix.
174 * @param[in] value A @c double value to add
176 void AddToEachElement(double value);
179 * Gets the number of column in the current instance of %DoubleMatrix.
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 %DoubleMatrix.
192 * @return A pointer to @c double 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 double* GetColumnN(int columnIndex) const;
200 * Gets the determinant of the current instance of %DoubleMatrix.
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 double GetDeterminant(void) const;
212 * Gets the value at the specified row and column of the current instance of %DoubleMatrix.
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 double GetElement(int rowIndex, int columnIndex) const;
225 * Gets the inverse matrix of the current instance of %DoubleMatrix.
229 * @return A pointer to the instance of %DoubleMatrix 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 DoubleMatrix* GetInverseN(void) const;
236 * Gets the number of row in the current instance of %DoubleMatrix.
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 %DoubleMatrix.
249 * @return A pointer to @c double 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 double* GetRowN(int rowIndex) const;
257 * Gets the trace of the current instance of %DoubleMatrix.
261 * @return An error code
262 * @param[out] value A @c double 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(double& value) const;
269 * Gets the transpose matrix of the current instance of %DoubleMatrix.
273 * @return A pointer to the instance of %DoubleMatrix 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 DoubleMatrix* 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 %DoubleMatrix.
304 * @return An error code
305 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
312 * Multiplies the value with each matrix members of the current instance of %DoubleMatrix.
316 * @param[in] value A @c double value to multiply
318 void Multiply(double value);
321 * Negates the matrix members of the current instance of %DoubleMatrix.
328 * Sets the value of the current instance of %DoubleMatrix 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 %DoubleMatrix 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 %DoubleMatrix 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 %DoubleMatrix.
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 double* pArray);
374 * Sets the values of the specified array to the specified row of the current instance of %DoubleMatrix.
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 double* pArray);
387 * Sets the value to the specified row and column of the current instance of %DoubleMatrix.
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 double 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, double value);
402 * Sets the values to the current instance of %DoubleMatrix 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 copy in column-major order
410 * @exception E_SUCCESS The method is successful.
411 * @exception E_INVALID_ARG The @c pArray is @c null.
413 result SetValue(const double* pArray, bool rowMajor = true);
416 * Sets the matrix members of current instance of %DoubleMatrix to zero.
420 void SetAsNull(void);
423 * Subtracts the value of the specified instance from the current instance of %DoubleMatrix.
427 * @return An error code
428 * @param[in] matrix An instance of %DoubleMatrix
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 DoubleMatrix& matrix);
435 * Subtracts the value from each matrix members of the current instance of %DoubleMatrix.
439 * @param[in] value A @c double value to subtract
441 void SubtractToEachElement(double 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(double** pSrc, double** pDest, int rowIndex, int columnIndex, int order) const;
453 double CalculateDeterminant(double** pMatrix, int order) const;
455 friend class _DoubleMatrixImpl;
456 class _DoubleMatrixImpl* __pImpl;
466 #endif //_FBASE_DOUBLE_MATRIX_H_