2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Anais AUBERT
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"
21 #include "pointer.hxx"
22 #include "overload.hxx"
27 #include "localization.h"
28 #include "elem_common.h"
32 types::Function::ReturnValue sci_lusolve(types::typed_list &in, int _iRetCount, types::typed_list &out)
35 double reltol = 0.001;
45 const void *pData = NULL;
49 int *fmatindex = NULL;
51 //check input parameters
54 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "lusolve", 2);
55 return types::Function::Error;
60 Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "lusolve", 1);
61 return types::Function::Error;
64 if (in[0]->isPointer())
66 types::Pointer *pPointerIn = in[0]->getAs<types::Pointer>();
67 m1 = pPointerIn->getRows();
68 n1 = pPointerIn->getCols();
69 pData = pPointerIn->get();
70 fmatindex = (int*)pData;
73 else if (in[0]->isSparse())
75 types::Sparse *pSpIn = in[0]->getAs<types::Sparse>();
76 m1 = pSpIn->getRows();
77 n1 = pSpIn->getCols();
80 Scierror(77, _("%s: Wrong size for input argument #%d: Square matrix expected.\n"), "lusolve", 1);
81 return types::Function::Error;
84 if (pSpIn->isComplex())
86 Scierror(77, _("%s: Wrong type for argument %d: Real matrix expected.\n"), "lusolve", 1);
87 return types::Function::Error;
90 nonZeros = (int)pSpIn->nonZeros();
91 dbl = new double[nonZeros];
92 pSpIn->outputValues(dbl, NULL);
93 colPos = new int[nonZeros];
94 itemsRow = new int[m1];
95 pSpIn->getColPos(colPos);
96 pSpIn->getNbItemByRow(itemsRow);
98 fmatindex = new int[1];
99 abstol = nc_eps_machine();
100 C2F(lufact1)(dbl, itemsRow, colPos, &m1, &nonZeros, fmatindex, &abstol, &reltol, &nrank, &ierr);
109 std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_lusolve";
110 return Overload::call(wstFuncName, in, _iRetCount, out);
113 if ((in[1]->isSparse() == false) && (in[1]->isDouble() == false))
115 std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_lusolve";
116 return Overload::call(wstFuncName, in, _iRetCount, out);
119 if (in[1]->isSparse() )
121 Scierror(999, _("%s not yet implemented for full input parameter.\n"), "lusolve");
122 return types::Function::Error;
125 if (in[1]->isDouble() )
127 types::Double *pDblIn = in[1]->getAs<types::Double>();
129 m2 = pDblIn->getRows();
130 n2 = pDblIn->getCols();
134 Scierror(999, _("%s: Wrong size for input argument #%d: Incompatible dimensions.\n"), "lusolve", 2);
135 return types::Function::Error;
138 double *dbl = pDblIn->getReal();
139 types::Double *pDblOut = new types::Double(m2, n2, pDblIn->isComplex());
140 double *oReal = pDblOut->get();
142 if (pDblIn->isComplex())
144 double *imag = pDblIn->getImg();
145 double *oImg = pDblOut->getImg();
146 for (int i = 0; i < n2; i++)
149 C2F(lusolve1)(fmatindex, dbl + iPos, oReal + iPos, &ierr);
152 Scierror(999, _("Wrong value for argument #%d: the lu handle is no more valid.\n"), 1);
153 return types::Function::Error;
155 C2F(lusolve1)(fmatindex, imag + iPos, oImg + iPos, &ierr);
158 Scierror(999, _("Wrong value for argument #%d: the lu handle is no more valid.\n"), 1);
159 return types::Function::Error;
165 for (int i = 0; i < n2; i++)
167 C2F(lusolve1)(fmatindex, &dbl[i * m2], &oReal[i * m2], &ierr);
170 Scierror(999, _("Wrong value for argument #%d: the lu handle is no more valid.\n"), 1);
171 return types::Function::Error;
178 C2F(ludel1)(fmatindex, &ierr);
181 out.push_back(pDblOut);
184 return types::Function::OK;