diff --git a/CMakeLists.txt b/CMakeLists.txt index 47d2ab28b..a35b80aee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,17 @@ if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/whereami/.git" ) message(FATAL_ERROR "The src/whereami git submodule is not initialised.\n Please run `git submodule update --init`") endif() +# add warnings +if (MSVC) + add_compile_options(/W4) + # not yet: make warnings fatal + #add_compile_options(/W4 /WX) +else() + add_compile_options(-Wall -Wextra -pedantic) + # not yet: make warnings fatal + #add_compile_options(-Wall -Wextra -pedantic -Werror) +endif() + # create version string based on git metadata (based on https://github.com/nocnokneo/cmake-git-versioning-example) # in case version.hpp does not exist (it is shipped in GDL tarballs but not stored in the repo) if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/version.hpp") @@ -187,7 +198,10 @@ check_include_file(malloc.h HAVE_MALLOC_H) check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) # locale -check_include_file(locale.h HAVE_LOCALE_H) +check_include_file_cxx(clocale HAVE_LOCALE_H) +if (NOT HAVE_LOCALE_H) + message(FATAL_ERROR "Necessary c++ header clocale not found") +endif() # std includes.. check_include_file(stdint.h HAVE_STDINT_H) diff --git a/config.h.cmake b/config.h.cmake index 12f447416..483e8a94b 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -18,7 +18,6 @@ #cmakedefine HAVE_LIBREADLINE 1 #cmakedefine HAVE_LIBWXWIDGETS 1 #cmakedefine HAVE_LIBZ 1 -#cmakedefine HAVE_LOCALE_H 1 #cmakedefine HAVE_SBRK 1 #cmakedefine HAVE_MALLINFO 1 #cmakedefine HAVE_MALLINFO2 1 diff --git a/src/accessdesc.hpp b/src/accessdesc.hpp index c7eab7c92..5c2ea3a76 100644 --- a/src/accessdesc.hpp +++ b/src/accessdesc.hpp @@ -356,7 +356,7 @@ class DotAccessDescT // no zeroing, here the new variable is created // zero only for GDL_PTR and GDL_OBJ (because of ref counting) if( top->Type() == GDL_PTR || top->Type() == GDL_OBJ) - newData=top->New( dim);//, BaseGDL::NOZERO); + newData=top->New(dim, BaseGDL::ZERO);//, BaseGDL::NOZERO); else newData=top->New( dim, BaseGDL::NOZERO); diff --git a/src/antlr/ANTLRException.hpp b/src/antlr/ANTLRException.hpp index 72fe2fbef..495becf0b 100644 --- a/src/antlr/ANTLRException.hpp +++ b/src/antlr/ANTLRException.hpp @@ -1,5 +1,5 @@ -#ifndef INC_ANTLRException_hpp__ -#define INC_ANTLRException_hpp__ +#ifndef INC_ANTLRException_hpp_ +#define INC_ANTLRException_hpp_ /* ANTLR Translator Generator * Project led by Terence Parr at http://www.jGuru.com @@ -10,50 +10,49 @@ #include #include +#include #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE namespace antlr { #endif -class ANTLR_API ANTLRException -{ +class ANTLR_API ANTLRException : std::exception { public: - /// Create ANTLR base exception without error message - ANTLRException() : text("") - { - } - /// Create ANTLR base exception with error message - ANTLRException(const ANTLR_USE_NAMESPACE(std)string& s) - : text(s) - { - } - virtual ~ANTLRException() throw() - { - } + /// Create ANTLR base exception without error message + ANTLRException() : msg("") { + } + /// Create ANTLR base exception with error message + ANTLRException(const ANTLR_USE_NAMESPACE(std)string &s) + : msg(s) { + } + virtual ~ANTLRException() throw() { + } - /** Return complete error message with line/column number info (if present) - * @note for your own exceptions override this one. Call getMessage from - * here to get the 'clean' error message stored in the text attribute. - */ - virtual ANTLR_USE_NAMESPACE(std)string toString() const - { - return text; - } + /** + * Return complete error message with line/column number info (if present) + * + * @note for your own exceptions override this one. Call getMessage from + * here to get the 'clean' error message stored in the text attribute. + */ + virtual ANTLR_USE_NAMESPACE(std)string toString() const { + return msg.what(); + } - /** Return error message without additional info (if present) - * @note when making your own exceptions classes override toString - * and call in toString getMessage which relays the text attribute - * from here. - */ - virtual ANTLR_USE_NAMESPACE(std)string getMessage() const - { - return text; - } -private: - ANTLR_USE_NAMESPACE(std)string text; + /** + * Return error message without additional info (if present) + * + * @note when making your own exceptions classes override toString + * and call in toString getMessage which relays the text attribute + * from here. + */ + virtual ANTLR_USE_NAMESPACE(std)string getMessage() const { + return msg.what(); + } +protected: + ANTLR_USE_NAMESPACE(std)runtime_error msg; }; #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE } #endif -#endif //INC_ANTLRException_hpp__ +#endif //INC_ANTLRException_hpp_ diff --git a/src/antlr/BaseAST.cpp b/src/antlr/BaseAST.cpp index 1440e0154..f6c46fd90 100644 --- a/src/antlr/BaseAST.cpp +++ b/src/antlr/BaseAST.cpp @@ -16,276 +16,247 @@ ANTLR_USING_NAMESPACE(std) namespace antlr { #endif -const char* const BaseAST::TYPE_NAME = "BaseAST"; +const char *const BaseAST::TYPE_NAME = "BaseAST"; //bool BaseAST::verboseStringConversion; //ANTLR_USE_NAMESPACE(std)vector BaseAST::tokenNames; -BaseAST::BaseAST() : AST() -{ +BaseAST::BaseAST() : AST() { } -BaseAST::~BaseAST() -{ -} +BaseAST::~BaseAST() = default; -BaseAST::BaseAST(const BaseAST& other) -: AST(other) // RK: don't copy links! , down(other.down), right(other.right) +BaseAST::BaseAST(const BaseAST &other) + : AST(other) // RK: don't copy links! , down(other.down), right(other.right) { } -const char* BaseAST::typeName( void ) const -{ - return BaseAST::TYPE_NAME; +const char *BaseAST::typeName() const { + return BaseAST::TYPE_NAME; } -RefAST BaseAST::clone( void ) const -{ - ANTLR_USE_NAMESPACE(std)cerr << "BaseAST::clone()" << ANTLR_USE_NAMESPACE(std)endl; - return nullAST; +RefAST BaseAST::clone() const { + ANTLR_USE_NAMESPACE(std)cerr << "BaseAST::clone()" << ANTLR_USE_NAMESPACE(std)endl; + return nullAST; } -void BaseAST::addChild( RefAST c ) -{ - if( !c ) - return; - - RefBaseAST tmp = down; - - if (tmp) - { - while (tmp->right) - tmp = tmp->right; - tmp->right = c; - } - else - down = c; +void BaseAST::addChild(RefAST c) { + if (!c) + return; + + RefBaseAST tmp = down; + + if (tmp) { + while (tmp->right) + tmp = tmp->right; + tmp->right = c; + } else + down = c; } -size_t BaseAST::getNumberOfChildren() const -{ - RefBaseAST t = this->down; - size_t n = 0; - if( t ) - { - n = 1; - while( t->right ) - { - t = t->right; - n++; - } - return n; - } - return n; +size_t BaseAST::getNumberOfChildren() const { + RefBaseAST t = this->down; + size_t n = 0; + if (t) { + n = 1; + while (t->right) { + t = t->right; + n++; + } + return n; + } + return n; } void BaseAST::doWorkForFindAll( - ANTLR_USE_NAMESPACE(std)vector& v, - RefAST target,bool partialMatch) -{ - // Start walking sibling lists, looking for matches. - for (RefAST sibling=this; - sibling; - sibling=sibling->getNextSibling()) - { - if ( (partialMatch && sibling->equalsTreePartial(target)) || - (!partialMatch && sibling->equalsTree(target)) ) { - v.push_back(sibling); - } - // regardless of match or not, check any children for matches - if ( sibling->getFirstChild() ) { - RefBaseAST(sibling->getFirstChild())->doWorkForFindAll(v, target, partialMatch); - } - } + ANTLR_USE_NAMESPACE(std)vector &v, + const RefAST &target, + bool partialMatch) { + // Start walking sibling lists, looking for matches. + for (RefAST sibling = this; + sibling; + sibling = sibling->getNextSibling()) { + if ((partialMatch && sibling->equalsTreePartial(target)) || + (!partialMatch && sibling->equalsTree(target))) { + v.push_back(sibling); + } + // regardless of match or not, check any children for matches + if (sibling->getFirstChild()) { + RefBaseAST(sibling->getFirstChild())->doWorkForFindAll(v, target, partialMatch); + } + } } /** Is t an exact structural and equals() match of this tree. The * 'this' reference is considered the start of a sibling list. */ -bool BaseAST::equalsList(RefAST t) const -{ - // the empty tree is not a match of any non-null tree. - if (!t) - return false; - - // Otherwise, start walking sibling lists. First mismatch, return false. - RefAST sibling=this; - for (;sibling && t; - sibling=sibling->getNextSibling(), t=t->getNextSibling()) { - // as a quick optimization, check roots first. - if (!sibling->equals(t)) - return false; - // if roots match, do full list match test on children. - if (sibling->getFirstChild()) { - if (!sibling->getFirstChild()->equalsList(t->getFirstChild())) - return false; - } - // sibling has no kids, make sure t doesn't either - else if (t->getFirstChild()) - return false; - } - - if (!sibling && !t) - return true; - - // one sibling list has more than the other - return false; +bool BaseAST::equalsList(RefAST t) const { + // the empty tree is not a match of any non-null tree. + if (!t) + return false; + + // Otherwise, start walking sibling lists. First mismatch, return false. + RefAST sibling = this; + for (; sibling && t; + sibling = sibling->getNextSibling(), t = t->getNextSibling()) { + // as a quick optimization, check roots first. + if (!sibling->equals(t)) + return false; + // if roots match, do full list match test on children. + if (sibling->getFirstChild()) { + if (!sibling->getFirstChild()->equalsList(t->getFirstChild())) + return false; + } + // sibling has no kids, make sure t doesn't either + else if (t->getFirstChild()) + return false; + } + + if (!sibling && !t) + return true; + + // one sibling list has more than the other + return false; } /** Is 'sub' a subtree of this list? * The siblings of the root are NOT ignored. */ -bool BaseAST::equalsListPartial(RefAST sub) const -{ - // the empty tree is always a subset of any tree. - if (!sub) - return true; - - // Otherwise, start walking sibling lists. First mismatch, return false. - RefAST sibling=this; - for (;sibling && sub; - sibling=sibling->getNextSibling(), sub=sub->getNextSibling()) { - // as a quick optimization, check roots first. - if (!sibling->equals(sub)) - return false; - // if roots match, do partial list match test on children. - if (sibling->getFirstChild()) - if (!sibling->getFirstChild()->equalsListPartial(sub->getFirstChild())) - return false; - } - - if (!sibling && sub) - // nothing left to match in this tree, but subtree has more - return false; - - // either both are null or sibling has more, but subtree doesn't - return true; +bool BaseAST::equalsListPartial(RefAST sub) const { + // the empty tree is always a subset of any tree. + if (!sub) + return true; + + // Otherwise, start walking sibling lists. First mismatch, return false. + RefAST sibling = this; + for (; sibling && sub; + sibling = sibling->getNextSibling(), sub = sub->getNextSibling()) { + // as a quick optimization, check roots first. + if (!sibling->equals(sub)) + return false; + // if roots match, do partial list match test on children. + if (sibling->getFirstChild()) + if (!sibling->getFirstChild()->equalsListPartial(sub->getFirstChild())) + return false; + } + + if (!sibling && sub) + // nothing left to match in this tree, but subtree has more + return false; + + // either both are null or sibling has more, but subtree doesn't + return true; } /** Is tree rooted at 'this' equal to 't'? The siblings * of 'this' are ignored. */ -bool BaseAST::equalsTree(RefAST t) const -{ - // check roots first - if (!equals(t)) - return false; - // if roots match, do full list match test on children. - if (getFirstChild()) { - if (!getFirstChild()->equalsList(t->getFirstChild())) - return false; - } - // sibling has no kids, make sure t doesn't either - else if (t->getFirstChild()) - return false; - - return true; +bool BaseAST::equalsTree(RefAST t) const { + // check roots first + if (!equals(t)) + return false; + // if roots match, do full list match test on children. + if (getFirstChild()) { + if (!getFirstChild()->equalsList(t->getFirstChild())) + return false; + } + // sibling has no kids, make sure t doesn't either + else if (t->getFirstChild()) + return false; + + return true; } /** Is 'sub' a subtree of the tree rooted at 'this'? The siblings * of 'this' are ignored. */ -bool BaseAST::equalsTreePartial(RefAST sub) const -{ - // the empty tree is always a subset of any tree. - if (!sub) - return true; - - // check roots first - if (!equals(sub)) - return false; - // if roots match, do full list partial match test on children. - if (getFirstChild()) - if (!getFirstChild()->equalsListPartial(sub->getFirstChild())) - return false; - - return true; +bool BaseAST::equalsTreePartial(RefAST sub) const { + // the empty tree is always a subset of any tree. + if (!sub) + return true; + + // check roots first + if (!equals(sub)) + return false; + // if roots match, do full list partial match test on children. + if (getFirstChild()) + if (!getFirstChild()->equalsListPartial(sub->getFirstChild())) + return false; + + return true; } /** Walk the tree looking for all exact subtree matches. Return * an ASTEnumerator that lets the caller walk the list * of subtree roots found herein. */ -ANTLR_USE_NAMESPACE(std)vector BaseAST::findAll(RefAST target) -{ - ANTLR_USE_NAMESPACE(std)vector roots; +ANTLR_USE_NAMESPACE(std)vector BaseAST::findAll(RefAST target) { + ANTLR_USE_NAMESPACE(std)vector roots; - // the empty tree cannot result in an enumeration - if (target) { - doWorkForFindAll(roots,target,false); // find all matches recursively - } + // the empty tree cannot result in an enumeration + if (target) { + doWorkForFindAll(roots, target, false); // find all matches recursively + } - return roots; + return roots; } /** Walk the tree looking for all subtrees. Return * an ASTEnumerator that lets the caller walk the list * of subtree roots found herein. */ -ANTLR_USE_NAMESPACE(std)vector BaseAST::findAllPartial(RefAST target) -{ - ANTLR_USE_NAMESPACE(std)vector roots; +ANTLR_USE_NAMESPACE(std)vector BaseAST::findAllPartial(RefAST target) { + ANTLR_USE_NAMESPACE(std)vector roots; - // the empty tree cannot result in an enumeration - if (target) - doWorkForFindAll(roots,target,true); // find all matches recursively + // the empty tree cannot result in an enumeration + if (target) + doWorkForFindAll(roots, target, true); // find all matches recursively - return roots; + return roots; } -void BaseAST::setText( const ANTLR_USE_NAMESPACE(std)string& ) -{ +void BaseAST::setText(const ANTLR_USE_NAMESPACE(std)string &) { } -void BaseAST::setType( int ) -{ +void BaseAST::setType(int) { } -ANTLR_USE_NAMESPACE(std)string BaseAST::toString() const -{ - return getText(); +ANTLR_USE_NAMESPACE(std)string BaseAST::toString() const { + return getText(); } -ANTLR_USE_NAMESPACE(std)string BaseAST::toStringList() const -{ - ANTLR_USE_NAMESPACE(std)string ts=""; - - if (getFirstChild()) - { - ts+=" ( "; - ts+=toString(); - ts+=getFirstChild()->toStringList(); - ts+=" )"; - } - else - { - ts+=" "; - ts+=toString(); - } - - if (getNextSibling()) - ts+=getNextSibling()->toStringList(); - - return ts; +ANTLR_USE_NAMESPACE(std)string BaseAST::toStringList() const { + ANTLR_USE_NAMESPACE(std)string ts; + + if (getFirstChild()) { + ts += " ( "; + ts += toString(); + ts += getFirstChild()->toStringList(); + ts += " )"; + } else { + ts += " "; + ts += toString(); + } + + if (getNextSibling()) + ts += getNextSibling()->toStringList(); + + return ts; } -ANTLR_USE_NAMESPACE(std)string BaseAST::toStringTree() const -{ - ANTLR_USE_NAMESPACE(std)string ts = ""; - - if (getFirstChild()) - { - ts+=" ( "; - ts+=toString(); - ts+=getFirstChild()->toStringList(); - ts+=" )"; - } - else - { - ts+=" "; - ts+=toString(); - } - return ts; +ANTLR_USE_NAMESPACE(std)string BaseAST::toStringTree() const { + ANTLR_USE_NAMESPACE(std)string ts; + + if (getFirstChild()) { + ts += " ( "; + ts += toString(); + ts += getFirstChild()->toStringList(); + ts += " )"; + } else { + ts += " "; + ts += toString(); + } + return ts; } #ifdef ANTLR_SUPPORT_XML @@ -297,31 +268,31 @@ ANTLR_USE_NAMESPACE(std)string BaseAST::toStringTree() const */ bool BaseAST::attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const { - out << "text=\"" << this->getText() - << "\" type=\"" << this->getType() << "\""; + out << "text=\"" << this->getText() + << "\" type=\"" << this->getType() << "\""; - return false; + return false; } void BaseAST::toStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const { - for( RefAST node = this; node != 0; node = node->getNextSibling() ) - { - out << "<" << this->typeName() << " "; - - // Write out attributes and if there is extra data... - bool need_close_tag = node->attributesToStream( out ); - - if( need_close_tag ) - { - // got children so write them... - if( node->getFirstChild() != 0 ) - node->getFirstChild()->toStream( out ); - - // and a closing tag.. - out << "typeName() << ">" << endl; - } - } + for( RefAST node = this; node != 0; node = node->getNextSibling() ) + { + out << "<" << this->typeName() << " "; + + // Write out attributes and if there is extra data... + bool need_close_tag = node->attributesToStream( out ); + + if( need_close_tag ) + { + // got children so write them... + if( node->getFirstChild() != 0 ) + node->getFirstChild()->toStream( out ); + + // and a closing tag.. + out << "typeName() << ">" << endl; + } + } } #endif @@ -331,7 +302,7 @@ ANTLR_API RefAST nullAST; #if defined(_MSC_VER) && !defined(__ICL) // Microsoft Visual C++ extern ANTLR_API AST* const nullASTptr = 0; #else -ANTLR_API AST* const nullASTptr = 0; +ANTLR_API AST *const nullASTptr = nullptr; #endif #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE diff --git a/src/antlr/BaseAST.hpp b/src/antlr/BaseAST.hpp index 069b00121..df607ab76 100644 --- a/src/antlr/BaseAST.hpp +++ b/src/antlr/BaseAST.hpp @@ -1,5 +1,5 @@ -#ifndef INC_BaseAST_hpp__ -#define INC_BaseAST_hpp__ +#ifndef INC_BaseAST_hpp_ +#define INC_BaseAST_hpp_ /* ANTLR Translator Generator * Project led by Terence Parr at http://www.jGuru.com @@ -20,145 +20,137 @@ typedef ASTRefCount RefBaseAST; class ANTLR_API BaseAST : public AST { public: - BaseAST(); - BaseAST(const BaseAST& other); + BaseAST(); + BaseAST(const BaseAST &other); - virtual ~BaseAST(); + ~BaseAST() override; - /// Return the class name - virtual const char* typeName( void ) const; + /// Return the class name + const char *typeName() const override; - /// Clone this AST node. - virtual RefAST clone( void ) const; + /// Clone this AST node. + RefAST clone() const override; - /// Is node t equal to this in terms of token type and text? - virtual bool equals(RefAST t) const; + /// Is node t equal to this in terms of token type and text? + bool equals(RefAST t) const override; - /** Is t an exact structural and equals() match of this tree. The - * 'this' reference is considered the start of a sibling list. - */ - virtual bool equalsList(RefAST t) const; - - /** Is 't' a subtree of this list? The siblings of the root are NOT ignored. - */ - virtual bool equalsListPartial(RefAST t) const; - - /** Is tree rooted at 'this' equal to 't'? The siblings of 'this' are - * ignored. - */ - virtual bool equalsTree(RefAST t) const; - - /** Is 't' a subtree of the tree rooted at 'this'? The siblings of - * 'this' are ignored. - */ - virtual bool equalsTreePartial(RefAST t) const; - - /** Walk the tree looking for all exact subtree matches. Return - * an ASTEnumerator that lets the caller walk the list - * of subtree roots found herein. - */ - virtual ANTLR_USE_NAMESPACE(std)vector findAll(RefAST t); - - /** Walk the tree looking for all subtrees. Return - * an ASTEnumerator that lets the caller walk the list - * of subtree roots found herein. + /** Is t an exact structural and equals() match of this tree. The + * 'this' reference is considered the start of a sibling list. */ - virtual ANTLR_USE_NAMESPACE(std)vector findAllPartial(RefAST t); - - /// Add a node to the end of the child list for this node - virtual void addChild(RefAST c); - /** Get the number of child nodes of this node (shallow e.g. not of the - * whole tree it spans). - */ - virtual size_t getNumberOfChildren() const; - - /// Get the first child of this node; null if no children - virtual RefAST getFirstChild() const - { - return RefAST(down); - } - /// Get the next sibling in line after this one - virtual RefAST getNextSibling() const - { - return RefAST(right); - } - - /// Get the token text for this node - virtual ANTLR_USE_NAMESPACE(std)string getText() const - { - return ""; - } - /// Get the token type for this node - virtual int getType() const - { - return 0; - } - - /// Remove all children - virtual void removeChildren() - { - down = static_cast(static_cast(nullAST)); - } - - /// Set the first child of a node. - virtual void setFirstChild(RefAST c) - { - down = static_cast(static_cast(c)); - } - - /// Set the next sibling after this one. - void setNextSibling(RefAST n) - { - right = static_cast(static_cast(n)); - } - - /// Set the token text for this node - virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt); - - /// Set the token type for this node - virtual void setType(int type); + bool equalsList(RefAST t) const override; + + /** Is 't' a subtree of this list? The siblings of the root are NOT ignored. + */ + bool equalsListPartial(RefAST t) const override; + + /** Is tree rooted at 'this' equal to 't'? The siblings of 'this' are + * ignored. + */ + bool equalsTree(RefAST t) const override; + + /** Is 't' a subtree of the tree rooted at 'this'? The siblings of + * 'this' are ignored. + */ + bool equalsTreePartial(RefAST t) const override; + + /** Walk the tree looking for all exact subtree matches. Return + * an ASTEnumerator that lets the caller walk the list + * of subtree roots found herein. + */ + ANTLR_USE_NAMESPACE(std)vector findAll(RefAST t) override; + + /** Walk the tree looking for all subtrees. Return + * an ASTEnumerator that lets the caller walk the list + * of subtree roots found herein. + */ + ANTLR_USE_NAMESPACE(std)vector findAllPartial(RefAST t) override; + + /// Add a node to the end of the child list for this node + void addChild(RefAST c) override; + /** Get the number of child nodes of this node (shallow e.g. not of the + * whole tree it spans). + */ + size_t getNumberOfChildren() const override; + + /// Get the first child of this node; null if no children + RefAST getFirstChild() const override { + return {down}; + } + /// Get the next sibling in line after this one + RefAST getNextSibling() const override { + return {right}; + } + + /// Get the token text for this node + ANTLR_USE_NAMESPACE(std)string getText() const override { + return ""; + } + /// Get the token type for this node + int getType() const override { + return 0; + } + + /// Remove all children + virtual void removeChildren() { + down = dynamic_cast(static_cast(nullAST)); + } + + /// Set the first child of a node. + void setFirstChild(RefAST c) override { + down = dynamic_cast(static_cast(c)); + } + + /// Set the next sibling after this one. + void setNextSibling(RefAST n) override { + right = dynamic_cast(static_cast(n)); + } + + /// Set the token text for this node + void setText(const ANTLR_USE_NAMESPACE(std)string &txt) override; + + /// Set the token type for this node + void setType(int type) override; #ifdef ANTLR_SUPPORT_XML - /** print attributes of this node to 'out'. Override to customize XML - * output. - * @param out the stream to write the AST attributes to. - */ - virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const; - /** Write this subtree to a stream. Overload this one to customize the XML - * output for AST derived AST-types - * @param output stream - */ - virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const; + /** print attributes of this node to 'out'. Override to customize XML + * output. + * @param out the stream to write the AST attributes to. + */ + virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const; + /** Write this subtree to a stream. Overload this one to customize the XML + * output for AST derived AST-types + * @param output stream + */ + virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const; #endif - /// Return string representation for the AST - virtual ANTLR_USE_NAMESPACE(std)string toString() const; + /// Return string representation for the AST + ANTLR_USE_NAMESPACE(std)string toString() const override; - /// Print out a child sibling tree in LISP notation - virtual ANTLR_USE_NAMESPACE(std)string toStringList() const; - virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const; + /// Print out a child sibling tree in LISP notation + ANTLR_USE_NAMESPACE(std)string toStringList() const override; + ANTLR_USE_NAMESPACE(std)string toStringTree() const override; - static const char* const TYPE_NAME; + static const char *const TYPE_NAME; protected: - RefBaseAST down; - RefBaseAST right; + RefBaseAST down; + RefBaseAST right; private: - void doWorkForFindAll(ANTLR_USE_NAMESPACE(std)vector& v, - RefAST target, - bool partialMatch); + void doWorkForFindAll(ANTLR_USE_NAMESPACE(std)vector &v, + const RefAST &target, + bool partialMatch); }; /** Is node t equal to this in terms of token type and text? */ -inline bool BaseAST::equals(RefAST t) const -{ - if (!t) - return false; - return ((getType() == t->getType()) && (getText() == t->getText())); +inline bool BaseAST::equals(RefAST t) const { + if (!t) + return false; + return ((getType() == t->getType()) && (getText() == t->getText())); } #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE } #endif -#endif //INC_BaseAST_hpp__ +#endif //INC_BaseAST_hpp_ diff --git a/src/basegdl.cpp b/src/basegdl.cpp index d7892802f..0878d48e5 100644 --- a/src/basegdl.cpp +++ b/src/basegdl.cpp @@ -171,6 +171,10 @@ BaseGDL* BaseGDL::New( const dimension& dim_, InitType noZero) const { throw GDLException("BaseGDL::New(...) called."); } +BaseGDL* BaseGDL::New(const SizeT& dimSize_, InitType noZero) const +{ + throw GDLException("BaseGDL::New(...) called."); +} BaseGDL* BaseGDL::NewResult() const { throw GDLException("BaseGDL::NewResult() called."); diff --git a/src/basegdl.hpp b/src/basegdl.hpp index 092ac9c10..37c6f714a 100644 --- a/src/basegdl.hpp +++ b/src/basegdl.hpp @@ -521,7 +521,8 @@ class BaseGDL: private MemStats virtual const std::string& TypeStr() const; virtual bool EqType( const BaseGDL*) const; virtual void* DataAddr();// SizeT elem=0); - virtual BaseGDL* New( const dimension& dim_, InitType noZero=ZERO) const; + virtual BaseGDL* New(const dimension &dim_, InitType noZero) const; + virtual BaseGDL* New(const SizeT& dimSize_, InitType noZero) const; virtual BaseGDL* NewResult() const; virtual BaseGDL* Dup() const; // virtual BaseGDL* Dup( char*) const; diff --git a/src/basic_fun.cpp b/src/basic_fun.cpp index 855171086..d2947a544 100644 --- a/src/basic_fun.cpp +++ b/src/basic_fun.cpp @@ -66,9 +66,7 @@ extern "C" char **environ; #include "base64.hpp" #include "gdlfpexceptions.hpp" -#ifdef HAVE_LOCALE_H -#include -#endif +#include /* max regexp error message length */ #define MAX_REGEXPERR_LENGTH 80 @@ -8600,19 +8598,20 @@ namespace lib { } BaseGDL* locale_get(EnvT* e) { -#ifdef HAVE_LOCALE_H - - // make GDL inherit the calling process locale - setlocale(LC_ALL, ""); - // note doen the inherited locale - DStringGDL *locale = new DStringGDL(setlocale(LC_CTYPE, NULL)); - // return to the C locale - setlocale(LC_ALL, "C"); + try { + // make GDL inherit the calling process locale + setlocale(LC_ALL, ""); + // note doen the inherited locale + auto *locale = new DStringGDL(setlocale(LC_CTYPE, nullptr)); + // return to the C locale + setlocale(LC_ALL, "C"); - return locale; -#else - e->Throw("OS does not provide locale information"); -#endif + return locale; + } + catch (const std::exception& ex) { + e->Throw("Unexpected error in locale_get(): " + string(ex.what())); + return nullptr; + } } // SA: relies on the contents of the lib::command_line_args vector diff --git a/src/basic_op.cpp b/src/basic_op.cpp index 38c6e5a3b..d86aabeac 100644 --- a/src/basic_op.cpp +++ b/src/basic_op.cpp @@ -19,10 +19,6 @@ #include #endif -#ifdef _OPENMP -#include -#endif - #include "dinterpreter.hpp" // needed with gcc-3.3.2 @@ -42,7 +38,7 @@ using namespace Eigen; // ex: b=(not a) template Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -51,11 +47,13 @@ Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ~(*this)[i]; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ~(*this)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ~(*this)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ~(*this)[i]; } return this; } @@ -64,7 +62,7 @@ Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) template<> Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { (*this)[0] = ((*this)[0] == 0.0f) ? 1.0f : 0.0f; @@ -72,18 +70,20 @@ Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__, } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ((*this)[i] == 0.0f) ? 1.0f : 0.0f; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ((*this)[i] == 0.0f) ? 1.0f : 0.0f; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ((*this)[i] == 0.0f) ? 1.0f : 0.0f; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ((*this)[i] == 0.0f) ? 1.0f : 0.0f; } return this; } template<> Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { (*this)[0] = ((*this)[0] == 0.0) ? 1.0 : 0.0; @@ -91,11 +91,13 @@ Data_* Data_::NotOp() { TRACE_ROUTINE(__FUNCTION__,__FILE_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ((*this)[i] == 0.0) ? 1.0 : 0.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ((*this)[i] == 0.0) ? 1.0 : 0.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = ((*this)[i] == 0.0) ? 1.0 : 0.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = ((*this)[i] == 0.0) ? 1.0 : 0.0; } return this; } @@ -135,7 +137,7 @@ Data_* Data_::NotOp() { template BaseGDL* Data_::UMinus() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { (*this)[0] = -(*this)[0]; @@ -143,11 +145,13 @@ BaseGDL* Data_::UMinus() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = -(*this)[i]; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = -(*this)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = -(*this)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = -(*this)[i]; } return this; } @@ -156,7 +160,7 @@ template<> BaseGDL* Data_::UMinus() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) ULong nEl = N_Elements(); assert(nEl != 0); - Data_* newThis = static_cast*> (this->Convert2(GDL_FLOAT)); + auto newThis = dynamic_cast *> (this->Convert2(GDL_FLOAT)); // this is deleted by convert2!!! return static_cast (newThis->UMinus()); } @@ -178,9 +182,9 @@ BaseGDL* Data_::UMinus() { template Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(this->dim, BaseGDL::NOZERO); + auto res = new Data_(this->dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0] == 0) ? 1 : 0; @@ -188,11 +192,13 @@ Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0) ? 1 : 0; } return res; } @@ -200,8 +206,8 @@ Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) if (this->Scalar()) { - DSubUD* isTrueOverload = static_cast (GDLInterpreter::GetObjHeapOperator(dd[0], OOIsTrue)); - if (isTrueOverload != NULL) { + auto isTrueOverload = static_cast (GDLInterpreter::GetObjHeapOperator(dd[0], OOIsTrue)); + if (isTrueOverload != nullptr) { if (this->LogTrue()) return new Data_(0); else @@ -209,9 +215,9 @@ Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__ } } - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(this->dim, BaseGDL::NOZERO); + auto res = new Data_(this->dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0] == 0) ? 1 : 0; @@ -219,116 +225,128 @@ Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0) ? 1 : 0; } return res; } template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(this->dim, BaseGDL::NOZERO); + auto res = new Data_(this->dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0] == 0.0f) ? 1 : 0; return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0.0f) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0.0f) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0.0f) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0.0f) ? 1 : 0; } return res; } template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0] == 0.0) ? 1 : 0; return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0.0) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0.0) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == 0.0) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == 0.0) ? 1 : 0; } return res; } template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); if (nEl == 1) { - (*res)[0] = ((*this)[0] == "") ? 1 : 0; + (*res)[0] = ((*this)[0].empty()) ? 1 : 0; return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == "") ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].empty()) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == "") ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].empty()) ? 1 : 0; } return res; } template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0].real() == 0.0 && (*this)[0].imag() == 0.0) ? 1 : 0; return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; } return res; } template<> Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = dd.size(); + const auto nEl = static_cast(dd.size()); assert(nEl); - DByteGDL* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); if (nEl == 1) { (*res)[0] = ((*this)[0].real() == 0.0 && (*this)[0].imag() == 0.0) ? 1 : 0; return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i].real() == 0.0 && (*this)[i].imag() == 0.0) ? 1 : 0; } return res; } @@ -338,7 +356,7 @@ Data_* Data_::LogNeg() { TRACE_ROUTINE(__FUNCTION__,__FI template void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -347,17 +365,19 @@ void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i]--; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i]--; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i]--; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i]--; } } template void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -366,19 +386,20 @@ void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i]++; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i]++; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i]++; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i]++; } } // float template<> void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -387,18 +408,19 @@ void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } } template<> void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -407,19 +429,20 @@ void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } } // double template<> void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -428,18 +451,19 @@ void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } } template<> void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -448,19 +472,20 @@ void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } } // complex template<> void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -469,18 +494,19 @@ void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } } template<> void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -489,18 +515,19 @@ void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } } template<> void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -509,18 +536,19 @@ void Data_::Dec() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] -= 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] -= 1.0; } } template<> void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl != 0); if (nEl == 1) { @@ -529,11 +557,13 @@ void Data_::Inc() { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] += 1.0; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] += 1.0; } } // forbidden types @@ -577,10 +607,10 @@ void Data_::Inc() { // ex: b=(a eq 0) template BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -595,11 +625,13 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -609,21 +641,25 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } } else // ( rEl >= nEl) { @@ -634,11 +670,13 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } } return res; @@ -648,16 +686,16 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) if (Scalar()) { - DSubUD* EQOverload = static_cast (GDLInterpreter::GetObjHeapOperator((*this)[0], OOEQ)); - if (EQOverload == NULL) { + auto EQOverload = static_cast (GDLInterpreter::GetObjHeapOperator((*this)[0], OOEQ)); + if (EQOverload == nullptr) { //scalar object 'this' can be equal to NullGDL::GetSingleInstance() only of it is undefined. If not scalar, not equal, if defined, not equal. if (r == NullGDL::GetSingleInstance()) { DObj pVal; if (this->Scalar(pVal)) { if (pVal == 0) return new Data_(1); - return new DByteGDL(!interpreter->ObjValid(pVal)); + return new DByteGDL(!DInterpreter::ObjValid(pVal)); } - Data_* res = new Data_(this->dim, BaseGDL::NOZERO); + auto res = new Data_(this->dim, BaseGDL::NOZERO); (*res)[0] = (0 == (*this)[0]); return res; } @@ -694,12 +732,12 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack - StackGuard guard(interpreter->CallStack()); + StackGuard guard(DInterpreter::CallStack()); - interpreter->CallStack().push_back(newEnv); + DInterpreter::CallStack().push_back(newEnv); // make the call - BaseGDL* res = interpreter->call_fun(static_cast (newEnv->GetPro())->GetTree()); + BaseGDL *res = interpreter->call_fun(dynamic_cast (newEnv->GetPro())->GetTree()); if (!internalDSubUD && self != selfGuard.Get()) { // always put out warning first, in case of a later crash @@ -721,17 +759,17 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ if (r->Type() != GDL_OBJ) { if (r == NullGDL::GetSingleInstance()) // "this" is not scalar here -> return always false { - Data_* res = new Data_(0); + auto res = new Data_(0); return res; } throw GDLException("Unable to convert variable to type object reference.", true, false); } // same code as for other types from here - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -746,11 +784,13 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] == s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] == s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -760,21 +800,25 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } } else // ( rEl >= nEl) { @@ -785,11 +829,13 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] == (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] == (*this)[i]); } } return res; @@ -800,10 +846,10 @@ BaseGDL* Data_::EqOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ // ex b=(a ne 0) template BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -818,11 +864,13 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] != s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] != s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] != s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] != s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -832,21 +880,25 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } } else // ( rEl >= nEl) { @@ -857,11 +909,13 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } } return res; @@ -872,11 +926,10 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) if (Scalar()) { - DSubUD* NEOverload = - static_cast (GDLInterpreter::GetObjHeapOperator((*this)[0], OONE)); - if (NEOverload == NULL) { + auto NEOverload = static_cast (GDLInterpreter::GetObjHeapOperator((*this)[0], OONE)); + if (NEOverload == nullptr) { if (r == NullGDL::GetSingleInstance()) { - Data_* res = new Data_(this->dim, BaseGDL::NOZERO); + auto res = new Data_(this->dim, BaseGDL::NOZERO); (*res)[0] = (0 != (*this)[0]); return res; } @@ -913,12 +966,12 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack - StackGuard guard(interpreter->CallStack()); + StackGuard guard(DInterpreter::CallStack()); - interpreter->CallStack().push_back(newEnv); + DInterpreter::CallStack().push_back(newEnv); // make the call - BaseGDL* res = interpreter->call_fun(static_cast (newEnv->GetPro())->GetTree()); + BaseGDL *res = interpreter->call_fun(dynamic_cast (newEnv->GetPro())->GetTree()); if (!internalDSubUD && self != selfGuard.Get()) { // always put out warning first, in case of a later crash @@ -940,7 +993,7 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ if (r->Type() != GDL_OBJ) { if (r == NullGDL::GetSingleInstance()) // "this" is not scalar here -> return always true { - Data_* res = new Data_(1); + auto res = new Data_(1); return res; } @@ -948,10 +1001,10 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } // same code as for other types from here - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -966,11 +1019,13 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] != s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] != s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] != s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] != s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -980,21 +1035,25 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } } else // ( rEl >= nEl) { @@ -1005,11 +1064,13 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] != (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] != (*this)[i]); } } return res; @@ -1020,10 +1081,10 @@ BaseGDL* Data_::NeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ //ex:b=(a le 0) template BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -1038,11 +1099,13 @@ BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] <= s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] <= s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] <= s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] <= s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -1052,21 +1115,25 @@ BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] >= s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] >= s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] >= s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] >= s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] >= (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] >= (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] >= (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] >= (*this)[i]); } } else // ( rEl >= nEl) { @@ -1077,11 +1144,13 @@ BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] >= (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] >= (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] >= (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] >= (*this)[i]); } } return res; @@ -1091,13 +1160,13 @@ BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::LeOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); - return NULL; + return nullptr; } template<> BaseGDL* Data_::LeOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); - return NULL; + return nullptr; } template<> @@ -1115,10 +1184,10 @@ BaseGDL* Data_::LeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__ // ex: b=(a lt 0) template BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -1133,11 +1202,13 @@ BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] < s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] < s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] < s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] < s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -1147,21 +1218,25 @@ BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] > s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] > s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] > s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] > s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] > (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] > (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] > (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] > (*this)[i]); } } else // ( rEl >= nEl) { @@ -1172,11 +1247,13 @@ BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] > (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] > (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] > (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] > (*this)[i]); } } return res; @@ -1186,13 +1263,13 @@ BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::LtOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); - return NULL; + return nullptr; } template<> BaseGDL* Data_::LtOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); - return NULL; + return nullptr; } template<> @@ -1210,10 +1287,10 @@ BaseGDL* Data_::LtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__ // ex: b=(a ge 0) template BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -1228,11 +1305,13 @@ BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] >= s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] >= s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] >= s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] >= s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -1242,21 +1321,25 @@ BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] <= s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] <= s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] <= s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] <= s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] <= (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] <= (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] <= (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] <= (*this)[i]); } } else // ( rEl >= nEl) { @@ -1267,11 +1350,13 @@ BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] <= (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] <= (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] <= (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] <= (*this)[i]); } } return res; @@ -1281,13 +1366,13 @@ BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::GeOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); - return NULL; + return nullptr; } template<> BaseGDL* Data_::GeOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); - return NULL; + return nullptr; } template<> @@ -1305,10 +1390,10 @@ BaseGDL* Data_::GeOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__F // ex: b=(a gt 0) template BaseGDL* Data_::GtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -1323,11 +1408,13 @@ BaseGDL* Data_::GtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] > s); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] > s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*this)[i] > s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*this)[i] > s); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -1337,21 +1424,25 @@ BaseGDL* Data_::GtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] < s); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] < s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] < s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] < s); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] < (*this)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] < (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = ((*right)[i] < (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = ((*right)[i] < (*this)[i]); } } else // ( rEl >= nEl) { @@ -1362,11 +1453,13 @@ BaseGDL* Data_::GtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] < (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] < (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = ((*right)[i] < (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) + (*res)[i] = ((*right)[i] < (*this)[i]); } } return res; @@ -1376,13 +1469,13 @@ BaseGDL* Data_::GtOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LIN template<> BaseGDL* Data_::GtOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); - return NULL; + return nullptr; } template<> BaseGDL* Data_::GtOp(BaseGDL* r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); - return NULL; + return nullptr; } template<> @@ -1404,7 +1497,7 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { T bool at = atranspose; bool bt = btranspose; - Data_* par1 = static_cast (r); + auto par1 = static_cast (r); long NbCol0, NbRow0, NbCol1, NbRow1; //, NbCol2, NbRow2; SizeT rank0 = this->Rank(); @@ -1455,7 +1548,7 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { T long& NbRow2 = NbCol1; dimension dim(NbCol2, NbRow2); - Data_* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); // no guarding necessary: eigen only throws on memory allocation Map < Matrix, Aligned > m2(&(*res)[0], NbCol2, NbRow2); @@ -1469,7 +1562,7 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { T long& NbRow2 = NbCol1; dimension dim(NbCol2, NbRow2); - Data_* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); Map < Matrix, Aligned > m2(&(*res)[0], NbCol2, NbRow2); m2.noalias() = m0 * m1.transpose(); return res; @@ -1481,7 +1574,7 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { T long& NbRow2 = NbRow1; dimension dim(NbCol2, NbRow2); - Data_* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); Map < Matrix, Aligned > m2(&(*res)[0], NbCol2, NbRow2); m2.noalias() = m0.transpose() * m1; return res; @@ -1493,7 +1586,7 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { T long& NbRow2 = NbRow1; dimension dim(NbCol2, NbRow2); - Data_* res = new Data_(dim, BaseGDL::NOZERO); + auto res = new Data_(dim, BaseGDL::NOZERO); Map < Matrix, Aligned > m2(&(*res)[0], NbCol2, NbRow2); m2.noalias() = m0*m1; return res; @@ -1688,13 +1781,13 @@ Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool b template<> Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); - return NULL; + return nullptr; } template<> Data_* Data_::MatrixOp(BaseGDL* r, bool atranspose, bool btranspose) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); - return NULL; + return nullptr; } @@ -1708,9 +1801,9 @@ template Data_* Data_::AndOp(BaseGDL* r) // GDL_DEFINE_INTEGER_FUNCTION( Data_*) AndOp( BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] = (*this)[0] & (*right)[0]; // & Ty(1); @@ -1720,11 +1813,13 @@ Data_* Data_::AndOp(BaseGDL* r) // might be larger than this->dd if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] & (*right)[i]; // & Ty(1); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] & (*right)[i]; // & Ty(1); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] & (*right)[i]; // & Ty(1); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] & (*right)[i]; // & Ty(1); } return this; } @@ -1801,9 +1896,9 @@ Data_* Data_::AndOpInv(BaseGDL* r) { template Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; @@ -1814,18 +1909,20 @@ Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] &= s; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] &= s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) shared(s) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] &= s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] &= s; } return this; } template<> Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); ULong nEl = N_Elements(); assert(nEl); @@ -1833,7 +1930,8 @@ Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ // right->Scalar(s); if (s == zero) { { - for (SizeT i = 0; i < nEl; ++i) (*this)[i] = zero; + for (SizeT i = 0; i < static_cast(nEl); ++i) + (*this)[i] = zero; } } return this; @@ -1842,14 +1940,14 @@ Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ template<> Data_* Data_::AndOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); ULong nEl = N_Elements(); assert(nEl); Ty s = (*right)[0]; if (s == zero) { - for (SizeT i = 0; i < nEl; ++i) + for (SizeT i = 0; i < static_cast(nEl); ++i) (*this)[i] = zero; } return this; @@ -1869,7 +1967,7 @@ Data_* Data_::AndOpS(BaseGDL* r) { template<> Data_* Data_::AndOpS(BaseGDL* r) { - Data_* right = static_cast (r); + auto right = dynamic_cast (r); ULong nEl = N_Elements(); assert(nEl); @@ -1877,7 +1975,8 @@ Data_* Data_::AndOpS(BaseGDL* r) { // right->Scalar(s); if (s == zero) { { - for (SizeT i = 0; i < nEl; ++i) (*this)[i] = zero; + for (SizeT i = 0; i < static_cast(nEl); ++i) + (*this)[i] = zero; } } return this; @@ -1931,9 +2030,9 @@ Data_* Data_::AndOpInvS(BaseGDL* r) { template Data_* Data_::OrOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] = (*this)[0] | (*right)[0]; // | Ty(1); @@ -1941,11 +2040,13 @@ Data_* Data_::OrOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__L } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] | (*right)[i]; // | Ty(1); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] | (*right)[i]; // | Ty(1); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] | (*right)[i]; // | Ty(1); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] | (*right)[i]; // | Ty(1); } return this; } @@ -2025,9 +2126,9 @@ Data_* Data_::OrOpInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTI template Data_* Data_::OrOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -2036,11 +2137,13 @@ Data_* Data_::OrOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] | s; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] | s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = (*this)[i] | s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = (*this)[i] | s; } return this; } @@ -2118,9 +2221,9 @@ Data_* Data_::OrOpInvS(BaseGDL* r) {TRACE_ROUTINE(__FUNCTI template Data_* Data_::XorOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] ^= (*right)[0]; @@ -2131,21 +2234,25 @@ Data_* Data_::XorOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__ if (s != Sp::zero) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= s; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= s; } } } else { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= (*right)[i]; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= (*right)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= (*right)[i]; } } return this; @@ -2153,7 +2260,7 @@ Data_* Data_::XorOp(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__ // invalid types template<> -Data_* Data_::XorOp(BaseGDL* r) { +Data_ *Data_::XorOp(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype FLOAT.", true, false); return this; } @@ -2196,9 +2303,9 @@ Data_* Data_::XorOp(BaseGDL* r) { template Data_* Data_::XorOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] ^= /*(*this)[0] ^*/ (*right)[0]; @@ -2207,16 +2314,17 @@ Data_* Data_::XorOpS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ Ty s = (*right)[0]; if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= s; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] ^= s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] ^= s; } return this; } // different for floats -// for floats template<> Data_* Data_::XorOpS(BaseGDL* r) { @@ -2268,9 +2376,9 @@ Data_* Data_::XorOpS(BaseGDL* r) { template Data_* Data_::LtMark(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*this)[0] > (*right)[0]) (*this)[0] = (*right)[0]; @@ -2278,11 +2386,15 @@ Data_* Data_::LtMark(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] > (*right)[i]) (*this)[i] = (*right)[i]; + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] > (*right)[i]) + (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] > (*right)[i]) (*this)[i] = (*right)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] > (*right)[i]) + (*this)[i] = (*right)[i]; } return this; } @@ -2318,9 +2430,9 @@ Data_* Data_::LtMark(BaseGDL* r) { template Data_* Data_::LtMarkS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*this)[0] > (*right)[0]) (*this)[0] = (*right)[0]; @@ -2329,11 +2441,15 @@ Data_* Data_::LtMarkS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__, Ty s = (*right)[0]; if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] > s) (*this)[i] = s; + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] > s) + (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] > s) (*this)[i] = s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] > s) + (*this)[i] = s; } return this; } @@ -2372,9 +2488,9 @@ Data_* Data_::LtMarkS(BaseGDL* r) { template Data_* Data_::GtMark(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*this)[0] < (*right)[0]) (*this)[0] = (*right)[0]; @@ -2382,11 +2498,15 @@ Data_* Data_::GtMark(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] < (*right)[i]) (*this)[i] = (*right)[i]; + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] < (*right)[i]) + (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] < (*right)[i]) (*this)[i] = (*right)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] < (*right)[i]) + (*this)[i] = (*right)[i]; } return this; } @@ -2422,9 +2542,9 @@ Data_* Data_::GtMark(BaseGDL* r) { template Data_* Data_::GtMarkS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*this)[0] < (*right)[0]) (*this)[0] = (*right)[0]; @@ -2434,11 +2554,15 @@ Data_* Data_::GtMarkS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__, Ty s = (*right)[0]; if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] < s) (*this)[i] = s; + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] < s) + (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] < s) (*this)[i] = s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + if ((*this)[i] < s) + (*this)[i] = s; } return this; } @@ -2491,9 +2615,9 @@ inline DDouble DModulo(const DDouble& l, const DDouble& r) { template //avoiding segfault on integer zero divide for integers, FP treatment specialized below Data_* Data_::Mod(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { //accelerator for single value on LEFT if ((*right)[0] != this->zero) (*this)[0] %= (*right)[0]; else (*this)[0] = this->zero; @@ -2501,11 +2625,19 @@ Data_* Data_::Mod(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LI } // Multiple LEFT values, parallel section slowed by inner 'if' clause. if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*right)[ix] != this->zero) (*this)[ix] %= (*right)[ix]; else (*this)[ix] = this->zero; + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*right)[ix] != this->zero) + (*this)[ix] %= (*right)[ix]; + else + (*this)[ix] = this->zero; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*right)[ix] != this->zero) (*this)[ix] %= (*right)[ix]; else (*this)[ix] = this->zero; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*right)[ix] != this->zero) + (*this)[ix] %= (*right)[ix]; + else + (*this)[ix] = this->zero; } return this; @@ -2516,9 +2648,9 @@ Data_* Data_::Mod(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LI template<> // catching FPE exceptions for FP Data_* Data_::Mod(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); if (nEl == 1) { @@ -2528,11 +2660,13 @@ Data_* Data_::Mod(BaseGDL* r) { } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*this)[i], (*right)[i]); } GDLStopRegisteringFPExceptions(); @@ -2545,9 +2679,9 @@ Data_* Data_::Mod(BaseGDL* r) { template<> // catching FPE exceptions for FP Data_* Data_::Mod(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); if (nEl == 1) { @@ -2557,11 +2691,13 @@ Data_* Data_::Mod(BaseGDL* r) { } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*this)[i], (*right)[i]); } GDLStopRegisteringFPExceptions(); @@ -2577,9 +2713,9 @@ Data_* Data_::Mod(BaseGDL* r) { template //avoiding segfault on integer zero divide for integers, FP treatment specialzed below Data_* Data_::ModInv(BaseGDL * r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { //accelerator for LEFT singleton if ((*this)[0] != this->zero) (*this)[0] = (*right)[0] % (*this)[0]; else (*this)[0] = this->zero; @@ -2587,11 +2723,19 @@ Data_* Data_::Mod(BaseGDL* r) { } // Multiple LEFT values, parallel section slowed by inner 'if' clause. if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*this)[ix] != this->zero) (*this)[ix] = (*right)[ix] % (*this)[ix]; else (*this)[ix] = this->zero; + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*this)[ix] != this->zero) + (*this)[ix] = (*right)[ix] % (*this)[ix]; + else + (*this)[ix] = this->zero; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*this)[ix] != this->zero) (*this)[ix] = (*right)[ix] % (*this)[ix]; else (*this)[ix] = this->zero; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*this)[ix] != this->zero) + (*this)[ix] = (*right)[ix] % (*this)[ix]; + else + (*this)[ix] = this->zero; } return this; @@ -2601,9 +2745,9 @@ Data_* Data_::Mod(BaseGDL* r) { template<> // catching FPE exceptions Data_* Data_::ModInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); if (nEl == 1) { @@ -2613,11 +2757,13 @@ Data_* Data_::ModInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*right)[i], (*this)[i]); } GDLStopRegisteringFPExceptions(); @@ -2629,9 +2775,9 @@ Data_* Data_::ModInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ template<>// catching FPE exceptions Data_* Data_::ModInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); if (nEl == 1) { @@ -2641,11 +2787,13 @@ Data_* Data_::ModInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTIO } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*right)[i], (*this)[i]); } GDLStopRegisteringFPExceptions(); @@ -2723,15 +2871,16 @@ Data_* Data_::ModInv(BaseGDL* r) { template //avoiding segfault on integer zero divide for integers, FP treatment specialized below Data_* Data_::ModS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (s == this->zero) { - for (SizeT i = 0; i < nEl; ++i) (*this)[i] = 0; + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = 0; //add an FP div by zero to counters GDLRegisterADivByZeroException(); return this; @@ -2742,11 +2891,13 @@ Data_* Data_::ModS(BaseGDL* r) { return this; } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt ix = 0; ix < nEl; ++ix) (*this)[ix] %= s; + for (OMPInt ix = 0; ix < nEl; ++ix) + (*this)[ix] %= s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt ix = 0; ix < nEl; ++ix) (*this)[ix] %= s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt ix = 0; ix < nEl; ++ix) + (*this)[ix] %= s; } return this; } @@ -2754,9 +2905,9 @@ Data_* Data_::ModS(BaseGDL* r) { template<> Data_* Data_::ModS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); Ty s = (*right)[0]; @@ -2767,11 +2918,13 @@ Data_* Data_::ModS(BaseGDL* r) { } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*this)[i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*this)[i], s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo((*this)[i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo((*this)[i], s); } GDLStopRegisteringFPExceptions(); @@ -2782,9 +2935,9 @@ Data_* Data_::ModS(BaseGDL* r) { template<> Data_* Data_::ModS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); Ty s = (*right)[0]; @@ -2795,11 +2948,13 @@ Data_* Data_::ModS(BaseGDL* r) { } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*this)[i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*this)[i], s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo((*this)[i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo((*this)[i], s); } GDLStopRegisteringFPExceptions(); @@ -2814,9 +2969,9 @@ Data_* Data_::ModS(BaseGDL* r) { template//avoiding segfault on integer zero divide for integers, FP treatment specialized below Data_* Data_::ModInvS(BaseGDL * r) { TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; @@ -2827,11 +2982,19 @@ template//avoiding segfault on integer zero divide for integers, FP t } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*this)[ix] != this->zero) (*this)[ix] = s % (*this)[ix]; else GDLRegisterADivByZeroException(); //add an FP div by zero to counters + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*this)[ix] != this->zero) + (*this)[ix] = s % (*this)[ix]; + else + GDLRegisterADivByZeroException(); //add an FP div by zero to counters } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt ix = 0; ix < nEl; ++ix) if ((*this)[ix] != this->zero) (*this)[ix] = s % (*this)[ix]; else GDLRegisterADivByZeroException(); //add an FP div by zero to counters +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt ix = 0; ix < nEl; ++ix) + if ((*this)[ix] != this->zero) + (*this)[ix] = s % (*this)[ix]; + else + GDLRegisterADivByZeroException(); //add an FP div by zero to counters } return this; @@ -2840,9 +3003,9 @@ template//avoiding segfault on integer zero divide for integers, FP t // float inverse modulo division: left=right % left template<> Data_* Data_::ModInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); Ty s = (*right)[0]; @@ -2853,11 +3016,13 @@ Data_* Data_::ModInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo(s, (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo(s, (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = Modulo(s, (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = Modulo(s, (*this)[i]); } GDLStopRegisteringFPExceptions(); @@ -2868,9 +3033,9 @@ Data_* Data_::ModInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION // double inverse modulo division: left=right % left template<> Data_* Data_::ModInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); GDLStartRegisteringFPExceptions(); Ty s = (*right)[0]; @@ -2881,11 +3046,13 @@ Data_* Data_::ModInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTI } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo(s, (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo(s, (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = DModulo(s, (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = DModulo(s, (*this)[i]); } GDLStopRegisteringFPExceptions(); @@ -2957,9 +3124,9 @@ Data_* Data_::ModInvS(BaseGDL* r) { template Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] = pow((*this)[0], (*right)[0]); @@ -2967,11 +3134,13 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LI } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); // valarray + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); // valarray } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); // valarray +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); // valarray } return this; } @@ -2979,9 +3148,9 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LI template Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { (*this)[0] = pow((*right)[0], (*this)[0]); @@ -2989,11 +3158,13 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } return this; } @@ -3001,10 +3172,10 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,_ template<> Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (nEl == 1) { @@ -3012,11 +3183,13 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,_ return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } @@ -3024,56 +3197,64 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,_ // anygdl (except complex) power to a GDL_LONG value left=left ^ right template Data_* Data_::PowInt(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - DLongGDL* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (r->StrictScalar()) { DLong r0 = (*right)[0]; if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = gdl::powI((*this)[i], r0); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = gdl::powI((*this)[i], r0); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = gdl::powI((*this)[i], r0); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, r0) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = gdl::powI((*this)[i], r0); } return this; } if (StrictScalar()) { - Data_* res = new Data_(right->Dim(), BaseGDL::NOZERO); + auto res = new Data_(right->Dim(), BaseGDL::NOZERO); Ty s0 = (*this)[ 0]; if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = gdl::powI(s0, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = gdl::powI(s0, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = gdl::powI(s0, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s0) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = gdl::powI(s0, (*right)[i]); } return res; } if (nEl <= rEl) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = gdl::powI((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = gdl::powI((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = gdl::powI((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = gdl::powI((*this)[i], (*right)[i]); } return this; } else { - Data_* res = new Data_(right->Dim(), BaseGDL::NOZERO); + auto res = new Data_(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = gdl::powI((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = gdl::powI((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = gdl::powI((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = gdl::powI((*this)[i], (*right)[i]); } return res; } @@ -3082,15 +3263,15 @@ template<> Data_* Data_::PowInt(BaseGDL* r) { assert(0); throw GDLException("Internal error: Data_::PowInt called.", true, false); - return NULL; + return nullptr; } template<> Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (nEl == 1) { @@ -3098,11 +3279,13 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } return this; } @@ -3110,10 +3293,10 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ template<> Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (nEl == 1) { @@ -3122,11 +3305,13 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } @@ -3134,10 +3319,10 @@ Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__ template<> Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (nEl == 1) { @@ -3146,11 +3331,13 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTIO } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } return this; } @@ -3159,156 +3346,168 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTIO template<> Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl > 0); assert(r->N_Elements() > 0); if (r->Type() == GDL_FLOAT) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); - DFloat s; + DFloat helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) // (must also be consistent with ComplexDbl) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplex s; if (StrictScalar(s)) { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } if (r->Type() == GDL_LONG) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); - DLong s; + DLong helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) // (must also be consistent with ComplexDbl) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplex s; if (StrictScalar(s)) { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } - Data_* right = static_cast (r); - -#if (__GNUC__ == 3) && (__GNUC_MINOR__ <= 2) - for (SizeT i = 0; i < nEl; ++i) - (*this)[ i] = pow((*this)[ i], (*right)[ i]); -#else - if (nEl == 1) { + auto right = dynamic_cast (r); + if (nEl == 1) { (*this)[0] = pow((*this)[0], (*right)[0]); return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } -#endif return this; } // complex inverse power of value: left=right ^ left template<> Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); if (nEl == 1) { @@ -3316,11 +3515,13 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCT return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } return this; } @@ -3328,222 +3529,231 @@ Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCT template<> Data_* Data_::Pow(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl > 0); if (r->Type() == GDL_DOUBLE) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); assert(right->N_Elements() > 0); - DDouble s; + DDouble helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplexDbl s; if (StrictScalar(s)) { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } if (r->Type() == GDL_LONG) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); assert(right->N_Elements() > 0); - DLong s; + DLong helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplexDbl s; if (StrictScalar(s)) { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } - Data_* right = static_cast (r); - -#if (__GNUC__ == 3) && (__GNUC_MINOR__ <= 2) - for (SizeT i = 0; i < nEl; ++i) - (*this)[ i] = pow((*this)[ i], (*right)[ i]); -#else + auto right = dynamic_cast (r); if (nEl == 1) { (*this)[0] = pow((*this)[0], (*right)[0]); return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], (*right)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } -#endif return this; } // double complex inverse power of value: left=right ^ left template<> Data_* Data_::PowInv(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); -#if (__GNUC__ == 3) && (__GNUC_MINOR__ <= 2) - for (SizeT i = 0; i < nEl; ++i) - (*this)[ i] = pow((*right)[ i], (*this)[i]); -#else if (nEl == 1) { (*this)[0] = pow((*right)[0], (*this)[0]); return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*right)[i], (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*right)[i], (*this)[i]); } -#endif return this; } // invalid types template<> -Data_* Data_::Pow(BaseGDL* r) { +Data_ *Data_::Pow(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype STRING.", true, false); return this; } template<> -Data_* Data_::PowInv(BaseGDL* r) { +Data_ *Data_::PowInv(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype STRING.", true, false); return this; } template<> -Data_* Data_::Pow(BaseGDL* r) { +Data_ *Data_::Pow(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); return this; } template<> -Data_* Data_::PowInv(BaseGDL* r) { +Data_ *Data_::PowInv(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype PTR.", true, false); return this; } template<> -Data_* Data_::Pow(BaseGDL* r) { +Data_ *Data_::Pow(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); return this; } template<> -Data_* Data_::PowInv(BaseGDL* r) { +Data_ *Data_::PowInv(BaseGDL *r) { throw GDLException("Cannot apply operation to datatype OBJECT.", true, false); return this; } template Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -3552,11 +3762,13 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__L } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow((*this)[i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } return this; } @@ -3564,9 +3776,9 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__L template Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = static_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -3575,11 +3787,13 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__, } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow(s, (*this)[i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = pow(s, (*this)[i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } return this; } @@ -3587,9 +3801,9 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__, template<> Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; @@ -3598,11 +3812,13 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(dd[ i], s); // valarray + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(dd[i], s); // valarray } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(dd[ i], s); // valarray +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(dd[i], s); // valarray } return this; } @@ -3610,9 +3826,9 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__, template<> Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -3620,11 +3836,13 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(s, dd[ i]); // valarray + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(s, dd[i]); // valarray } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(s, dd[ i]); // valarray +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(s, dd[i]); // valarray } return this; } @@ -3632,9 +3850,9 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION template<> Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; @@ -3644,11 +3862,13 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(dd[ i], s); // valarray + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(dd[i], s); // valarray } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(dd[ i], s); // valarray +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(dd[i], s); // valarray } return this; } @@ -3656,9 +3876,9 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION_ template<> Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -3667,11 +3887,13 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTI } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(s, dd[ i]); // valarray + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(s, dd[i]); // valarray } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) dd[ i] = pow(s, dd[ i]); // valarray +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + dd[i] = pow(s, dd[i]); // valarray } return this; } @@ -3680,129 +3902,145 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTI template<> Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl > 0); assert(r->N_Elements() > 0); if (r->Type() == GDL_FLOAT) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); - DFloat s; + DFloat helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) // (must also be consistent with ComplexDbl) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplex s; if (StrictScalar(s)) { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } if (r->Type() == GDL_LONG) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); - DLong s; + DLong helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) // (must also be consistent with ComplexDbl) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplex s; if (StrictScalar(s)) { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexGDL* res = new DComplexGDL(right->Dim(), + auto res = new DComplexGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } - Data_* right = static_cast (r); + auto right = dynamic_cast (r); Ty s = (*right)[0]; if (nEl == 1) { @@ -3810,11 +4048,13 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTIO return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } return this; } @@ -3822,10 +4062,10 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTIO template<> Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); Ty s = (*right)[0]; @@ -3834,11 +4074,13 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNC return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow(s, (*this)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow(s, (*this)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } return this; } @@ -3846,132 +4088,148 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNC template<> Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - SizeT nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl > 0); if (r->Type() == GDL_DOUBLE) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); assert(right->N_Elements() > 0); - DDouble s; + DDouble helper; // note: changes here have to be reflected in POWNCNode::Eval() (prognodeexpr.cpp) // (concerning when a new variable is created vs. using this) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplexDbl s; if (StrictScalar(s)) { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } if (r->Type() == GDL_LONG) { - Data_* right = static_cast*> (r); + auto right = dynamic_cast *> (r); assert(right->N_Elements() > 0); - DLong s; + DLong helper; // note: changes here have to be reflected in POWNCNode::Eval() (dnode.cpp) // (concerning when a new variable is created vs. using this) - if (right->StrictScalar(s)) { + if (right->StrictScalar(helper)) { if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, helper) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], helper); } return this; } else { - SizeT rEl = right->N_Elements(); + const auto rEl = static_cast(right->N_Elements()); if (nEl < rEl) { DComplexDbl s; if (StrictScalar(s)) { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow(s, (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow(s, (*right)[i]); } return res; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], (*right)[i]); } return this; } else { - DComplexDblGDL* res = new DComplexDblGDL(right->Dim(), + auto res = new DComplexDblGDL(right->Dim(), BaseGDL::NOZERO); if ((GDL_NTHREADS=parallelize( rEl))==1) { - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[ i] = pow((*this)[ i], (*right)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) + (*res)[i] = pow((*this)[i], (*right)[i]); } return res; } } } - Data_* right = static_cast (r); + auto right = dynamic_cast (r); Ty s = (*right)[0]; if (nEl == 1) { @@ -3979,11 +4237,13 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__F return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow((*this)[ i], s); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow((*this)[i], s); } return this; } @@ -3992,9 +4252,9 @@ Data_* Data_::PowS(BaseGDL* r) { TRACE_ROUTINE(__F template<> Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -4002,11 +4262,13 @@ Data_* Data_::PowInvS(BaseGDL* r) { TRACE_ROUTINE( return this; } if ((GDL_NTHREADS=parallelize( nEl))==1) { - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow(s, (*this)[ i]); + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[ i] = pow(s, (*this)[ i]); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) + (*this)[i] = pow(s, (*this)[i]); } return this; } diff --git a/src/datatypes.cpp b/src/datatypes.cpp index e26ea730b..7a8f6a6d8 100644 --- a/src/datatypes.cpp +++ b/src/datatypes.cpp @@ -493,6 +493,196 @@ template<> Data_::Data_(const dimension& dim_, BaseGDL::InitType iT, DDo } } +template Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble off, DDouble inc): + Sp(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + this->dim.Purge(); + + if (iT == BaseGDL::NOZERO) + return; //very frequent + + if (iT == BaseGDL::ZERO) { //rather frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } + } else if (iT == BaseGDL::INDGEN) { //less frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + if (off == 0 && inc == 1) { + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = i; + } else { + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = off + (double) i * inc; + } + } else { + if (off == 0 && inc == 1) { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = i; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(inc, off, sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = off + (double) i * inc; + } + } + } +} + +//IDL uses floats increments and offset for floats and complex (normal) . +template<> Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble off, DDouble inc): + SpDFloat(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + this->dim.Purge(); + + if (iT == BaseGDL::NOZERO) + return; //very frequent + + if (iT == BaseGDL::ZERO) { //rather frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } + } else if (iT == BaseGDL::INDGEN) { //less frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + if (off == 0 && inc == 1) { + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = static_cast(i); + } else { + auto f_off = static_cast(off); + auto f_inc = static_cast(inc); + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = f_off + i * f_inc; + } + } else { + if (off == 0 && inc == 1) { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = static_cast(i); + } else { + auto f_off = static_cast(off); + auto f_inc = static_cast(inc); + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(f_inc, f_off, sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = f_off + static_cast(i) * f_inc; + } + } + } +} + +template<> Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble off, DDouble inc): + SpDComplex(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + this->dim.Purge(); + + if (iT == BaseGDL::NOZERO) + return; //very frequent + + if (iT == BaseGDL::ZERO) { //rather frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } + } else if (iT == BaseGDL::INDGEN) { //less frequent + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + if (off == 0 && inc == 1) { + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = static_cast(i); + } else { + auto f_off = static_cast(off); + auto f_inc = static_cast(inc); + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = f_off + static_cast(i) * f_inc; + } + } else { + if (off == 0 && inc == 1) { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = static_cast(i); + } else { + auto f_off = static_cast(off); + auto f_inc = static_cast(inc); + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(f_inc, f_off, sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = f_off + static_cast(i) * f_inc; + } + } + } +} + +template<> Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble, DDouble): + SpDString(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + dim.Purge(); + + if (iT == BaseGDL::INDGEN) + throw GDLException("DStringGDL(dim,InitType=INDGEN) called."); +} + +template<> Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble, DDouble): + SpDPtr(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + dim.Purge(); + + if (iT == BaseGDL::INDGEN) + throw GDLException("DPtrGDL(dim,InitType=INDGEN) called."); + + if (iT != BaseGDL::NOALLOC && iT != BaseGDL::NOZERO) { + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } + } +} +template<> Data_::Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble, DDouble): + SpDObj(dimension(dimSize_)), dd((iT == BaseGDL::NOALLOC) ? 0 : this->dim.NDimElements(), false) { + dim.Purge(); + + if (iT == BaseGDL::INDGEN) + throw GDLException("DObjGDL(dim,InitType=INDGEN) called."); + + if (iT != BaseGDL::NOALLOC && iT != BaseGDL::NOZERO) { + SizeT sz = dd.size(); + if ((GDL_NTHREADS = parallelize(sz, TP_ARRAY_INITIALISATION)) == 1) { //most frequent + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } else { + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(sz) + for (SizeT i = 0; i < sz; ++i) + (*this)[i] = 0; + } + } +} + // c-i //template //Data_::Data_(const Data_& d_): Sp(d_.dim), dd(d_.dd) { } diff --git a/src/datatypes.hpp b/src/datatypes.hpp index f08077e78..ed035d4f9 100644 --- a/src/datatypes.hpp +++ b/src/datatypes.hpp @@ -113,7 +113,10 @@ static void operator delete( void *ptr); // new array, no zero or indgen Data_(const dimension& dim_, BaseGDL::InitType iT, DDouble start = 0, DDouble increment = 1); - + + // convenience constructor, since we often call using integer dimensions + Data_(const SizeT &dimSize_, BaseGDL::InitType iT, DDouble start = 0, DDouble increment = 1); + // new array, zero fields Data_(const dimension& dim_); diff --git a/src/dialog.cpp b/src/dialog.cpp index 8a594f25a..aceb8695c 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -44,9 +44,7 @@ namespace lib { TITLE=title) */ -#ifdef HAVE_LOCALE_H setlocale(LC_ALL, "C"); -#endif bool isdefault_extension = false; bool isdirectory = false; @@ -323,9 +321,7 @@ namespace lib { BaseGDL* dialog_message_wxwidgets(EnvT* e) { -#ifdef HAVE_LOCALE_H setlocale(LC_ALL, "C"); -#endif DStringGDL* messagestr; bool iscancel = false; diff --git a/src/dimension.hpp b/src/dimension.hpp index 39518deb4..390988c53 100644 --- a/src/dimension.hpp +++ b/src/dimension.hpp @@ -28,55 +28,49 @@ typedef char RankT; -inline SizeT RankIx( const SizeT rank) -{ - return (rank <= 1)? 0 : rank-1; +inline SizeT RankIx(const SizeT rank) { + return (rank <= 1) ? 0 : rank - 1; } -class dimension -{ - SizeT dim[MAXRANK]; // dimension - mutable SizeT stride[MAXRANK+1]; // stride +class dimension { + SizeT dim[MAXRANK]{}; // dimension + mutable SizeT stride[MAXRANK + 1]{}; // stride - char rank; // how many dim are valid + unsigned char rank; // how many dim are valid public: // structors - dimension(): rank(0) - { + dimension() : rank(0) { stride[0] = 0; // mark as not set } // c-i - dimension(const dimension& dim_) - { + dimension(const dimension &dim_) { rank = dim_.rank; - for(SizeT i=0; i MAXRANK) - throw GDLException("Only "+MAXRANK_STR+" dimensions allowed."); + if (rank > MAXRANK) + throw GDLException("Only " + MAXRANK_STR + " dimensions allowed."); + + for (SizeT i = thisRank; i < rank; ++i) + dim[i] = add.dim[i - thisRank]; - for( SizeT i=thisRank; i>(const SizeT add) - { - SizeT thisRank = rank++; - - if( rank > MAXRANK) - throw GDLException("Only "+MAXRANK_STR+" dimensions allowed."); - - for( int i=thisRank-1; i>=0; i--) - { - dim[i+1]=dim[i]; - } - - dim[0]=add; - + void operator>>(const SizeT add) { + unsigned char thisRank = rank++; + + if (rank > MAXRANK) + throw GDLException("Only " + MAXRANK_STR + " dimensions allowed."); + + for (auto i = thisRank - 1; i >= 0; i--) { + dim[i + 1] = dim[i]; + } + + dim[0] = add; + stride[0] = 0; // not set } // cat add to left - void operator>>(const dimension& add) - { + void operator>>(const dimension &add) { int thisRank = rank; - int addRank = add.rank; - + int addRank = add.rank; + rank += addRank; - if( rank > static_cast(MAXRANK)) - throw GDLException("Only "+MAXRANK_STR+" dimensions allowed."); + if (rank > MAXRANK) + throw GDLException("Only " + MAXRANK_STR + " dimensions allowed."); // shift dim by addRank - for( int i=thisRank-1; i>=0; i--) - { - dim[i+addRank]=dim[i]; - } + for (int i = thisRank - 1; i >= 0; i--) { + dim[i + addRank] = dim[i]; + } // insert add on the left - for( int i=0; i static_cast(MAXRANK)) - throw GDLException("Only "+MAXRANK_STR+" dimensions allowed."); + if (rank > MAXRANK) + throw GDLException("Only " + MAXRANK_STR + " dimensions allowed."); // shift dim by addRank - for( int i=thisRank-1; i>=0; i--) - { - dim[i+addRank]=dim[i]; - } + for (int i = thisRank - 1; i >= 0; i--) { + dim[i + addRank] = dim[i]; + } // insert add on the left - for( int i=0; i= rank) return 0; + SizeT operator[](const SizeT d1) const { + if (d1 >= rank) + return 0; return dim[d1]; } // members // number of elements - SizeT NDimElements() - { - if( stride[0] == 0) InitStride(); - return stride[ rank]; + SizeT NDimElements() { + if (stride[0] == 0) + InitStride(); + return stride[rank]; // SizeT res=1; // for(unsigned i=0; i= rank) rank = ix+1; - dim[ix]=d; + void SetOneDim(const SizeT ix, const SizeT d) { + if (ix >= rank) + rank = ix + 1; + dim[ix] = d; stride[0] = 0; // not set } - SizeT Stride(const SizeT i) const - { - if( stride[0] == 0) + SizeT Stride(const SizeT i) const { + if (stride[0] == 0) this->InitStride(); // const_cast(this)->InitStride(); - return stride[ (iInitStride(); return stride; } - - void Stride( SizeT s[], SizeT upto) const - { - assert( upto >= 1); - if( stride[0] == 0) + + void Stride(SizeT s[], SizeT upto) const { + assert(upto >= 1); + if (stride[0] == 0) this->InitStride(); // copy - for(int m=0; m<=upto; ++m) + for (SizeT m = 0; m <= upto; ++m) s[m] = stride[m]; // s[0]=1; // upto must be at least 1 // if( stride[0] == 0) // stride not set yet @@ -374,69 +350,62 @@ class dimension // } // } } - + // we must do a full stride calculation here because // variables might be indexed with more dimensions they actually have // (which indices then must all be zero) - void InitStride() const - { - if( rank == 0) - { - for(int m=0; m<=MAXRANK; ++m) - stride[m] = 1; - } - else - { - stride[0]=1; - stride[1]=dim[0]; - int m=1; - for(; mscalar .. MAXRANK) // dim[rank]=0 for rank1 && dim[eqrank-1] <= 1; --eqrank); - return eqrank-i; + SizeT EquivalentRank() const { + unsigned char eqrank = rank; + unsigned char i = 0; + for (; i < eqrank && dim[i] <= 1; ++i); + for (; eqrank > 1 && dim[eqrank - 1] <= 1; --eqrank); + return eqrank - i; } - // throw away unused ranks (ie. ranks == 1) - inline void Purge() - { - for(; rank>1 && dim[rank-1] <= 1; --rank); + // throw away unused ranks (i.e. ranks == 1) + inline void Purge() { + for (; rank > 1 && dim[rank - 1] <= 1; --rank); } // set the rank to r (pads 1s) if it is smaller than r - void InsureRankAtLeast(SizeT r) - { - SizeT rNow=rank; - if( rNow >= r) return; - if( r > MAXRANK) - throw GDLException("Maximum "+MAXRANK_STR+" dimensions are allowed."); - for( SizeT i=rNow; i= r) + return; + if (r > MAXRANK) + throw GDLException("Maximum " + MAXRANK_STR + " dimensions are allowed."); + for (SizeT i = rNow; i < r; ++i) + dim[i] = 1; rank = r; // as we always InitStride() to MAXRANK+1 stride is still valid // stride[0] = 0; } - void MakeArrayFromScalar() - { - assert( rank == 0); - assert( stride[0] == 0); - dim[0]=1; - rank=1; + void MakeArrayFromScalar() { + assert(rank == 0); + assert(stride[0] == 0); + dim[0] = 1; + rank = 1; } }; diff --git a/src/gdl.cpp b/src/gdl.cpp index 482b29701..2a504ec74 100644 --- a/src/gdl.cpp +++ b/src/gdl.cpp @@ -53,9 +53,7 @@ # include "mpi.h" #endif -#ifdef HAVE_LOCALE_H -# include -#endif +#include // GDLDATADIR #include "config.h" @@ -102,7 +100,7 @@ void InitOpenMP() { // update of !cpu.TPOOL_NTHREADS DStructGDL* cpu = SysVar::Cpu(); static unsigned NTHREADSTag = cpu->Desc()->TagIndex( "TPOOL_NTHREADS"); - (*static_cast( cpu->GetTag( NTHREADSTag, 0)))[0] =suggested_num_threads; + (*dynamic_cast(cpu->GetTag( NTHREADSTag, 0)))[0] = suggested_num_threads; // effective global change of num of treads using omp_set_num_threads() CpuTPOOL_NTHREADS=suggested_num_threads; @@ -125,16 +123,18 @@ void AtExit() } #ifndef _WIN32 -void GDLSetLimits() -{ -#define GDL_PREFERED_STACKSIZE 1024000000 //1000000*1024 like IDL -struct rlimit gdlstack; - int r=getrlimit(RLIMIT_STACK,&gdlstack); -// cerr <<"Current rlimit = "<rlim_cur<= gdlPreferredStackSize) return; //the bigger, the better. + if (gdlstack.rlim_max > gdlPreferredStackSize) gdlstack.rlim_cur = gdlPreferredStackSize; //not completely satisfactory. + + result = setrlimit(RLIMIT_STACK, &gdlstack); + if (result != 0) throw GDLException(DString("setrlimit failed with error: ") + strerror(errno)); } #endif @@ -173,58 +173,43 @@ void InitGDL() // ensuring we work in the C locale (needs to be called after InitObjects and LibInit!!! // as some code there calls setlocale as well, e.g. MagickInit) -#ifdef HAVE_LOCALE_H setlocale(LC_ALL, "C"); -#endif lib::SetGDLGenericGSLErrorHandler(); } -static bool trace_me; - // SA: for use in COMMAND_LINE_ARGS() namespace lib { extern std::vector command_line_args; #ifdef _WIN32 bool posixpaths; #endif - bool gdlarg_present(const char* s) - { - for (size_t i = 0; i < command_line_args.size(); i++) - if( command_line_args[i] == s ) return true; - return false; - } + bool gdlarg_present(const char* s) { + return std::any_of(command_line_args.begin(), command_line_args.end(), [s](const std::string &arg) { return arg == s; }); + } bool trace_arg() { - for (size_t i = 0; i < command_line_args.size(); i++) - if( command_line_args[i] == "trace" ) return true; - return false; - } - + return std::any_of(command_line_args.begin(), command_line_args.end(), [](const std::string &arg) { return arg == "trace"; }); + } } #include namespace MyPaths { - std::string getExecutablePath(){ - char* path = NULL; - - int length, dirname_length; - int i; - length = wai_getExecutablePath(NULL, 0, &dirname_length); - if (length > 0) - { - path = (char*)malloc(length + 1); - if (!path) return std::string("."); - wai_getExecutablePath(path, length, &dirname_length); - path[dirname_length] = '\0'; -// printf(" dirname: %s\n", path); - std::string pathstring(path); - free(path); - return pathstring; + std::string getExecutablePath() { + int length = wai_getExecutablePath(nullptr, 0, nullptr); + if (length > 0) + { + char* path = (char*)calloc(length + 1, sizeof(char)); + if (!path) return {"."}; + wai_getExecutablePath(path, length, nullptr); + path[length] = '\0'; + std::string pathstring(path); + free(path); + return pathstring; + } + return {"."}; } - return std::string("."); -} } int main(int argc, char *argv[]) @@ -235,7 +220,7 @@ int main(int argc, char *argv[]) bool gdlde = false; bool setQuietSysvar=false; bool willSuppressEditInput=false; - std::string myMessageBoxName=""; + std::string myMessageBoxName; //The default installation location --- will not always be there. gdlDataDir = std::string(GDLDATADIR); @@ -257,11 +242,11 @@ int main(int argc, char *argv[]) //PATH. This one is often modified by people before starting GDL. string gdlPath=GetEnvPathString("GDL_PATH"); //warning: is a Path, use system separator. - if( gdlPath == "") gdlPath=GetEnvString("IDL_PATH"); //warning: is a Path, use system separator. - if( gdlPath == "") gdlPath = gdlDataDir + lib::PathSeparator() + "lib"; + if( gdlPath.empty()) gdlPath = GetEnvString("IDL_PATH"); //warning: is a Path, use system separator. + if( gdlPath.empty()) gdlPath = gdlDataDir + lib::PathSeparator() + "lib"; char* wantCalm = getenv("IDL_QUIET"); - if (wantCalm != NULL) setQuietSysvar=true; + if (wantCalm != nullptr) setQuietSysvar=true; // keeps a list of files to be executed after the startup file // and before entering the interactive mode @@ -270,32 +255,28 @@ int main(int argc, char *argv[]) string pretendRelease; bool strict_syntax=false; bool syntaxOptionSet=false; - +#ifdef HAVE_X bool force_no_wxgraphics = false; - usePlatformDeviceName=false; +#endif + usePlatformDeviceName = false; tryToMimicOriginalWidgets = false; useDSFMTAcceleration = true; - iAmANotebook=false; //option --notebook - iAmMaster=true; //special option --subprocess - #ifdef HAVE_LIBWXWIDGETS - - #if defined (__WXMAC__) - useWxWidgets=true; - #elif defined (__WXMSW__) - useWxWidgets=true; - #else - if (GetEnvString("DISPLAY").length() > 0) useWxWidgets=true; else useWxWidgets=false; - #endif - + iAmANotebook = false; //option --notebook + iAmMaster = true; //special option --subprocess +#ifdef HAVE_LIBWXWIDGETS + #if defined (__WXMAC__) || defined (__WXMSW__) + useWxWidgets = true; + #else + useWxWidgets = !GetEnvString("DISPLAY").empty(); + #endif #else - useWxWidgets=false; + useWxWidgets = false; #endif #ifdef _WIN32 lib::posixpaths = false; #endif - for( SizeT a=1; a< argc; ++a) - { - if( string( argv[a]) == "--help" || string( argv[a]) == "-h") { + for( int a = 1; a < argc; ++a) { + if( string( argv[a]) == "--help" || string( argv[a]) == "-h") { cerr << "Usage: gdl [ OPTIONS ] [ batch_file ... ]" << endl; cerr << "Start the GDL interpreter (incremental compiler)" << endl; cerr << endl; @@ -338,31 +319,25 @@ int main(int argc, char *argv[]) cerr << "Homepage: https://gnudatalanguage.github.io" << endl; return 0; } - else if (string(argv[a])=="--version" || string(argv[a])=="-v" || string(argv[a])=="-V") - { + else if (string(argv[a])=="--version" || string(argv[a])=="-v" || string(argv[a])=="-V") { cerr << "GDL - GNU Data Language, Version " << VERSION << endl; return 0; } - else if( string( argv[a]) == "-arg") - { - if (a == argc - 1) - { - cerr << "gdl: -arg must be followed by a user argument." << endl; - return 0; - } - lib::command_line_args.push_back(string(argv[++a])); + else if( string( argv[a]) == "-arg") { + if (a == argc - 1) { + cerr << "gdl: -arg must be followed by a user argument." << endl; + return 0; } - else if( string( argv[a]) == "-args") - { - for (int i = a + 1; i < argc; i++) lib::command_line_args.push_back(string(argv[i])); + lib::command_line_args.emplace_back(argv[++a]); + } + else if (string(argv[a]) == "-args") { + for (int i = a + 1; i < argc; i++) lib::command_line_args.emplace_back(argv[i]); break; - } - else if (string(argv[a])=="-quiet" || string(argv[a])=="--quiet" || string(argv[a])=="-q") - { + } + else if (string(argv[a])=="-quiet" || string(argv[a])=="--quiet" || string(argv[a])=="-q") { quiet = true; } - else if (string(argv[a]).find("-pref=") ==0) - { + else if (string(argv[a]).find("-pref=") ==0) { cerr << "This option is not operational now" << endl; string tmp; tmp=string(argv[a]); @@ -378,113 +353,101 @@ int main(int argc, char *argv[]) } file_params.close(); } - else if (string(argv[a]) == "-e") - { - if (a == argc - 1) - { - cerr << "gdl: -e must be followed by a user argument." << endl; - return 0; - } + else if (string(argv[a]) == "-e") { + if (a == argc - 1) { + cerr << "gdl: -e must be followed by a user argument." << endl; + return 0; + } statement = string(argv[++a]); statement.append("\n"); // apparently not needed but this way the empty-string case is covered // (e.g. $ gdl -e "") } - else if ( - string(argv[a]) == "-demo" || - string(argv[a]) == "-em" || + else if ( + string(argv[a]) == "-demo" || + string(argv[a]) == "-em" || string(argv[a]) == "-novm" || string(argv[a]) == "-queue" || string(argv[a]) == "-rt" || string(argv[a]) == "-ulicense" || - string(argv[a]) == "-vm" - ) - cerr << argv[0] << ": " << argv[a] << " option ignored." << endl; - else if (string(argv[a]) == "-gdlde") - { - gdlde = true; - } - else if (string(argv[a]) == "--fussy") - { - strict_syntax = true; - syntaxOptionSet = true; - } - else if (string(argv[a]) == "--sloppy") - { - strict_syntax = false; - syntaxOptionSet = true; - } - else if (string(argv[a]) == "--no-dSFMT") - { - useDSFMTAcceleration = false; - } - else if (string(argv[a]) == "--widget-compat") - { - tryToMimicOriginalWidgets = true; - } + string(argv[a]) == "-vm" + ) + cerr << argv[0] << ": " << argv[a] << " option ignored." << endl; + else if (string(argv[a]) == "-gdlde") { + gdlde = true; + } + else if (string(argv[a]) == "--fussy") { + strict_syntax = true; + syntaxOptionSet = true; + } + else if (string(argv[a]) == "--sloppy") { + strict_syntax = false; + syntaxOptionSet = true; + } + else if (string(argv[a]) == "--no-dSFMT") { + useDSFMTAcceleration = false; + } + else if (string(argv[a]) == "--widget-compat") { + tryToMimicOriginalWidgets = true; + } #ifdef _WIN32 - else if (string(argv[a]) == "--posix") lib::posixpaths=true; + else if (string(argv[a]) == "--posix") lib::posixpaths=true; #endif - else if (string(argv[a]) == "--MAC") - { - usePlatformDeviceName = true; - } - else if (string(argv[a]) == "--no-use-wx" || string(argv[a]) == "-X") - { - force_no_wxgraphics = true; - } - else if (string(argv[a]) == "--with-eigen-transpose") - { - useEigenForTransposeOps = true; - } - else if (string(argv[a]) == "--smart-tpool") - { - useSmartTpool = true; - } - else if (string(argv[a]) == "--notebook") - { - iAmANotebook = true; - } - else if (string(argv[a]) == "--silent") - { - setQuietSysvar=true; - } - else if (string(argv[a]) == "--subprocess") { - if (a == argc - 1) { - cerr << "gdl: --subprocess must be followed by the parent's pid" << endl; - return 0; - } - myMessageBoxName = argv[++a]; - iAmMaster = false; - setQuietSysvar = true; - willSuppressEditInput = true; - // std::cerr<<"I am a SubProcess"< 0 && batch_files.size() > 0) - { + else if (string(argv[a]) == "--fakerelease") { + if (a == argc - 1) + { + cerr << "gdl: --fakerelease must be followed by a string argument like \"6.4\"" << endl; + return 0; + } + pretendRelease = string(argv[++a]); + } + else if (string(argv[a]) == "--clean-at-exit") { + if (atexit(AtExit) != 0) cerr << "atexit registration failed. option \"--clean-at-exit\" unefficient." << endl; + } + else if (*argv[a] == '-') { + cerr << argv[0] << ": " << argv[a] << " option not recognized." << endl; + return 0; + } + else { + batch_files.emplace_back(argv[a]); + } + } +#if 0 + if (!statement.empty() && !batch_files.empty()) { cerr << argv[0] << ": " << "-e option cannot be specified with batch files" << endl; return 0; } - +#endif //depending on master or not, attach to respective message boxes if (!iAmMaster) gdl_ipc_ClientGetsMailboxAddress(myMessageBoxName); @@ -505,7 +468,7 @@ int main(int argc, char *argv[]) if (force_no_wxgraphics) useWxWidgetsForGraphics=false; //this has the last answer, whatever the setup. #endif std::string doUseUglyFonts=GetEnvString("GDL_WIDGETS_COMPAT"); - if ( doUseUglyFonts.length() > 0) tryToMimicOriginalWidgets=true; + if ( !doUseUglyFonts.empty()) tryToMimicOriginalWidgets=true; InitGDL(); @@ -537,37 +500,36 @@ int main(int argc, char *argv[]) cerr << "- Default library routine search path used (GDL_PATH/IDL_PATH env. var. not set): " << gdlPath << endl; if (useWxWidgetsForGraphics) cerr << "- Using WxWidgets as graphics library (windows and widgets)." << endl; } - if (useDSFMTAcceleration && (GetEnvString("GDL_NO_DSFMT").length() > 0)) useDSFMTAcceleration=false; - if (setQuietSysvar) SysVar::Make_Quiet(); - if (willSuppressEditInput) SysVar::Suppress_Edit_Input(); + if (useDSFMTAcceleration && (!GetEnvString("GDL_NO_DSFMT").empty())) useDSFMTAcceleration = false; + if (setQuietSysvar) SysVar::Make_Quiet(); + if (willSuppressEditInput) SysVar::Suppress_Edit_Input(); //report in !GDL status struct DStructGDL* gdlconfig = SysVar::GDLconfig(); unsigned DSFMTTag= gdlconfig->Desc()->TagIndex("GDL_USE_DSFMT"); - (*static_cast (gdlconfig->GetTag(DSFMTTag, 0)))[0]=useDSFMTAcceleration; + (*dynamic_cast (gdlconfig->GetTag(DSFMTTag, 0)))[0]=useDSFMTAcceleration; //same for use of wxwidgets unsigned useWXTAG= gdlconfig->Desc()->TagIndex("GDL_USE_WX"); - (*static_cast (gdlconfig->GetTag(useWXTAG, 0)))[0]=useWxWidgetsForGraphics; + (*dynamic_cast (gdlconfig->GetTag(useWXTAG, 0)))[0]=useWxWidgetsForGraphics; if (!pretendRelease.empty()) SysVar::SetFakeRelease(pretendRelease); //fussyness setup and change if switch at start if (syntaxOptionSet) { //take it no matters any env. var. - if (strict_syntax == true) SetStrict(true); + if (strict_syntax) SetStrict(true); } else { - if (GetEnvString("GDL_IS_FUSSY").size()> 0) SetStrict(true); + if (!GetEnvString("GDL_IS_FUSSY").empty()) SetStrict(true); } string startup=GetEnvPathString("GDL_STARTUP"); - if( startup == "") startup=GetEnvPathString("IDL_STARTUP"); - if( startup == "") - { - if (gdlde || (isatty(0) && !quiet)) cerr << - "- No startup file read (GDL_STARTUP/IDL_STARTUP env. var. not set). " << endl; + if( startup.empty()) startup=GetEnvPathString("IDL_STARTUP"); + if( startup.empty()) { + if (gdlde || (isatty(0) && !quiet)) { + cerr << "- No startup file read (GDL_STARTUP/IDL_STARTUP env. var. not set). " << endl; } + } - if (gdlde || (isatty(0) && !quiet)) - { + if (gdlde || (isatty(0) && !quiet)) { cerr << "- Please report bugs, feature or help requests and patches at: https://github.com/gnudatalanguage/gdl" << endl << endl; } // else @@ -586,28 +548,26 @@ int main(int argc, char *argv[]) #ifdef USE_MPI if (iAmMaster) { - { - // warning the user if MPI changes the working directory of GDL - char wd1[PATH_MAX], wd2[PATH_MAX]; - char *wd1p, *wd2p; - wd1p = getcwd(wd1, PATH_MAX); - MPI_Init(&argc, &argv); - wd2p = getcwd(wd2, PATH_MAX); - if (strcmp(wd1, wd2) != 0) - cerr << "Warning: MPI has changed the working directory of GDL!" << endl; - } - int myrank = 0; - MPI_Comm_rank( MPI_COMM_WORLD, &myrank); - int size; - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int tag = 0; - char* mpi_procedure = getenv("GDL_MPI"); - if (myrank == 0 && mpi_procedure != NULL){ - for( SizeT i = 0; i < size; i++) - MPI_Send(mpi_procedure, strlen(mpi_procedure)+1, MPI_CHAR, i, - tag, MPI_COMM_WORLD); - } + { + // warning the user if MPI changes the working directory of GDL + char wd1[PATH_MAX], wd2[PATH_MAX]; + getcwd(wd1, PATH_MAX); + MPI_Init(&argc, &argv); + getcwd(wd2, PATH_MAX); + if (strcmp(wd1, wd2) != 0) + cerr << "Warning: MPI has changed the working directory of GDL!" << endl; + } + int myrank = 0; + MPI_Comm_rank( MPI_COMM_WORLD, &myrank); + int size = 0; + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int tag = 0; + char* mpi_procedure = getenv("GDL_MPI"); + if (myrank == 0 && mpi_procedure != nullptr) { + for (int i = 0; i < size; i++) + MPI_Send(mpi_procedure, (int)strlen(mpi_procedure)+1, MPI_CHAR, i, tag, MPI_COMM_WORLD); + } } #endif // USE_MPI diff --git a/src/gdlexception.cpp b/src/gdlexception.cpp index d283ce02f..e8e7e6436 100644 --- a/src/gdlexception.cpp +++ b/src/gdlexception.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "gdlexception.hpp" + #include "dnode.hpp" #include "initsysvar.hpp" #include "gdljournal.hpp" @@ -26,298 +27,225 @@ using namespace std; -DInterpreter* GDLException::interpreter = NULL; +DInterpreter *GDLException::interpreter = nullptr; -string GDLException::Name( BaseGDL* b) -{ -if(interpreter!=NULL && interpreter->CallStack().size()>0) - return interpreter->Name(b); -return ""; +string GDLException::Name(BaseGDL *b) { + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) + return DInterpreter::Name(b); + return ""; } -GDLException::GDLException(DLong eC, const string& s, bool pre, bool decorate): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(eC), - line( 0), col( 0), prefix( pre), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ -if(decorate && interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; -} -else -{ - msg = s; -} +GDLException::GDLException(DLong eC, const string &s, bool pre, bool decorate) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorCode(eC), + col(0), + prefix(pre), + ioException(false) { + if (decorate && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + errorNodeP = e->CallingNode(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); + } // note: This is for cases, when form a destructor is thrown // in these cases, program aborts #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(const string& s, bool pre, bool decorate): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(-1), - line( 0), col( 0), prefix( pre), - ioException( false), - targetEnv( NULL) -{ -if(decorate && interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; -} -else -{ - msg = s; -} +GDLException::GDLException(const string &s, bool pre, bool decorate) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorCode(-1L), + col(0), + prefix(pre), + ioException(false) { + if (decorate && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + errorNodeP = e->CallingNode(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); + } // note: This is for cases, when form a destructor is thrown // in these cases, program aborts #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(const RefDNode eN, const string& s): - ANTLRException(s), - errorNode(eN), - errorNodeP( NULL), - errorCode(-1), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ -if(interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; -} -else -{ - msg = s; -} +GDLException::GDLException(const RefDNode &eN, const string &s) : + ANTLRException(s), + errorNode(eN), + errorCode(-1L), + col(0), + prefix(true), + ioException(false) { + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + errorNodeP = e->CallingNode(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); + } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(DLong eC, const RefDNode eN, const string& s): - ANTLRException(s), - errorNode(eN), - errorNodeP( NULL), - errorCode(eC), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ -if(interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; -} -else -{ - msg = s; -} +GDLException::GDLException(DLong eC, const RefDNode &eN, const string &s) : + ANTLRException(s), + errorNode(eN), + errorCode(eC), + col(0), + prefix(true), + ioException(false) { + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + errorNodeP = e->CallingNode(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); + } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(const ProgNodeP eN, const string& s, bool decorate, bool overWriteNode): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( eN), - errorCode(-1), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ -if( overWriteNode && interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - errorNodeP = e->CallingNode(); -} -if( decorate && interpreter!=NULL && interpreter->CallStack().size()>0) -{ - EnvBaseT* e = interpreter->CallStack().back(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; -} -else -{ - msg = s; -} +GDLException::GDLException(ProgNodeP eN, const string &s, bool decorate, bool overWriteNode) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorNodeP(eN), + errorCode(-1L), + col(0), + prefix(true), + ioException(false) { + if (overWriteNode && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + errorNodeP = e->CallingNode(); + } + if (decorate && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); + } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(DLong eC, const ProgNodeP eN, const string& s, bool decorate, bool overWriteNode): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( eN), - errorCode(eC), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ - if( overWriteNode && interpreter!=NULL && interpreter->CallStack().size()>0) - { - EnvBaseT* e = interpreter->CallStack().back(); +GDLException::GDLException(DLong eC, ProgNodeP eN, const string &s, bool decorate, bool overWriteNode) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorNodeP(eN), + errorCode(eC), + col(0), + prefix(true), + ioException(false) { + if (overWriteNode && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); errorNodeP = e->CallingNode(); } - if( decorate && interpreter!=NULL && interpreter->CallStack().size()>0) - { - EnvBaseT* e = interpreter->CallStack().back(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; - } - else - { - msg = s; + if (decorate && interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(SizeT l, SizeT c, const string& s, const string& file): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(-1), - line( l), col( c), filename(file), - prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ - if(interpreter!=NULL && interpreter->CallStack().size()>0) - { - EnvBaseT* e = interpreter->CallStack().back(); +GDLException::GDLException(SizeT l, SizeT c, const string &s, const string &file) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorCode(-1L), + line(l), + col(c), + prefix(true), + ioException(false) { + strncpy(filename, file.c_str(), 255); + filename[255] = '\0'; + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; - } - else - { - msg = s; + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(SizeT l, SizeT c, const string& s): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(-1), - line( l), col( c), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) -{ - if(interpreter!=NULL && interpreter->CallStack().size()>0) - { - EnvBaseT* e = interpreter->CallStack().back(); +GDLException::GDLException(SizeT l, SizeT c, const string &s) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorCode(-1L), + line(l), + col(c), + prefix(true), + ioException(false) { + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; - } - else - { - msg = s; + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); } #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -GDLException::GDLException(DLong eC, SizeT l, SizeT c, const string& s): - ANTLRException(s), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(eC), - line( l), col( c), prefix( true), - arrayexprIndexeeFailed(false), - targetEnv( NULL) -{ - if(interpreter!=NULL && interpreter->CallStack().size()>0) - { - EnvBaseT* e = interpreter->CallStack().back(); +GDLException::GDLException(DLong eC, SizeT l, SizeT c, const string &s) : + ANTLRException(s), + errorNode(static_cast(antlr::nullAST)), + errorCode(eC), + line(l), + col(c), + prefix(true), + ioException(false) { + if (interpreter != nullptr && !DInterpreter::CallStack().empty()) { + EnvBaseT *e = DInterpreter::CallStack().back(); errorNodeP = e->CallingNode(); - msg = e->GetProName(); - if( msg != "$MAIN$") msg += ": "+ s; else msg = s; - } - else - { - msg = s; + if (e->GetProName() != "$MAIN$") + msg = std::runtime_error(e->GetProName() + ": " + s); } - if (!iAmMaster) gdl_ipc_ClientSendReturn(3,s); + if (!iAmMaster) + gdl_ipc_ClientSendReturn(3, s); #ifdef GDL_DEBUG - cerr << s << endl; + cerr << s << endl; #endif } -void Message(const string& s) -{ - if( SysVar::Quiet() == 0) - { - cerr << SysVar::MsgPrefix() << s << endl; - lib::write_journal_comment( SysVar::MsgPrefix() + s); - } -} +void Message(const string &s) { + if (SysVar::Quiet() == 0) { + cerr << SysVar::MsgPrefix() << s << endl; + lib::write_journal_comment(SysVar::MsgPrefix() + s); + } +} -void Warning(const std::string& s) -{ - cerr << SysVar::MsgPrefix() << s << endl; - lib::write_journal_comment( SysVar::MsgPrefix() + s); -} +void Warning(const std::string &s) { + cerr << SysVar::MsgPrefix() << s << endl; + lib::write_journal_comment(SysVar::MsgPrefix() + s); +} -void ThrowGDLException( const std::string& str) -{ -throw GDLException( str); +void ThrowGDLException(const std::string &str) { + throw GDLException(str); } -void WarnAboutObsoleteRoutine(const string& name) -{ +void WarnAboutObsoleteRoutine(const string &name) { // no static here due to .RESET_SESSION - DStructGDL* warnStruct = SysVar::Warn(); + DStructGDL *warnStruct = SysVar::Warn(); // this static is ok as it will evaluate always to the same value - static unsigned obs_routinesTag = warnStruct->Desc()->TagIndex( "OBS_ROUTINES"); - if (((static_cast( warnStruct->GetTag(obs_routinesTag, 0)))[0]).LogTrue()) + static unsigned obs_routinesTag = warnStruct->Desc()->TagIndex("OBS_ROUTINES"); + if (((dynamic_cast( warnStruct->GetTag(obs_routinesTag, 0)))[0]).LogTrue()) Message("Routine compiled from an obsolete library: " + name); // TODO: journal / !QUIET?? } -void WarnAboutObsoleteRoutine(const RefDNode eN, const string& name) -{ +void WarnAboutObsoleteRoutine(const RefDNode &eN, const string &name) { // TODO: journal? // no static here due to .RESET_SESSION - DStructGDL* warnStruct = SysVar::Warn(); + DStructGDL *warnStruct = SysVar::Warn(); // this static is ok as it will evaluate always to the same value - static unsigned obs_routinesTag = warnStruct->Desc()->TagIndex( "OBS_ROUTINES"); - if (((static_cast( warnStruct->GetTag(obs_routinesTag, 0)))[0]).LogTrue()) - { - GDLException* e = new GDLException(eN, - "Routine compiled from an obsolete library: " + name + static unsigned obs_routinesTag = warnStruct->Desc()->TagIndex("OBS_ROUTINES"); + if (((dynamic_cast( warnStruct->GetTag(obs_routinesTag, 0)))[0]).LogTrue()) { + auto e = new GDLException(eN, + "Routine compiled from an obsolete library: " + name ); Guard eGuard(e); GDLInterpreter::ReportCompileError(*e, ""); diff --git a/src/gdlexception.hpp b/src/gdlexception.hpp index a51cafc27..ab97e9ff8 100644 --- a/src/gdlexception.hpp +++ b/src/gdlexception.hpp @@ -29,157 +29,137 @@ class EnvUDT; -class GDLException: public antlr::ANTLRException -{ - static DInterpreter* interpreter; - - std::string msg; - - RefDNode errorNode; - ProgNodeP errorNodeP; - DLong errorCode; - SizeT line; - SizeT col; - std::string filename; //the filename (or "" for interactive $MAIN$) where the problem arised - bool prefix; - - bool arrayexprIndexeeFailed; - +class GDLException : public antlr::ANTLRException { + static DInterpreter *interpreter; + + const RefDNode errorNode; + ProgNodeP errorNodeP = nullptr; + const DLong errorCode; + SizeT line = 0; + const SizeT col; + // Note: Windows allows longer filenames... + char filename[256] = ""; //the filename (or "" for interactive $MAIN$) where the problem arose + const bool prefix; + + bool arrayExprIndexesFailed = false; + protected: bool ioException; - -private: - EnvUDT* targetEnv; // where to stop (depending on ON_ERROR) + +private: + EnvUDT *targetEnv = nullptr; // where to stop (depending on ON_ERROR) public: - static DInterpreter* Interpreter() { return interpreter;} - static void SetInterpreter( DInterpreter* i) { interpreter = i;} - - static std::string Name( BaseGDL* b); - - void SetErrorNodeP( ProgNodeP p) { errorNodeP = p;} - - bool GetArrayexprIndexeeFailed() const { return arrayexprIndexeeFailed;} - void SetArrayexprIndexeeFailed( bool b) { arrayexprIndexeeFailed = b;} - - GDLException(): ANTLRException(), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(-1), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) - {} - GDLException( DLong eC): ANTLRException(), - errorNode(static_cast(antlr::nullAST)), - errorNodeP( NULL), - errorCode(eC), - line( 0), col( 0), prefix( true), - arrayexprIndexeeFailed(false), - ioException( false), - targetEnv( NULL) - {} - GDLException(const std::string& s, bool pre = true, bool decorate=true); - GDLException(const RefDNode eN, const std::string& s); - GDLException(const ProgNodeP eN, const std::string& s, bool decorate=true, bool overWriteNode=true); - GDLException(SizeT l, SizeT c, const std::string& s, const std::string &file); - GDLException(SizeT l, SizeT c, const std::string& s); - - GDLException(DLong eC, const std::string& s, bool pre = true, bool decorate=true); - GDLException(DLong eC, const RefDNode eN, const std::string& s); - GDLException(DLong eC, const ProgNodeP eN, const std::string& s, bool decorate=true, bool overWriteNode=true); - GDLException(DLong eC, SizeT l, SizeT c, const std::string& s); - - ~GDLException() throw() {} - - DLong ErrorCode() const { return errorCode;} - - std::string toString() const - { - return msg; + static DInterpreter *Interpreter() { return interpreter; } + static void SetInterpreter(DInterpreter *i) { interpreter = i; } + + static std::string Name(BaseGDL *b); + + void SetErrorNodeP(ProgNodeP p) { errorNodeP = p; } + + bool GetArrayexprIndexeeFailed() const { return arrayExprIndexesFailed; } + void SetArrayexprIndexeeFailed(bool b) { arrayExprIndexesFailed = b; } + + GDLException() : + ANTLRException(), + errorNode(static_cast(antlr::nullAST)), + errorNodeP(nullptr), + errorCode(-1), + col(0), + prefix(true), + ioException(false) {} + explicit GDLException(DLong eC) : + ANTLRException(), + errorNode(static_cast(antlr::nullAST)), + errorNodeP(nullptr), + errorCode(eC), + col(0), + prefix(true), + ioException(false) {} + explicit GDLException(const std::string &s, bool pre = true, bool decorate = true); + GDLException(const RefDNode &eN, const std::string &s); + GDLException(ProgNodeP eN, const std::string &s, bool decorate = true, bool overWriteNode = true); + GDLException(SizeT l, SizeT c, const std::string &s, const std::string &file); + GDLException(SizeT l, SizeT c, const std::string &s); + + GDLException(DLong eC, const std::string &s, bool pre = true, bool decorate = true); + GDLException(DLong eC, const RefDNode &eN, const std::string &s); + GDLException(DLong eC, ProgNodeP eN, const std::string &s, bool decorate = true, bool overWriteNode = true); + GDLException(DLong eC, SizeT l, SizeT c, const std::string &s); + + ~GDLException() noexcept override = default; + + DLong ErrorCode() const { return errorCode; } + + std::string toString() const override { + return msg.what(); } - std::string getFilename() const - { - return filename; + std::string getFilename() const { + return filename; } - SizeT getLine() const - { - if( line != 0) + SizeT getLine() const { + if (line != 0) return line; - if( errorNodeP != NULL) + if (errorNodeP != nullptr) return errorNodeP->getLine(); - if( errorNode != static_cast(antlr::nullAST)) + if (errorNode != static_cast(antlr::nullAST)) return errorNode->getLine(); return 0; } - void SetLine( SizeT l) { line = l;} + void SetLine(SizeT l) { line = l; } - SizeT getColumn() const - { + SizeT getColumn() const { // if( errorNode != static_cast(antlr::nullAST)) // return errorNode->getColumn(); return col; } - bool Prefix() const - { + bool Prefix() const { return prefix; } - void SetTargetEnv( EnvUDT* tEnv) - { + void SetTargetEnv(EnvUDT *tEnv) { targetEnv = tEnv; } - EnvUDT* GetTargetEnv() - { + EnvUDT *GetTargetEnv() { return targetEnv; } - bool IsIOException() const { return ioException;} + bool IsIOException() const { return ioException; } }; // for ON_IOERROR -class GDLIOException: public GDLException -{ +class GDLIOException : public GDLException { public: - GDLIOException(): - GDLException() - { ioException = true;} - - GDLIOException(const std::string& s, bool pre = true): - GDLException( s, pre) - { ioException = true;} - - GDLIOException(const ProgNodeP eN, const std::string& s): - GDLException( eN, s) - { ioException = true;} - - GDLIOException(DLong eC): - GDLException(eC) - { ioException = true;} - - GDLIOException(DLong eC,const std::string& s, bool pre = true): - GDLException( eC, s, pre) - { ioException = true;} - - GDLIOException(DLong eC,const ProgNodeP eN, const std::string& s): - GDLException( eC, eN, s) - { ioException = true;} + GDLIOException() : + GDLException() { ioException = true; } + + explicit GDLIOException(const std::string &s, bool pre = true) : + GDLException(s, pre) { ioException = true; } + + GDLIOException(ProgNodeP eN, const std::string &s) : + GDLException(eN, s) { ioException = true; } + + explicit GDLIOException(DLong eC) : + GDLException(eC) { ioException = true; } + + GDLIOException(DLong eC, const std::string &s, bool pre = true) : + GDLException(eC, s, pre) { ioException = true; } + + GDLIOException(DLong eC, ProgNodeP eN, const std::string &s) : + GDLException(eC, eN, s) { ioException = true; } }; // warnings ignore !QUIET -void Warning(const std::string& s); +void Warning(const std::string &s); // messages honor !QUIET -void Message(const std::string& s); - -void ThrowGDLException( const std::string& str); +void Message(const std::string &s); -void WarnAboutObsoleteRoutine(const std::string& name); -void WarnAboutObsoleteRoutine(const RefDNode eN, const std::string& name); +void WarnAboutObsoleteRoutine(const std::string &name); +void WarnAboutObsoleteRoutine(const RefDNode &eN, const std::string &name); #endif diff --git a/src/libinit.cpp b/src/libinit.cpp index eb4b2824d..93b9f08f5 100644 --- a/src/libinit.cpp +++ b/src/libinit.cpp @@ -18,9 +18,7 @@ #include "includefirst.hpp" #include -#include -#include "envt.hpp" #include "dpro.hpp" #include "objects.hpp" @@ -85,7 +83,7 @@ void LibInit() LibInit_ac(); LibInit_gm(); LibInit_ng(); - LibInit_jp(); //absence of wxWidgets will trigger a message for each finction using widgets. + LibInit_jp(); //absence of wxWidgets will trigger a message for each function using widgets. LibInit_exists(); const char KLISTEND[] = ""; @@ -131,7 +129,7 @@ void LibInit() // new DLibPro(lib::gdl_config_pro,string("GDL_CONFIG"),0,gdlconfigKey); const string get_kbrdKey[]={"ESCAPE","KEY_NAME",KLISTEND}; - new DLibFunRetNew(lib::get_kbrd,string("GET_KBRD"),1,NULL,get_kbrdKey); + new DLibFunRetNew(lib::get_kbrd, string("GET_KBRD"), 1, nullptr, get_kbrdKey); const string svdcKey[]={"COLUMN","ITMAX","DOUBLE",KLISTEND}; new DLibPro(lib::svdc,string("SVDC"),4,svdcKey); @@ -172,12 +170,12 @@ void LibInit() "FTOXDR","DTOXDR","XDRTOF","XDRTOD", "DTOGFLOAT","GFLOATTOD", // obsoleted 2 keywords only on the VMS platform KLISTEND}; - new DLibPro(lib::byteorder,string("BYTEORDER"),-1,byteorderKey,NULL,0,true); //UsesThreadPOOL + new DLibPro(lib::byteorder, string("BYTEORDER"), -1, byteorderKey, nullptr, 0, true); //UsesThreadPOOL const string obj_classKey[]={"COUNT","SUPERCLASS",KLISTEND}; new DLibFunRetNew(lib::obj_class,string("OBJ_CLASS"),1,obj_classKey); - new DLibFunRetNew(lib::obj_isa,string("OBJ_ISA"),2,NULL,NULL,false,2); + new DLibFunRetNew(lib::obj_isa, string("OBJ_ISA"), 2, nullptr, nullptr, false, 2); new DLibFunRetNew(lib::obj_hasmethod,string("OBJ_HASMETHOD"),2); const string rebinKey[]={"SAMPLE",KLISTEND}; @@ -214,10 +212,10 @@ void LibInit() new DLibFunRetNew(lib::expand_path,string("EXPAND_PATH"),1,expand_pathKey); const string strjoinKey[]={"SINGLE",KLISTEND}; - new DLibFunRetNew(lib::strjoin,string("STRJOIN"),2,strjoinKey,NULL,true/*retConstant*/); + new DLibFunRetNew(lib::strjoin, string("STRJOIN"), 2, strjoinKey, nullptr, true/*retConstant*/); const string strcmpKey[]={"FOLD_CASE",KLISTEND}; - new DLibFunRetNew(lib::strcmp_fun,string("STRCMP"),3,strcmpKey,NULL,true); + new DLibFunRetNew(lib::strcmp_fun, string("STRCMP"), 3, strcmpKey, nullptr, true); new DLibFunRetNew(lib::eof_fun,string("EOF"),1); @@ -281,13 +279,13 @@ void LibInit() const string file_mkdirKey[]={"NOEXPAND_PATH",KLISTEND}; new DLibPro(lib::file_mkdir,string("FILE_MKDIR"),-1,file_mkdirKey); - new DLibFunRetNew(lib::shift_fun,string("SHIFT"),9,NULL,NULL,true); - new DLibFunRetNewTP(lib::ishft_fun,string("ISHFT"),2,NULL,NULL,true); //UsesThreadPOOL + new DLibFunRetNew(lib::shift_fun, string("SHIFT"), 9, nullptr, nullptr, true); + new DLibFunRetNewTP(lib::ishft_fun, string("ISHFT"), 2, nullptr, nullptr, true); //UsesThreadPOOL const string sortKey[]={"L64",KLISTEND}; - new DLibFunRetNew(lib::sort_fun,string("SORT"),1,sortKey,NULL,true); + new DLibFunRetNew(lib::sort_fun, string("SORT"), 1, sortKey, nullptr, true); const string gdlsortKey[]={"L64","QUICK","MERGE","RADIX","INSERT","AUTO",KLISTEND}; //,"CHECK" - new DLibFunRetNew(lib::gdl_sort_fun,string("GDL_SORT"),1,gdlsortKey,NULL,true); + new DLibFunRetNew(lib::gdl_sort_fun, string("GDL_SORT"), 1, gdlsortKey, nullptr, true); const string medianKey[]={"EVEN","DOUBLE","DIMENSION",KLISTEND}; new DLibFunRetNew(lib::median,string("MEDIAN"),2,medianKey); @@ -298,7 +296,7 @@ void LibInit() const string momentKey[]={"DOUBLE","DIMENSION","NAN","KURTOSIS","MAXMOMENT","MDEV","MEAN","SDEV","SKEWNESS","VARIANCE",KLISTEND}; new DLibFunRetNew(lib::moment_fun,string("MOMENT"),1,momentKey); - new DLibFunRetNew(lib::transpose,string("TRANSPOSE"),2,NULL,NULL,true); + new DLibFunRetNew(lib::transpose, string("TRANSPOSE"), 2, nullptr, nullptr, true); new DLibPro(lib::retall,string("RETALL")); @@ -320,8 +318,8 @@ void LibInit() const string helpWarnKey[]={"BREAKPOINTS","DLM", "MESSAGES", KLISTEND}; new DLibPro(lib::help_pro,string("HELP"),-1,helpKey,helpWarnKey); - new DLibPro(lib::delvar_pro,string("DELVAR"),-1,NULL,NULL); - DLibPro* hide = new DLibPro(lib::findvar_pro,string("FINDVAR"),-1,NULL,NULL); + new DLibPro(lib::delvar_pro, string("DELVAR"), -1, nullptr, nullptr); + auto hide = new DLibPro(lib::findvar_pro, string("FINDVAR"), -1, nullptr, nullptr); hide->SetHideHelp(true); //stub to avoid setting errors on pref_set. One may want to really write pref_set, @@ -335,7 +333,7 @@ void LibInit() const string memoryKey[]={"CURRENT","HIGHWATER","NUM_ALLOC", "NUM_FREE","STRUCTURE","L64",KLISTEND}; - new DLibFunRetNew(lib::memory_fun, string("MEMORY"), 1, memoryKey, NULL); + new DLibFunRetNew(lib::memory_fun, string("MEMORY"), 1, memoryKey, nullptr); // printKey, readKey and stringKey are closely associated // as the same functions are called "FORMAT" till "MONTH" @@ -381,23 +379,23 @@ void LibInit() new DLibPro(lib::ptr_free,string("PTR_FREE"),-1); const string arrKey[]={"NOZERO",KLISTEND}; - new DLibFunRetNew(lib::bytarr,string("BYTARR"),MAXRANK,arrKey,NULL,true/*retConstant*/); - new DLibFunRetNew(lib::intarr,string("INTARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::uintarr,string("UINTARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::lonarr,string("LONARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::ulonarr,string("ULONARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::lon64arr,string("LON64ARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::ulon64arr,string("ULON64ARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::fltarr,string("FLTARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::dblarr,string("DBLARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::complexarr,string("COMPLEXARR"),MAXRANK,arrKey,NULL,true); - new DLibFunRetNew(lib::dcomplexarr,string("DCOMPLEXARR"),MAXRANK,arrKey,NULL,true); - - new DLibFunRetNew(lib::strarr,string("STRARR"),MAXRANK,NULL,NULL,true); + new DLibFunRetNew(lib::bytarr, string("BYTARR"), MAXRANK, arrKey, nullptr, true/*retConstant*/); + new DLibFunRetNew(lib::intarr, string("INTARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::uintarr, string("UINTARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::lonarr, string("LONARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::ulonarr, string("ULONARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::lon64arr, string("LON64ARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::ulon64arr, string("ULON64ARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::fltarr, string("FLTARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::dblarr, string("DBLARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::complexarr, string("COMPLEXARR"), MAXRANK, arrKey, nullptr, true); + new DLibFunRetNew(lib::dcomplexarr, string("DCOMPLEXARR"), MAXRANK, arrKey, nullptr, true); + + new DLibFunRetNew(lib::strarr, string("STRARR"), MAXRANK, nullptr, nullptr, true); const string ptrArrKey[]={"ALLOCATE_HEAP","NOZERO",KLISTEND}; - new DLibFunRetNew(lib::ptrarr,string("PTRARR"),MAXRANK,ptrArrKey,NULL,true); - new DLibFunRetNew(lib::objarr,string("OBJARR"),MAXRANK,arrKey,NULL,true); + new DLibFunRetNew(lib::ptrarr, string("PTRARR"), MAXRANK, ptrArrKey, nullptr, true); + new DLibFunRetNew(lib::objarr, string("OBJARR"), MAXRANK, arrKey, nullptr, true); const string ptr_newKey[]={"NO_COPY","ALLOCATE_HEAP",KLISTEND}; new DLibFunRetNew(lib::ptr_new,string("PTR_NEW"),1,ptr_newKey); @@ -421,20 +419,20 @@ void LibInit() "STRING","UINT","UL64","ULONG", "START", "INCREMENT", KLISTEND}; const string xindKey[]={"START", "INCREMENT", KLISTEND}; - new DLibFunRetNewTP(lib::bindgen,string("BINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::indgen,string("INDGEN"),MAXRANK,indKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::uindgen,string("UINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::sindgen,string("SINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::lindgen,string("LINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::ulindgen,string("ULINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::l64indgen,string("L64INDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::ul64indgen,string("UL64INDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::findgen,string("FINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::dindgen,string("DINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::cindgen,string("CINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::dcindgen,string("DCINDGEN"),MAXRANK,xindKey,NULL,true); //UsesThreadPOOL - - new DLibFunRetNew(lib::n_elements,string("N_ELEMENTS"),1,NULL,NULL,true,1); + new DLibFunRetNewTP(lib::bindgen, string("BINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::indgen, string("INDGEN"), MAXRANK, indKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::uindgen, string("UINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::sindgen, string("SINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::lindgen, string("LINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::ulindgen, string("ULINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::l64indgen, string("L64INDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::ul64indgen, string("UL64INDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::findgen, string("FINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::dindgen, string("DINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::cindgen, string("CINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::dcindgen, string("DCINDGEN"), MAXRANK, xindKey, nullptr, true); //UsesThreadPOOL + + new DLibFunRetNew(lib::n_elements, string("N_ELEMENTS"), 1, nullptr, nullptr, true, 1); new DLibFun(lib::execute_fun,string("EXECUTE"),3); @@ -492,7 +490,7 @@ void LibInit() const string assocKey[]={"PACKED",KLISTEND}; new DLibFunRetNew(lib::assoc,string("ASSOC"),3,assocKey); - new DLibFun(lib::byte_fun,string("BYTE"),10,NULL,NULL,0,true); //UsesThreadPOOL + new DLibFun(lib::byte_fun, string("BYTE"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL /* new DLibFunRetNew(lib::fix_fun,string("FIX"),10,fixKey,NULL,true); @@ -508,29 +506,29 @@ void LibInit() */ // that's apparently the desired bahaviour, see bug no. 3151760 const string fixKey[]={"TYPE","PRINT","IMPLIED_PRINT",KLISTEND}; //Fix never uses IMPLIED_PRINT, but called print_os does. - new DLibFun(lib::fix_fun,string("FIX"),10,fixKey,NULL,0,true); //UsesThreadPOOL + new DLibFun(lib::fix_fun, string("FIX"), 10, fixKey, nullptr, 0, true); //UsesThreadPOOL - new DLibFun(lib::uint_fun,string("UINT"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::long_fun,string("LONG"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::ulong_fun,string("ULONG"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::long64_fun,string("LONG64"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::ulong64_fun,string("ULONG64"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::float_fun,string("FLOAT"),10,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::double_fun,string("DOUBLE"),10,NULL,NULL,0,true); //UsesThreadPOOL + new DLibFun(lib::uint_fun, string("UINT"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::long_fun, string("LONG"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::ulong_fun, string("ULONG"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::long64_fun, string("LONG64"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::ulong64_fun, string("ULONG64"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::float_fun, string("FLOAT"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::double_fun, string("DOUBLE"), 10, nullptr, nullptr, 0, true); //UsesThreadPOOL const string complexKey[]={"DOUBLE",KLISTEND}; - new DLibFun(lib::complex_fun,string("COMPLEX"),MAXRANK+2,complexKey,NULL,0,true); //UsesThreadPOOL - new DLibFun(lib::dcomplex_fun,string("DCOMPLEX"),MAXRANK+2,NULL,NULL,0,true); //UsesThreadPOOL + new DLibFun(lib::complex_fun, string("COMPLEX"), MAXRANK + 2, complexKey, nullptr, 0, true); //UsesThreadPOOL + new DLibFun(lib::dcomplex_fun, string("DCOMPLEX"), MAXRANK + 2, nullptr, nullptr, 0, true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::gdl_logical_and,string("LOGICAL_AND"),2,NULL,NULL,true); //UsesThreadPOOL - new DLibFunRetNewTP(lib::gdl_logical_or,string("LOGICAL_OR"),2,NULL,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::gdl_logical_and, string("LOGICAL_AND"), 2, nullptr, nullptr, true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::gdl_logical_or, string("LOGICAL_OR"), 2, nullptr, nullptr, true); //UsesThreadPOOL new DLibFunDirectTP(lib::logical_true,string("LOGICAL_TRUE")); //UsesThreadPOOL - new DLibFunRetNew(lib::replicate,string("REPLICATE"),9,NULL,NULL,true); - new DLibPro(lib::replicate_inplace_pro,string("REPLICATE_INPLACE"),6,NULL,NULL,0,true); //UsesThreadPOOL - new DLibFunDirectTP(lib::signum_fun,string("SIGNUM")); //UsesThreadPOOL - - new DLibFunDirectTP(lib::sin_fun,string("SIN")); //UsesThreadPOOL + new DLibFunRetNew(lib::replicate, string("REPLICATE"), 9, nullptr, nullptr, true); + new DLibPro(lib::replicate_inplace_pro, string("REPLICATE_INPLACE"), 6, nullptr, nullptr, 0, true); //UsesThreadPOOL + new DLibFunDirectTP(lib::signum_fun, string("SIGNUM")); //UsesThreadPOOL + + new DLibFunDirectTP(lib::sin_fun,string("SIN")); //UsesThreadPOOL new DLibFunDirectTP(lib::cos_fun,string("COS")); //UsesThreadPOOL new DLibFunDirectTP(lib::tan_fun,string("TAN")); //UsesThreadPOOL @@ -541,7 +539,7 @@ void LibInit() new DLibFunDirectTP(lib::asin_fun,string("ASIN")); //UsesThreadPOOL new DLibFunDirectTP(lib::acos_fun,string("ACOS")); //UsesThreadPOOL const string atanKey[] = {"PHASE", KLISTEND}; - new DLibFunRetNewTP(lib::atan_fun,string("ATAN"),2,atanKey,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::atan_fun, string("ATAN"), 2, atanKey, nullptr, true); //UsesThreadPOOL new DLibFunDirectTP(lib::alog_fun,string("ALOG")); //UsesThreadPOOL new DLibFunDirectTP(lib::alog2_fun,string("ALOG2")); //UsesThreadPOOL @@ -554,7 +552,7 @@ void LibInit() const string roundKey[]={"L64",KLISTEND}; // retConstant: check definition of the rounding functions if they depend - // from some sys var (defining a round mode) + // on some sys var (defining a round mode) // (probably nobody rounds a constant anyway) const string roundceilfloorKey[]={"L64",KLISTEND}; new DLibFunRetNewTP(lib::round_fun,string("ROUND"),1,roundceilfloorKey); //UsesThreadPOOL @@ -566,49 +564,49 @@ void LibInit() new DLibFunDirectTP(lib::real_part_fun,string("REAL_PART")); const string strcompressKey[]={"REMOVE_ALL",KLISTEND}; - new DLibFunRetNew(lib::strcompress,string("STRCOMPRESS"),1,strcompressKey,NULL,true); + new DLibFunRetNew(lib::strcompress, string("STRCOMPRESS"), 1, strcompressKey, nullptr, true); new DLibFunDirectTP(lib::strlowcase,string("STRLOWCASE")); new DLibFunDirectTP(lib::strupcase,string("STRUPCASE")); new DLibFunDirectTP(lib::strlen,string("STRLEN")); const string strmidKey[]={"REVERSE_OFFSET",KLISTEND}; - new DLibFunRetNew(lib::strmid,string("STRMID"),3,strmidKey,NULL,true); - new DLibFunRetNew(lib::strtrim,string("STRTRIM"),2,NULL,NULL,true); + new DLibFunRetNew(lib::strmid, string("STRMID"), 3, strmidKey, nullptr, true); + new DLibFunRetNew(lib::strtrim, string("STRTRIM"), 2, nullptr, nullptr, true); const string strposKey[]={"REVERSE_OFFSET","REVERSE_SEARCH",KLISTEND}; - new DLibFunRetNew(lib::strpos,string("STRPOS"),3,strposKey,NULL,true,2); - new DLibPro(lib::strput,string("STRPUT"),3,NULL,NULL,2); + new DLibFunRetNew(lib::strpos, string("STRPOS"), 3, strposKey, nullptr, true, 2); + new DLibPro(lib::strput, string("STRPUT"), 3, nullptr, nullptr, 2); const string whereKey[]={"COMPLEMENT","NCOMPLEMENT","NULL","L64",KLISTEND}; new DLibFunRetNewTP(lib::where_fun,string("WHERE"),2,whereKey); //UsesThreadPOOL const string totalKey[]={"CUMULATIVE","DOUBLE","NAN","INTEGER","PRESERVE_TYPE",KLISTEND}; - new DLibFunRetNewTP(lib::total_fun,string("TOTAL"),2,totalKey,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::total_fun, string("TOTAL"), 2, totalKey, nullptr, true); //UsesThreadPOOL const string productKey[]={"CUMULATIVE","NAN","INTEGER","PRESERVE_TYPE",KLISTEND}; - new DLibFunRetNewTP(lib::product_fun,string("PRODUCT"),2,productKey,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::product_fun, string("PRODUCT"), 2, productKey, nullptr, true); //UsesThreadPOOL new DLibFunRetNew(lib::n_params,string("N_PARAMS"),1); // IDL allows one parameter new DLibFunRetNew(lib::keyword_set,string("KEYWORD_SET"),1); const string array_equalKey[]={"NO_TYPECONV","NOT_EQUAL","QUIET",KLISTEND}; - new DLibFunRetNew(lib::array_equal,string("ARRAY_EQUAL"),2,array_equalKey,NULL,true); + new DLibFunRetNew(lib::array_equal, string("ARRAY_EQUAL"), 2, array_equalKey, nullptr, true); const string minKey[]={"MAX","NAN","SUBSCRIPT_MAX","DIMENSION","ABSOLUTE",KLISTEND}; - new DLibFunRetNewTP(lib::min_fun,string("MIN"),2,minKey,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::min_fun, string("MIN"), 2, minKey, nullptr, true); //UsesThreadPOOL const string maxKey[]={"MIN","NAN","SUBSCRIPT_MIN","DIMENSION","ABSOLUTE",KLISTEND}; - new DLibFunRetNewTP(lib::max_fun,string("MAX"),2,maxKey,NULL,true); //UsesThreadPOOL + new DLibFunRetNewTP(lib::max_fun, string("MAX"), 2, maxKey, nullptr, true); //UsesThreadPOOL - // retConstant: structs are tricky: struct resolution depends from !PATH + // retConstant: structs are tricky: struct resolution depends on !PATH // and this might change during runtime, but if treated as retConstant // the struct would be already defined at compile time. const string create_structKey[]={"NAME",KLISTEND}; new DLibFunRetNew(lib::create_struct,string("CREATE_STRUCT"),-1,create_structKey/*,true*/); - new DLibFunRetNew(lib::rotate,string("ROTATE"),2,NULL,NULL,true); + new DLibFunRetNew(lib::rotate, string("ROTATE"), 2, nullptr, nullptr, true); const string reverseKey[] = {"OVERWRITE", KLISTEND}; - new DLibFun(lib::reverse, string("REVERSE"), 2, reverseKey, NULL, true); + new DLibFun(lib::reverse, string("REVERSE"), 2, reverseKey, nullptr, true); #ifdef USE_PYTHON @@ -686,7 +684,7 @@ void LibInit() "GLYPH_CACHE", //PRINTER,PS,WIN,Z,METAFILE //"INDEX_COLOR", (METAFILE, PRINTER) "ITALIC", //PS - "LANGUAGE_LEVEL" //PS, + "LANGUAGE_LEVEL", //PS, "DEMI","LIGHT","MEDIUM","NARROW","OBLIQUE", //PS //"OPTIMIZE", (PCL) "ORDERED", //(PCL,X) diff --git a/src/math_fun.cpp b/src/math_fun.cpp index f7eb91503..81aec116b 100644 --- a/src/math_fun.cpp +++ b/src/math_fun.cpp @@ -2288,7 +2288,7 @@ namespace lib { static int degreesIx=e->KeywordIx("DEGREES"); - BaseGDL* rt = p0->New(dimension(2, BaseGDL::NOZERO)); + BaseGDL* rt = p0->New(2, BaseGDL::NOZERO); if (type == GDL_FLOAT) { ll_arc_distance_helper( (*static_cast (p1))[0], diff --git a/src/snippets/basic_op_AndOpCplx.incpp b/src/snippets/basic_op_AndOpCplx.incpp index 3305c0b5b..202537743 100644 --- a/src/snippets/basic_op_AndOpCplx.incpp +++ b/src/snippets/basic_op_AndOpCplx.incpp @@ -1,6 +1,6 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*right)[0] == zero) (*this)[0] = zero; @@ -11,7 +11,7 @@ for (OMPInt i = 0; i < nEl; ++i) if ((*right)[i] == zero) (*this)[i] = zero; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*right)[i] == zero) (*this)[i] = zero; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) if ((*right)[i] == zero) (*this)[i] = zero; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_AndOpInv.incpp b/src/snippets/basic_op_AndOpInv.incpp index cbeb985ec..0cf110238 100644 --- a/src/snippets/basic_op_AndOpInv.incpp +++ b/src/snippets/basic_op_AndOpInv.incpp @@ -1,18 +1,18 @@ - TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) - Data_* right = static_cast (r); +TRACE_ROUTINE(__FUNCTION__, __FILE__, __LINE__) + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { - if ((*this)[0] != zero) (*this)[0] = (*right)[0]; - return this; + if ((*this)[0] != zero) (*this)[0] = (*right)[0]; + return this; } if ((GDL_NTHREADS = parallelize(nEl)) == 1) { - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = (*right)[i]; + for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = (*right)[i]; } else { - TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = (*right)[i]; + TRACEOMP(__FILE__, __LINE__) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = (*right)[i]; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_AndOpInvS.incpp b/src/snippets/basic_op_AndOpInvS.incpp index 1b7d89474..5123ebdd6 100644 --- a/src/snippets/basic_op_AndOpInvS.incpp +++ b/src/snippets/basic_op_AndOpInvS.incpp @@ -1,13 +1,13 @@ TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (s == zero) { { - for (SizeT i = 0; i < nEl; ++i) + for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = zero; } } else { @@ -20,8 +20,8 @@ TRACE_ROUTINE(__FUNCTION__,__FILE__,__LINE__) for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] != zero) (*this)[i] = s; } } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_GeOpCplx.incpp b/src/snippets/basic_op_GeOpCplx.incpp index 5c07ed6a5..0874433eb 100644 --- a/src/snippets/basic_op_GeOpCplx.incpp +++ b/src/snippets/basic_op_GeOpCplx.incpp @@ -1,7 +1,7 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -19,8 +19,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) >= std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) >= std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) >= std::norm(s)); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -33,8 +33,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm(s)); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -43,8 +43,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); } } else // ( rEl >= nEl) { @@ -58,9 +58,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) <= std::norm((*this)[i])); } } - return res; - + return res; \ No newline at end of file diff --git a/src/snippets/basic_op_GtMarkCplx.incpp b/src/snippets/basic_op_GtMarkCplx.incpp index fc1c6b293..f50798b07 100644 --- a/src/snippets/basic_op_GtMarkCplx.incpp +++ b/src/snippets/basic_op_GtMarkCplx.incpp @@ -1,6 +1,6 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*this)[0]) < std::norm((*right)[0])) (*this)[0] = (*right)[0]; @@ -11,7 +11,7 @@ for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) < std::norm((*right)[i])) (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) < std::norm((*right)[i])) (*this)[i] = (*right)[i]; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_GtMarkSCplx.incpp b/src/snippets/basic_op_GtMarkSCplx.incpp index 58cdc78bc..1cb68f360 100644 --- a/src/snippets/basic_op_GtMarkSCplx.incpp +++ b/src/snippets/basic_op_GtMarkSCplx.incpp @@ -1,6 +1,6 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*this)[0]) < std::norm((*right)[0])) (*this)[0] = (*right)[0]; @@ -13,7 +13,7 @@ for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) < snorm) (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s, snorm) for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) < snorm) (*this)[i] = s; } return this; diff --git a/src/snippets/basic_op_GtOpCplx.incpp b/src/snippets/basic_op_GtOpCplx.incpp index 272a01656..42eb5321b 100644 --- a/src/snippets/basic_op_GtOpCplx.incpp +++ b/src/snippets/basic_op_GtOpCplx.incpp @@ -1,7 +1,7 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -19,8 +19,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) > std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) > std::norm(s)); + #pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) > std::norm(s)); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -33,8 +33,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm(s)); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -43,8 +43,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); } } else // ( rEl >= nEl) { @@ -58,9 +58,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) < std::norm((*this)[i])); } } - return res; - + return res; \ No newline at end of file diff --git a/src/snippets/basic_op_LeOpCplx.incpp b/src/snippets/basic_op_LeOpCplx.incpp index 437f33cfc..aac0c9ede 100644 --- a/src/snippets/basic_op_LeOpCplx.incpp +++ b/src/snippets/basic_op_LeOpCplx.incpp @@ -1,7 +1,7 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -19,8 +19,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) <= std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) <= std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) <= std::norm(s)); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -33,8 +33,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm(s)); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -43,8 +43,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); } } else // ( rEl >= nEl) { @@ -58,9 +58,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) >= std::norm((*this)[i])); } } - return res; - + return res; \ No newline at end of file diff --git a/src/snippets/basic_op_LtMarkCplx.incpp b/src/snippets/basic_op_LtMarkCplx.incpp index fb1b0d0ba..d0412a493 100644 --- a/src/snippets/basic_op_LtMarkCplx.incpp +++ b/src/snippets/basic_op_LtMarkCplx.incpp @@ -1,6 +1,6 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*this)[0]) > std::norm((*right)[0])) (*this)[0] = (*right)[0]; @@ -11,7 +11,7 @@ for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) > std::norm((*right)[i])) (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) > std::norm((*right)[i])) (*this)[i] = (*right)[i]; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_LtMarkSCplx.incpp b/src/snippets/basic_op_LtMarkSCplx.incpp index 8294ed23f..9923b216f 100644 --- a/src/snippets/basic_op_LtMarkSCplx.incpp +++ b/src/snippets/basic_op_LtMarkSCplx.incpp @@ -1,6 +1,6 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*this)[0]) > std::norm((*right)[0])) (*this)[0] = (*right)[0]; @@ -13,7 +13,7 @@ for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) > snorm) (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s, snorm) for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) > snorm) (*this)[i] = s; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_LtOpCplx.incpp b/src/snippets/basic_op_LtOpCplx.incpp index 040dbb61b..3c4a64221 100644 --- a/src/snippets/basic_op_LtOpCplx.incpp +++ b/src/snippets/basic_op_LtOpCplx.incpp @@ -1,7 +1,7 @@ - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong rEl = right->N_Elements(); - ULong nEl = N_Elements(); + const auto rEl = static_cast(right->N_Elements()); + const auto nEl = static_cast(N_Elements()); assert(rEl); assert(nEl); @@ -19,8 +19,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) < std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) < std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, s) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*this)[i]) < std::norm(s)); } } else if (StrictScalar(s)) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -33,8 +33,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm(s)); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm(s)); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right, s) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm(s)); } } else if (rEl < nEl) { res = new Data_(right->dim, BaseGDL::NOZERO); @@ -43,8 +43,8 @@ for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(rEl, res, right) + for (OMPInt i = 0; i < rEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); } } else // ( rEl >= nEl) { @@ -58,9 +58,8 @@ for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, res, right) + for (OMPInt i = 0; i < nEl; ++i) (*res)[i] = (std::norm((*right)[i]) > std::norm((*this)[i])); } } - return res; - + return res; \ No newline at end of file diff --git a/src/snippets/basic_op_OrOp.incpp b/src/snippets/basic_op_OrOp.incpp index 3acb49244..bc1c82578 100644 --- a/src/snippets/basic_op_OrOp.incpp +++ b/src/snippets/basic_op_OrOp.incpp @@ -1,7 +1,7 @@ // e1->N_Elements() > e2->N_Elements() -> e2->OrOp(e1) : this (e2) =e1 unless e1=right==0 -Data_* right = static_cast (r); +auto right = dynamic_cast (r); -ULong nEl = N_Elements(); +const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*right)[0] != zero) (*this)[0] = (*right)[0]; @@ -14,9 +14,9 @@ if ((GDL_NTHREADS = parallelize(nEl)) == 1) { } } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) { - if ((*right)[i] != zero) (*this)[i] = (*right)[i]; - } +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) { + if ((*right)[i] != zero) (*this)[i] = (*right)[i]; + } } -return this; +return this; \ No newline at end of file diff --git a/src/snippets/basic_op_OrOpCplx.incpp b/src/snippets/basic_op_OrOpCplx.incpp index 884b4d6fc..f877aca12 100644 --- a/src/snippets/basic_op_OrOpCplx.incpp +++ b/src/snippets/basic_op_OrOpCplx.incpp @@ -1,7 +1,7 @@ // e1->N_Elements() > e2->N_Elements() -> e2->OrOp(e1) : this (e2) =e1 unless e1==0 -Data_* right = static_cast (r); +auto right = dynamic_cast (r); -ULong nEl = N_Elements(); +const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*right)[0]) != 0) (*this)[0] = (*right)[0]; @@ -14,9 +14,9 @@ if ((GDL_NTHREADS = parallelize(nEl)) == 1) { } } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) { +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) { if (std::norm((*right)[i]) != 0 ) (*this)[i] = (*right)[i]; - } + } } -return this; +return this; \ No newline at end of file diff --git a/src/snippets/basic_op_OrOpInv.incpp b/src/snippets/basic_op_OrOpInv.incpp index 15462342e..33eb11914 100644 --- a/src/snippets/basic_op_OrOpInv.incpp +++ b/src/snippets/basic_op_OrOpInv.incpp @@ -1,7 +1,7 @@ // e1->N_Elements() < e2->N_Elements() -> e1->OrOpInv(e2) : this (e1) unless e1==0 - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if ((*this)[0] == zero) (*this)[0] = (*right)[0]; @@ -12,7 +12,7 @@ for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] == zero) (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] == zero) (*this)[i] = (*right)[i]; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) + for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i] == zero) (*this)[i] = (*right)[i]; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_OrOpInvCplx.incpp b/src/snippets/basic_op_OrOpInvCplx.incpp index 6a2e416c7..f11652b92 100644 --- a/src/snippets/basic_op_OrOpInvCplx.incpp +++ b/src/snippets/basic_op_OrOpInvCplx.incpp @@ -1,7 +1,7 @@ // e1->N_Elements() < e2->N_Elements() -> e1->OrOpInv(e2) : this (e1) unless e1==0 - Data_* right = static_cast (r); + auto right = dynamic_cast (r); - ULong nEl = N_Elements(); + const auto nEl = static_cast(N_Elements()); assert(nEl); if (nEl == 1) { if (std::norm((*this)[0]) == 0) (*this)[0] = (*right)[0]; @@ -12,7 +12,7 @@ for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) == 0) (*this)[i] = (*right)[i]; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, right) for (OMPInt i = 0; i < nEl; ++i) if (std::norm((*this)[i]) == 0) (*this)[i] = (*right)[i]; } - return this; + return this; \ No newline at end of file diff --git a/src/snippets/basic_op_OrOpInvSCplx.incpp b/src/snippets/basic_op_OrOpInvSCplx.incpp index 1f18c3be5..fe171963a 100644 --- a/src/snippets/basic_op_OrOpInvSCplx.incpp +++ b/src/snippets/basic_op_OrOpInvSCplx.incpp @@ -1,7 +1,7 @@ // e1 Or e2=StrictScalar() : e1 everywhere except if e1==0 -Data_* right = static_cast (r); +auto right = dynamic_cast (r); -ULong nEl = N_Elements(); +const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (nEl == 1) { @@ -13,7 +13,7 @@ if ((GDL_NTHREADS = parallelize(nEl)) == 1) { for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i]==zero) (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) for (OMPInt i = 0; i < nEl; ++i) if ((*this)[i]==zero) (*this)[i] = s; } return this; diff --git a/src/snippets/basic_op_OrOpSCplx.incpp b/src/snippets/basic_op_OrOpSCplx.incpp index 57894d5a9..ac81b19b9 100644 --- a/src/snippets/basic_op_OrOpSCplx.incpp +++ b/src/snippets/basic_op_OrOpSCplx.incpp @@ -1,7 +1,7 @@ // e1=StrictScalar() OR e2 -> e2 <- e1 : e1 everywhere except if e1==0 -Data_* right = static_cast (r); +auto right = dynamic_cast (r); -ULong nEl = N_Elements(); +const auto nEl = static_cast(N_Elements()); assert(nEl); Ty s = (*right)[0]; if (s != zero) { @@ -14,8 +14,8 @@ if (s != zero) { for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = s; } else { TRACEOMP(__FILE__, __LINE__) -#pragma omp parallel for num_threads(GDL_NTHREADS) - for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = s; +#pragma omp parallel for num_threads(GDL_NTHREADS) default(none) shared(nEl, s) + for (OMPInt i = 0; i < nEl; ++i) (*this)[i] = s; } } -return this; +return this; \ No newline at end of file diff --git a/src/typedefs.hpp b/src/typedefs.hpp index eec73c187..00445d002 100644 --- a/src/typedefs.hpp +++ b/src/typedefs.hpp @@ -115,7 +115,7 @@ typedef unsigned long long int SizeT; typedef long long int RangeT; typedef long long int OMPInt; -const SizeT MAXRANK=8; // arrays are limited to 8 dimensions +constexpr unsigned char MAXRANK = 8; // arrays are limited to 8 dimensions const std::string MAXRANK_STR("8"); // for use in strings (error messages) const std::string INTERNAL_LIBRARY_STR(""); diff --git a/src/typetraits.cpp b/src/typetraits.cpp index 99a726243..ecfe7a836 100644 --- a/src/typetraits.cpp +++ b/src/typetraits.cpp @@ -87,7 +87,7 @@ const std::string& SpDDouble::TypeStr() const { return str;} const DType SpDString::t=GDL_STRING; // type ID const string SpDString::str("STRING"); // type string -const DString SpDString::zero(""); // zero string +const DString SpDString::zero; // zero string BaseGDL* SpDString::GetTag() const { return new SpDString(*this);} DType SpDString::Type() const { return t;} const std::string& SpDString::TypeStr() const { return str;} @@ -95,9 +95,8 @@ const std::string& SpDString::TypeStr() const { return str;} const DType SpDStruct::t=GDL_STRUCT; // type ID const string SpDStruct::str("STRUCT"); // type string const SpDStruct::Ty SpDStruct::zero=0; // zero struct, special meaning -BaseGDL* SpDStruct::GetTag() const -{ - SpDStruct* newTag = new SpDStruct(*this); +BaseGDL* SpDStruct::GetTag() const { + auto newTag = new SpDStruct(*this); newTag->MakeOwnDesc(); return newTag; } @@ -146,9 +145,8 @@ BaseGDL* SpDDouble::GetInstance() const { return new Data_(dim);} BaseGDL* SpDString::GetInstance() const { return new Data_(dim);} BaseGDL* SpDPtr::GetInstance() const { return new Data_(dim);} BaseGDL* SpDObj::GetInstance() const { return new Data_(dim);} -BaseGDL* SpDStruct::GetInstance() const -{ - DStructGDL* newInstance = new DStructGDL(desc,dim); +BaseGDL* SpDStruct::GetInstance() const { + auto newInstance = new DStructGDL(desc, dim); newInstance->MakeOwnDesc(); return newInstance; } @@ -168,9 +166,8 @@ BaseGDL* SpDDouble::GetEmptyInstance() const { return new Data_( dim, BaseGDL* SpDString::GetEmptyInstance() const { return new Data_( dim, BaseGDL::NOALLOC);} BaseGDL* SpDPtr::GetEmptyInstance() const { return new Data_( dim, BaseGDL::NOALLOC);} BaseGDL* SpDObj::GetEmptyInstance() const { return new Data_( dim, BaseGDL::NOALLOC);} -BaseGDL* SpDStruct::GetEmptyInstance() const -{ - DStructGDL* newInstance = new DStructGDL( desc, dim, BaseGDL::NOALLOC); +BaseGDL* SpDStruct::GetEmptyInstance() const { + auto newInstance = new DStructGDL(desc, dim, BaseGDL::NOALLOC); newInstance->MakeOwnDesc(); return newInstance; } @@ -179,44 +176,48 @@ BaseGDL* SpDComplexDbl::GetEmptyInstance() const { return new Data_N_Elements() * sizeof(Ty)); +} SpDLong::SpDLong(): BaseGDL() {} SpDLong::SpDLong( const dimension& dim_): BaseGDL(dim_) {} -SpDLong::~SpDLong() {} +SpDLong::~SpDLong() = default; SpDULong::SpDULong(): BaseGDL() {} SpDULong::SpDULong( const dimension& dim_): BaseGDL(dim_) {} -SpDULong::~SpDULong() {} +SpDULong::~SpDULong() = default; SpDLong64::SpDLong64(): BaseGDL() {} SpDLong64::SpDLong64( const dimension& dim_): BaseGDL(dim_) {} -SpDLong64::~SpDLong64() {} +SpDLong64::~SpDLong64() = default; SpDULong64::SpDULong64(): BaseGDL() {} SpDULong64::SpDULong64( const dimension& dim_): BaseGDL(dim_) {} -SpDULong64::~SpDULong64() {} +SpDULong64::~SpDULong64() = default; SpDFloat::SpDFloat(): BaseGDL() {} SpDFloat::SpDFloat( const dimension& dim_): BaseGDL(dim_) {} -SpDFloat::~SpDFloat() {} +SpDFloat::~SpDFloat() = default; SpDDouble::SpDDouble(): BaseGDL() {} SpDDouble::SpDDouble( const dimension& dim_): BaseGDL(dim_) {} -SpDDouble::~SpDDouble() {} +SpDDouble::~SpDDouble() = default; SpDString::SpDString(): BaseGDL() {} SpDString::SpDString( const dimension& dim_): BaseGDL(dim_) {} -SpDString::~SpDString() {} +SpDString::~SpDString() = default; +#if 0 SpDStruct::SpDStruct( DStructDesc* desc_): BaseGDL(), desc(desc_) @@ -224,6 +225,7 @@ SpDStruct::SpDStruct( DStructDesc* desc_): // if( desc != NULL && desc->IsUnnamed()) // desc = new DStructDesc( desc); } +#endif SpDStruct::SpDStruct( DStructDesc* desc_, const dimension& dim_): BaseGDL(dim_), @@ -236,24 +238,25 @@ SpDStruct::SpDStruct( DStructDesc* desc_, const dimension& dim_): SpDStruct::~SpDStruct() { - if( desc != NULL && desc->IsUnnamed()) desc->Delete(); + if (desc != nullptr && desc->IsUnnamed()) + desc->Delete(); } SpDPtr::SpDPtr(): BaseGDL() {} SpDPtr::SpDPtr( const dimension& dim_): BaseGDL(dim_) {} -SpDPtr::~SpDPtr() {} +SpDPtr::~SpDPtr() = default; SpDObj::SpDObj(): BaseGDL() {} SpDObj::SpDObj( const dimension& dim_): BaseGDL(dim_) {} -SpDObj::~SpDObj() {} +SpDObj::~SpDObj() = default; SpDComplex::SpDComplex(): BaseGDL() {} SpDComplex::SpDComplex( const dimension& dim_): BaseGDL(dim_) {} -SpDComplex::~SpDComplex() {} +SpDComplex::~SpDComplex() = default; SpDComplexDbl::SpDComplexDbl(): BaseGDL() {} SpDComplexDbl::SpDComplexDbl( const dimension& dim_): BaseGDL(dim_) {} -SpDComplexDbl::~SpDComplexDbl() {} +SpDComplexDbl::~SpDComplexDbl() = default; diff --git a/src/typetraits.hpp b/src/typetraits.hpp index 096a727d4..2602997e2 100644 --- a/src/typetraits.hpp +++ b/src/typetraits.hpp @@ -33,11 +33,11 @@ struct SpDByte: public BaseGDL SpDByte(); explicit SpDByte( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -46,19 +46,13 @@ struct SpDByte: public BaseGDL static const std::string str; static const DByte zero; -// static const bool IS_INTEGER; -// static const bool IS_SIGNED; -// static const bool IS_NUMERIC; -// static const bool IS_COMPLEX; -// static const bool IS_POD; -// static const bool IS_CONVERTABLE; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DByte Ty; typedef GDLArray DataT; @@ -72,11 +66,11 @@ struct SpDByte: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; - ~SpDByte(); + DType Type() const override; + const std::string &TypeStr() const override; + + ~SpDByte() override; }; struct SpDInt: public BaseGDL @@ -84,11 +78,11 @@ struct SpDInt: public BaseGDL SpDInt(); explicit SpDInt( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -97,13 +91,13 @@ struct SpDInt: public BaseGDL static const std::string str; static const DInt zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DInt Ty; typedef GDLArray DataT; @@ -116,11 +110,11 @@ struct SpDInt: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; - ~SpDInt(); + DType Type() const override; + const std::string &TypeStr() const override; + + ~SpDInt() override; }; struct SpDUInt: public BaseGDL @@ -128,26 +122,23 @@ struct SpDUInt: public BaseGDL SpDUInt(); explicit SpDUInt( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const - { - return (this->N_Elements() * sizeof( Ty)); - } + SizeT NBytes() const override; static const DType t; static const std::string str; static const DUInt zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DUInt Ty; typedef GDLArray DataT; @@ -160,12 +151,11 @@ struct SpDUInt: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDUInt(); + ~SpDUInt() override; }; struct SpDLong: public BaseGDL @@ -173,11 +163,11 @@ struct SpDLong: public BaseGDL SpDLong(); explicit SpDLong( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -186,13 +176,13 @@ struct SpDLong: public BaseGDL static const std::string str; static const DLong zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DLong Ty; typedef GDLArray DataT; @@ -205,12 +195,11 @@ struct SpDLong: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDLong(); + ~SpDLong() override; }; struct SpDULong: public BaseGDL @@ -218,11 +207,11 @@ struct SpDULong: public BaseGDL SpDULong(); explicit SpDULong( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -231,13 +220,13 @@ struct SpDULong: public BaseGDL static const std::string str; static const DULong zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DULong Ty; typedef GDLArray DataT; @@ -250,12 +239,11 @@ struct SpDULong: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDULong(); + ~SpDULong() override; }; struct SpDLong64: public BaseGDL @@ -263,11 +251,11 @@ struct SpDLong64: public BaseGDL SpDLong64(); explicit SpDLong64( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -276,13 +264,13 @@ struct SpDLong64: public BaseGDL static const std::string str; static const DLong64 zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DLong64 Ty; typedef GDLArray DataT; @@ -295,12 +283,11 @@ struct SpDLong64: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDLong64(); + ~SpDLong64() override; }; struct SpDULong64: public BaseGDL @@ -308,11 +295,11 @@ struct SpDULong64: public BaseGDL SpDULong64(); explicit SpDULong64( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -321,13 +308,13 @@ struct SpDULong64: public BaseGDL static const std::string str; static const DULong64 zero; - static const bool IS_INTEGER = true; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = true; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DULong64 Ty; typedef GDLArray DataT; @@ -340,12 +327,11 @@ struct SpDULong64: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDULong64(); + ~SpDULong64() override; }; struct SpDFloat: public BaseGDL @@ -353,11 +339,11 @@ struct SpDFloat: public BaseGDL SpDFloat(); explicit SpDFloat( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -366,13 +352,13 @@ struct SpDFloat: public BaseGDL static const std::string str; static const DFloat zero; - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = true; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = true; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DFloat Ty; typedef GDLArray DataT; @@ -385,11 +371,11 @@ struct SpDFloat: public BaseGDL struct IfComplex {}; template struct IfOther {}; - - DType Type() const; - const std::string& TypeStr() const; - ~SpDFloat(); + DType Type() const override; + const std::string &TypeStr() const override; + + ~SpDFloat() override; }; struct SpDDouble: public BaseGDL @@ -397,11 +383,11 @@ struct SpDDouble: public BaseGDL SpDDouble(); explicit SpDDouble( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } @@ -410,13 +396,13 @@ struct SpDDouble: public BaseGDL static const std::string str; static const DDouble zero; - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = true; - static const bool IS_COMPLEX = false; - static const bool IS_POD = true; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = true; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = true; + //static constexpr bool IS_CONVERTABLE = true; typedef DDouble Ty; typedef GDLArray DataT; @@ -430,10 +416,10 @@ struct SpDDouble: public BaseGDL template struct IfOther {}; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDDouble(); + ~SpDDouble() override; }; struct SpDString: public BaseGDL @@ -441,22 +427,22 @@ struct SpDString: public BaseGDL SpDString(); explicit SpDString( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = false; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = false; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = false; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = false; + //static constexpr bool IS_CONVERTABLE = true; typedef DString Ty; typedef GDLArray DataT; @@ -474,10 +460,10 @@ struct SpDString: public BaseGDL template struct IfOther { typedef ReturnType type; }; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDString(); + ~SpDString() override; }; // attention: structs are special @@ -486,13 +472,13 @@ struct SpDStruct: public BaseGDL protected: DStructDesc* desc; - explicit SpDStruct( DStructDesc* desc_=NULL); + //explicit SpDStruct( DStructDesc* desc_= nullptr); SpDStruct( DStructDesc* desc_, const dimension& dim_); void MakeOwnDesc() { // if( /* desc != NULL && */ desc->IsUnnamed()) desc = new DStructDesc( desc); - assert( desc != NULL); + assert(desc != nullptr); if( desc->IsUnnamed()) desc->AddRef(); } @@ -500,29 +486,29 @@ struct SpDStruct: public BaseGDL inline SizeT NTags() const { return desc->NTags();} inline DStructDesc* Desc() const { return desc;} - inline void SetDesc( DStructDesc* newDesc) - { - if( desc != NULL && desc->IsUnnamed()) delete desc; + inline void SetDesc(DStructDesc *newDesc) { + if (desc != nullptr && desc->IsUnnamed()) + delete desc; desc=newDesc; } // GetTag returns a tag descriptor (SpType) - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return ( this->N_Elements() * desc->NBytes()); } - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = false; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = false; - static const bool IS_CONVERTABLE = false; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = false; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = false; + //static constexpr bool IS_CONVERTABLE = false; typedef char Ty; typedef GDLArray DataT; // we are using char here @@ -531,10 +517,10 @@ struct SpDStruct: public BaseGDL static const std::string str; static const Ty zero; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDStruct(); + ~SpDStruct() override; }; @@ -543,22 +529,22 @@ struct SpDPtr: public BaseGDL SpDPtr(); explicit SpDPtr( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = false; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = false; // due to ref counting - static const bool IS_CONVERTABLE = false; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = false; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = false; // due to ref counting + //static constexpr bool IS_CONVERTABLE = false; typedef DPtr Ty; typedef GDLArray DataT; // on this level, DPtr is POD @@ -576,10 +562,10 @@ struct SpDPtr: public BaseGDL static const std::string str; static const Ty zero; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDPtr(); + ~SpDPtr() override; }; // objects are pointer to structs @@ -588,22 +574,22 @@ struct SpDObj: public BaseGDL SpDObj(); explicit SpDObj( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = false; - static const bool IS_NUMERIC = false; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = false; - static const bool IS_POD = false; // due to ref counting - static const bool IS_CONVERTABLE = false; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = false; + //static constexpr bool IS_NUMERIC = false; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = false; + static constexpr bool IS_POD = false; // due to ref counting + //static constexpr bool IS_CONVERTABLE = false; typedef DObj Ty; typedef GDLArray DataT; // on this level, DObj is POD @@ -621,10 +607,10 @@ struct SpDObj: public BaseGDL static const std::string str; static const Ty zero; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDObj(); + ~SpDObj() override; }; struct SpDComplex: public BaseGDL @@ -632,25 +618,25 @@ struct SpDComplex: public BaseGDL SpDComplex(); explicit SpDComplex( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } - static const bool IS_INTEGER = false; - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = true; - static const bool IS_POD = false; - static const bool IS_CONVERTABLE = true; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = true; + static constexpr bool IS_POD = false; + //static constexpr bool IS_CONVERTABLE = true; typedef DComplex Ty; - typedef GDLArray DataT; // ATTENTION: srictly complex is non-pod + typedef GDLArray DataT; // ATTENTION: strictly complex is non-pod template struct IfInteger {}; @@ -665,10 +651,10 @@ struct SpDComplex: public BaseGDL static const std::string str; static const DComplex zero; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDComplex(); + ~SpDComplex() override; }; struct SpDComplexDbl: public BaseGDL @@ -676,22 +662,22 @@ struct SpDComplexDbl: public BaseGDL SpDComplexDbl(); explicit SpDComplexDbl( const dimension& dim_); - BaseGDL* GetTag() const; - BaseGDL* GetInstance() const; - BaseGDL* GetEmptyInstance() const; + BaseGDL *GetTag() const override; + BaseGDL *GetInstance() const override; + BaseGDL *GetEmptyInstance() const override; - SizeT NBytes() const + SizeT NBytes() const override { return (this->N_Elements() * sizeof( Ty)); } - static const bool IS_SIGNED = true; - static const bool IS_NUMERIC = true; - static const bool IS_INTEGER = false; - static const bool IS_FLOAT = false; - static const bool IS_COMPLEX = true; - static const bool IS_POD = false; - static const bool IS_CONVERTABLE = true; + //static constexpr bool IS_SIGNED = true; + //static constexpr bool IS_NUMERIC = true; + static constexpr bool IS_INTEGER = false; + //static constexpr bool IS_FLOAT = false; + static constexpr bool IS_COMPLEX = true; + static constexpr bool IS_POD = false; + //static constexpr bool IS_CONVERTABLE = true; typedef DComplexDbl Ty; typedef GDLArray DataT; // ATTENTION: srictly complex is non-pod @@ -709,10 +695,10 @@ struct SpDComplexDbl: public BaseGDL static const std::string str; static const DComplexDbl zero; - DType Type() const; - const std::string& TypeStr() const; + DType Type() const override; + const std::string &TypeStr() const override; - ~SpDComplexDbl(); + ~SpDComplexDbl() override; }; diff --git a/src/widget.cpp b/src/widget.cpp index 473b1fac3..fcfe895b7 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1908,7 +1908,7 @@ BaseGDL* widget_info( EnvT* e ) { if (debug) { DLongGDL* wid = static_cast( GDLWidget::GetWidgetsList( ) ); Guard guard_wid(wid); - DStringGDL* res = new DStringGDL(wid->N_Elements()); + DStringGDL *res = new DStringGDL(dimension(wid->N_Elements())); for ( SizeT i = 0; i < wid->N_Elements(); i++ ) { GDLWidget *widget = GDLWidget::GetWidget( (*wid)[i] ); //protect against internal error where wid is not up-to-date