<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
+ <LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
+ <LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
+ <LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
+ <LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
e.getSelect()->accept(*this);
exps_t* cases = e.getCases();
- for (exps_t::iterator it = cases->begin(), itEnd = cases->end(); it != itEnd ; ++it)
+ for (auto exp : *cases)
{
- (*it)->accept(*this);
+ exp->accept(*this);
}
delete cases;
public :
ScilabException()
{
- createScilabException();
+ createScilabException(L"", 0, Location());
}
ScilabException(std::wstring _wstErrorMesssage)
{
setLastError(999, _wstErrorMesssage.c_str(), 0, NULL);
- createScilabException(_wstErrorMesssage);
+ createScilabException(_wstErrorMesssage, 0, Location());
}
ScilabException(std::string _stErrorMesssage)
{
wchar_t* pwst = to_wide_string(_stErrorMesssage.c_str());
setLastError(999, pwst, 0, NULL);
- createScilabException(pwst);
+ createScilabException(pwst, 0, Location());
FREE(pwst);
}
ScilabException(const Location& _ErrorLocation)
Location m_ErrorLocation;
protected :
- void createScilabException(std::wstring _wstErrorMessage = L"", int _iErrorNumber = 0, const Location& _ErrorLocation = *new Location())
+ void createScilabException(std::wstring _wstErrorMessage, int _iErrorNumber, const Location& _ErrorLocation)
{
m_wstErrorMessage = _wstErrorMessage;
m_iErrorNumber = _iErrorNumber;
ScilabMessage() : ScilabException() {}
ScilabMessage(std::wstring _wstErrorMesssage)
{
- createScilabException(_wstErrorMesssage);
+ createScilabException(_wstErrorMesssage, 0, Location());
}
ScilabMessage(std::string _stErrorMesssage)
{
wchar_t* pwst = to_wide_string(_stErrorMesssage.c_str());
- //setLastError(999, pwst, 0, NULL);
- createScilabException(pwst);
+ createScilabException(pwst, 0, Location());
FREE(pwst);
}
ScilabMessage(const Location& _ErrorLocation) : ScilabException(_ErrorLocation) {}
ScilabMessage(std::wstring _wstErrorMesssage, int _iErrorNumber, const Location& _ErrorLocation)
{
- //setLastError(_iErrorNumber, _wstErrorMesssage.c_str(), 0, NULL);
createScilabException(_wstErrorMesssage, _iErrorNumber, _ErrorLocation);
}
};
void add_exps(const exps_t& exps)
{
add_uint32((unsigned int)exps.size());
- for (exps_t::const_iterator it = exps.begin(), itEnd = exps.end(); it != itEnd ; ++it)
+ if (exps.size() != 0)
{
- (*it)->getOriginal()->accept(*this);
+ for (auto exp : exps)
+ {
+ exp->getOriginal()->accept(*this);
+ }
}
}
exps_t* cases = e.getCases();
add_uint32((unsigned int)cases->size());
- for (exps_t::iterator it = cases->begin(), itEnd = cases->end(); it != itEnd ; ++it)
+ for (auto exp : *cases)
{
- const CaseExp *ce = (*it)->getAs<CaseExp>();
+ const CaseExp *ce = exp->getAs<CaseExp>();
add_location(ce->getLocation());
add_location(ce->getBody()->getLocation());
add_exp(ce->getTest());
exps_t& vars)
: Var (location)
{
- for (exps_t::iterator it = vars.begin(), itEnd = vars.end(); it != itEnd ; ++it)
+ for (auto var : vars)
{
- (*it)->setParent(this);
- _exps.push_back(*it);
+ var->setParent(this);
+ _exps.push_back(var);
}
delete &vars;
{
if (_old && _new)
{
- for (exps_t::iterator it = _exps.begin(), itEnd = _exps.end(); it != itEnd ; ++it)
+ exps_t::iterator it = _exps.begin();
+ exps_t::iterator itEnd = _exps.end();
+ for (; it != itEnd; ++it)
{
if (*it == _old)
{
virtual MatrixExp* clone()
{
- exps_t* lines = new exps_t;
- for (exps_t::const_iterator it = getLines().begin(), itEnd = getLines().end(); it != itEnd; ++it)
+ exps_t* newlines = new exps_t;
+ exps_t& lines = getLines();
+
+ for (auto line : lines)
{
- lines->push_back((*it)->clone());
+ newlines->push_back(line->clone());
}
- MatrixExp* cloned = new MatrixExp(getLocation(), *lines);
+ MatrixExp* cloned = new MatrixExp(getLocation(), *newlines);
cloned->setVerbose(isVerbose());
return cloned;
}
exps_t& columns)
: MathExp (location)
{
- for (exps_t::const_iterator it = columns.begin(), itEnd = columns.end(); it != itEnd ; ++it)
+ for (auto exp : columns)
{
- (*it)->setParent(this);
- _exps.push_back(*it);
+ exp->setParent(this);
+ _exps.push_back(exp);
}
delete &columns;
void clearAll()
{
- for (MapLibs::iterator it = libs.begin(); it != libs.end() ; ++it)
+ for (auto lib : libs)
{
- while (!it->second->empty())
+ while (!lib.second->empty())
{
- ScopedLibrary * pSL = it->second->top();
+ ScopedLibrary * pSL = lib.second->top();
types::InternalType * pIT = pSL->m_pLib;
pIT->DecreaseRef();
pIT->killMe();
- it->second->pop();
+ lib.second->pop();
delete pSL;
}
- delete it->second;
+ delete lib.second;
}
}
{
std::list<Symbol>* symb = new std::list<Symbol>();
- MapVars::iterator it = vars.begin();
- for (; it != vars.end() ; ++it)
+ for (auto var : vars)
{
- if (it->second->empty())
+ if (var.second->empty())
{
continue;
}
- if ((it->second->top()->m_iLevel == _iLevel || _iLevel == 1) && it->second->top()->m_pIT->isCallable())
+ if ((var.second->top()->m_iLevel == _iLevel || _iLevel == 1) && var.second->top()->m_pIT->isCallable())
{
- types::Callable* pCall = it->second->top()->m_pIT->getAs<types::Callable>();
+ types::Callable* pCall = var.second->top()->m_pIT->getAs<types::Callable>();
if (_stModuleName == L"" || _stModuleName == pCall->getModule())
{
- symb->push_back(it->first);
+ symb->push_back(var.first);
}
}
}
void clearAll()
{
- for (MapVars::iterator it = vars.begin(); it != vars.end() ; ++it)
+ for (auto var : vars)
{
- delete it->second;
+ delete var.second;
}
}
virtual void deleteAll();
virtual void deleteImg();
virtual InternalType** allocData(int _iSize);
-
+ virtual void deleteData(InternalType* _pData);
};
}
*/
struct EXTERN_AST SparseBool : GenericType
{
-
+ virtual ~SparseBool();
/* @param src: Bool matrix to copy into a new sparse matrix
**/
SparseBool(Bool SPARSE_CONST& src);
e.getSelect()->accept(*this);
exps_t* cases = e.getCases();
- for (exps_t::iterator it = cases->begin(), itEnd = cases->end(); it != itEnd ; ++it)
+ for (auto exp : *cases)
{
- (*it)->accept(*this);
+ exp->accept(*this);
}
delete cases;
if (m_pArgs && m_pArgsOwner)
{
- types::typed_list::iterator iter = m_pArgs->begin();
- for (; iter != m_pArgs->end(); ++iter)
+ for (auto arg : *m_pArgs)
{
- (*iter)->killMe();
+ arg->killMe();
}
delete m_pArgs;
bool MacrovarVisitor::isAlreadyIn(std::list<std::wstring>& lst)
{
- std::list<std::wstring>::iterator it;
- for (it = lst.begin(); it != lst.end() ; it++)
+ for (auto l : lst)
{
- if (*it == m_current)
+ if (l == m_current)
{
return true;
}
*ostr << SCI_CLOSE_TEST << std::endl;
++indent;
exps_t* cases = e.getCases();
- for (exps_t::iterator it = cases->begin(), itEnd = cases->end(); it != itEnd ; ++it)
+ for (auto exp : *cases)
{
- (*it)->getOriginal()->accept(*this);
+ exp->getOriginal()->accept(*this);
}
delete cases;
InternalType *pNewSize = AddElementToVariable(NULL, poRow, pGTResult->getRows(), pGTResult->getCols() + pGT->getCols());
InternalType* p = AddElementToVariable(pNewSize, pGT, 0, pGTResult->getCols());
-
+ if (p != pNewSize)
+ {
+ pNewSize->killMe();
+ }
// call overload
if (p == NULL)
{
- pNewSize->killMe();
poRow = callOverloadMatrixExp(L"c", pGTResult, pGT);
continue;
}
//condition
e.getTest().accept(*this);
- while (getResult()->isTrue())
+ InternalType* pIT = getResult();
+ while (pIT->isTrue())
{
e.getBody().accept(*this);
if (e.getBody().isBreak())
getResult()->killMe();
}
+ std::wcout << L"ref : " << pIT->getRef();
+ pIT->killMe();
e.getTest().accept(*this);
+ pIT = getResult();
}
+ //pIT->killMe();
//clear result of condition or result of body
clearResult();
}
e.getSelect()->accept(*this);
bool bCase = false;
-
InternalType* pIT = getResult();
setResult(NULL);
if (pIT)
{
//find good case
- exps_t::iterator it;
exps_t* cases = e.getCases();
- for (it = cases->begin(); it != cases->end() ; it++)
+ for (auto exp : *cases)
{
- CaseExp* pCase = (*it)->getAs<CaseExp>();
+ CaseExp* pCase = exp->getAs<CaseExp>();
pCase->getTest()->accept(*this);
InternalType *pITCase = getResult();
setResult(NULL);
pCase->getBody()->setReturnable();
}
- //the good one
- pCase->getBody()->accept(*this);
+ try
+ {
+ //the good one
+ pCase->getBody()->accept(*this);
+ }
+ catch (ScilabMessage& sm)
+ {
+ pIT->killMe();
+ delete cases;
+ throw sm;
+ }
if (e.isBreakable() && pCase->getBody()->isBreak())
{
pCase->getBody()->resetReturn();
}
+ pITCase->killMe();
bCase = true;
break;
}
+
+ pITCase->killMe();
}
}
bImplicitCall = true;
}
- catch (ScilabMessage sm)
+ catch (ScilabMessage& sm)
{
wostringstream os;
PrintVisitor printMe(os);
throw ScilabMessage(os.str(), 999, (*itExp)->getLocation());
}
}
- catch (ScilabError se2)
+ catch (ScilabError& se2)
{
//just to catch exception, do nothing
}
//cases
- types::List* cases = new types::List();
- for (auto c : *e.getCases())
+ types::List* lcases = new types::List();
+ ast::exps_t* cases = e.getCases();
+ for (auto c : *cases)
{
c->accept(*this);
- cases->append(getList());
+ lcases->append(getList());
}
+ delete cases;
- select->append(cases);
+ select->append(lcases);
//default
if (e.hasDefault())
/*
* Generate destination variable from _poSource type and size parameters
*/
-types::InternalType* allocDest(types::InternalType* _poSource, int _iRows, int _iCols)
+InternalType* allocDest(InternalType* _poSource, int _iRows, int _iCols)
{
- types::InternalType* poResult = NULL;
+ InternalType* poResult = NULL;
switch (_poSource->getType())
{
- case types::GenericType::ScilabDouble :
- poResult = new types::Double(_iRows, _iCols, false);
+ case GenericType::ScilabDouble :
+ poResult = new Double(_iRows, _iCols, false);
break;
- case types::GenericType::ScilabBool :
- poResult = new types::Bool(_iRows, _iCols);
+ case GenericType::ScilabBool :
+ poResult = new Bool(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt8 :
- poResult = new types::Int8(_iRows, _iCols);
+ case GenericType::ScilabInt8 :
+ poResult = new Int8(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt8 :
- poResult = new types::UInt8(_iRows, _iCols);
+ case GenericType::ScilabUInt8 :
+ poResult = new UInt8(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt16 :
- poResult = new types::Int16(_iRows, _iCols);
+ case GenericType::ScilabInt16 :
+ poResult = new Int16(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt16 :
- poResult = new types::UInt16(_iRows, _iCols);
+ case GenericType::ScilabUInt16 :
+ poResult = new UInt16(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt32 :
- poResult = new types::Int32(_iRows, _iCols);
+ case GenericType::ScilabInt32 :
+ poResult = new Int32(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt32 :
- poResult = new types::UInt32(_iRows, _iCols);
+ case GenericType::ScilabUInt32 :
+ poResult = new UInt32(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt64 :
- poResult = new types::Int64(_iRows, _iCols);
+ case GenericType::ScilabInt64 :
+ poResult = new Int64(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt64 :
- poResult = new types::UInt64(_iRows, _iCols);
+ case GenericType::ScilabUInt64 :
+ poResult = new UInt64(_iRows, _iCols);
break;
- case types::GenericType::ScilabString :
- poResult = new types::String(_iRows, _iCols);
+ case GenericType::ScilabString :
+ poResult = new String(_iRows, _iCols);
break;
- case types::GenericType::ScilabPolynom :
+ case GenericType::ScilabPolynom :
{
int* piRank = new int[_iRows * _iCols];
memset(piRank, 0x00, _iRows * _iCols * sizeof(int));
- poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), _iRows, _iCols, piRank);
+ poResult = new Polynom(_poSource->getAs<Polynom>()->getVariableName(), _iRows, _iCols, piRank);
delete[] piRank;
break;
}
- case types::InternalType::ScilabImplicitList :
- poResult = new types::ImplicitList();
+ case InternalType::ScilabImplicitList :
+ poResult = new ImplicitList();
break;
default :
// FIXME : What should we do here ??
return poResult;
}
-types::InternalType* AddElementToVariableFromCol(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols, int *_piCols)
+InternalType* AddElementToVariableFromCol(InternalType* _poDest, InternalType* _poSource, int _iRows, int _iCols, int *_piCols)
{
- types::InternalType *poResult = NULL;
- types::InternalType::ScilabType TypeSource = _poSource->getType();
- types::InternalType::ScilabType TypeDest = types::InternalType::ScilabInternal;
+ InternalType *poResult = NULL;
+ InternalType::ScilabType TypeSource = _poSource->getType();
+ InternalType::ScilabType TypeDest = InternalType::ScilabInternal;
if (_poDest == NULL)
{
{
switch (TypeDest)
{
- case types::GenericType::ScilabDouble :
- if (poResult->getAs<types::Double>()->isComplex() == false && _poSource->getAs<types::Double>()->isComplex() == true)
+ case GenericType::ScilabDouble :
+ if (poResult->getAs<Double>()->isComplex() == false && _poSource->getAs<Double>()->isComplex() == true)
{
- poResult->getAs<types::Double>()->setComplex(true);
+ poResult->getAs<Double>()->setComplex(true);
}
- poResult->getAs<types::Double>()->fillFromCol(*_piCols, _poSource->getAs<types::Double>());
- *_piCols += _poSource->getAs<types::Double>()->getCols();
+ poResult->getAs<Double>()->fillFromCol(*_piCols, _poSource->getAs<Double>());
+ *_piCols += _poSource->getAs<Double>()->getCols();
break;
default:
return NULL;
}
-types::InternalType* AddElementToVariableFromRow(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols, int *_piRows)
+InternalType* AddElementToVariableFromRow(InternalType* _poDest, InternalType* _poSource, int _iRows, int _iCols, int *_piRows)
{
- types::InternalType *poResult = NULL;
- types::InternalType::ScilabType TypeSource = _poSource->getType();
- types::InternalType::ScilabType TypeDest = types::InternalType::ScilabInternal;
+ InternalType *poResult = NULL;
+ InternalType::ScilabType TypeSource = _poSource->getType();
+ InternalType::ScilabType TypeDest = InternalType::ScilabInternal;
if (_poDest == NULL)
{
{
switch (TypeDest)
{
- case types::GenericType::ScilabDouble :
- if (poResult->getAs<types::Double>()->isComplex() == false && _poSource->getAs<types::Double>()->isComplex() == true)
+ case GenericType::ScilabDouble :
+ if (poResult->getAs<Double>()->isComplex() == false && _poSource->getAs<Double>()->isComplex() == true)
{
- poResult->getAs<types::Double>()->setComplex(true);
+ poResult->getAs<Double>()->setComplex(true);
}
- poResult->getAs<types::Double>()->fillFromRow(*_piRows, _poSource->getAs<types::Double>());
- *_piRows += _poSource->getAs<types::Double>()->getRows();
+ poResult->getAs<Double>()->fillFromRow(*_piRows, _poSource->getAs<Double>());
+ *_piRows += _poSource->getAs<Double>()->getRows();
break;
default:
_iRows : Position if _poDest allready initialized else size of the matrix
_iCols : Position if _poDest allready initialized else size of the matrix
*/
-types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols)
+InternalType* AddElementToVariable(InternalType* _poDest, InternalType* _poSource, int _iRows, int _iCols)
{
- types::InternalType *poResult = NULL;
- types::InternalType::ScilabType TypeSource = _poSource->getType();
- types::InternalType::ScilabType TypeDest = types::InternalType::ScilabInternal;
+ InternalType *poResult = NULL;
+ bool isNew = true;
+ InternalType::ScilabType TypeSource = _poSource->getType();
+ InternalType::ScilabType TypeDest = InternalType::ScilabInternal;
int iCurRow = _iRows;
int iCurCol = _iCols;
{
switch (TypeSource)
{
- case types::GenericType::ScilabDouble :
- poResult = new types::Double(_iRows, _iCols, false);
+ case GenericType::ScilabDouble :
+ poResult = new Double(_iRows, _iCols);
break;
- case types::GenericType::ScilabBool :
- poResult = new types::Bool(_iRows, _iCols);
+ case GenericType::ScilabBool :
+ poResult = new Bool(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt8 :
- poResult = new types::Int8(_iRows, _iCols);
+ case GenericType::ScilabInt8 :
+ poResult = new Int8(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt8 :
- poResult = new types::UInt8(_iRows, _iCols);
+ case GenericType::ScilabUInt8 :
+ poResult = new UInt8(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt16 :
- poResult = new types::Int16(_iRows, _iCols);
+ case GenericType::ScilabInt16 :
+ poResult = new Int16(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt16 :
- poResult = new types::UInt16(_iRows, _iCols);
+ case GenericType::ScilabUInt16 :
+ poResult = new UInt16(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt32 :
- poResult = new types::Int32(_iRows, _iCols);
+ case GenericType::ScilabInt32 :
+ poResult = new Int32(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt32 :
- poResult = new types::UInt32(_iRows, _iCols);
+ case GenericType::ScilabUInt32 :
+ poResult = new UInt32(_iRows, _iCols);
break;
- case types::GenericType::ScilabInt64 :
- poResult = new types::Int64(_iRows, _iCols);
+ case GenericType::ScilabInt64 :
+ poResult = new Int64(_iRows, _iCols);
break;
- case types::GenericType::ScilabUInt64 :
- poResult = new types::UInt64(_iRows, _iCols);
+ case GenericType::ScilabUInt64 :
+ poResult = new UInt64(_iRows, _iCols);
break;
- case types::GenericType::ScilabString :
- poResult = new types::String(_iRows, _iCols);
+ case GenericType::ScilabString :
+ poResult = new String(_iRows, _iCols);
break;
- case types::GenericType::ScilabSparse :
- poResult = new types::Sparse(_iRows, _iCols);
+ case GenericType::ScilabSparse :
+ poResult = new Sparse(_iRows, _iCols);
break;
- case types::GenericType::ScilabSparseBool :
- poResult = new types::SparseBool(_iRows, _iCols);
+ case GenericType::ScilabSparseBool :
+ poResult = new SparseBool(_iRows, _iCols);
break;
- case types::GenericType::ScilabPolynom :
+ case GenericType::ScilabPolynom :
{
int* piRank = new int[_iRows * _iCols];
memset(piRank, 0x00, _iRows * _iCols * sizeof(int));
- poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), _iRows, _iCols, piRank);
+ poResult = new Polynom(_poSource->getAs<Polynom>()->getVariableName(), _iRows, _iCols, piRank);
delete[] piRank;
break;
}
- case types::InternalType::ScilabImplicitList :
- poResult = new types::ImplicitList();
+ case InternalType::ScilabImplicitList :
+ poResult = new ImplicitList();
break;
- case types::GenericType::ScilabHandle :
- poResult = new types::GraphicHandle(_iRows, _iCols);
+ case GenericType::ScilabHandle :
+ poResult = new GraphicHandle(_iRows, _iCols);
break;
- case types::GenericType::ScilabDollar :
+ case GenericType::ScilabDollar :
{
int* piRank = new int[_iRows * _iCols];
memset(piRank, 0x00, _iRows * _iCols * sizeof(int));
- poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), _iRows, _iCols, piRank);
+ poResult = new Polynom(_poSource->getAs<Polynom>()->getVariableName(), _iRows, _iCols, piRank);
delete[] piRank;
break;
}
{
TypeDest = _poDest->getType();
poResult = _poDest;
+ isNew = false;
}
//check if source type is compatible with dest type
switch (TypeDest)
{
- case types::GenericType::ScilabDouble :
- if (TypeSource == types::GenericType::ScilabPolynom)
+ case GenericType::ScilabDouble :
+ if (TypeSource == GenericType::ScilabPolynom)
{
- types::Double *poDest = _poDest->getAs<types::Double>();
- Polynom* pPSource = _poSource->getAs<types::Polynom>();
+ Double *poDest = _poDest->getAs<Double>();
+ Polynom* pPSource = _poSource->getAs<Polynom>();
//Convert Dest to ScilabPolynom
int iSize = poDest->getSize();
int *piRank = new int[iSize];
memset(piRank, 0x00, iSize * sizeof(int));
- poResult = new types::Polynom(pPSource->getVariableName(), poDest->getRows(), poDest->getCols(), piRank);
+ if (isNew && poResult)
+ {
+ poResult->killMe();
+ }
+ poResult = new Polynom(pPSource->getVariableName(), poDest->getRows(), poDest->getCols(), piRank);
delete[] piRank;
- Polynom* pPResult = poResult->getAs<types::Polynom>();
+ Polynom* pPResult = poResult->getAs<Polynom>();
pPResult->setComplex(poDest->isComplex());
double *pR = poDest->getReal();
return poResult;
}
break;
- case types::GenericType::ScilabPolynom :
- if (TypeSource == types::GenericType::ScilabDouble)
+ case GenericType::ScilabPolynom :
+ if (TypeSource == GenericType::ScilabDouble)
{
//Add Source like coef of the new element
Double* pD = _poSource->getAs<Double>();
- types::Polynom* pPolyOut = poResult->getAs<types::Polynom>();
+ Polynom* pPolyOut = poResult->getAs<Polynom>();
if (pD->isComplex())
{
{
for (int j = 0 ; j < pD->getCols() ; j++)
{
- types::SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
+ SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
pSPOut->setRank(0);
double pDblR = pD->get(i, j);
{
for (int j = 0 ; j < pD->getCols() ; j++)
{
- types::SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
+ SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
pSPOut->setRank(0);
double pDbl = pD->get(i, j);
return poResult;
}
- else if (TypeSource == types::GenericType::ScilabDollar)
+ else if (TypeSource == GenericType::ScilabDollar)
{
- poResult->getAs<types::Polynom>()->append(iCurRow, iCurCol, _poSource->getAs<types::Dollar>());
+ poResult->getAs<Polynom>()->append(iCurRow, iCurCol, _poSource->getAs<Dollar>());
return poResult;
}
break;
- case types::GenericType::ScilabSparse :
- if (TypeSource == types::GenericType::ScilabDouble)
+ case GenericType::ScilabSparse :
+ if (TypeSource == GenericType::ScilabDouble)
{
- types::Double* poSource = _poSource->getAs<types::Double>();
- types::Sparse* spResult = poResult->getAs<types::Sparse>();
+ Double* poSource = _poSource->getAs<Double>();
+ Sparse* spResult = poResult->getAs<Sparse>();
// Set complex the result if one of inputs is complex
if (poSource->isComplex())
return poResult;
}
break;
- case types::GenericType::ScilabSparseBool :
- if (TypeSource == types::GenericType::ScilabBool)
+ case GenericType::ScilabSparseBool :
+ if (TypeSource == GenericType::ScilabBool)
{
- types::Bool* poSource = _poSource->getAs<types::Bool>();
- types::SparseBool* spResult = poResult->getAs<types::SparseBool>();
+ Bool* poSource = _poSource->getAs<Bool>();
+ SparseBool* spResult = poResult->getAs<SparseBool>();
// Add poSource at the end of spResult
for (int i = 0; i < poSource->getRows(); i++)
//Just add the new value in the current item
switch (TypeDest)
{
- case types::GenericType::ScilabDouble :
- ((Double*)poResult)->append(iCurRow, iCurCol, (Double*)_poSource);
+ case GenericType::ScilabDouble :
+ poResult->getAs<Double>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabPolynom :
- poResult->getAs<types::Polynom>()->append(iCurRow, iCurCol, _poSource->getAs<types::Polynom>());
+ case GenericType::ScilabPolynom :
+ poResult->getAs<Polynom>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabBool:
- poResult->getAs<types::Bool>()->append(iCurRow, iCurCol, _poSource->getAs<types::Bool>());
+ case GenericType::ScilabBool:
+ poResult->getAs<Bool>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabInt8 :
- poResult->getAs<types::Int8>()->append(iCurRow, iCurCol, _poSource->getAs<types::Int8>());
+ case GenericType::ScilabInt8 :
+ poResult->getAs<Int8>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabUInt8 :
- poResult->getAs<types::UInt8>()->append(iCurRow, iCurCol, _poSource->getAs<types::UInt8>());
+ case GenericType::ScilabUInt8 :
+ poResult->getAs<UInt8>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabInt16 :
- poResult->getAs<types::Int16>()->append(iCurRow, iCurCol, _poSource->getAs<types::Int16>());
+ case GenericType::ScilabInt16 :
+ poResult->getAs<Int16>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabUInt16 :
- poResult->getAs<types::UInt16>()->append(iCurRow, iCurCol, _poSource->getAs<types::UInt16>());
+ case GenericType::ScilabUInt16 :
+ poResult->getAs<UInt16>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabInt32 :
- poResult->getAs<types::Int32>()->append(iCurRow, iCurCol, _poSource->getAs<types::Int32>());
+ case GenericType::ScilabInt32 :
+ poResult->getAs<Int32>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabUInt32 :
- poResult->getAs<types::UInt32>()->append(iCurRow, iCurCol, _poSource->getAs<types::UInt32>());
+ case GenericType::ScilabUInt32 :
+ poResult->getAs<UInt32>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabInt64 :
- poResult->getAs<types::Int64>()->append(iCurRow, iCurCol, _poSource->getAs<types::Int64>());
+ case GenericType::ScilabInt64 :
+ poResult->getAs<Int64>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabUInt64 :
- poResult->getAs<types::UInt64>()->append(iCurRow, iCurCol, _poSource->getAs<types::UInt64>());
+ case GenericType::ScilabUInt64 :
+ poResult->getAs<UInt64>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabSparse :
- poResult->getAs<types::Sparse>()->append(iCurRow, iCurCol, _poSource->getAs<types::Sparse>());
+ case GenericType::ScilabSparse :
+ poResult->getAs<Sparse>()->append(iCurRow, iCurCol, _poSource->getAs<Sparse>());
break;
- case types::GenericType::ScilabSparseBool :
- poResult->getAs<types::SparseBool>()->append(iCurRow, iCurCol, _poSource->getAs<types::SparseBool>());
+ case GenericType::ScilabSparseBool :
+ poResult->getAs<SparseBool>()->append(iCurRow, iCurCol, _poSource->getAs<SparseBool>());
break;
- case types::GenericType::ScilabString :
+ case GenericType::ScilabString :
{
- types::String* pSource = _poSource->getAs<types::String>();
- poResult->getAs<types::String>()->append(iCurRow, iCurCol, pSource);
+ poResult->getAs<String>()->append(iCurRow, iCurCol, _poSource);
}
break;
- case types::GenericType::ScilabImplicitList :
+ case GenericType::ScilabImplicitList :
{
- if (_poSource->getAs<ImplicitList>()->getStartType() == types::InternalType::ScilabPolynom)
- {
- poResult->getAs<ImplicitList>()->setStart(_poSource->getAs<ImplicitList>()->getStart());
- }
- else
- {
- poResult->getAs<ImplicitList>()->setStart(_poSource->getAs<ImplicitList>()->getStart());
- }
-
- if (_poSource->getAs<ImplicitList>()->getStepType() == types::InternalType::ScilabPolynom)
- {
- poResult->getAs<ImplicitList>()->setStep(_poSource->getAs<ImplicitList>()->getStep());
- }
- else
- {
- poResult->getAs<ImplicitList>()->setStep(_poSource->getAs<ImplicitList>()->getStep());
- }
-
- if (_poSource->getAs<ImplicitList>()->getEndType() == types::InternalType::ScilabPolynom)
- {
- poResult->getAs<ImplicitList>()->setEnd(_poSource->getAs<ImplicitList>()->getEnd());
- }
- else
- {
- poResult->getAs<ImplicitList>()->setEnd(_poSource->getAs<ImplicitList>()->getEnd());
- }
+ ImplicitList* pIL = _poSource->getAs<ImplicitList>();
+ ImplicitList* pOL = poResult->getAs<ImplicitList>();
+ pOL->setStart(pIL->getStart());
+ pOL->setStep(pIL->getStep());
+ pOL->setEnd(pIL->getEnd());
break;
}
- case types::GenericType::ScilabHandle :
- poResult->getAs<types::GraphicHandle>()->append(iCurRow, iCurCol, _poSource->getAs<types::GraphicHandle>());
+ case GenericType::ScilabHandle :
+ poResult->getAs<GraphicHandle>()->append(iCurRow, iCurCol, _poSource);
break;
- case types::GenericType::ScilabDollar:
+ case GenericType::ScilabDollar:
{
- poResult->getAs<types::Polynom>()->append(iCurRow, iCurCol, _poSource->getAs<types::Dollar>());
+ poResult->getAs<Polynom>()->append(iCurRow, iCurCol, _poSource);
break;
}
default:
//i1, ..., in : indexes
//dest : variable where insert data || NULL
//source : data to insert || extract indexes from source
-types::InternalType* callOverload(const ast::Exp& e, std::wstring _strType, types::typed_list* _pArgs, types::InternalType* _source, types::InternalType* _dest)
+InternalType* callOverload(const ast::Exp& e, std::wstring _strType, typed_list* _pArgs, InternalType* _source, InternalType* _dest)
{
- types::Function::ReturnValue ret = types::Function::Error;
- types::InternalType* pITOut = NULL;
- types::typed_list in;
- types::typed_list out;
+ Function::ReturnValue ret = Function::Error;
+ InternalType* pITOut = NULL;
+ typed_list in;
+ typed_list out;
std::wstring function_name;
function_name = L"%" + _source->getShortTypeStr() + L"_" + _strType;
_dest->DecreaseRef();
}
- if (ret == types::Function::Error)
+ if (ret == Function::Error)
{
if (bThrow)
{
else if (pCall)
{
bool bArgList = false;
- types::List* pList = NULL;
+ List* pList = NULL;
int iListIncr = 0;
int iListSize = 0;
(*pCurrentArgs)[0]->isMList() == false)
{
bArgList = true;
- pList = (*pCurrentArgs)[0]->getAs<types::List>();
+ pList = (*pCurrentArgs)[0]->getAs<List>();
//pList->IncreaseRef();
pCurrentArgs->clear();
pCurrentArgs->push_back(pList->get(iListIncr));
if (iListIncr < iListSize)
{
// create new args for next loop.
- pCurrentArgs = new types::typed_list();
+ pCurrentArgs = new typed_list();
pCurrentArgs->push_back(pList->get(iListIncr));
}
}
}
}
-types::InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fields, InternalType* _pAssignValue)
+InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fields, InternalType* _pAssignValue)
{
std::list<ExpHistory*> evalFields;
std::list<ExpHistory*> workFields;
evalFields.push_back(pEH);
workFields.pop_front();
- types::InternalType* pITCurrent = pEH->getCurrent();
+ InternalType* pITCurrent = pEH->getCurrent();
if (pEH->isCellExp() && pITCurrent->isCell() == false)
{
if (pEH->getArgs())
{
// a(x)
- InternalType* pExtract = pITCurrent->getAs<types::UserType>()->extract(pEH->getArgs());
+ InternalType* pExtract = pITCurrent->getAs<UserType>()->extract(pEH->getArgs());
if (pExtract == NULL)
{
// call overload
}
else
{
- InternalType* pExtract = pITCurrent->getAs<types::UserType>()->extract(args);
+ InternalType* pExtract = pITCurrent->getAs<UserType>()->extract(args);
if (pExtract == NULL)
{
// call overload
}
case InternalType::ScilabHandle :
{
- types::GraphicHandle* pH = _pVar->getAs<GraphicHandle>();
- types::String *pS = (*_pArgs)[0]->getAs<types::String>();
+ GraphicHandle* pH = _pVar->getAs<GraphicHandle>();
+ String *pS = (*_pArgs)[0]->getAs<String>();
typed_list in;
typed_list out;
//if _pVar == NULL and pArg is single string, it's a struct creation
if ((*_pArgs)[0]->isString())
{
- String *pS = (*_pArgs)[0]->getAs<types::String>();
+ String *pS = (*_pArgs)[0]->getAs<String>();
Struct* pStr = new Struct(1, 1);
if (_pArgs->size() != 1 || pS->isScalar() == false)
default :
{
// overload
- types::Double* pEmpty = types::Double::Empty();
+ Double* pEmpty = Double::Empty();
pOut = callOverload(e, L"i", _pArgs, _pInsert, pEmpty);
pEmpty->killMe();
break;
Double* pD = new Double(pSp->getRows(), pSp->getCols(), pSp->isComplex());
pSp->fill(*pD);
pRet = _pVar->getAs<Double>()->insert(_pArgs, pD);
- free(pD);
+ delete pD;
}
else if (_pVar->isString() && _pInsert->isString())
{
if (_pArgs->size() == 1 && (*_pArgs)[0]->isString())
{
//s("x") = y
- String *pS = (*_pArgs)[0]->getAs<types::String>();
+ String *pS = (*_pArgs)[0]->getAs<String>();
if (pS->isScalar() == false)
{
if (pIL)
if ((*_pArgs)[0]->isString())
{
//s("x") = y
- String *pS = (*_pArgs)[0]->getAs<types::String>();
+ String *pS = (*_pArgs)[0]->getAs<String>();
if (pS->isScalar() == false)
{
if (pIL)
return callOverload(e, L"i", _pArgs, _pInsert, _pVar);
//ExecVisitor exec;
- //types::typed_list in;
- //types::typed_list out;
+ //typed_list in;
+ //typed_list out;
//std::wstring function_name = L"%l_e";
//_pInsert->IncreaseRef();
// in the first element, the TList have to be a List.
if (pTL->get(0)->isString() == false)
{
- types::List* pL = new List();
+ List* pL = new List();
for (int i = 0; i < pTL->getSize(); i++)
{
pL->append(pTL->get(i));
}
else if (_pVar->isList())
{
- types::List* pL = NULL;
+ List* pL = NULL;
// In case where pL is in several scilab variable,
// we have to clone it for keep the other variables unchanged.
if (_pVar->getRef() > 1)
if (_pArgs->size() == 1 && (*_pArgs)[0]->isString())
{
//s(["x"])
- types::GraphicHandle* pH = _pVar->getAs<types::GraphicHandle>();
- types::String *pS = (*_pArgs)[0]->getAs<types::String>();
+ GraphicHandle* pH = _pVar->getAs<GraphicHandle>();
+ String *pS = (*_pArgs)[0]->getAs<String>();
typed_list in;
typed_list out;
optional_list opt;
}
else
{
- pRet = _pVar->getAs<types::GraphicHandle>()->insert(_pArgs, _pInsert);
+ pRet = _pVar->getAs<GraphicHandle>()->insert(_pArgs, _pInsert);
}
}
else if (_pVar->isUserType())
{
- pRet = _pVar->getAs<types::UserType>()->insert(_pArgs, _pInsert);
+ pRet = _pVar->getAs<UserType>()->insert(_pArgs, _pInsert);
if (pRet == NULL)
{
pRet = callOverload(e, L"i", _pArgs, _pInsert, _pVar);
onPrompt = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"%onprompt"));
}
- types::InternalType* pOnPrompt = NULL;
+ InternalType* pOnPrompt = NULL;
pOnPrompt = onPrompt->get();
if (pOnPrompt != NULL && pOnPrompt->isCallable())
{
- types::typed_list in;
- types::typed_list out;
- types::optional_list opt;
+ typed_list in;
+ typed_list out;
+ optional_list opt;
ast::ExecVisitor execCall;
- pOnPrompt->getAs<types::Callable>()->call(in, opt, 1, out, &execCall);
+ pOnPrompt->getAs<Callable>()->call(in, opt, 1, out, &execCall);
}
}
pTemp->get(), pTemp->getImg());
}
+ pCoef->killMe();
(*_pPolyOut)->setCoef(pTemp);
(*_pPolyOut)->updateRank();
delete pTemp;
}
}
}
+
+ pTemp->killMe();
}
else if (bComplex1 == false && bComplex2 == true)
{
}
}
}
+
+ pTemp->killMe();
}
else if (bComplex1 == true && bComplex2 == false)
{
}
}
}
+
+ pTemp->killMe();
}
else if (bComplex1 == true && bComplex2 == true)
{
}
}
}
+
+ pTemp->killMe();
}
(*_pPolyOut)->updateRank();
}
(*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly1->getDims(), _pPoly1->getDimsArray(), piRank);
+ delete[] piRank;
if (_pPoly1->isComplex() && _pPoly2->isComplex())
{
}
Polynom* pOut = new Polynom(_pPoly->getVariableName(), _pDouble->getRows(), _pDouble->getCols(), piRank);
+ delete[] piRank;
pOut->setComplex(bComplex1);
for (int i = 0 ; i < _pDouble->getSize() ; i++)
while (iLoop)
{
+ SinglePoly* ps = pP->get()[0];
if (iLoop % 2)
{
int iRank = pP->getMaxRank();
if (bComplex1)
{
- C2F(wpmul1)(pCoeffOut->get(), pCoeffOut->getImg(), &iCurrentRank, pP->getCoef()->get(), pP->getCoef()->getImg(), &iRank, pCoeffOut->get(), pCoeffOut->getImg());
+ C2F(wpmul1)(pCoeffOut->get(), pCoeffOut->getImg(), &iCurrentRank, ps->get(), ps->getImg(), &iRank, pCoeffOut->get(), pCoeffOut->getImg());
}
else
{
- C2F(dpmul1)(pCoeffOut->get(), &iCurrentRank, pP->getCoef()->get(), &iRank, pCoeffOut->get());
+ C2F(dpmul1)(pCoeffOut->get(), &iCurrentRank, ps->get(), &iRank, pCoeffOut->get());
}
iCurrentRank += iRank;
}
//p = p * p
Polynom* pTemp = NULL;
MultiplyPolyByPoly(pP, pP, &pTemp);
- delete pP;
+ pP->killMe();
pP = pTemp;
}
}
+
+ pP->killMe();
}
*_pOut = pOut;
}
}
pOut = new Polynom(_pR->getVariableName(), _pL->getDims(), _pL->getDimsArray(), piRank);
+ delete[] piRank;
if (bComplex1 || bComplex2)
{
pOut->setComplex(true);
}
VarList* varList = varStack.top();
- std::map<Symbol, Variable*>::iterator it = varList->begin();
- for (; it != varList->end() ; ++it)
+ for (auto var : *varList)
{
- if (it->second->empty() == false && it->second->top()->m_iLevel == m_iLevel)
+ if (var.second->empty() == false && var.second->top()->m_iLevel == m_iLevel)
{
- ScopedVariable * pSV = it->second->top();
+ ScopedVariable * pSV = var.second->top();
types::InternalType * pIT = pSV->m_pIT;
pIT->DecreaseRef();
pIT->killMe();
- it->second->pop();
+ var.second->pop();
delete pSV;
}
}
void ConfigVariable::setLastErrorMessage(std::wstring _wstError)
{
- wchar_t* pwstTemp1 = os_wcsdup(_wstError.c_str());
- m_wstError = pwstTemp1;
+ m_wstError = _wstError;
}
std::wstring ConfigVariable::getLastErrorMessage()
types::Cell *pcResult = new types::Cell(iSize, 1);
std::list<types::ThreadId *>::iterator it;
- for (it = ConfigVariable::m_threadList.begin() ; it != ConfigVariable::m_threadList.end() ; ++it, ++i)
+ for (auto thread : ConfigVariable::m_threadList)
{
- pcResult->set(i, *it);
+ pcResult->set(i++, *it);
}
return pcResult;
void ConfigVariable::deleteThread(__threadKey _key)
{
- //for(int i = 0 ; i < m_threadList.size() ; i++)
- //{
- // types::ThreadId* pThread = m_threadList[i];
- // if(pThread->getKey() == _key)
- // {
- // pThread->DecreaseRef();
- // if(pThread->isDeletable())
- // {
- // delete pThread;
- // m_threadList.erase(.begin() + i - 1);
- // }
- // }
- //}
std::list<types::ThreadId *>::iterator it;
for (it = ConfigVariable::m_threadList.begin() ; it != ConfigVariable::m_threadList.end() ; ++it)
{
bool ConfigVariable::checkReferenceModule(std::wstring _module)
{
- std::list<std::wstring>::iterator it = m_ReferenceModules.begin();
- for ( ; it != m_ReferenceModules.end() ; ++it)
+ for (auto ref : m_ReferenceModules)
{
- if (*it == _module)
+ if (ref == _module)
{
return true;
}
T* pImgData = pArrayOut->getImg();
for (int i = 0 ; i < pArrayOut->getSize() ; i++)
{
+ pArrayOut->deleteData(pRealData[i]);
pRealData[i] = pSource->getNullValue();
- pImgData[i] = pSource->getNullValue();
+ pArrayOut->deleteData(pImgData[i]);
+ pImgData[i] = pSource->getNullValue();
}
}
else
{
for (int i = 0 ; i < pArrayOut->getSize() ; i++)
{
+ pArrayOut->deleteData(pRealData[i]);
pRealData[i] = pSource->getNullValue();
}
}
{
deleteAll();
}
+
+ delete m_pRealData;
#ifndef NDEBUG
Inspector::removeItem(this);
#endif
create(_piDims, _iDims, &pIT, NULL);
for (int i = 0; i < getSize(); i++)
{
- double* pReal = NULL;
m_pRealData[i] = Double::Empty();
m_pRealData[i]->IncreaseRef();
}
{
if (isDeletable() == true)
{
- for (int i = 0 ; i < getSize() ; i++)
+ for (int i = 0; i < m_iSizeMax; i++)
{
m_pRealData[i]->DecreaseRef();
m_pRealData[i]->killMe();
}
}
+
+ delete[] m_pRealData;
#ifndef NDEBUG
Inspector::removeItem(this);
#endif
}
return pData;
}
+
+void Cell::deleteData(InternalType* _pData)
+{
+ if (_pData)
+ {
+ _pData->DecreaseRef();
+ _pData->killMe();
+ }
+}
}
}
}
- for (int i = 0 ; i < iMinDim ; i++)
+ int* piIndex = new int[_iDims];
+ for (int i = 0; i < iMinDim; i++)
{
- int* piIndex = new int[_iDims];
for (int j = 0 ; j < _iDims ; j++)
{
piIndex[j] = i;
int index = getIndexWithDims(piIndex, _piDims, _iDims);
pI->set(index, 1);
}
+
+ delete[] piIndex;
return pI;
}
}
}
+ int* piIndex = new int[_iDims];
for (int i = 0; i < iMinDim; i++)
{
- int* piIndex = new int[_iDims];
for (int j = 0; j < _iDims; j++)
{
piIndex[j] = i;
int index = getIndexWithDims(piIndex, _piDims, _iDims);
pI->set(index, _dblReal);
}
+
+ delete[] piIndex;
return pI;
}
void Inspector::addItem(InternalType* _pIT)
{
types::GenericType* pGT = _pIT->getAs<types::GenericType>();
-
- if (pGT)
- {
- //std::wcout << L"addItem " << pGT->getTypeStr() << L"[" << pGT->getSize() << L"] : " << pGT << std::endl;
- }
- else
- {
- //std::wcout << L"addItem " << _pIT->getTypeStr() << L" : " << _pIT << std::endl;
- }
m_vIT.push_back(_pIT);
}
void Inspector::removeItem(InternalType* _pIT)
{
std::vector<InternalType*>::iterator it;
-
for (it = m_vIT.begin() ; it != m_vIT.end() ; it++)
{
if ((*it) == _pIT)
{
types::GenericType* pGT = _pIT->getAs<types::GenericType>();
-
- if (pGT)
- {
- //std::wcout << L"removeItem " << pGT->getTypeStr() << L"[" << pGT->getSize() << L"] : " << pGT << std::endl;
- }
- else
- {
- //std::wcout << L"removeItem " << _pIT->getTypeStr() << L" : " << _pIT << std::endl;
- }
m_vIT.erase(it);
break;
}
Library::~Library()
{
//delete all macrofile*
- for (MacroMap::iterator it = m_macros.begin(); it != m_macros.end() ; ++it)
+ for (auto macro : m_macros)
{
- MacroFile* pMacro = it->second;
+ MacroFile* pMacro = macro.second;
pMacro->DecreaseRef();
if (pMacro->isDeletable())
{
size_t iLineLen = (size_t)ConfigVariable::getConsoleWidth();
size_t iCurrentLen = 0;
- MacroMap::iterator it = m_macros.begin();
- for (int i = 0; it != m_macros.end() ; ++it, ++i)
+ for (auto macro : m_macros)
{
- if (iCurrentLen + it->first.length() + 2 > iLineLen)
+ if (iCurrentLen + macro.first.length() + 2 > iLineLen)
{
ostr << std::endl;
iCurrentLen = 0;
}
- ostr << it->first << " ";
- iCurrentLen += it->first.length() + 2;
+ ostr << macro.first << " ";
+ iCurrentLen += macro.first.length() + 2;
}
ostr << std::endl;
std::list<std::wstring>* Library::getMacrosName()
{
std::list<std::wstring>* pOut = new std::list<std::wstring>;
- MacroMap::iterator it = m_macros.begin();
- for (; it != m_macros.end() ; ++it)
+ for (auto macro : m_macros)
{
- pOut->push_back(it->first);
+ pOut->push_back(macro.first);
}
return pOut;
{
if (isDeletable() == true)
{
- std::vector<InternalType *>::iterator itValues;
- for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues)
+ for (auto data : *m_plData)
{
- (*itValues)->DecreaseRef();
- (*itValues)->killMe();
+ data->DecreaseRef();
+ data->killMe();
}
delete m_plData;
}
*/
List::List(List *_oListCopyMe)
{
- std::vector<InternalType *>::iterator itValues;
m_plData = new std::vector<InternalType *>;
for (int i = 0 ; i < (int)_oListCopyMe->getData()->size() ; i++)
{
wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
int iPosition = 1;
- std::vector<InternalType *>::iterator itValues;
- for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues, ++iPosition)
+ for (auto val : *m_plData)
{
std::wostringstream nextVarName;
ostr.str(L"");
- nextVarName << " " << SPACES_LIST << wcsVarName << L"(" << iPosition << L")";
+ nextVarName << " " << SPACES_LIST << wcsVarName << L"(" << iPosition++ << L")";
ostr << std::endl << nextVarName.str() << std::endl << std::endl;
scilabForcedWriteW(ostr.str().c_str());
- if (VariableToString(*itValues, nextVarName.str().c_str()) == types::Function::Error)
+ if (VariableToString(val, nextVarName.str().c_str()) == types::Function::Error)
{
free(wcsVarName);
ostr.str(L"");
int* piCountDim = new int[iDims];
int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
+ delete[] piMaxDim;
+ delete[] piCountDim;
if (iSeqCount == 0)
{
//free pArg content
//find FunctionDec
ast::FunctionDec* pFD = NULL;
- ast::exps_t::iterator j;
ast::exps_t LExp = tree->getAs<ast::SeqExp>()->getExps();
std::map<symbol::Symbol, Macro*> sub;
- for (j = LExp.begin() ; j != LExp.end() ; j++)
+ for (auto exp : LExp)
{
- if ((*j)->isFunctionDec() == false)
+ if (exp->isFunctionDec() == false)
{
continue;
}
- pFD = (*j)->getAs<ast::FunctionDec>();
+ pFD = exp->getAs<ast::FunctionDec>();
//get input parameters list
std::list<symbol::Variable*> *pVarList = new std::list<symbol::Variable*>();
ast::ArrayListVar *pListVar = pFD->getArgs().getAs<ast::ArrayListVar>();
ast::exps_t & vars = pListVar->getVars();
- for (ast::exps_t::const_iterator it = vars.begin(), itEnd = vars.end(); it != itEnd; ++it)
+ for (auto var : vars)
{
- pVarList->push_back((*it)->getAs<ast::SimpleVar>()->getStack());
+ pVarList->push_back(var->getAs<ast::SimpleVar>()->getStack());
}
//get output parameters list
std::list<symbol::Variable*> *pRetList = new std::list<symbol::Variable*>();
ast::ArrayListVar *pListRet = pFD->getReturns().getAs<ast::ArrayListVar>();
ast::exps_t & recs = pListRet->getVars();
- for (ast::exps_t::const_iterator it = recs.begin(), itEnd = recs.end(); it != itEnd; ++it)
+ for (auto rec : recs)
{
- pRetList->push_back((*it)->getAs<ast::SimpleVar>()->getStack());
+ pRetList->push_back(rec->getAs<ast::SimpleVar>()->getStack());
}
const symbol::Symbol & sym = pFD->getSymbol();
std::wstring wstError(pwstError);
FREE(pwstError);
FREE(pstFuncName);
- throw ast::ScilabError(wstError, 999, *new Location());
+ throw ast::ScilabError(wstError, 999, Location());
}
else
{
std::wstring wstError(pwstError);
FREE(pwstError);
FREE(pstFuncName);
- throw ast::ScilabError(wstError, 999, *new Location());
+ throw ast::ScilabError(wstError, 999, Location());
}
}
types::Callable *pCall = pIT->getAs<types::Callable>();
void Polynom::deleteAll()
{
- for (int i = 0 ; i < getSize() ; i++)
+ for (int i = 0 ; i < m_iSizeMax ; i++)
{
m_pRealData[i]->killMe();
}
{
if (isDeletable() == true)
{
- std::list<InternalType*>::iterator iterFieldData;
- for (iterFieldData = m_Data.begin(); iterFieldData != m_Data.end() ; iterFieldData++)
+ for (auto data : m_Data)
{
- (*iterFieldData)->DecreaseRef();
- (*iterFieldData)->killMe();
+ data->DecreaseRef();
+ data->killMe();
}
}
#ifndef NDEBUG
std::list<std::wstring> wstFields = _oSingleStructCopyMe->getFields();
std::list<InternalType *> Data = _oSingleStructCopyMe->getData();
- std::list<InternalType*>::iterator iterFieldData;
std::list<std::wstring>::iterator iterFieldName = wstFields.begin();
- for (iterFieldData = Data.begin(); iterFieldData != Data.end() ; iterFieldData++, iterFieldName++)
+ for (auto data : Data)
{
m_wstFields.push_back(*iterFieldName);
- m_Data.push_back(*iterFieldData);
+ m_Data.push_back(data);
m_Data.back()->IncreaseRef();
+ iterFieldName++;
}
#ifndef NDEBUG
Inspector::addItem(this);
int SingleStruct::getFieldIndex(const std::wstring& _field)
{
+ int idx = 0;
std::list<std::wstring>::iterator iterFieldNames = m_wstFields.begin();
- for (int idx = 0; iterFieldNames != m_wstFields.end() ; iterFieldNames++, idx++)
+ for (auto name : m_wstFields)
{
- if (*iterFieldNames == _field)
+ if (name == _field)
{
return idx;
}
+ idx++;
}
return -1;
String* SingleStruct::getFieldNames()
{
String* pOut = new String((int)m_wstFields.size(), 1);
- std::list<std::wstring>::iterator iterFieldNames = m_wstFields.begin();
-
- for (int i = 0 ; iterFieldNames != m_wstFields.end() ; iterFieldNames++, i++)
+ int i = 0;
+ for (auto name : m_wstFields)
{
- pOut->set(i, (*iterFieldNames).c_str());
+ pOut->set(i++, name.c_str());
}
return pOut;
}
p[i + size] = (double)(i / row) + 1;
}
create2(src.getRows(), src.getCols(), src, *idx);
- delete idx;
+ idx->killMe();
}
Sparse::Sparse(Double SPARSE_CONST& src, Double SPARSE_CONST& idx)
}
else
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
return NULL;
}
else
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
return NULL;
pOut->finalize();
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
p[i + size] = (double)(i / row) + 1;
}
create2(src.getRows(), src.getCols(), src, *idx);
+ idx->killMe();
}
/* @param src : Bool matrix to copy into a new sparse matrix
@param idx : Double matrix to use as indexes to get values from the src
finalize();
}
+SparseBool::~SparseBool()
+{
+ delete matrixBool;
+}
+
bool SparseBool::toString(std::wostringstream& ostr) const
{
ostr << ::toString(*matrixBool, 0);
cleanIndexesArguments(_pArgs, &pArg);
if (_pArgs->size() == 0)
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//a()
return this;
}
else
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//a([])
return Double::Empty();
}
}
else
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
return NULL;
}
else
{
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
return NULL;
finalize();
+ delete[] piMaxDim;
+ delete[] piCountDim;
//free pArg content
cleanIndexesArguments(_pArgs, &pArg);
create(piDims, 2, &pwsData, NULL);
for (int i = 0 ; i < m_iSize ; i++)
{
- set(i, os_wcsdup(_pstData[i]));
+ set(i, _pstData[i]);
}
#ifndef NDEBUG
Inspector::addItem(this);
{
if (isDeletable() == true)
{
- for (int i = 0 ; i < getSize() ; i++)
+ for (int i = 0 ; i < m_iSizeMax ; i++)
{
SingleStruct *pStr = m_pRealData[i];
if (pStr)
wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
int iPosition = 1;
const wchar_t * wcsDesc[7] = {L" (state-space system:)", L"= A matrix =", L"= B matrix =", L"= C matrix =", L"= D matrix =", L"= X0 (initial state) =", L"= Time domain ="};
- std::vector<InternalType *>::iterator itValues;
- for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues, ++iPosition)
+ for (auto val : *m_plData)
{
std::wostringstream nextVarName;
ostr.str(L"");
nextVarName << " " << wcsVarName << L"(" << iPosition << L")";
ostr << std::endl << nextVarName.str() << wcsDesc[iPosition - 1] << std::endl << std::endl;
scilabWriteW(ostr.str().c_str());
- VariableToString(*itValues, nextVarName.str().c_str());
+ VariableToString(val, nextVarName.str().c_str());
+ iPosition++;
}
ostr.str(L"");
free(wcsVarName);
#include "localization.h"
#include "charEncoding.h"
}
-
-
-int mint(int *tab, int length)
-{
- int ret = *tab;
- for (int i = 1; i < length ; i++)
- {
- if (ret > tab[i])
- {
- ret = tab[i];
- }
- }
- return ret;
-}
-
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_eye(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
{
if (in[1]->isDouble() == false)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), "matrix", 2);
return types::Function::Error;
}
if (pDblNewSize->isComplex())
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), "matrix", 2);
return types::Function::Error;
}
}
else
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong value for input argument #%d : Only one value can be equal to %d.\n"), "matrix", 2, -1);
return types::Function::Error;
}
}
else if (piSizes[i] < -1)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong value for input argument #%d : At most %d expected.\n"), "matrix", 2, -1);
return types::Function::Error;
}
}
else
{
- iDims = in.size() - 1;
+ iDims = static_cast<int>(in.size()) - 1;
piSizes = new int[iDims];
for (int i = 1; i < in.size(); i++)
{
if (in[i]->isDouble() == false)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), "matrix", i + 1);
return types::Function::Error;
}
if (pDblNewSize->isComplex() || pDblNewSize->isScalar() == false)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong type for input argument #%d : A real scalar expected.\n"), "matrix", i + 1);
return types::Function::Error;
}
}
else
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong value for input argument #%d : Only one value can be equal to %d.\n"), "matrix", i + 1, -1);
return types::Function::Error;
}
}
else if (piSizes[i - 1] < -1)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong value for input argument #%d : At most %d expected.\n"), "matrix", i + 1, -1);
return types::Function::Error;
}
if (pGTOut->isSparse() && iDims > 2)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Wrong value for input argument(s) : Sparse matrix cannot be reshaped beyond %d dimensions.\n"), "matrix", 2);
return types::Function::Error;
}
if (bOk == false)
{
+ pGTOut->killMe();
Scierror(999, _("%s: Input and output matrices must have the same number of elements.\n"), "matrix");
return types::Function::Error;
}
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, types::typed_list &out, const char* fname)
{
- int iCountElem = in.size();
+ int iCountElem = static_cast<int>(in.size());
int iDims = 0;
int* piDimsArray = NULL;
int iOrientation = 0;
return types::Function::Error;
}
+ bool isNotDouble = true;
/***** get data *****/
if (in[0]->isDouble()) // double
{
pDblIn = in[0]->getAs<types::Double>();
+ isNotDouble = false;
}
else if (in[0]->isBool()) // bool
{
if (pDbl->isScalar() == false)
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "prod", 2);
return types::Function::Error;
}
if (iOrientation <= 0)
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "prod", 2);
return types::Function::Error;
}
if (pStr->isScalar() == false)
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "prod", 2);
return types::Function::Error;
}
pstrExpected = "\"*\",\"r\",\"c\",\"m\"";
}
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "prod", 2, pstrExpected);
return types::Function::Error;
}
}
else
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix or a string expected.\n"), "prod", 2);
return types::Function::Error;
}
{
if (in[2]->isString() == false)
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "prod", 3);
return types::Function::Error;
}
if (pStr->isScalar() == false)
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "prod", 3);
return types::Function::Error;
}
}
else
{
+ if (isNotDouble && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: %s or %s expected.\n"), "prod", 3, "\"native\"", "\"double\"");
return types::Function::Error;
}
out.push_back(types::Double::Empty());
}
- if (in[0]->isDouble() == false)
+ if (isNotDouble)
{
delete pDblIn;
pDblIn = NULL;
if (iOrientation > pDblIn->getDims())
{
- if (in[0]->isDouble())
+ if (isNotDouble)
{
- pDblOut = pDblIn->clone()->getAs<types::Double>();
+ pDblOut = pDblIn;
}
else
{
- pDblOut = pDblIn;
+ pDblOut = pDblIn->clone()->getAs<types::Double>();
}
}
else
{
pDblOut = prod(pDblIn, iOrientation);
- if (in[0]->isDouble() == false)
+ if (isNotDouble)
{
delete pDblIn;
pDblIn = NULL;
}
/***** set result *****/
- if ((iOuttype == 1) && (in[0]->isDouble() == false))
+ if ((iOuttype == 1) && isNotDouble)
{
if (in[0]->isBool())
{
}
out.push_back(pIOut);
}
+
+ if (pDblOut)
+ {
+ pDblOut->killMe();
+ }
}
else
{
return types::Function::Error;
}
+ bool isCopy = true;
/***** get data *****/
if (in[0]->isDouble()) // double
{
pDblIn = in[0]->getAs<types::Double>();
+ isCopy = false;
}
else if (in[0]->isBool()) // bool
{
{
ast::ExecVisitor exec;
std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_sum";
- return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
+ types::Function::ReturnValue ret = Overload::call(wstFuncName, in, _iRetCount, out, &exec);
+
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
+ return ret;
}
if (in.size() >= 2)
if (pDbl->isScalar() == false)
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "sum", 2);
return types::Function::Error;
}
if (iOrientation <= 0)
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: A positive scalar expected.\n"), "sum", 2);
return types::Function::Error;
}
if (pStr->isScalar() == false)
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "sum", 2);
return types::Function::Error;
}
pstrExpected = "\"*\",\"r\",\"c\",\"m\"";
}
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "sum", 2, pstrExpected);
return types::Function::Error;
}
}
else
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix or a string expected.\n"), "sum", 2);
return types::Function::Error;
}
{
if (in[2]->isString() == false)
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "sum", 3);
return types::Function::Error;
}
if (pStr->isScalar() == false)
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong size for input argument #%d: A scalar string expected.\n"), "sum", 3);
return types::Function::Error;
}
}
else
{
+ if (isCopy && pDblIn)
+ {
+ pDblIn->killMe();
+ }
+
Scierror(999, _("%s: Wrong value for input argument #%d: %s or %s expected.\n"), "sum", 3, "\"native\"", "\"double\"");
return types::Function::Error;
}
out.push_back(Double::Empty());
}
- if (in[0]->isDouble() == false)
+ if (isCopy)
{
- delete pDblIn;
- pDblIn = NULL;
+ pDblIn->killMe();
}
+
return types::Function::OK;
}
else if (iOrientation > pDblIn->getDims())
{
- if (in[0]->isDouble())
- {
- pDblOut = pDblIn->clone()->getAs<types::Double>();
- }
- else
- {
- pDblOut = pDblIn;
- }
+ pDblOut = pDblIn;
if (in[0]->isBool() == false)
{
else
{
pDblOut = sum(pDblIn, iOrientation);
- if (in[0]->isDouble() == false)
+ if (isCopy)
{
- delete pDblIn;
- pDblIn = NULL;
+ pDblIn->killMe();
}
}
}
iOuttype = 1;
if (iOrientation > pPolyIn->getDims())
{
- pPolyOut = pPolyIn->clone()->getAs<types::Polynom>();
+ pPolyOut = pPolyIn->getAs<types::Polynom>();
}
else
{
}
/***** set result *****/
- if ((iOuttype == 1) && (in[0]->isDouble() == false))
+ if ((iOuttype == 1) && isCopy)
{
if (in[0]->isBool())
{
{
pDblOut->get(i) ? pBOut->set(i, 1) : pBOut->set(i, 0);
}
+
out.push_back(pBOut);
}
else if (in[0]->isPoly())
{
pIOut->set(i, static_cast<char>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isInt16())
{
pIOut->set(i, static_cast<short int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isInt32())
{
pIOut->set(i, static_cast<int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isInt64())
{
pIOut->set(i, static_cast<long long int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isUInt8())
{
pIOut->set(i, static_cast<unsigned char>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isUInt16())
{
pIOut->set(i, static_cast<unsigned short int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isUInt32())
{
pIOut->set(i, static_cast<unsigned int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
else if (in[0]->isUInt64())
{
pIOut->set(i, static_cast<unsigned long long int>(pDblOut->get(i)));
}
+
out.push_back(pIOut);
}
+
+ if (pDblOut)
+ {
+ pDblOut->killMe();
+ }
}
else
{
{
pOut = pIn->clone()->getAs<types::Double>();
double* pdblOutR = pOut->get();
- if (wstrWay == L"i")
- {
- std::sort(pdblOutR, pdblOutR + pOut->getSize(), (*pFuncWayBasic));
- }
- else // strWay == L"d"
- {
- std::sort(pdblOutR, pdblOutR + pOut->getSize(), (*pFuncWayBasic));
- }
+ std::sort(pdblOutR, pdblOutR + pOut->getSize(), (*pFuncWayBasic));
}
else if (wstrProcess == L"c")
{
// transpose input in output
vTransposeRealMatrix(pdblInR, pIn->getRows(), pIn->getCols(), pdblOutR);
- // sort output
- if (wstrWay == L"i")
- {
- for (int i = 0; i < iTimes; i++)
- {
- std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
- }
- }
- else // strWay == L"d"
+ for (int i = 0; i < iTimes; i++)
{
- for (int i = 0; i < iTimes; i++)
- {
- std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
- }
+ std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
}
// transpose output
pOut = pIn->clone()->getAs<types::Double>();
double* pdblOutR = pOut->get();
- if (wstrWay == L"i")
- {
- for (int i = 0; i < iTimes; i++)
- {
- std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
- }
- }
- else // strWay == L"d"
+ for (int i = 0; i < iTimes; i++)
{
- for (int i = 0; i < iTimes; i++)
- {
- std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
- }
+ std::sort(pdblOutR + (iItem * i), pdblOutR + (iItem * (i + 1)), (*pFuncWayBasic));
}
}
}
/*--------------------------- String ---------------------------------------*/
types::String* gsort(types::String* pIn, types::Double* pDblInd, std::wstring wstrWay, std::wstring wstrProcess)
{
- types::String* pOut = new types::String(pIn->getDims(), pIn->getDimsArray());
+ types::String* pOut = nullptr;
int iTimes = 1;
int iItem = 0;
{
if (pDblInd)
{
+ pOut = new types::String(pIn->getDims(), pIn->getDimsArray());
+
std::vector<std::pair<int, wchar_t*> > V;
std::vector<std::pair<int, wchar_t*> >::iterator it;
}
else// wstrProcess == L"lr" and wstrProcess == L"lc"
{
+ pOut = new types::String(pIn->getDims(), pIn->getDimsArray());
std::vector<std::pair<int, std::pair<wchar_t**, wchar_t**> > > V;
std::vector<std::pair<int, std::pair<wchar_t**, wchar_t**> > >::iterator it;
int iIndex = pDblRanksOut->getIndex(piIndex);
pdblOut[iIndex] += pdblIn[i];
}
+ pDblRanks->killMe();
// move output ranks from types::Double to int*
int* piRankMax = new int[pDblRanksOut->getSize()];
iMaxOutputRank = std::max(iMaxOutputRank, piRankMax[i]);
}
+ pDblRanksOut->killMe();
// create the outpout polynom
pOut = new types::Polynom(pIn->getVariableName(), iDims, piDims, piRankMax);
pOut->setComplex(pIn->isComplex());
}
}
}
+
+ delete[] piRanks;
}
else // sum on one dimension
{
int iIndex = pDblRanksOut->getIndex(piIndex);
pdblOut[iIndex] = std::max(pdblOut[iIndex], pdblIn[i]);
}
+
+ pDblRanks->killMe();
// move output ranks from types::Double to int*
int* piRankMax = new int[pDblRanksOut->getSize()];
piRankMax[i] = static_cast<int>(pdblOut[i]);
}
+ pDblRanksOut->killMe();
+
// create the outpout polynom
pOut = new types::Polynom(pIn->getVariableName(), iDims, piDims, piRankMax);
+ delete[] piRankMax;
pOut->setComplex(pIn->isComplex());
pOut->setZeros();
//================================ Matrix of string case ===========================================
N = 4;
P = 20;
-a = int(10*rand(N,P,'u'));
+a = int(10*rand(N,P,"u"));
//-----Global sort
-[a1,ind] = gsort(string(a),'g');
-[a2,ind2] = gsort(a,'g');
+[a1,ind] = gsort(string(a),"g");
+[a2,ind2] = gsort(a,"g");
assert_checkalmostequal(norm(evstr(a1)- matrix(a(ind),N,P)), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
//-- rows
-[a1,ind1]=gsort(string(a),'r');
-[a2,ind2]=gsort(a,'r');
+[a1,ind1]=gsort(string(a),"r");
+[a2,ind2]=gsort(a,"r");
assert_checkalmostequal(norm(ind1-ind2), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
//--columns
-[a1,ind1] = gsort(string(a),'c');
-[a2,ind2] = gsort(a,'c');
+[a1,ind1] = gsort(string(a),"c");
+[a2,ind2] = gsort(a,"c");
assert_checkalmostequal(norm(ind1-ind2), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = alr(perm,:);
-[a1,ind] = gsort(string(a),'lr');
-[a2,ind] = gsort(a,'lr') ;
+[a1,ind] = gsort(string(a),"lr");
+[a2,ind] = gsort(a,"lr") ;
assert_checkalmostequal(norm(evstr(a1)- matrix(a(ind,:),N1,P1)), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = alr(:,perm);
-[a1,ind] = gsort(string(a),'lc');
-[a2,ind] = gsort(a,'lc') ;
+[a1,ind] = gsort(string(a),"lc");
+[a2,ind] = gsort(a,"lc") ;
assert_checkalmostequal(norm(evstr(a1)- matrix(a(:,ind),N1,P1)), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
//================================ Matrix of double case ===========================================
N = 4;P = 20;Nrand = 100;
-a = matrix(grand(1,'prm',(1:N*P)'),N,P);
+a = matrix(grand(1,"prm",(1:N*P)'),N,P);
//-----Global sort --------------------------------
-[a1,ind]=gsort(a,'g');
+[a1,ind]=gsort(a,"g");
assert_checkalmostequal(norm(a1- matrix(N*P:-1:1,N,P)), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(ind),N,P)), %eps, [], %eps);
for i=1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkalmostequal(norm(b1- matrix(b(ind),N,P)), %eps, [], %eps);
assert_checktrue(or(b1(1:$-1)-b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkalmostequal(norm(a1- matrix(1:N*P,N,P)), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(ind),N,P)), %eps, [], %eps);
for i=1:100
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkalmostequal(norm(b1- matrix(b(ind),N,P)), %eps, [], %eps);
assert_checktrue(or(b1(1:$-1)-b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc;
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
test = [];
for i = 1:nc;
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
for i = 1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
assert_checkalmostequal(norm(b1- test), %eps, [], %eps);
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
for i = 1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checkequal(or(b1(:,2:$) - b1(:,1:$-1) > 0), %f);
test = [];
for j = 1:nr
assert_checkalmostequal(norm(b1- test), %eps, [], %eps);
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1, N1, 'u'));
+[ax,perm] = gsort(rand(1, N1, "u"));
a = alr(perm,:);
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkalmostequal(norm(a1 - alr), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(ind,:),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkalmostequal(norm(b1 - b(ind,:)), %eps, [], %eps);
v = b1 * ((vmax + 1) ^ [P - 1 : -1 : 0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkalmostequal(norm(a1 - alr(N1:-1:1,:)), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(ind,:),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort(a * [100;10;1],'g','i');
+[a2,ind2] = gsort(a * [100;10;1],"g","i");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkalmostequal(norm(b1 - b(ind,:)), %eps, [], %eps);
v= b1*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = alr(:,perm);
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkalmostequal(norm(a1 - alr), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(:,ind),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkalmostequal(norm(b1 - b(:,ind)), %eps, [], %eps);
v = ((vmax+1)^[N1-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkalmostequal(norm(a1 - alr(:,P1:-1:1)), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(:,ind),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkalmostequal(norm(b1 - b(:,ind)), %eps, [], %eps);
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
//================================ Matrix of int32 or uint32 case =======================================
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int32(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int32(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int32(matrix(N * P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int32(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int32(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int32(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:100
- b = int32(10*rand(N,P,'u'));
- [b1,ind]=gsort(b,'g','i');
+ b = int32(10*rand(N,P,"u"));
+ [b1,ind]=gsort(b,"g","i");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i =1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int32(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int32(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
assert_checkequal(b1, test);
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int32(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int32(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checkequal(or(b1(:,2:$) - b1(:,1:$-1) > 0), %f);
test = [];
for j = 1:nr
assert_checkequal(b1, test);
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int32(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int32(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int32(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int32(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int32(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int32(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int32(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int32(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
// Copyright Inria
// test of gsort for int16 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int16(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int16(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int16(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind]=gsort(b,'g');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind]=gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int16(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:100
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkequal(b1, int16(matrix(b(ind),N,P)));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checktrue(or( b1(2:$,:) - b1(1:$-1,:) <= 0));
test = [];
for j = 1:nc
assert_checkequal(b1, test);
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test =[];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c') ;
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c") ;
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checktrue(or(b1(:,2:$) - b1(:,1:$-1) <= 0));
test = [];
for j = 1:nr
assert_checkequal(b1, test);
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int16(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int16(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g');
+[a2,ind2]=gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int16(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int16(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int16(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int16(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int16(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int16(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
//================================ Matrix of int8 or uint8 case =======================================
// test of gsort for int8 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int8(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int8(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int8(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int8(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
assert_checkequal(b1, test);
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test =[];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, int8(test));
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checktrue(or(b1(:,2:$) - b1(:,1:$-1) <= 0));
test = [];
for j = 1:nr
assert_checkequal(b1, test);
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int8(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int8(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int8(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int8(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int8(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g','i');
+[a2,ind2]=gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int8(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int8(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2]=gsort([100,10,1]*a,'g');
+[a2,ind2]=gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int8(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2]=gsort([100,10,1]*a,'g','i');
+[a2,ind2]=gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind]=gsort(a,'lr','d');
+[b,ind]=gsort(a,"lr","d");
t=b(1:$-1,:)-b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint32(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint32(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint32(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint32(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint32(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint32(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc ;
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc ;
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint32(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint32(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g');
+[a2,ind2]=gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint32(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint32(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint32(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g','i');
+[a2,ind2]=gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint32(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint32(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint32(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:),b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
// test of gsort for uuint16 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint16(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint16(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint16(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint16(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint16(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint16(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint16(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint16(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a * [100;10;1],'g');
+[a2,ind2] = gsort(a * [100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint16(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint16(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint16(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a * [100;10;1],'g','i');
+[a2,ind2] = gsort(a * [100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1) * ((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint16(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint16(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g');
+[a2,ind2] = gsort([100,10,1] * a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N1-1:-1:0]) * double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint16(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
vmax = 4;
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
////////////////////////////////////////////////////////////////////////
// test of gsort for uint8 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint8(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint8(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint8(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1)-b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint8(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr;
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
//----sort the rows of a in lexicographic order
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint8(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint8(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint8(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint8(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint8(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint8(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint8(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint8(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:),b);
end
-[b,ind]=gsort(a,'lr','d');
+[b,ind]=gsort(a,"lr","d");
t=b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
end
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
//testing gsort with Nan's
-b = gsort([1 2 %nan 3 4],'g','i');
+b = gsort([1 2 %nan 3 4],"g","i");
assert_checkequal(b(1:4), (1:4));
assert_checkequal(find(isnan(b)), 5);
-b = gsort([1 2 %nan 1 3 ],'g','i');
+b = gsort([1 2 %nan 1 3 ],"g","i");
assert_checkequal(b(1:4), [1 1 2 3]);
assert_checkequal(find(isnan(b)), 5);
-b = gsort([1 2 %nan 1 3 ],'g','d');
+b = gsort([1 2 %nan 1 3 ],"g","d");
assert_checkequal(b(2:$), [3 2 1 1]);
assert_checkequal(find(isnan(b)), 1);
-b = gsort([1 2 %nan 1 3 %nan 2 3],'g','d');
+b = gsort([1 2 %nan 1 3 %nan 2 3],"g","d");
assert_checkequal(b(3:$), [3,3,2,2,1,1]);
assert_checkequal(find(isnan(b)), [1 2]);
-b = gsort([1 2 %nan 1 3 %nan 2 3],'g','i');
+b = gsort([1 2 %nan 1 3 %nan 2 3],"g","i");
assert_checkequal(b(1:$-2), [1,1,2,2,3,3]);
assert_checkequal(find(isnan(b)), [7 8]);
m = [1 2 %nan;1 3 %nan;1 2 3];
-b = gsort(m,'lr','i');
-assert_checkequal(sci2exp(b,0), '[1,2,3;1,2,%nan;1,3,%nan]');
-b = gsort(m,'lr','d');
-assert_checkequal(sci2exp(b,0), '[1,3,%nan;1,2,%nan;1,2,3]');
+b = gsort(m,"lr","i");
+assert_checkequal(sci2exp(b,0), "[1,2,3;1,2,%nan;1,3,%nan]");
+b = gsort(m,"lr","d");
+assert_checkequal(sci2exp(b,0), "[1,3,%nan;1,2,%nan;1,2,3]");
m = m(:,[3 1 2]);
-b = gsort(m,'lc','i');
-assert_checkequal(sci2exp(b,0), '[1,2,%nan;1,3,%nan;1,2,3]');
-b = gsort(m,'lc','d');
-assert_checkequal(sci2exp(b,0), '[%nan,2,1;%nan,3,1;3,2,1]');
+b = gsort(m,"lc","i");
+assert_checkequal(sci2exp(b,0), "[1,2,%nan;1,3,%nan;1,2,3]");
+b = gsort(m,"lc","d");
+assert_checkequal(sci2exp(b,0), "[%nan,2,1;%nan,3,1;3,2,1]");
//testing gsort with Inf's
-b = gsort([1 2 %inf 3 4],'g','i');
+b = gsort([1 2 %inf 3 4],"g","i");
assert_checkequal(b(1:4), (1:4));
assert_checkequal(find(isinf(b)), 5);
-b=gsort([1 2 %inf 1 3 ],'g','i');
+b=gsort([1 2 %inf 1 3 ],"g","i");
assert_checkequal(b(1:4), [1 1 2 3]);
assert_checkequal(find(isinf(b)), 5);
-b=gsort([1 2 %inf 1 3 ],'g','d');
+b=gsort([1 2 %inf 1 3 ],"g","d");
assert_checkequal(b(2:$), [3 2 1 1]);
assert_checkequal(find(isinf(b)), 1);
-b=gsort([1 2 %inf 1 3 %inf 2 3],'g','d');
+b=gsort([1 2 %inf 1 3 %inf 2 3],"g","d");
assert_checkequal(b(3:$), [3,3,2,2,1,1]);
assert_checkequal(find(isinf(b)), [1 2]);
-b=gsort([1 2 %inf 1 3 %inf 2 3],'g','i');
+b=gsort([1 2 %inf 1 3 %inf 2 3],"g","i");
assert_checkequal(b(1:$-2), [1,1,2,2,3,3]);
assert_checkequal(find(isinf(b)), [7 8]);
m = [1 2 %inf;1 3 %inf;1 2 3];
-b = gsort(m,'lr','i');
-assert_checkequal(sci2exp(b,0), '[1,2,3;1,2,%inf;1,3,%inf]');
-b = gsort(m,'lr','d');
-assert_checkequal(sci2exp(b,0), '[1,3,%inf;1,2,%inf;1,2,3]');
+b = gsort(m,"lr","i");
+assert_checkequal(sci2exp(b,0), "[1,2,3;1,2,%inf;1,3,%inf]");
+b = gsort(m,"lr","d");
+assert_checkequal(sci2exp(b,0), "[1,3,%inf;1,2,%inf;1,2,3]");
m = m(:,[3 1 2]);
-b = gsort(m,'lc','i');
-assert_checkequal(sci2exp(b,0), '[1,2,%inf;1,3,%inf;1,2,3]');
-b = gsort(m,'lc','d');
-assert_checkequal(sci2exp(b,0), '[%inf,2,1;%inf,3,1;3,2,1]');
+b = gsort(m,"lc","i");
+assert_checkequal(sci2exp(b,0), "[1,2,%inf;1,3,%inf;1,2,3]");
+b = gsort(m,"lc","d");
+assert_checkequal(sci2exp(b,0), "[%inf,2,1;%inf,3,1;3,2,1]");
//gsort
a = [5 1 3 2 4];
assert_checkequal(gsort(a), [5 4 3 2 1]);
assert_checkequal(k, [1 5 3 4 2]);
assert_checkequal(s, [5 4 3 2 1]);
a = string([5 1 3 2 4]);
-assert_checkequal(gsort(a,'g','i'), string(1:5));
-[s,k]=gsort(a,'g','i');
+assert_checkequal(gsort(a,"g","i"), string(1:5));
+[s,k]=gsort(a,"g","i");
assert_checkequal(k, [2 4 3 5 1]);
assert_checkequal(s, string(1:5));
a = [];
b = [5 1 3 2 4;6 1 2 4 1];
B = sparse(b);
// opts = 'r' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'r','d');
-[s1,k1] = gsort(B(:),'r','d');
+[s,k] = gsort(b(:),"r","d");
+[s1,k1] = gsort(B(:),"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'r','i');
-[s1,k1] = gsort(B(:),'r','i');
+[s,k] = gsort(b(:),"r","i");
+[s1,k1] = gsort(B(:),"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','r','d');
-[s1,k1] = gsort(B(:)','r','d');
+[s,k] = gsort(b(:)',"r","d");
+[s1,k1] = gsort(B(:)',"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','r','i');
-[s1,k1] = gsort(B(:)','r','i');
+[s,k] = gsort(b(:)',"r","i");
+[s1,k1] = gsort(B(:)',"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'c' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'c','d');
-[s1,k1] = gsort(B(:),'c','d');
+[s,k] = gsort(b(:),"c","d");
+[s1,k1] = gsort(B(:),"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'c','i');
-[s1,k1] = gsort(B(:),'c','i');
+[s,k] = gsort(b(:),"c","i");
+[s1,k1] = gsort(B(:),"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','c','d');
-[s1,k1] = gsort(B(:)','c','d');
+[s,k] = gsort(b(:)',"c","d");
+[s1,k1] = gsort(B(:)',"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','c','i');
-[s1,k1] = gsort(B(:)','c','i');
+[s,k] = gsort(b(:)',"c","i");
+[s1,k1] = gsort(B(:)',"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'g' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'g','d');
-[s1,k1] = gsort(B(:),'g','d');
+[s,k] = gsort(b(:),"g","d");
+[s1,k1] = gsort(B(:),"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'g','i');
-[s1,k1] = gsort(B(:),'g','i');
+[s,k] = gsort(b(:),"g","i");
+[s1,k1] = gsort(B(:),"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','g','d');
-[s1,k1] = gsort(B(:)','g','d');
+[s,k] = gsort(b(:)',"g","d");
+[s1,k1] = gsort(B(:)',"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','g','i');
-[s1,k1] = gsort(B(:)','g','i');
+[s,k] = gsort(b(:)',"g","i");
+[s1,k1] = gsort(B(:)',"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'lr' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'lr','d');
-[s1,k1] = gsort(B(:),'lr','d');
+[s,k] = gsort(b(:),"lr","d");
+[s1,k1] = gsort(B(:),"lr","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'lr','i');
-[s1,k1] = gsort(B(:),'lr','i');
+[s,k] = gsort(b(:),"lr","i");
+[s1,k1] = gsort(B(:),"lr","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lr','d');
-[s1,k1] = gsort(B(:)','lr','d');
+[s,k] = gsort(b(:)',"lr","d");
+[s1,k1] = gsort(B(:)',"lr","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lr','i');
-[s1,k1] = gsort(B(:)','lr','i');
+[s,k] = gsort(b(:)',"lr","i");
+[s1,k1] = gsort(B(:)',"lr","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'lc' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'lc','d');
-[s1,k1] = gsort(B(:),'lc','d');
+[s,k] = gsort(b(:),"lc","d");
+[s1,k1] = gsort(B(:),"lc","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'lc','i');
-[s1,k1] = gsort(B(:),'lc','i');
+[s,k] = gsort(b(:),"lc","i");
+[s1,k1] = gsort(B(:),"lc","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lc','d');
-[s1,k1] = gsort(B(:)','lc','d');
+[s,k] = gsort(b(:)',"lc","d");
+[s1,k1] = gsort(B(:)',"lc","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lc','i');
-[s1,k1] = gsort(B(:)','lc','i');
+[s,k] = gsort(b(:)',"lc","i");
+[s1,k1] = gsort(B(:)',"lc","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// gsort with complex sparses :
A = [1 -%i;%i 0];
A1 = sparse(A);
-c = gsort(A(:),'g','d');
-d = full(gsort(A1(:),'g','d'));
+c = gsort(A(:),"g","d");
+d = full(gsort(A1(:),"g","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'g','i');
-d = full(gsort(A1(:),'g','i'));
+c = gsort(A(:),"g","i");
+d = full(gsort(A1(:),"g","i"));
assert_checkequal(c,d);
-c = gsort(A(:),'r','d');
-d = full(gsort(A1(:),'r','d'));
+c = gsort(A(:),"r","d");
+d = full(gsort(A1(:),"r","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'r','i');
-d = full(gsort(A1(:),'r','i'));
+c = gsort(A(:),"r","i");
+d = full(gsort(A1(:),"r","i"));
assert_checkequal(c,d);
-c = gsort(A(:),'c','d');
-d = full(gsort(A1(:),'c','d'));
+c = gsort(A(:),"c","d");
+d = full(gsort(A1(:),"c","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'c','i');
-d = full(gsort(A1(:),'c','i'));
+c = gsort(A(:),"c","i");
+d = full(gsort(A1(:),"c","i"));
assert_checkequal(c,d);
B = [1 1+%i 4; -2*%i 3 3-%i];
B1 = sparse(B);
-c = gsort(B(:),'g','d');
-d = full(gsort(B1(:),'g','d'));
+c = gsort(B(:),"g","d");
+d = full(gsort(B1(:),"g","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'g','i');
-d = full(gsort(B1(:),'g','i'));
+c = gsort(B(:),"g","i");
+d = full(gsort(B1(:),"g","i"));
assert_checkequal(c,d);
-c = gsort(B(:),'r','d');
-d = full(gsort(B1(:),'r','d'));
+c = gsort(B(:),"r","d");
+d = full(gsort(B1(:),"r","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'r','i');
-d = full(gsort(B1(:),'r','i'));
+c = gsort(B(:),"r","i");
+d = full(gsort(B1(:),"r","i"));
assert_checkequal(c,d);
-c = gsort(B(:),'c','d');
-d = full(gsort(B1(:),'c','d'));
+c = gsort(B(:),"c","d");
+d = full(gsort(B1(:),"c","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'c','i');
-d = full(gsort(B1(:),'c','i'));
+c = gsort(B(:),"c","i");
+d = full(gsort(B1(:),"c","i"));
assert_checkequal(c,d);
C = [-%i 3*%i;4 9;-2*%i 7];
C1 = sparse(C);
-[s,k] = gsort(C(:),'g','d');
-[s1,k1] = gsort(C1(:),'g','d');
+[s,k] = gsort(C(:),"g","d");
+[s1,k1] = gsort(C1(:),"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'g','i');
-[s1,k1] = gsort(C1(:),'g','i');
+[s,k] = gsort(C(:),"g","i");
+[s1,k1] = gsort(C1(:),"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'r','d');
-[s1,k1] = gsort(C1(:),'r','d');
+[s,k] = gsort(C(:),"r","d");
+[s1,k1] = gsort(C1(:),"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'r','i');
-[s1,k1] = gsort(C1(:),'r','i');
+[s,k] = gsort(C(:),"r","i");
+[s1,k1] = gsort(C1(:),"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'c','d');
-[s1,k1] = gsort(C1(:),'c','d');
+[s,k] = gsort(C(:),"c","d");
+[s1,k1] = gsort(C1(:),"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'c','i');
-[s1,k1] = gsort(C1(:),'c','i');
+[s,k] = gsort(C(:),"c","i");
+[s1,k1] = gsort(C1(:),"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
//================================ hypermatrix ================================================
hs = gsort(A);
assert_checkequal(hs(:), s);
// 'c' 'r' 'lc' 'lr'
-[hsc hindc] = gsort(A, 'c');
-[hsr hindr] = gsort(A, 'r');
-[hslc hindlc] = gsort(A, 'lc');
-[hslr hindlr] = gsort(A, 'lr');
+[hsc hindc] = gsort(A, "c");
+[hsr hindr] = gsort(A, "r");
+[hslc hindlc] = gsort(A, "lc");
+[hslr hindlr] = gsort(A, "lr");
a = matrix(A, 6, 4, 16); // 2 * 8 = 16
sc = zeros(a);
indc = zeros(a);
slr = zeros(a);
indlr = zeros(6, 1, 16);
for i = 1:16
- [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),'c');
- [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),'r');
- [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),'lc');
- [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),'lr');
+ [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),"c");
+ [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),"r");
+ [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),"lc");
+ [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),"lr");
end
sc = matrix(sc, 6, 4, 2, 8);
indc = matrix(indc, 6, 4, 2, 8);
assert_checkequal(hslr, slr);
assert_checkequal(hindlr, indlr);
// whitout indices
-hsc = gsort(A, 'c');
-hsr = gsort(A, 'r');
-hslc = gsort(A, 'lc');
-hslr = gsort(A, 'lr');
+hsc = gsort(A, "c");
+hsr = gsort(A, "r");
+hslc = gsort(A, "lc");
+hslr = gsort(A, "lr");
assert_checkequal(hsc, sc);
assert_checkequal(hsr, sr);
assert_checkequal(hslc, slc);
assert_checkequal(hslr, slr);
// ----- increasing -----
// 'g'
-[hs hind] = gsort(A, 'g', 'i');
-[s ind] = gsort(A(:), 'g', 'i');
+[hs hind] = gsort(A, "g", "i");
+[s ind] = gsort(A(:), "g", "i");
assert_checkequal(hs(:), s);
assert_checkequal(hind(:), ind);
-hs = gsort(A, 'g', 'i');
+hs = gsort(A, "g", "i");
assert_checkequal(hs(:), s);
// 'c' 'r' 'lc' 'lr'
-[hsc hindc] = gsort(A, 'c', 'i');
-[hsr hindr] = gsort(A, 'r', 'i');
-[hslc hindlc] = gsort(A, 'lc', 'i');
-[hslr hindlr] = gsort(A, 'lr', 'i');
+[hsc hindc] = gsort(A, "c", "i");
+[hsr hindr] = gsort(A, "r", "i");
+[hslc hindlc] = gsort(A, "lc", "i");
+[hslr hindlr] = gsort(A, "lr", "i");
a = matrix(A, 6, 4, 16); // 2 * 8 = 16
sc = zeros(a);
indc = zeros(a);
slr = zeros(a);
indlr = zeros(6, 1, 16);
for i = 1:16
- [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),'c', 'i');
- [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),'r', 'i');
- [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),'lc', 'i');
- [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),'lr', 'i');
+ [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),"c", "i");
+ [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),"r", "i");
+ [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),"lc", "i");
+ [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),"lr", "i");
end
sc = matrix(sc, 6, 4, 2, 8);
indc = matrix(indc, 6, 4, 2, 8);
assert_checkequal(hslr, slr);
assert_checkequal(hindlr, indlr);
// whitout indices
-hsc = gsort(A, 'c', 'i');
-hsr = gsort(A, 'r', 'i');
-hslc = gsort(A, 'lc', 'i');
-hslr = gsort(A, 'lr', 'i');
+hsc = gsort(A, "c", "i");
+hsr = gsort(A, "r", "i");
+hslc = gsort(A, "lc", "i");
+hslr = gsort(A, "lr", "i");
assert_checkequal(hsc, sc);
assert_checkequal(hsr, sr);
assert_checkequal(hslc, slc);
//================================ Matrix of string case ===========================================
N = 4;
P = 20;
-a = int(10*rand(N,P,'u'));
+a = int(10*rand(N,P,"u"));
//-----Global sort
-[a1,ind] = gsort(string(a),'g');
-[a2,ind2] = gsort(a,'g');
+[a1,ind] = gsort(string(a),"g");
+[a2,ind2] = gsort(a,"g");
assert_checkalmostequal(norm(evstr(a1)- matrix(a(ind),N,P)), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
assert_checkalmostequal(norm(evstr(a1)- a2), %eps, [], %eps);
//-- rows
-[a1,ind1]=gsort(string(a),'r');
-[a2,ind2]=gsort(a,'r');
+[a1,ind1]=gsort(string(a),"r");
+[a2,ind2]=gsort(a,"r");
assert_checkalmostequal(norm(ind1-ind2), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
//--columns
-[a1,ind1] = gsort(string(a),'c');
-[a2,ind2] = gsort(a,'c');
+[a1,ind1] = gsort(string(a),"c");
+[a2,ind2] = gsort(a,"c");
assert_checkalmostequal(norm(ind1-ind2), %eps, [], %eps);
// a or string(a) are in the same order in the previous example
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = alr(perm,:);
-[a1,ind] = gsort(string(a),'lr');
-[a2,ind] = gsort(a,'lr') ;
+[a1,ind] = gsort(string(a),"lr");
+[a2,ind] = gsort(a,"lr") ;
assert_checkalmostequal(norm(evstr(a1)- matrix(a(ind,:),N1,P1)), %eps, [], %eps);
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = alr(:,perm);
-[a1,ind] = gsort(string(a),'lc');
-[a2,ind] = gsort(a,'lc') ;
+[a1,ind] = gsort(string(a),"lc");
+[a2,ind] = gsort(a,"lc") ;
assert_checkalmostequal(norm(evstr(a1)- matrix(a(:,ind),N1,P1)), %eps, [], %eps);
//================================ Matrix of double case ===========================================
N = 4;P = 20;Nrand = 100;
-a = matrix(grand(1,'prm',(1:N*P)'),N,P);
+a = matrix(grand(1,"prm",(1:N*P)'),N,P);
//-----Global sort --------------------------------
-[a1,ind]=gsort(a,'g');
+[a1,ind]=gsort(a,"g");
assert_checkalmostequal(norm(a1- matrix(N*P:-1:1,N,P)), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(ind),N,P)), %eps, [], %eps);
for i=1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkalmostequal(norm(b1- matrix(b(ind),N,P)), %eps, [], %eps);
assert_checktrue(or(b1(1:$-1)-b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkalmostequal(norm(a1- matrix(1:N*P,N,P)), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(ind),N,P)), %eps, [], %eps);
for i=1:100
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkalmostequal(norm(b1- matrix(b(ind),N,P)), %eps, [], %eps);
assert_checktrue(or(b1(1:$-1)-b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc;
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc;
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
for i = 1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
for i = 1:Nrand
- b = int(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checkequal(or(b1(:,2:$) - b1(:,1:$-1) > 0), %f);
test = [];
for j = 1:nr
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkalmostequal(norm(a1- test), %eps, [], %eps);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1, N1, 'u'));
+[ax,perm] = gsort(rand(1, N1, "u"));
a = alr(perm,:);
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkalmostequal(norm(a1 - alr), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(ind,:),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkalmostequal(norm(b1 - b(ind,:)), %eps, [], %eps);
v = b1 * ((vmax + 1) ^ [P - 1 : -1 : 0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkalmostequal(norm(a1 - alr(N1:-1:1,:)), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(ind,:),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort(a * [100;10;1],'g','i');
+[a2,ind2] = gsort(a * [100;10;1],"g","i");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkalmostequal(norm(b1 - b(ind,:)), %eps, [], %eps);
v= b1*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = alr(:,perm);
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkalmostequal(norm(a1 - alr), %eps, [], %eps);
assert_checkalmostequal(norm(a1- matrix(a(:,ind),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkalmostequal(norm(b1 - b(:,ind)), %eps, [], %eps);
v = ((vmax+1)^[N1-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkalmostequal(norm(a1 - alr(:,P1:-1:1)), %eps, [], %eps);
assert_checkalmostequal(norm(a1 - matrix(a(:,ind),N1,P1)), %eps, [], %eps);
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkalmostequal(norm(ind2 - ind), %eps, [], %eps);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkalmostequal(norm(b1 - b(:,ind)), %eps, [], %eps);
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
//================================ Matrix of int32 or uint32 case =======================================
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int32(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int32(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int32(matrix(N * P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int32(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int32(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int32(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:100
- b = int32(10*rand(N,P,'u'));
- [b1,ind]=gsort(b,'g','i');
+ b = int32(10*rand(N,P,"u"));
+ [b1,ind]=gsort(b,"g","i");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i =1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int32(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int32(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int32(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int32(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checkequal(or(b1(:,2:$) - b1(:,1:$-1) > 0), %f);
test = [];
for j = 1:nr
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int32(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int32(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int32(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int32(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int32(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int32(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int32(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int32(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
// test of gsort for int16 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int16(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int16(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int16(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind]=gsort(b,'g');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind]=gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int16(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:100
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkequal(b1, int16(matrix(b(ind),N,P)));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checktrue(or( b1(2:$,:) - b1(1:$-1,:) <= 0));
test = [];
for j = 1:nc
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test =[];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c') ;
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c") ;
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int16(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int16(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checktrue(or(b1(:,2:$) - b1(:,1:$-1) <= 0));
test = [];
for j = 1:nr
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int16(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int16(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g');
+[a2,ind2]=gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int16(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int16(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int16(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int16(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int16(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int16(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) >= 0));
assert_checktrue(or(t(find(t(:,1)==0),2) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
// test of gsort for int8 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = int8(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = int8(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, int8(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, int8(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g','i');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g","i");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) <= 0));
end
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'r');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"r");
assert_checkequal(or(b1(2:$,:) - b1(1:$-1,:) > 0), %f);
test = [];
for j = 1:nc
end
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test =[];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, int8(test));
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
for i = 1:Nrand
- b = int8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'c');
+ b = int8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"c");
assert_checktrue(or(b1(:,2:$) - b1(:,1:$-1) <= 0));
test = [];
for j = 1:nr
end
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr ;
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = int8(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, int8(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = int8(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = int8(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, int8(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g','i');
+[a2,ind2]=gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = int8(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, int8(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2]=gsort([100,10,1]*a,'g');
+[a2,ind2]=gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax*rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$) - v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, int8(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2]=gsort([100,10,1]*a,'g','i');
+[a2,ind2]=gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$) - v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19])';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(p(ind),:), b);
end
-[b,ind]=gsort(a,'lr','d');
+[b,ind]=gsort(a,"lr","d");
t=b(1:$-1,:)-b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
assert_checkequal(a(ind,:), b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) - b(1:$-1,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
+
+
assert_checkequal(a(ind,:), b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(1:$-1,:) - b(2:$,:);
assert_checktrue(or(t(:,1) <= 0));
assert_checktrue(or(t(find(t(:,1)==0),2)>=0));
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint32(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint32(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint32(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint32(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint32(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint32(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc ;
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc ;
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
assert_checkequal(a1, test);
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint32(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint32(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g');
+[a2,ind2]=gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint32(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint32(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint32(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2]=gsort(a*[100;10;1],'g','i');
+[a2,ind2]=gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint32(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint32(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint32(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:),b);
end
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
// test of gsort for uuint16 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint16(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint16(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint16(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint16(10 * rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint16(10 * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1) - b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint16(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
assert_checkequal(a1, test);
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint16(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint16(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a * [100;10;1],'g');
+[a2,ind2] = gsort(a * [100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint16(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint16(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint16(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a * [100;10;1],'g','i');
+[a2,ind2] = gsort(a * [100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v = double(b1) * ((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint16(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint16(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g');
+[a2,ind2] = gsort([100,10,1] * a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N1-1:-1:0]) * double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint16(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1] * a,'g','i');
+[a2,ind2] = gsort([100,10,1] * a,"g","i");
assert_checkequal(ind2, ind);
vmax = 4;
for i = 1:Nrand
- b = int(vmax * rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax * rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
// test of gsort for uint8 matrices:
N = 4;P = 20;Nrand = 100; vmax = 4;
-a = uint8(matrix(grand(1,'prm',(1:N*P)'),N,P));
+a = uint8(matrix(grand(1,"prm",(1:N*P)'),N,P));
//-----Global sort --------------------------------
-[a1,ind] = gsort(a,'g');
+[a1,ind] = gsort(a,"g");
assert_checkequal(a1, uint8(matrix(N*P:-1:1,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
for i = 1:Nrand
- b = uint8(10*rand(N,P,'u'));
- [b1,ind] = gsort(b,'g');
+ b = uint8(10*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"g");
assert_checkequal(b1, matrix(b(ind),N,P));
assert_checktrue(or(b1(1:$-1)-b1(2:$) >= 0));
end
//increasing values
-[a1,ind] = gsort(a,'g','i');
+[a1,ind] = gsort(a,"g","i");
assert_checkequal(a1, uint8(matrix(1:N*P,N,P)));
assert_checkequal(a1, matrix(a(ind),N,P));
//----sort each column of a ('r' means that the row indice is used for sorting)
-[a1,ind] = gsort(a,'r');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc
- test = [test, gsort(a(:,i),'g')];
+ test = [test, gsort(a(:,i),"g")];
end
assert_checkequal(a1, test);
//increasing values
-[a1,ind] = gsort(a,'r','i');
-nc = size(a,'c');
+[a1,ind] = gsort(a,"r","i");
+nc = size(a,"c");
test = [];
for i = 1:nc
test = [test, matrix(a(ind(:,i),i),N,1)];
test = [];
for i = 1:nc ;
- test = [test, gsort(a(:,i),'g','i')];
+ test = [test, gsort(a(:,i),"g","i")];
end
assert_checkequal(a1, test);
//----sort each row of a ('c' means that the column indice is used for sorting)
-[a1,ind] = gsort(a,'c');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c");
+nr = size(a,"r");
test = [];
for i = 1:nr;
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g')];
+ test = [test; gsort(a(i,:),"g")];
end
assert_checkequal(a1, test);
//increasing
-[a1,ind] = gsort(a,'c','i');
-nr = size(a,'r');
+[a1,ind] = gsort(a,"c","i");
+nr = size(a,"r");
test = [];
for i = 1:nr
test = [test; matrix(a(i,ind(i,:)),1,P)];
test = [];
for i = 1:nr
- test = [test; gsort(a(i,:),'g','i')];
+ test = [test; gsort(a(i,:),"g","i")];
end
assert_checkequal(a1, test);
1,1,2;
1,1,1];
// a random permutation
-[ax,perm] = gsort(rand(1,N1,'u'));
+[ax,perm] = gsort(rand(1,N1,"u"));
a = uint8(alr(perm,:));
-[a1,ind] = gsort(a,'lr');
+[a1,ind] = gsort(a,"lr");
assert_checkequal(a1, uint8(alr));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g');
+[a2,ind2] = gsort(a*[100;10;1],"g");
assert_checkequal(ind2, ind);
///////////////////////
for i = 1:Nrand
- b = uint8(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr');
+ b = uint8(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr");
assert_checkequal(b1, b(ind,:));
v = double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
// increasing
-[a1,ind] = gsort(a,'lr','i');
+[a1,ind] = gsort(a,"lr","i");
assert_checkequal(a1, uint8(alr(N1:-1:1,:)));
assert_checkequal(a1, matrix(a(ind,:),N1,P1));
-[a2,ind2] = gsort(a*[100;10;1],'g','i');
+[a2,ind2] = gsort(a*[100;10;1],"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lr','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lr","i");
assert_checkequal(b1, b(ind,:));
v= double(b1)*((vmax+1)^[P-1:-1:0])';
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
N1 = 3;P1 = 4;
alr = alr';
// a random permutation
-[ax,perm] = gsort(rand(1,P1,'u'));
+[ax,perm] = gsort(rand(1,P1,"u"));
a = uint8(alr(:,perm));
-[a1,ind] = gsort(a,'lc');
+[a1,ind] = gsort(a,"lc");
assert_checkequal(a1, uint8(alr));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g');
+[a2,ind2] = gsort([100,10,1]*a,"g");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax * rand(N1,P1,'u'));
- [b1,ind] = gsort(b,'lc');
+ b = int(vmax * rand(N1,P1,"u"));
+ [b1,ind] = gsort(b,"lc");
assert_checkequal(b1, b(:,ind));
v = ((vmax+1)^[N1-1:-1:0])*double(b1);
assert_checktrue(or(v(2:$)-v(1:$-1) <= 0));
end
//increasing
-[a1,ind] = gsort(a,'lc','i');
+[a1,ind] = gsort(a,"lc","i");
assert_checkequal(a1, uint8(alr(:,P1:-1:1)));
assert_checkequal(a1, matrix(a(:,ind),N1,P1));
-[a2,ind2] = gsort([100,10,1]*a,'g','i');
+[a2,ind2] = gsort([100,10,1]*a,"g","i");
assert_checkequal(ind2, ind);
for i = 1:Nrand
- b = int(vmax*rand(N,P,'u'));
- [b1,ind] = gsort(b,'lc','i');
+ b = int(vmax*rand(N,P,"u"));
+ [b1,ind] = gsort(b,"lc","i");
assert_checkequal(b1, b(:,ind));
v= ((vmax+1)^[N-1:-1:0])*b1;
assert_checktrue(or(v(2:$)-v(1:$-1) >= 0));
3,4,4,5,3,8,4,4,7,8,8,8,5,5,8,9,10,10,9,8,6,10,10,10,10,11,8,8,13,13,9,9,13,13,10,10,13,..
13,14,15,15,12,14,11,11,15,15,15,15,16,17,14,14,17,17,15,15,13,13,17,17,18,18,19,19,16,..
16,19,19,19,18,19]-5)';
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','i');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(p(ind),:),b);
end
-[b,ind]=gsort(a,'lr','d');
+[b,ind]=gsort(a,"lr","d");
t=b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
for k = 1:30
- p = grand(1,'prm',(1:size(a,1))');
- [b,ind] = gsort(a(p,:),'lr','d');
+ p = grand(1,"prm",(1:size(a,1))');
+ [b,ind] = gsort(a(p,:),"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
a = b;
a([10 60],:) = a([60 10],:);
-[b,ind] = gsort(a,'lr','i');
+[b,ind] = gsort(a,"lr","i");
t = b(2:$,:) < b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
-[b,ind] = gsort(a,'lr','d');
+[b,ind] = gsort(a,"lr","d");
t = b(2:$,:) > b(1:$-1,:);
assert_checkfalse(or(t(:,1)));
assert_checkfalse(or(t(b(2:$,1)==b(1:$-1,1),2)));
assert_checkequal(a(ind,:),b);
//testing gsort with Nan's
-b = gsort([1 2 %nan 3 4],'g','i');
+b = gsort([1 2 %nan 3 4],"g","i");
assert_checkequal(b(1:4), (1:4));
assert_checkequal(find(isnan(b)), 5);
-b = gsort([1 2 %nan 1 3 ],'g','i');
+b = gsort([1 2 %nan 1 3 ],"g","i");
assert_checkequal(b(1:4), [1 1 2 3]);
assert_checkequal(find(isnan(b)), 5);
-b = gsort([1 2 %nan 1 3 ],'g','d');
+b = gsort([1 2 %nan 1 3 ],"g","d");
assert_checkequal(b(2:$), [3 2 1 1]);
assert_checkequal(find(isnan(b)), 1);
-b = gsort([1 2 %nan 1 3 %nan 2 3],'g','d');
+b = gsort([1 2 %nan 1 3 %nan 2 3],"g","d");
assert_checkequal(b(3:$), [3,3,2,2,1,1]);
assert_checkequal(find(isnan(b)), [1 2]);
-b = gsort([1 2 %nan 1 3 %nan 2 3],'g','i');
+b = gsort([1 2 %nan 1 3 %nan 2 3],"g","i");
assert_checkequal(b(1:$-2), [1,1,2,2,3,3]);
assert_checkequal(find(isnan(b)), [7 8]);
m = [1 2 %nan;1 3 %nan;1 2 3];
-b = gsort(m,'lr','i');
-assert_checkequal(sci2exp(b,0), '[1,2,3;1,2,%nan;1,3,%nan]');
+b = gsort(m,"lr","i");
+assert_checkequal(sci2exp(b,0), "[1,2,3;1,2,%nan;1,3,%nan]");
-b = gsort(m,'lr','d');
-assert_checkequal(sci2exp(b,0), '[1,3,%nan;1,2,%nan;1,2,3]');
+b = gsort(m,"lr","d");
+assert_checkequal(sci2exp(b,0), "[1,3,%nan;1,2,%nan;1,2,3]");
m = m(:,[3 1 2]);
-b = gsort(m,'lc','i');
-assert_checkequal(sci2exp(b,0), '[1,2,%nan;1,3,%nan;1,2,3]');
+b = gsort(m,"lc","i");
+assert_checkequal(sci2exp(b,0), "[1,2,%nan;1,3,%nan;1,2,3]");
-b = gsort(m,'lc','d');
-assert_checkequal(sci2exp(b,0), '[%nan,2,1;%nan,3,1;3,2,1]');
+b = gsort(m,"lc","d");
+assert_checkequal(sci2exp(b,0), "[%nan,2,1;%nan,3,1;3,2,1]");
//testing gsort with Inf's
-b = gsort([1 2 %inf 3 4],'g','i');
+b = gsort([1 2 %inf 3 4],"g","i");
assert_checkequal(b(1:4), (1:4));
assert_checkequal(find(isinf(b)), 5);
-b=gsort([1 2 %inf 1 3 ],'g','i');
+b=gsort([1 2 %inf 1 3 ],"g","i");
assert_checkequal(b(1:4), [1 1 2 3]);
assert_checkequal(find(isinf(b)), 5);
-b=gsort([1 2 %inf 1 3 ],'g','d');
+b=gsort([1 2 %inf 1 3 ],"g","d");
assert_checkequal(b(2:$), [3 2 1 1]);
assert_checkequal(find(isinf(b)), 1);
-b=gsort([1 2 %inf 1 3 %inf 2 3],'g','d');
+b=gsort([1 2 %inf 1 3 %inf 2 3],"g","d");
assert_checkequal(b(3:$), [3,3,2,2,1,1]);
assert_checkequal(find(isinf(b)), [1 2]);
-b=gsort([1 2 %inf 1 3 %inf 2 3],'g','i');
+b=gsort([1 2 %inf 1 3 %inf 2 3],"g","i");
assert_checkequal(b(1:$-2), [1,1,2,2,3,3]);
assert_checkequal(find(isinf(b)), [7 8]);
m = [1 2 %inf;1 3 %inf;1 2 3];
-b = gsort(m,'lr','i');
-assert_checkequal(sci2exp(b,0), '[1,2,3;1,2,%inf;1,3,%inf]');
+b = gsort(m,"lr","i");
+assert_checkequal(sci2exp(b,0), "[1,2,3;1,2,%inf;1,3,%inf]");
-b = gsort(m,'lr','d');
-assert_checkequal(sci2exp(b,0), '[1,3,%inf;1,2,%inf;1,2,3]');
+b = gsort(m,"lr","d");
+assert_checkequal(sci2exp(b,0), "[1,3,%inf;1,2,%inf;1,2,3]");
m = m(:,[3 1 2]);
-b = gsort(m,'lc','i');
-assert_checkequal(sci2exp(b,0), '[1,2,%inf;1,3,%inf;1,2,3]');
+b = gsort(m,"lc","i");
+assert_checkequal(sci2exp(b,0), "[1,2,%inf;1,3,%inf;1,2,3]");
-b = gsort(m,'lc','d');
-assert_checkequal(sci2exp(b,0), '[%inf,2,1;%inf,3,1;3,2,1]');
+b = gsort(m,"lc","d");
+assert_checkequal(sci2exp(b,0), "[%inf,2,1;%inf,3,1;3,2,1]");
//gsort
a = [5 1 3 2 4];
assert_checkequal(s, [5 4 3 2 1]);
a = string([5 1 3 2 4]);
-assert_checkequal(gsort(a,'g','i'), string(1:5));
+assert_checkequal(gsort(a,"g","i"), string(1:5));
-[s,k]=gsort(a,'g','i');
+[s,k]=gsort(a,"g","i");
assert_checkequal(k, [2 4 3 5 1]);
assert_checkequal(s, string(1:5));
B = sparse(b);
// opts = 'r' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'r','d');
-[s1,k1] = gsort(B(:),'r','d');
+[s,k] = gsort(b(:),"r","d");
+[s1,k1] = gsort(B(:),"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'r','i');
-[s1,k1] = gsort(B(:),'r','i');
+[s,k] = gsort(b(:),"r","i");
+[s1,k1] = gsort(B(:),"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','r','d');
-[s1,k1] = gsort(B(:)','r','d');
+[s,k] = gsort(b(:)',"r","d");
+[s1,k1] = gsort(B(:)',"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','r','i');
-[s1,k1] = gsort(B(:)','r','i');
+[s,k] = gsort(b(:)',"r","i");
+[s1,k1] = gsort(B(:)',"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'c' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'c','d');
-[s1,k1] = gsort(B(:),'c','d');
+[s,k] = gsort(b(:),"c","d");
+[s1,k1] = gsort(B(:),"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'c','i');
-[s1,k1] = gsort(B(:),'c','i');
+[s,k] = gsort(b(:),"c","i");
+[s1,k1] = gsort(B(:),"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','c','d');
-[s1,k1] = gsort(B(:)','c','d');
+[s,k] = gsort(b(:)',"c","d");
+[s1,k1] = gsort(B(:)',"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','c','i');
-[s1,k1] = gsort(B(:)','c','i');
+[s,k] = gsort(b(:)',"c","i");
+[s1,k1] = gsort(B(:)',"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'g' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'g','d');
-[s1,k1] = gsort(B(:),'g','d');
+[s,k] = gsort(b(:),"g","d");
+[s1,k1] = gsort(B(:),"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'g','i');
-[s1,k1] = gsort(B(:),'g','i');
+[s,k] = gsort(b(:),"g","i");
+[s1,k1] = gsort(B(:),"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','g','d');
-[s1,k1] = gsort(B(:)','g','d');
+[s,k] = gsort(b(:)',"g","d");
+[s1,k1] = gsort(B(:)',"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','g','i');
-[s1,k1] = gsort(B(:)','g','i');
+[s,k] = gsort(b(:)',"g","i");
+[s1,k1] = gsort(B(:)',"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'lr' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'lr','d');
-[s1,k1] = gsort(B(:),'lr','d');
+[s,k] = gsort(b(:),"lr","d");
+[s1,k1] = gsort(B(:),"lr","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'lr','i');
-[s1,k1] = gsort(B(:),'lr','i');
+[s,k] = gsort(b(:),"lr","i");
+[s1,k1] = gsort(B(:),"lr","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lr','d');
-[s1,k1] = gsort(B(:)','lr','d');
+[s,k] = gsort(b(:)',"lr","d");
+[s1,k1] = gsort(B(:)',"lr","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lr','i');
-[s1,k1] = gsort(B(:)','lr','i');
+[s,k] = gsort(b(:)',"lr","i");
+[s1,k1] = gsort(B(:)',"lr","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
// opts = 'lc' and direction = 'd' or 'i'
-[s,k] = gsort(b(:),'lc','d');
-[s1,k1] = gsort(B(:),'lc','d');
+[s,k] = gsort(b(:),"lc","d");
+[s1,k1] = gsort(B(:),"lc","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:),'lc','i');
-[s1,k1] = gsort(B(:),'lc','i');
+[s,k] = gsort(b(:),"lc","i");
+[s1,k1] = gsort(B(:),"lc","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lc','d');
-[s1,k1] = gsort(B(:)','lc','d');
+[s,k] = gsort(b(:)',"lc","d");
+[s1,k1] = gsort(B(:)',"lc","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(b(:)','lc','i');
-[s1,k1] = gsort(B(:)','lc','i');
+[s,k] = gsort(b(:)',"lc","i");
+[s1,k1] = gsort(B(:)',"lc","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
A = [1 -%i;%i 0];
A1 = sparse(A);
-c = gsort(A(:),'g','d');
-d = full(gsort(A1(:),'g','d'));
+c = gsort(A(:),"g","d");
+d = full(gsort(A1(:),"g","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'g','i');
-d = full(gsort(A1(:),'g','i'));
+c = gsort(A(:),"g","i");
+d = full(gsort(A1(:),"g","i"));
assert_checkequal(c,d);
-c = gsort(A(:),'r','d');
-d = full(gsort(A1(:),'r','d'));
+c = gsort(A(:),"r","d");
+d = full(gsort(A1(:),"r","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'r','i');
-d = full(gsort(A1(:),'r','i'));
+c = gsort(A(:),"r","i");
+d = full(gsort(A1(:),"r","i"));
assert_checkequal(c,d);
-c = gsort(A(:),'c','d');
-d = full(gsort(A1(:),'c','d'));
+c = gsort(A(:),"c","d");
+d = full(gsort(A1(:),"c","d"));
assert_checkequal(c,d);
-c = gsort(A(:),'c','i');
-d = full(gsort(A1(:),'c','i'));
+c = gsort(A(:),"c","i");
+d = full(gsort(A1(:),"c","i"));
assert_checkequal(c,d);
B = [1 1+%i 4; -2*%i 3 3-%i];
B1 = sparse(B);
-c = gsort(B(:),'g','d');
-d = full(gsort(B1(:),'g','d'));
+c = gsort(B(:),"g","d");
+d = full(gsort(B1(:),"g","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'g','i');
-d = full(gsort(B1(:),'g','i'));
+c = gsort(B(:),"g","i");
+d = full(gsort(B1(:),"g","i"));
assert_checkequal(c,d);
-c = gsort(B(:),'r','d');
-d = full(gsort(B1(:),'r','d'));
+c = gsort(B(:),"r","d");
+d = full(gsort(B1(:),"r","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'r','i');
-d = full(gsort(B1(:),'r','i'));
+c = gsort(B(:),"r","i");
+d = full(gsort(B1(:),"r","i"));
assert_checkequal(c,d);
-c = gsort(B(:),'c','d');
-d = full(gsort(B1(:),'c','d'));
+c = gsort(B(:),"c","d");
+d = full(gsort(B1(:),"c","d"));
assert_checkequal(c,d);
-c = gsort(B(:),'c','i');
-d = full(gsort(B1(:),'c','i'));
+c = gsort(B(:),"c","i");
+d = full(gsort(B1(:),"c","i"));
assert_checkequal(c,d);
C = [-%i 3*%i;4 9;-2*%i 7];
C1 = sparse(C);
-[s,k] = gsort(C(:),'g','d');
-[s1,k1] = gsort(C1(:),'g','d');
+[s,k] = gsort(C(:),"g","d");
+[s1,k1] = gsort(C1(:),"g","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'g','i');
-[s1,k1] = gsort(C1(:),'g','i');
+[s,k] = gsort(C(:),"g","i");
+[s1,k1] = gsort(C1(:),"g","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'r','d');
-[s1,k1] = gsort(C1(:),'r','d');
+[s,k] = gsort(C(:),"r","d");
+[s1,k1] = gsort(C1(:),"r","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'r','i');
-[s1,k1] = gsort(C1(:),'r','i');
+[s,k] = gsort(C(:),"r","i");
+[s1,k1] = gsort(C1(:),"r","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'c','d');
-[s1,k1] = gsort(C1(:),'c','d');
+[s,k] = gsort(C(:),"c","d");
+[s1,k1] = gsort(C1(:),"c","d");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
-[s,k] = gsort(C(:),'c','i');
-[s1,k1] = gsort(C1(:),'c','i');
+[s,k] = gsort(C(:),"c","i");
+[s1,k1] = gsort(C1(:),"c","i");
assert_checkequal(full(s1),s);
assert_checkequal(k1,k);
assert_checkequal(hs(:), s);
// 'c' 'r' 'lc' 'lr'
-[hsc hindc] = gsort(A, 'c');
-[hsr hindr] = gsort(A, 'r');
-[hslc hindlc] = gsort(A, 'lc');
-[hslr hindlr] = gsort(A, 'lr');
+[hsc hindc] = gsort(A, "c");
+[hsr hindr] = gsort(A, "r");
+[hslc hindlc] = gsort(A, "lc");
+[hslr hindlr] = gsort(A, "lr");
a = matrix(A, 6, 4, 16); // 2 * 8 = 16
sc = zeros(a);
indlr = zeros(6, 1, 16);
for i = 1:16
- [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),'c');
- [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),'r');
- [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),'lc');
- [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),'lr');
+ [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),"c");
+ [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),"r");
+ [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),"lc");
+ [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),"lr");
end
sc = matrix(sc, 6, 4, 2, 8);
assert_checkequal(hindlr, indlr);
// whitout indices
-hsc = gsort(A, 'c');
-hsr = gsort(A, 'r');
-hslc = gsort(A, 'lc');
-hslr = gsort(A, 'lr');
+hsc = gsort(A, "c");
+hsr = gsort(A, "r");
+hslc = gsort(A, "lc");
+hslr = gsort(A, "lr");
assert_checkequal(hsc, sc);
assert_checkequal(hsr, sr);
// ----- increasing -----
// 'g'
-[hs hind] = gsort(A, 'g', 'i');
-[s ind] = gsort(A(:), 'g', 'i');
+[hs hind] = gsort(A, "g", "i");
+[s ind] = gsort(A(:), "g", "i");
assert_checkequal(hs(:), s);
assert_checkequal(hind(:), ind);
-hs = gsort(A, 'g', 'i');
+hs = gsort(A, "g", "i");
assert_checkequal(hs(:), s);
// 'c' 'r' 'lc' 'lr'
-[hsc hindc] = gsort(A, 'c', 'i');
-[hsr hindr] = gsort(A, 'r', 'i');
-[hslc hindlc] = gsort(A, 'lc', 'i');
-[hslr hindlr] = gsort(A, 'lr', 'i');
+[hsc hindc] = gsort(A, "c", "i");
+[hsr hindr] = gsort(A, "r", "i");
+[hslc hindlc] = gsort(A, "lc", "i");
+[hslr hindlr] = gsort(A, "lr", "i");
a = matrix(A, 6, 4, 16); // 2 * 8 = 16
sc = zeros(a);
indlr = zeros(6, 1, 16);
for i = 1:16
- [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),'c', 'i');
- [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),'r', 'i');
- [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),'lc', 'i');
- [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),'lr', 'i');
+ [sc(:,:,i) indc(:,:,i)] = gsort(a(:,:,i),"c", "i");
+ [sr(:,:,i) indr(:,:,i)] = gsort(a(:,:,i),"r", "i");
+ [slc(:,:,i) indlc(:,:,i)] = gsort(a(:,:,i),"lc", "i");
+ [slr(:,:,i) indlr(:,:,i)] = gsort(a(:,:,i),"lr", "i");
end
sc = matrix(sc, 6, 4, 2, 8);
assert_checkequal(hindlr, indlr);
// whitout indices
-hsc = gsort(A, 'c', 'i');
-hsr = gsort(A, 'r', 'i');
-hslc = gsort(A, 'lc', 'i');
-hslr = gsort(A, 'lr', 'i');
+hsc = gsort(A, "c", "i");
+hsr = gsort(A, "r", "i");
+hslc = gsort(A, "lc", "i");
+hslr = gsort(A, "lr", "i");
assert_checkequal(hsc, sc);
assert_checkequal(hsr, sr);
assert_checkequal(Akl, Ak);
// test max(A,'c') and max(A,'r')
// max(A,'r') returns a row vector which contains max for each column
-[Am, Akm] = max(A1, 'r');
-nc = size(A1, 'c');
+[Am, Akm] = max(A1, "r");
+nc = size(A1, "c");
Am1 = [];
Ak1 = [];
for i = 1:nc
assert_checkequal(Am, Am1);
assert_checkequal(Akm, Ak1);
// max(A,'c');
-[Am, Akm] = max(A1, 'c');
-nc = size(A1, 'r');
+[Am, Akm] = max(A1, "c");
+nc = size(A1, "r");
Am1 = [];
Ak1 = [];
for i = 1:nc
assert_checkequal(Al, sparse(Am));
// test max(A,'c') and max(A,'r')
// max(A,'r') returns a row vector which contains max for each column
-[Am] = max(A1, 'r');
-nc = size(A1, 'c');
+[Am] = max(A1, "r");
+nc = size(A1, "c");
Am1 = [];
for i = 1:nc
[am] = max(A1(:,i));
end
assert_checkequal(Am, sparse(Am1));
// max(A,'c');
-[Am] = max(A1, 'c');
-nc = size(A1, 'r');
+[Am] = max(A1, "c");
+nc = size(A1, "r");
Am1 = [];
for i = 1:nc
[am] = max(A1(i,:));
assert_checkequal(Al, sparse(Am));
// test min(A,'c') and min(A,'r')
// min(A,'r') returns a row vector which contains min for each column
-[Am] = min(A1, 'r');
-nc = size(A1, 'c');
+[Am] = min(A1, "r");
+nc = size(A1, "c");
Am1 = [];
for i = 1:nc
[am] = min(A1(:,i));
end
assert_checkequal(Am, sparse(Am1));
// min(A,'c');
-[Am] = min(A1, 'c');
-nc = size(A1, 'r');
+[Am] = min(A1, "c");
+nc = size(A1, "r");
Am1 = [];
for i = 1:nc
[am] = min(A1(i,:));
// test max(A,'c') and max(A,'r')
// max(A,'r') returns a row vector which contains max for each column
-[Am, Akm] = max(A1, 'r');
-nc = size(A1, 'c');
+[Am, Akm] = max(A1, "r");
+nc = size(A1, "c");
Am1 = [];
Ak1 = [];
for i = 1:nc
// max(A,'c');
-[Am, Akm] = max(A1, 'c');
-nc = size(A1, 'r');
+[Am, Akm] = max(A1, "c");
+nc = size(A1, "r");
Am1 = [];
Ak1 = [];
for i = 1:nc
// test max(A,'c') and max(A,'r')
// max(A,'r') returns a row vector which contains max for each column
-[Am] = max(A1, 'r');
-nc = size(A1, 'c');
+[Am] = max(A1, "r");
+nc = size(A1, "c");
Am1 = [];
for i = 1:nc
[am] = max(A1(:,i));
// max(A,'c');
-[Am] = max(A1, 'c');
-nc = size(A1, 'r');
+[Am] = max(A1, "c");
+nc = size(A1, "r");
Am1 = [];
for i = 1:nc
[am] = max(A1(i,:));
// test min(A,'c') and min(A,'r')
// min(A,'r') returns a row vector which contains min for each column
-[Am] = min(A1, 'r');
-nc = size(A1, 'c');
+[Am] = min(A1, "r");
+nc = size(A1, "c");
Am1 = [];
for i = 1:nc
[am] = min(A1(:,i));
// min(A,'c');
-[Am] = min(A1, 'c');
-nc = size(A1, 'r');
+[Am] = min(A1, "c");
+nc = size(A1, "r");
Am1 = [];
for i = 1:nc
[am] = min(A1(i,:));
return types::Function::Error;
}
- pDblMatrix = in[0]->getAs<types::Double>()->clone()->getAs<types::Double>(); // input data will be modified
+ pDblMatrix = in[0]->clone()->getAs<types::Double>(); // input data will be modified
if (pDblMatrix->getRows() != pDblMatrix->getCols())
{
Scierror(20, _("%s: Wrong type for argument %d: Square matrix expected.\n"), "bdiag", 1);
if (_iRetCount == 2)
{
out.push_back(pDblOut[0]);
+ pDblOut[0] = NULL;
}
out.push_back(pDbl[0]); // pDbl[0] has been overwritten by its real Schur form T.
+
break;
}
case 11: // double double
for (int i = 0; i < 2; i++)
{
out.push_back(pDbl[i]);
+ pDbl[1] = NULL;
}
if (_iRetCount == 4)
{
out.push_back(pDblOut[0]);
+ pDblOut[0] = NULL;
if (_iRetCount > 1)
{
out.push_back(pDblOut[1]);
+ pDblOut[1] = NULL;
}
}
else
{
out.push_back(pDblOut[0]);
+ pDblOut[0] = NULL;
out.push_back(pDblOut[2]);
+ pDblOut[2] = NULL;
if (_iRetCount == 3)
{
for (int i = 0; i < 2; i++)
{
out.push_back(pDbl[i]);
+ pDbl[1] = NULL;
}
out.push_back(pDblOut[1]);
+ pDblOut[1] = NULL;
break;
}
case 3 : // Q Z dim
{
out.push_back(pDblOut[0]);
+ pDblOut[0] = NULL;
}
case 2 : // Z dim
{
out.push_back(pDblOut[1]);
+ pDblOut[1] = NULL;
break;
}
}
out.push_back(pDblOut[2]);
+ pDblOut[2] = NULL;
break;
}
}
+ for (int i = 0; i < 3; ++i)
+ {
+ if (pDblOut[i])
+ {
+ pDblOut[i]->killMe();
+ }
+ }
+
+
+ if (pDbl[1])
+ {
+ pDbl[1]->killMe();
+ }
ConfigVariable::setSchurFunction(NULL);
return types::Function::OK;
}
std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_spec";
return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
}
- pDblA = in[0]->getAs<types::Double>()->clone()->getAs<types::Double>();
+ pDblA = in[0]->clone()->getAs<types::Double>();
if (pDblA->getCols() != pDblA->getRows())
{
out.push_back(pValues);
}
}
+ else
+ {
+ if (pBools)
+ {
+ pBools->killMe();
+ }
+
+ if (pValues)
+ {
+ pValues->killMe();
+ }
+ }
if (_iRetCount > 2)
{
src/nowindows_tools/nowindows_tools.def
#memory leaks tools configuration files
src/c/CScilex/vld.ini
+src/c/WScilex/vld.ini
src/c/CScilex/memory_leak_report.txt