2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010-2010 - DIGITEO - Bernard HUGUENEY
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 #include "sparse_gw.hxx"
14 #include "function.hxx"
19 #include "charEncoding.h"
21 #include "localization.h"
24 using namespace types;
26 //[xadj,adjncy,anz]= sp2adj(
27 Function::ReturnValue sci_sp2adj(typed_list &in, int nbRes, typed_list &out)
29 Sparse *pRetVal = NULL;
33 Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), "sp2adj", 1);
34 return Function::Error;
37 if (in[0]->isSparse() == false)
39 Scierror(999, _("%s: Wrong type for input argument #%d: sparse matrix expected.\n"), "sp2adj", 1);
40 return Function::Error;
44 Scierror(999, _("%s: Wrong number of output arguments: %d to %d expected.\n"), "sp2adj", 1, 3);
45 return Function::Error;
48 InternalType* pIT = NULL;
49 Sparse* SPARSE_CONST spIn = in[0]->getAs<Sparse>();
51 Sparse* sp = pIT->getAs<Sparse>();
52 std::size_t const nonZeros = sp->nonZeros();
54 types::Double* res = new Double(sp->getCols() + 1, 1);
56 for (std::size_t i = 0; i != sp->getCols() ; i++)
58 res->set(static_cast<int>(i + 1), res->get(static_cast<int>(i)) + sp->nonZeros(i));
65 res = new Double(static_cast<int>(nonZeros), 1);
66 sp->outputCols(res->getReal());
67 for (int i = 0 ; i < res->getSize() ; i++)
76 res = new Double(static_cast<int>(nonZeros), 1, sp->isComplex());
77 sp->outputValues(res->getReal(), res->getImg());