2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
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 #include "sparse_gw.hxx"
17 #include "function.hxx"
22 #include "charEncoding.h"
25 #include "localization.h"
28 types::Function::ReturnValue sci_spzeros(types::typed_list &in, int _iRetCount, types::typed_list &out)
30 types::Sparse *pSpOut = NULL;
31 if (in.size() < 1 || in.size() > 2)
33 Scierror(999, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "spzeros", 1, 2);
34 return types::Function::Error;
39 Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "spzeros", 1);
40 return types::Function::Error;
45 types::Double* pDblRows = NULL;
46 types::Double* pDblCols = NULL;
48 if (in[0]->isDouble() == false)
50 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "spzeros", 1);
51 return types::Function::Error;
54 if (in[1]->isDouble() == false)
56 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "spzeros", 2);
57 return types::Function::Error;
60 pDblRows = in[0]->getAs<types::Double>();
61 pDblCols = in[1]->getAs<types::Double>();
63 if (pDblRows->isScalar() == false)
65 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "spzeros", 1);
66 return types::Function::Error;
69 if (pDblCols->isScalar() == false)
71 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "spzeros", 2);
72 return types::Function::Error;
75 double dblRows = pDblRows->get(0);
76 double dblCols = pDblCols->get(0);
77 if (dblRows > (double) INT_MAX)
79 Scierror(999, _("%s: Wrong value for input argument #%d: Must be less than %d.\n"), "spzeros", 1,INT_MAX);
80 return types::Function::Error;
82 if (dblRows != (double) ((unsigned int) dblRows))
84 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 1);
85 return types::Function::Error;
88 if (dblCols > (double) INT_MAX)
90 Scierror(999, _("%s: Wrong value for input argument #%d: Must be less than %d.\n"), "spzeros", 2,INT_MAX);
91 return types::Function::Error;
93 if (dblCols != (double) ((unsigned int) dblCols))
95 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 1);
96 return types::Function::Error;
99 if (dblRows * dblCols > (double) INT_MAX)
101 // FIXME: should be an error. To fix we need GenericType::m_iSize huger than int
102 if (getWarningMode())
104 sciprint(_("%s: Warning: You have created a Sparse of size > %d.\nDue to a Scilab limitation, reading or writing values from/to \nthis sparse using a unique index could lead to unexpected behavior."), "sparse", INT_MAX);
108 if (pDblRows->get(0) == 0. || pDblCols->get(0) == 0.)
110 pSpOut = new types::Sparse(0, 0, false);
114 pSpOut = new types::Sparse((int)pDblRows->get(0), (int)pDblCols->get(0), false);
118 else // in.size() == 1
120 switch (in[0]->getType())
122 case types::InternalType::ScilabInt8 :
123 case types::InternalType::ScilabUInt8 :
124 case types::InternalType::ScilabInt16 :
125 case types::InternalType::ScilabUInt16 :
126 case types::InternalType::ScilabInt32 :
127 case types::InternalType::ScilabUInt32 :
128 case types::InternalType::ScilabInt64 :
129 case types::InternalType::ScilabUInt64 :
130 case types::InternalType::ScilabString :
131 case types::InternalType::ScilabDouble :
132 case types::InternalType::ScilabBool :
133 case types::InternalType::ScilabFloat :
134 case types::InternalType::ScilabPolynom :
135 case types::InternalType::ScilabSinglePolynom :
136 case types::InternalType::ScilabSparse :
137 case types::InternalType::ScilabSparseBool :
141 Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), "spzeros", 1);
142 return types::Function::Error;
146 types::GenericType* pGT = in[0]->getAs<types::GenericType>();
147 pSpOut = new types::Sparse(pGT->getRows(), pGT->getCols(), false);
151 out.push_back(pSpOut);
152 return types::Function::OK;