2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
16 // This code is separated in double.hxx
17 // but will be inlined in arrayof.hxx
19 // If you need additionnal headers, please add it in arrayof.hxx
21 //#ifndef __ARRAYOF_HXX__
22 // #error This file must only be include by arrayof.hxx
25 #ifndef __DOUBLE_HXX__
26 #define __DOUBLE_HXX__
28 #include "arrayof.hxx"
30 #include "types_transposition.hxx"
34 class EXTERN_AST Double : public ArrayOf<double>
39 Double(double _dblReal);
40 Double(double _dblReal, double _dblImg);
41 Double(int _iRows, int _iCols, bool _bComplex = false, bool _bZComplex = false);
42 Double(int _iRows, int _iCols, double **_pdblReal);
43 Double(int _iRows, int _iCols, double **_pdblReal, double **_pdblImg);
44 Double(int _iDims, const int* _piDims, bool _bComplex = false, bool _bZComplex = false);
46 static Double* Empty();
47 static Double* Identity(int _iRows, int _iCols);
48 static Double* Identity(int _iDims, const int* _piDims);
49 static Double* Identity(int _iDims, const int* _piDims, double _dblReal);
50 static Double* Identity(int _iDims, const int* _piDims, double _dblReal, double _dblImg);
54 double* getReal() const;
55 double getReal(int _iRows, int _iCols);
56 bool setInt(int* _piReal); //to translate int to double matrix
58 /*zero or one set filler*/
67 bool fillFromCol(int _iCols, Double *_poSource);
68 bool fillFromRow(int _iRows, Double *_poSource);
69 Double* append(int _iRows, int _iCols, InternalType* _poSource);
71 //bool append(int _iRows, int _iCols, Double *_poSource);
73 bool operator==(const InternalType& it);
74 bool operator!=(const InternalType& it);
83 return (m_pImgData != NULL) || isViewAsZComplex();
86 inline bool isNumericallyComplex(double tolerance = 0)
90 int listSize = getSize();
91 double* bImg = getImg();
92 for (int i = 0; i < listSize; i++)
94 if (abs(bImg[i]) > tolerance)
105 bool neg(InternalType *& out)
113 return ArrayOf<double>::neg(out);
116 void setViewAsInteger(bool _bViewAsInteger = true)
118 m_bViewAsInteger = _bViewAsInteger;
120 bool isViewAsInteger()
122 return m_bViewAsInteger;
125 void convertToInteger();
126 void convertFromInteger();
128 void setViewAsZComplex(bool _bViewAsZComplex = true)
130 m_bViewAsZComplex = _bViewAsZComplex;
132 bool isViewAsZComplex()
134 return m_bViewAsZComplex;
137 void convertToZComplex();
138 void convertFromZComplex();
140 /* return type as string ( double, int, cell, list, ... )*/
141 virtual std::wstring getTypeStr() const
145 /* return type as short string ( s, i, ce, l, ... )*/
146 virtual std::wstring getShortTypeStr() const
151 inline ScilabType getType(void)
155 inline ScilabId getId(void)
157 return isIdentity() ? isComplex() ? IdIdentityComplex : IdIdentity
158 : isEmpty() ? IdEmpty
159 : isComplex() ? isScalar() ? IdScalarDoubleComplex
161 : isScalar() ? IdScalarDouble
165 inline bool conjugate(InternalType *& out)
167 if (isEmpty() || isIdentity() || !isComplex())
175 out = new Double(m_pRealData[0], -m_pImgData[0]);
181 Double * pReturn = new Double(getCols(), getRows(), true);
184 Transposition::conjugate(getSize(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
192 virtual bool adjoint(InternalType *& out)
210 out = new Double(m_pRealData[0], -m_pImgData[0]);
222 Double * pReturn = new Double(getCols(), getRows(), isComplex());
226 Transposition::adjoint(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
230 Transposition::adjoint(getRows(), getCols(), m_pRealData, pReturn->m_pRealData);
239 virtual bool transpose(InternalType *& out)
247 if (isIdentity() || isScalar())
255 Double * pReturn = new Double(getCols(), getRows(), isComplex());
259 Transposition::transpose(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
263 Transposition::transpose(getRows(), getCols(), m_pRealData, pReturn->m_pRealData);
272 virtual ast::Exp* getExp(const Location& loc);
274 virtual Double* set(int _iPos, const double _data)
276 if (_iPos >= m_iSize)
281 typedef Double* (Double::*set_t)(int, double);
282 Double* pIT = checkRef(this, (set_t)&Double::set, _iPos, _data);
288 m_pRealData[_iPos] = _data;
292 virtual Double* set(int _iRows, int _iCols, const double _data)
294 return set(_iCols * getRows() + _iRows, _data);
297 virtual Double* set(double* _pdata)
299 if (m_pRealData == NULL)
304 typedef Double* (Double::*set_t)(double*);
305 Double* pIT = checkRef(this, (set_t)&Double::set, _pdata);
311 for (int i = 0; i < m_iSize; i++)
313 m_pRealData[i] = _pdata[i];
319 virtual Double* set(const double* _pdata)
321 if (m_pRealData == NULL)
326 typedef Double* (Double::*set_t)(const double*);
327 Double* pIT = checkRef(this, (set_t)&Double::set, _pdata);
333 for (int i = 0; i < m_iSize; i++)
335 m_pRealData[i] = _pdata[i];
341 virtual bool isNativeType() override
346 virtual void fillDefaultValues() override
348 int size = getSize();
349 memset(m_pRealData, 0x00, sizeof(double) * size);
352 memset(m_pImgData, 0x00, sizeof(double) * size);
357 virtual bool subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims) override;
359 virtual double getNullValue();
360 virtual Double* createEmpty(int _iDims, int* _piDims, bool _bComplex = false);
361 virtual double copyValue(double _dblData);
362 virtual void deleteAll();
363 virtual void deleteImg();
364 virtual double* allocData(int _iSize);
365 virtual void deleteData(double /*data*/) { }
367 bool m_bViewAsInteger;
368 bool m_bViewAsZComplex;
374 template class types::ArrayOf<double>; //Double
376 #endif /* !__DOUBLE_HXX__ */