2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 // This code is separated in double.hxx
14 // but will be inlined in arrayof.hxx
16 // If you need additionnal headers, please add it in arrayof.hxx
18 //#ifndef __ARRAYOF_HXX__
19 // #error This file must only be include by arrayof.hxx
22 #ifndef __DOUBLE_HXX__
23 #define __DOUBLE_HXX__
25 #include "arrayof.hxx"
27 #include "types_transposition.hxx"
31 class EXTERN_AST Double : public ArrayOf<double>
36 Double(double _dblReal);
37 Double(double _dblReal, double _dblImg);
38 Double(int _iRows, int _iCols, bool _bComplex = false, bool _bZComplex = false);
39 Double(int _iRows, int _iCols, double **_pdblReal);
40 Double(int _iRows, int _iCols, double **_pdblReal, double **_pdblImg);
41 Double(int _iDims, const int* _piDims, bool _bComplex = false, bool _bZComplex = false);
43 static Double* Empty();
44 static Double* Identity(int _iRows, int _iCols);
45 static Double* Identity(int _iDims, const int* _piDims);
46 static Double* Identity(int _iDims, const int* _piDims, double _dblReal);
47 static Double* Identity(int _iDims, const int* _piDims, double _dblReal, double _dblImg);
51 double* getReal() const;
52 double getReal(int _iRows, int _iCols);
53 bool setInt(int* _piReal); //to translate int to double matrix
55 /*zero or one set filler*/
63 InternalType* clone();
64 bool fillFromCol(int _iCols, Double *_poSource);
65 bool fillFromRow(int _iRows, Double *_poSource);
66 bool append(int _iRows, int _iCols, InternalType* _poSource);
68 //bool append(int _iRows, int _iCols, Double *_poSource);
70 bool operator==(const InternalType& it);
71 bool operator!=(const InternalType& it);
80 return (m_pImgData != NULL) || isViewAsZComplex();
85 bool neg(InternalType *& out)
93 return ArrayOf<double>::neg(out);
96 void setViewAsInteger(bool _bViewAsInteger = true)
98 m_bViewAsInteger = _bViewAsInteger;
100 bool isViewAsInteger()
102 return m_bViewAsInteger;
105 void convertToInteger();
106 void convertFromInteger();
108 void setViewAsZComplex(bool _bViewAsZComplex = true)
110 m_bViewAsZComplex = _bViewAsZComplex;
112 bool isViewAsZComplex()
114 return m_bViewAsZComplex;
117 void convertToZComplex();
118 void convertFromZComplex();
120 /* return type as string ( double, int, cell, list, ... )*/
121 virtual std::wstring getTypeStr()
125 /* return type as short string ( s, i, ce, l, ... )*/
126 virtual std::wstring getShortTypeStr()
131 inline ScilabType getType(void)
135 inline ScilabId getId(void)
137 return isIdentity() ? isComplex() ? IdIdentityComplex : IdIdentity
138 : isEmpty() ? IdEmpty
139 : isComplex() ? isScalar() ? IdScalarDoubleComplex
141 : isScalar() ? IdScalarDouble
145 inline bool conjugate(InternalType *& out)
147 if (isEmpty() || isIdentity() || !isComplex())
155 out = new Double(m_pRealData[0], -m_pImgData[0]);
161 Double * pReturn = new Double(getCols(), getRows(), true);
164 Transposition::conjugate(getSize(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
172 virtual bool adjoint(InternalType *& out)
190 out = new Double(m_pRealData[0], -m_pImgData[0]);
202 Double * pReturn = new Double(getCols(), getRows(), isComplex());
206 Transposition::adjoint(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
210 Transposition::adjoint(getRows(), getCols(), m_pRealData, pReturn->m_pRealData);
219 virtual bool transpose(InternalType *& out)
227 if (isIdentity() || isScalar())
235 Double * pReturn = new Double(getCols(), getRows(), isComplex());
239 Transposition::transpose(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
243 Transposition::transpose(getRows(), getCols(), m_pRealData, pReturn->m_pRealData);
252 virtual ast::Exp* getExp(const Location& loc);
254 virtual bool set(int _iPos, double _data)
256 if (_iPos >= m_iSize)
261 m_pRealData[_iPos] = _data;
265 virtual bool set(int _iRows, int _iCols, double _data)
267 return set(_iCols * getRows() + _iRows, _data);
270 virtual bool set(double* _pdata)
272 if (m_pRealData == NULL)
277 for (int i = 0; i < m_iSize; i++)
279 m_pRealData[i] = _pdata[i];
284 virtual bool set(const double* _pdata)
286 if (m_pRealData == NULL)
291 for (int i = 0; i < m_iSize; i++)
293 m_pRealData[i] = _pdata[i];
300 virtual bool subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims) override;
302 virtual double getNullValue();
303 virtual Double* createEmpty(int _iDims, int* _piDims, bool _bComplex = false);
304 virtual double copyValue(double _dblData);
305 virtual void deleteAll();
306 virtual void deleteImg();
307 virtual double* allocData(int _iSize);
308 virtual void deleteData(double /*data*/) { }
310 bool m_bViewAsInteger;
311 bool m_bViewAsZComplex;
317 template class types::ArrayOf<double>; //Double
319 #endif /* !__DOUBLE_HXX__ */