InternalType* or_M_M<SparseBool, SparseBool, SparseBool>(SparseBool* _pL, SparseBool* _pR) { SparseBool* pOut = NULL; if (_pL->isScalar()) { if (_pL->get(0, 0)) { pOut = new SparseBool(_pR->getRows(), _pR->getCols()); int iCols = pOut->getCols(); int iRows = pOut->getRows(); for (int i = 0 ; i < iRows ; i++) { for (int j = 0 ; j < iCols ; j++) { pOut->set(i, j, true, false); } } pOut->finalize(); } else { pOut = _pR; } return pOut; } if (_pR->isScalar()) { if (_pR->get(0, 0)) { pOut = new SparseBool(_pL->getRows(), _pL->getCols()); int iCols = pOut->getCols(); int iRows = pOut->getRows(); for (int i = 0 ; i < iRows ; i++) { for (int j = 0 ; j < iCols ; j++) { pOut->set(i, j, true, false); } } pOut->finalize(); } else { pOut = _pL; } return pOut; } if (_pL->getRows() != _pR->getRows() || _pL->getCols() != _pR->getCols()) { throw ast::InternalError(_W("Inconsistent row/column dimensions.\n")); } return _pL->newLogicalOr(*_pR); }
int SparseBoolAndSparseBool(InternalType* _pL, Bool** _pOut) { SparseBool* pL = _pL->getAs<SparseBool>(); if (pL->nbTrue() != (size_t)pL->getSize()) { *_pOut = new Bool(0); return 0; } *_pOut = NULL; return 0; }
void isValueTrue(SparseBool* _pL, Bool** _pOut) { SparseBool* pL = _pL->getAs<SparseBool>(); if (pL->nbTrue() == pL->getSize()) { *_pOut = new Bool(1); return; } *_pOut = NULL; return; }
bool getDimsFromArguments(types::typed_list& in, const std::string& _pstName, int* _iDims, int** _piDims, bool* _alloc) { types::Double* pOut = 0; *_alloc = false; *_iDims = 0; *_piDims = NULL; if (in.size() == 0) { *_iDims = 2; *_piDims = new int[*_iDims]; (*_piDims)[0] = 1; (*_piDims)[1] = 1; *_alloc = true; return true; } else if (in.size() == 1) { *_iDims = 1; // : if (in[0]->isColon()) { *_iDims = -1; return false; } if (in[0]->isArrayOf() == false) { if (in[0]->isSparse()) { Sparse* sp = in[0]->getAs<Sparse>(); *_iDims = sp->getDims(); *_piDims = sp->getDimsArray(); return true; } else if (in[0]->isSparseBool()) { SparseBool* sp = in[0]->getAs<SparseBool>(); *_iDims = sp->getDims(); *_piDims = sp->getDimsArray(); return true; } return false; } GenericType* pIn = in[0]->getAs<GenericType>(); *_iDims = pIn->getDims(); *_piDims = pIn->getDimsArray(); return true; } else { *_iDims = static_cast<int>(in.size()); *_piDims = new int[*_iDims]; *_alloc = true; for (int i = 0; i < *_iDims; i++) { if (in[i]->isArrayOf() == false) { delete[] * _piDims; Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), _pstName.c_str(), i + 1); return false; } types::GenericType* pGTIn = in[i]->getAs<types::GenericType>(); if (pGTIn->isScalar() == false || pGTIn->isComplex()) { delete[] * _piDims; Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), _pstName.c_str(), i + 1); return false; } switch (in[i]->getType()) { case types::InternalType::ScilabDouble: { double dValue = in[i]->getAs<types::Double>()->get(0); if (dValue >= INT_MAX) { delete[] * _piDims; Scierror(999, _("%s: variable size exceeded : less than %d expected.\n"), _pstName.c_str(), INT_MAX); return false; } (*_piDims)[i] = static_cast<int>(dValue); } break; case types::InternalType::ScilabInt8: (*_piDims)[i] = static_cast<int>(in[i]->getAs<types::Int8>()->get()[0]); break; case types::InternalType::ScilabUInt8: (*_piDims)[i] = static_cast<int>(in[i]->getAs<types::UInt8>()->get()[0]); break; case types::InternalType::ScilabInt16: (*_piDims)[i] = static_cast<int>(in[i]->getAs<types::Int16>()->get()[0]); break; case types::InternalType::ScilabUInt16: (*_piDims)[i] = static_cast<int>(in[i]->getAs<types::UInt16>()->get()[0]); break; case types::InternalType::ScilabInt32: (*_piDims)[i] = in[i]->getAs<types::Int32>()->get()[0]; break; case types::InternalType::ScilabUInt32: (*_piDims)[i] = static_cast<int>(in[i]->getAs<types::UInt32>()->get()[0]); break; case types::InternalType::ScilabInt64: { long long llValue = in[i]->getAs<types::Int64>()->get(0); if (llValue >= INT_MAX) { delete[] * _piDims; Scierror(999, _("%s: variable size exceeded : less than %d expected.\n"), _pstName.c_str(), INT_MAX); return false; } (*_piDims)[i] = static_cast<int>(llValue); break; } case types::InternalType::ScilabUInt64: { unsigned long long ullValue = in[i]->getAs<types::UInt64>()->get(0); if (ullValue >= INT_MAX) { delete[] * _piDims; Scierror(999, _("%s: variable size exceeded : less than %d expected.\n"), _pstName.c_str(), INT_MAX); return false; } (*_piDims)[i] = static_cast<int>(ullValue); break; } default: Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), _pstName.c_str(), i + 1); return false; } } return true; } return false; }