Example #1
0
static int comp_rows(int n)
{
    int s = comp_size(n, 1);

    return n <= s * (s - 1) ? s - 1 : s;
}
Example #2
0
static int comp_size(int n, int s)
{
    return n <= s * s ? s : comp_size(n, s + 1);
}
Example #3
0
static int comp_cols(int n)
{
    return comp_size(n, 1);
}
Example #4
0
types::Function::ReturnValue sci_duplicate(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() != 2)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }

    if (_iRetCount > 1)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }
    types::Double* pIn1 = in[0]->getAs<types::Double>();
    if (pIn1->isComplex())
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }

    if (in[1]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }
    types::Double* pIn2 = in[1]->getAs<types::Double>();
    if (pIn2->isComplex())
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }

    int m1, n1, n, m2, n2, m3, n3;

    m1 = pIn1->getRows();
    n1 = pIn1->getCols();
    n = m1 * n1;

    if (n == 0)
    {
        out.push_back(types::Double::Empty());
        return types::Function::OK;
    }

    m2 = pIn2->getRows();
    n2 = pIn2->getCols();

    if (n != m2 * n2)
    {
        Scierror(999, _("%s: 1st and 2nd argument must have equal size\n"), funname.data());
        return types::Function::Error;
    }

    comp_size(pIn2->getReal(), n3, n);

    m3 = 1;
    double* d3;
    types::Double* pOut = new types::Double(n3, m3, &d3);
    duplicata(n, pIn1->getReal(), pIn2->getReal(), d3, n3);
    out.push_back(pOut);

    return types::Function::OK;
}