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 FBaseDoubleMatrix.h
20 * @brief This is the header file for the %DoubleMatrix class.
22 * This header file contains the declarations of the %DoubleMatrix class.
26 #ifndef _FBASE_DOUBLE_MATRIX_H_
27 #define _FBASE_DOUBLE_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 %DoubleMatrix class provides a @c double precision, two-dimensional matrix class.
44 class _OSP_EXPORT_ DoubleMatrix
45 : public Tizen::Base::Object
49 * Copying of objects using this copy constructor is allowed.
53 * @param[in] rhs An instance of %DoubleMatrix
55 DoubleMatrix(const DoubleMatrix& 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 DoubleMatrix(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 DoubleMatrix(int rowCount, int columnCount, const double* 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 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 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 The reference to this instance
127 * @param[in] rhs An instance of %DoubleMatrix
128 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
129 * @remarks The specific error code can be accessed using the GetLastResult() method.
130 * @remarks If either row or column count of the current instance is not same with that of the specified instance,
131 * return the reference to this instance without assigning.
133 DoubleMatrix& operator =(const DoubleMatrix& rhs);
136 * Checks whether the current instance of %DoubleMatrix equals the specified instance of %DoubleMatrix.
140 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
142 * @param[in] obj An instance of %DoubleMatrix
143 * @remarks This method overrides Tizen::Base::Object::Equals(). This method uses the values of the Matrix components to compare the two instances.
145 virtual bool Equals(const Tizen::Base::Object& obj) const;
148 * Gets the hash value of the current instance of %DoubleMatrix.
152 * @return The hash value of the current instance
153 * @remarks Two equal instances must return the same hash value. For better performance,
154 * the used hash function must generate a random distribution for all inputs.
156 virtual int GetHashCode(void) const;
159 * Adds the value of the specified instance to the current instance of %DoubleMatrix.
163 * @return An error code
164 * @param[in] matrix An instance of %DoubleMatrix
165 * @exception E_SUCCESS The method is successful.
166 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
168 result Add(const DoubleMatrix& matrix);
171 * Adds the value to each matrix members of current instance of %DoubleMatrix.
175 * @param[in] value A @c double value to add
177 void AddToEachElement(double value);
180 * Gets the number of column in the current instance of %DoubleMatrix.
184 * @return The number of column in the current instance
186 int GetColumnCount(void) const;
189 * Gets a new array that includes the values of the specified column in the current instance of %DoubleMatrix.
193 * @return A pointer to @c double array
194 * @param[in] columnIndex The target column number in the current instance
195 * @exception E_INVALID_ARG The @c columnIndex is larger than the column count of the current instance.
196 * @remarks The specific error code can be accessed using the GetLastResult() method.
198 double* GetColumnN(int columnIndex) const;
201 * Gets the determinant of the current instance of %DoubleMatrix.
205 * @return The determinant value of the current instance
206 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
207 * @remarks The specific error code can be accessed using the GetLastResult() method.
208 * @remarks If the current instance is not a square matrix, return zero.
210 double GetDeterminant(void) const;
213 * Gets the value at the specified row and column of the current instance of %DoubleMatrix.
217 * @return The value at the specified row and column of the current instance
218 * @param[in] rowIndex The target row number in the current instance
219 * @param[in] columnIndex The target column number in the current instance
220 * @exception E_INVALID_ARG The @c columnIndex or @c rowIndex is larger than that of the current instance.
221 * @remarks The specific error code can be accessed using the GetLastResult() method.
223 double GetElement(int rowIndex, int columnIndex) const;
226 * Gets the inverse matrix of the current instance of %DoubleMatrix.
230 * @return A pointer to the instance of %DoubleMatrix containing the resulting value of the operation
231 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
232 * @remarks The specific error code can be accessed using the GetLastResult() method.
234 DoubleMatrix* GetInverseN(void) const;
237 * Gets the number of row in the current instance of %DoubleMatrix.
241 * @return The number of row in the current instance
243 int GetRowCount(void) const;
246 * Gets a new array that includes the values of the specified row in the current instance of %DoubleMatrix.
250 * @return A pointer to @c double array
251 * @param[in] rowIndex The target row number in the current instance
252 * @exception E_INVALID_ARG The @c rowIndex is larger than the row count of the current instance.
253 * @remarks The specific error code can be accessed using the GetLastResult() method.
255 double* GetRowN(int rowIndex) const;
258 * Gets the trace of the current instance of %DoubleMatrix.
262 * @return An error code
263 * @param[out] value A @c double value
264 * @exception E_SUCCESS The method is successful.
265 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
267 result GetTrace(double& value) const;
270 * Gets the transpose matrix of the current instance of %DoubleMatrix.
274 * @return A pointer to the instance of %DoubleMatrix containing the resulting value of the operation
275 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
276 * @remarks The specific error code can be accessed using the GetLastResult() method.
278 DoubleMatrix* GetTransposeN(void) const;
281 * Checks whether the current instance is an identity matrix.
285 * @return @c true if the matrix is an identity matrix, @n
288 bool IsIdentity(void) const;
291 * Checks whether the current matrix is invertible.
295 * @return @c true if the matrix is invertible, @n
298 bool IsInvertible(void) const;
301 * Multiplies the value of the specified instance with the current instance of %DoubleMatrix.
305 * @return An error code
306 * @param[in] matrix An instance of %DoubleMatrix
307 * @exception E_SUCCESS The method is successful.
308 * @exception E_INVALID_ARG The column count of the current instance is not same with the row count of the specified instance.
310 result Multiply(const DoubleMatrix& matrix);
313 * Multiplies the value to each matrix members of current instance of %DoubleMatrix.
317 * @param[in] value A @c double value to multiply
319 void Multiply(double value);
322 * Negates the matrix members of current instance of %DoubleMatrix.
329 * Sets the value of the current instance of %DoubleMatrix to its identity.
333 * @return An error code
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
337 result SetAsIdentity(void);
340 * Sets the value of the current instance of %DoubleMatrix to its inverse.
344 * @return An error code
345 * @exception E_SUCCESS The method is successful.
346 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
351 * Sets the value of the current instance of %DoubleMatrix to its transpose.
355 * @return An error code
356 * @exception E_SUCCESS The method is successful.
357 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
359 result Transpose(void);
362 * Sets the values of the specified array to the specified column of the current instance of %DoubleMatrix.
366 * @return An error code
367 * @param[in] columnIndex The target column number in the current instance
368 * @param[in] pArray An array which includes the values @n The array must be at least row in length.
369 * @exception E_SUCCESS The method is successful.
370 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c columnIndex is larger than the column count of the current instance.
372 result SetColumn(int columnIndex, const double* pArray);
375 * Sets the values of the specified array to the specified row of the current instance of %DoubleMatrix.
379 * @return An error code
380 * @param[in] rowIndex The target row number in the current instance
381 * @param[in] pArray An array which includes the values @n The array must be at least column in length.
382 * @exception E_SUCCESS The method is successful.
383 * @exception E_INVALID_ARG The @c pArray is @c null, or the @c rowIndex is larger than the row count of the current instance.
385 result SetRow(int rowIndex, const double* pArray);
388 * Sets the value to the specified row and column of the current instance of %DoubleMatrix.
392 * @return An error code
393 * @param[in] rowIndex The target row number in the current instance
394 * @param[in] columnIndex The target column number in the current instance
395 * @param[in] value A @c double value
396 * @exception E_SUCCESS The method is successful.
397 * @exception E_INVALID_ARG The pArray is @c null, or the @c rowIndex is larger than the row count of the current instance,
398 * or the @c columnIndex is larger than the column count of the current instance.
400 result SetElement(int rowIndex, int columnIndex, double value);
403 * Sets the values to the current instance of %DoubleMatrix in either the row-major or column-major order.
407 * @return An error code
408 * @param[in] pArray A one-dimensional array @n The array must be at least row * column in length.
409 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
410 * else @c copy in column-major order
411 * @exception E_SUCCESS The method is successful.
412 * @exception E_INVALID_ARG The @c pArray is @c null.
414 result SetValue(const double* pArray, bool rowMajor = true);
417 * Sets the matrix members of current instance of %DoubleMatrix to zero.
421 void SetAsNull(void);
424 * Subtracts the value of the specified instance from the current instance of %DoubleMatrix.
428 * @return An error code
429 * @param[in] matrix An instance of %DoubleMatrix
430 * @exception E_SUCCESS The method is successful.
431 * @exception E_INVALID_ARG Either row or column count of the current instance is not same with that of the specified instance.
433 result Subtract(const DoubleMatrix& matrix);
436 * Subtracts the value from each matrix members of current instance of %DoubleMatrix.
440 * @param[in] value A @c double value to subtract
442 void SubtractToEachElement(double value);
446 * This default constructor is intentionally declared as private so that only the platform can create an instance.
452 bool AllocateCapacity(int rowCount, int columnCount);
453 void GetMinor(double** pSrc, double** pDest, int rowIndex, int columnIndex, int order) const;
454 double CalculateDeterminant(double** pMatrix, int order) const;
456 friend class _DoubleMatrixImpl;
457 class _DoubleMatrixImpl* __pImpl;
467 #endif //_FBASE_DOUBLE_MATRIX_H_