sketchmap icon indicating copy to clipboard operation
sketchmap copied to clipboard

Compilation error

Open peterbjorgensen opened this issue 8 years ago • 4 comments

Using "g++ (GCC) 6.2.1 20160830" as compiler I get the following error when using "make":

make -C libs all
make[1]: Entering directory '/home/peter/kodesjov/sketchmap/libs'
g++  -g -O3 -ftracer -floop-optimize -funroll-loops -D_IBM -I../libs/    -c -o libfmblas.o libfmblas.cpp
In file included from matrices.hpp:10:0,
                 from matrix-full.hpp:11,
                 from matrix-full-blas.hpp:11,
                 from libfmblas.cpp:7:
ioparser.hpp: In member function ‘virtual bool toolbox::IFBase::operator>>(std::__cxx11::string&) const’:
ioparser.hpp:103:103: error: cannot convert ‘std::ostream {aka std::basic_ostream<char>}’ to ‘bool’ in initialization
     virtual bool operator>> (std::string& str) const { std::ostringstream os; bool rval=(os << (*this)); str=os.str(); return rval; }
                                                                                                       ^
make[1]: *** [<builtin>: libfmblas.o] Error 1
make[1]: Leaving directory '/home/peter/kodesjov/sketchmap/libs'
make: *** [Makefile:9: libs] Error 2

Thanks

peterbjorgensen avatar Jan 03 '17 14:01 peterbjorgensen

Hi, gcc switched to a new standard - I tried a quick fix for that specific line so please try to pull. if that does not work, try to add -std=c++03 to the compiler options in make.in

On 3 January 2017 at 15:54, peder2tm [email protected] wrote:

Using "g++ (GCC) 6.2.1 20160830" as compiler I get the following error when using "make":

make -C libs all make[1]: Entering directory '/home/peter/kodesjov/sketchmap/libs' g++ -g -O3 -ftracer -floop-optimize -funroll-loops -D_IBM -I../libs/ -c -o libfmblas.o libfmblas.cpp In file included from matrices.hpp:10:0, from matrix-full.hpp:11, from matrix-full-blas.hpp:11, from libfmblas.cpp:7: ioparser.hpp: In member function ‘virtual bool toolbox::IFBase::operator>>(std::__cxx11::string&) const’: ioparser.hpp:103:103: error: cannot convert ‘std::ostream {aka std::basic_ostream}’ to ‘bool’ in initialization virtual bool operator>> (std::string& str) const { std::ostringstream os; bool rval=(os << (*this)); str=os.str(); return rval; } ^ make[1]: *** [: libfmblas.o] Error 1 make[1]: Leaving directory '/home/peter/kodesjov/sketchmap/libs' make: *** [Makefile:9: libs] Error 2

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/epfl-cosmo/sketchmap/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/ABESZyzDVLtsnvL7h0J5keAgtJ7BOV-wks5rOmESgaJpZM4LZsEa .

ceriottm avatar Jan 03 '17 17:01 ceriottm

there are other lines where there are complaints -- I fixed them all, trying to push now.

On Tue, Jan 3, 2017 at 3:26 PM, Michele Ceriotti [email protected] wrote:

Hi, gcc switched to a new standard - I tried a quick fix for that specific line so please try to pull. if that does not work, try to add -std=c++03 to the compiler options in make.in

On 3 January 2017 at 15:54, peder2tm [email protected] wrote:

Using "g++ (GCC) 6.2.1 20160830" as compiler I get the following error when using "make":

make -C libs all make[1]: Entering directory '/home/peter/kodesjov/sketchmap/libs' g++ -g -O3 -ftracer -floop-optimize -funroll-loops -D_IBM -I../libs/ -c -o libfmblas.o libfmblas.cpp In file included from matrices.hpp:10:0, from matrix-full.hpp:11, from matrix-full-blas.hpp:11, from libfmblas.cpp:7: ioparser.hpp: In member function ‘virtual bool toolbox::IFBase::operator>>(std::__cxx11::string&) const’: ioparser.hpp:103:103: error: cannot convert ‘std::ostream {aka std::basic_ostream}’ to ‘bool’ in initialization virtual bool operator>> (std::string& str) const { std::ostringstream os; bool rval=(os << (*this)); str=os.str(); return rval; } ^ make[1]: *** [: libfmblas.o] Error 1 make[1]: Leaving directory '/home/peter/kodesjov/sketchmap/libs' make: *** [Makefile:9: libs] Error 2

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/epfl-cosmo/sketchmap/issues/3, or mute the thread <https://github.com/notifications/unsubscribe-auth/ ABESZyzDVLtsnvL7h0J5keAgtJ7BOV-wks5rOmESgaJpZM4LZsEa> .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/epfl-cosmo/sketchmap/issues/3#issuecomment-270170594, or mute the thread https://github.com/notifications/unsubscribe-auth/AGbkQq3FLmCoq188SWvr5aEK2ec5BR2Yks5rOoThgaJpZM4LZsEa .

mahrossi avatar Jan 03 '17 22:01 mahrossi

Thanks. Now I got a bunch of new compilation errors saying that the abs function is ambiguous. I changed abs(x) to std::abs(x) wherever I got the error and now it compiles. The code below is a patch of the changes

From 79f69b72750bf80c0587b06dcfd6ff864b713ec4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20Bj=C3=B8rn=20J=C3=B8rgensen?=
 <[email protected]>
Date: Wed, 4 Jan 2017 12:57:37 +0100
Subject: [PATCH] Changed abs to std::abs where ambigious

---
 libs/matrix-crs.hpp  | 62 ++++++++++++++++++++++++++--------------------------
 libs/matrix-full.hpp |  8 +++----
 libs/minsearch.hpp   |  2 +-
 libs/tbdefs.hpp      |  8 +++----
 tools/dimred.cpp     |  2 +-
 5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/libs/matrix-crs.hpp b/libs/matrix-crs.hpp
index 5f297143..83299b42 100644
--- a/libs/matrix-crs.hpp
+++ b/libs/matrix-crs.hpp
@@ -470,7 +470,7 @@ public:
             
             for (; k<rpoints[i+1]; ++k)
             {
-                if (abs(values[k])<=thresh) {++sh; continue;}
+                if (std::abs(values[k])<=thresh) {++sh; continue;}
                 
                 values[h]=values[k];
                 indices[h]=indices[k];
@@ -583,12 +583,12 @@ void incr(CrsMatrix<U>& a, const CrsMatrix<V>& b)
                 for (; ka<a.rpoints[i+1]; ++ka) 
                 {   
                     while (kb<b.rpoints[i+1] && b.indices[kb]<a.indices[ka])
-                    { if (abs((U) b.values[kb])>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb;  }
+                    { if (std::abs((U) b.values[kb])>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb;  }
                     if (kb==b.rpoints[i+1]) continue;
                     if (b.indices[kb]==a.indices[ka]) {  a.values[ka]+=(U) b.values[kb]; ++kb;}
                 }
                 
-                while (kb<b.rpoints[i+1]) { if (abs((U) b.values[kb])>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; }
+                while (kb<b.rpoints[i+1]) { if (std::abs((U) b.values[kb])>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; }
             }
         }
         else
@@ -606,16 +606,16 @@ void incr(CrsMatrix<U>& a, const CrsMatrix<V>& b)
                     {                   
                         while (kb<b.rpoints[i+1] && b.indices[kb]<a.indices[ka])
                         { 
-                            ta=abs((U) b.values[kb]); if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
+                            ta=std::abs((U) b.values[kb]); if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki;} ++kb; 
                         }
                         if (kb==b.rpoints[i+1]) continue;
                         //if the element A is already present, it is a waste of time to remove it here.
                         if (b.indices[kb]==a.indices[ka]) {a.values[ka]+=(U) b.values[kb]; ++kb;}
-                        if (!a.pops.atnodiag || a.indices[ka]!=i+a.RBASE) tr+=abs(a.values[ka]);
+                        if (!a.pops.atnodiag || a.indices[ka]!=i+a.RBASE) tr+=std::abs(a.values[ka]);
                     }
                     while (kb<b.rpoints[i+1]) { 
-                        ta=abs((U) b.values[kb]);  if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
+                        ta=std::abs((U) b.values[kb]);  if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                         if (ta>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; }
                         if (nguess<tr) nguess=tr; thresh=nguess*a.pops.atthresh;
                 }
@@ -703,11 +703,11 @@ void incr(CrsMatrix<U>& a, const CrsMatrix<V>& b, const T& s)
                 for (; ka<a.rpoints[i+1]; ++ka) 
                 {   
                     while (kb<b.rpoints[i+1] && b.indices[kb]<a.indices[ka])
-                    { if (abs((U) (b.values[kb]*s))>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb;  }
+                    { if (std::abs((U) (b.values[kb]*s))>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb;  }
                     if (kb==b.rpoints[i+1]) continue;
                     if (b.indices[kb]==a.indices[ka]) {a.values[ka]+=(U) (b.values[kb]*s); ++kb;}
                 }
-                while (kb<b.rpoints[i+1]) { if (abs((U) (b.values[kb]*s))>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; }
+                while (kb<b.rpoints[i+1]) { if (std::abs((U) (b.values[kb]*s))>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; }
             }
         }
         else
@@ -724,16 +724,16 @@ void incr(CrsMatrix<U>& a, const CrsMatrix<V>& b, const T& s)
                     {
                         while (kb<b.rpoints[i+1] && b.indices[kb]<a.indices[ka])
                         {
-                            ta=abs((U) (b.values[kb]*s)); if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
+                            ta=std::abs((U) (b.values[kb]*s)); if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki;} ++kb; 
                         }
                         if (kb==b.rpoints[i+1]) continue;
                     //if the element A is already present, it is a waste of time to remove it here, but we must update the trace
                         if (b.indices[kb]==a.indices[ka]) {a.values[ka]+=(U) (b.values[kb]*s); ++kb;}
-                        if (!a.pops.atnodiag || a.indices[ka]!=i+a.RBASE) tr+=abs(a.values[ka]);
+                        if (!a.pops.atnodiag || a.indices[ka]!=i+a.RBASE) tr+=std::abs(a.values[ka]);
                     }
                     while (kb<b.rpoints[i+1]) { 
-                        ta=abs((U) (b.values[kb]*s)); if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
+                        ta=std::abs((U) (b.values[kb]*s)); if (!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                         if (ta>thresh) { a_insert[ki]=ka; b_insert[ki]=kb; ++ki; } ++kb; 
                     }
                     //also implement shifting of norm
@@ -835,24 +835,24 @@ void add(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
                 {
                 //exausts row of matrix c
                     while (kc<c.rpoints[i+1]) 
-                    { if (abs(c.values[kc])>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka;} ++kc; }
+                    { if (std::abs(c.values[kc])>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka;} ++kc; }
                     a.rpoints[i+1]=ka; ++i;
                 }
                 else if (kc==c.rpoints[i+1])
                 {
                 //exausts row of matrix b
                     while (kb<b.rpoints[i+1]) 
-                    { if (abs(b.values[kb])>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } ++kb; }
+                    { if (std::abs(b.values[kb])>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } ++kb; }
                     a.rpoints[i+1]=ka; ++i;
                 }
                 else 
                 {
                     if (b.indices[kb]<c.indices[kc])
-                    { if (abs(b.values[kb])>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } ++kb; }
+                    { if (std::abs(b.values[kb])>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } ++kb; }
                     else if (b.indices[kb]>c.indices[kc])
-                    { if (abs(c.values[kc])>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka; } ++kc; }
+                    { if (std::abs(c.values[kc])>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka; } ++kc; }
                     else
-                    { if (abs(c.values[kc]+b.values[kb])>thresh) 
+                    { if (std::abs(c.values[kc]+b.values[kb])>thresh) 
                     { a.indices[ka]=b.indices[kb]; a.values[ka]=(U)c.values[kc]+b.values[kb]; ++ka; } ++kb; ++kc; }
                 }
             }
@@ -871,7 +871,7 @@ void add(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
                 //exausts row of matrix c
                         while (kc<c.rpoints[i+1]) 
                         { 
-                            ta=abs((U) c.values[kc]);
+                            ta=std::abs((U) c.values[kc]);
                             if(!a.pops.atnodiag || c.indices[kc]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka;} 
                             ++kc; 
@@ -884,7 +884,7 @@ void add(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
                 //exausts row of matrix b
                         while (kb<b.rpoints[i+1]) 
                         { 
-                            (ta=abs(b.values[kb])); if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
+                            (ta=std::abs(b.values[kb])); if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } 
                             ++kb; 
                         }
@@ -895,18 +895,18 @@ void add(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
                     {
                         if (b.indices[kb]<c.indices[kc])
                         { 
-                            ta=abs(b.values[kb]); 
+                            ta=std::abs(b.values[kb]); 
                             if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a.indices[ka]=b.indices[kb]; a.values[ka]=b.values[kb]; ++ka; } ++kb; 
                         }
                         else if (b.indices[kb]>c.indices[kc])
                         { 
-                            ta=abs((U) c.values[kc]); 
+                            ta=std::abs((U) c.values[kc]); 
                             if(!a.pops.atnodiag || c.indices[kc]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) { a.indices[ka]=c.indices[kc]; a.values[ka]=(U) c.values[kc]; ++ka; } ++kc; }
                         else
                         { 
-                            ta=abs((U) c.values[kc]+b.values[kb]);
+                            ta=std::abs((U) c.values[kc]+b.values[kb]);
                             if(!a.pops.atnodiag || b.indices[kb]!=i+a.RBASE) tr+=ta;
                             if (ta>thresh) 
                             { a.indices[ka]=b.indices[kb]; a.values[ka]=(U)c.values[kc]+b.values[kb]; ++ka; } ++kb; ++kc; }
@@ -1126,12 +1126,12 @@ void mult(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
             else
             { 
                 if (!a.pops.atrel)
-                { for (ic=0; ic<kc; ++ic) if (abs(v1[ic])>a.pops.atthresh) {v1[jc]=v1[ic]; i1[jc++]=i1[ic];} } //absolute 
+                { for (ic=0; ic<kc; ++ic) if (std::abs(v1[ic])>a.pops.atthresh) {v1[jc]=v1[ic]; i1[jc++]=i1[ic];} } //absolute 
                 else switch (a.pops.atnorm)
                 {
                 case at_norminf:
                     tr=0;
-                    for (ic=0; ic<kc; ++ic) { ta=abs(v1[ic]); if(!a.pops.atnodiag || i1[ic]!=ib+a.RBASE) tr+=ta; if (ta>thresh) {v1[jc]=v1[ic]; i1[jc++]=i1[ic];} }
+                    for (ic=0; ic<kc; ++ic) { ta=std::abs(v1[ic]); if(!a.pops.atnodiag || i1[ic]!=ib+a.RBASE) tr+=ta; if (ta>thresh) {v1[jc]=v1[ic]; i1[jc++]=i1[ic];} }
                     if(tr>nguess) nguess=tr; thresh=nguess*a.pops.atthresh;
                     break;
                 default:
@@ -1200,7 +1200,7 @@ void mult(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
             else
             { 
                 if (!a.pops.atrel)
-                { for (jc=0; jc<a.wc; ++jc) if (a_val[jc]!=(U) 0. && abs(a_val[jc])>a.pops.atthresh) { a_ind[kc]=jc; a_val[kc++]=a_val[jc]; } }
+                { for (jc=0; jc<a.wc; ++jc) if (a_val[jc]!=(U) 0. && std::abs(a_val[jc])>a.pops.atthresh) { a_ind[kc]=jc; a_val[kc++]=a_val[jc]; } }
                 else switch (a.pops.atnorm)
                 {
                     case at_norminf:
@@ -1209,7 +1209,7 @@ void mult(const CrsMatrix<U>& b, const CrsMatrix<V>& c, CrsMatrix<U>& a)
                         { 
                             if (a_val[jc]!=(U) 0.) 
                             { 
-                                (ta=abs(a_val[jc])); if (!a.pops.atnodiag || jc!=ib+a.RBASE) tr+=ta;
+                                (ta=std::abs(a_val[jc])); if (!a.pops.atnodiag || jc!=ib+a.RBASE) tr+=ta;
                                 if (ta>thresh) { a_ind[kc]=jc; a_val[kc++]=a_val[jc]; } 
                             }
                         }
@@ -1500,10 +1500,10 @@ double norm1(const CrsMatrix<U>& a, const bool nodiag)
     std::valarray<double> maxc((double) 0., a.wc);
     if (nodiag)
         for (typename CrsMatrix<U>::index_type k=0; k<a.rpoints[a.wr]; ++k)
-            if (a.indices[k]!=k+a.RBASE) maxc[a.indices[k]]+=abs(a.values[k]);
+            if (a.indices[k]!=k+a.RBASE) maxc[a.indices[k]]+=std::abs(a.values[k]);
     else
         for (typename CrsMatrix<U>::index_type k=0; k<a.rpoints[a.wr]; ++k)
-            maxc[a.indices[k]]+=abs(a.values[k]);
+            maxc[a.indices[k]]+=std::abs(a.values[k]);
     
     return maxc.max();
 }
@@ -1517,14 +1517,14 @@ double norminf(const CrsMatrix<U>& a, const bool nodiag)
         for (typename CrsMatrix<U>::index_type i=0; i<a.wr; ++i)
         {
             ti=0;
-            for (; k<a.rpoints[i+1]; ++k) if(a.indices[k]!=i+a.RBASE) ti+=abs(a.values[k]);
+            for (; k<a.rpoints[i+1]; ++k) if(a.indices[k]!=i+a.RBASE) ti+=std::abs(a.values[k]);
             if (ti>maxc) maxc=ti;
         }
     else
         for (typename CrsMatrix<U>::index_type i=0; i<a.wr; ++i)
         {
             ti=0;
-            for (; k<a.rpoints[i+1]; ++k) ti+=abs(a.values[k]);
+            for (; k<a.rpoints[i+1]; ++k) ti+=std::abs(a.values[k]);
             if (ti>maxc) maxc=ti;
         }
     //std::cerr<<"NORM IS "<<maxc<<" NODIAG: "<<nodiag<<" RBASE "<<a.RBASE<<"\n";
@@ -1539,11 +1539,11 @@ double normfrob(const CrsMatrix<U>& a, const bool nodiag)
     if (nodiag)
         for (typename CrsMatrix<U>::index_type i=0; i<a.wr; ++i)
         {
-            for (; k<a.rpoints[i+1]; ++k) if (a.indices[k]!=i+a.RBASE) {ak=abs(a.values[k]); fn+=ak*ak; }
+            for (; k<a.rpoints[i+1]; ++k) if (a.indices[k]!=i+a.RBASE) {ak=std::abs(a.values[k]); fn+=ak*ak; }
         }
     else 
     for (; k<a.rpoints[a.wr]; ++k)
-        { ak=abs(a.values[k]); fn+=ak*ak; }
+        { ak=std::abs(a.values[k]); fn+=ak*ak; }
 
     return sqrt(fn);
 }
diff --git a/libs/matrix-full.hpp b/libs/matrix-full.hpp
index d27d2255..917040bd 100644
--- a/libs/matrix-full.hpp
+++ b/libs/matrix-full.hpp
@@ -245,7 +245,7 @@ public:
         if (thresh<0.) ERROR("Negative truncation threshold")
 #endif
         
-        for (index_type k=0; k<data.size(); ++k) if (abs(data[k])<=thresh) data[k]=(U) 0.;
+        for (index_type k=0; k<data.size(); ++k) if (std::abs(data[k])<=thresh) data[k]=(U) 0.;
     }
     
     //overloaded operators
@@ -374,7 +374,7 @@ template <class U> double norm1(const FMatrix<U>& a)
     typename FMatrix<U>::index_type k=0;
     for (typename FMatrix<U>::index_type i=0; i<a.wr; ++i)
         for (typename FMatrix<U>::index_type j=0; j<a.wc; ++j)
-            maxc[j]+=abs(a.data[k++]);
+            maxc[j]+=std::abs(a.data[k++]);
     
     return maxc.max();
 }
@@ -388,7 +388,7 @@ template <class U> double norminf(const FMatrix<U>& a)
     for (typename FMatrix<U>::index_type i=0; i<a.wr; ++i)
     {
         rtot=0;
-        for (typename FMatrix<U>::index_type j=0; j<a.wc; ++j) rtot+=abs(a.data[k++]);
+        for (typename FMatrix<U>::index_type j=0; j<a.wc; ++j) rtot+=std::abs(a.data[k++]);
         if (rtot>max) max=rtot;
     }
     
@@ -400,7 +400,7 @@ template <class U> double norminf(const FMatrix<U>& a)
 template <class U> double normfrob(const FMatrix<U>& a)
 { 
     double nf=0,av; 
-    for (typename FMatrix<U>::index_type k=0; k<a.data.size();++k) nf+=(av=abs(a.data[k]))*av;
+    for (typename FMatrix<U>::index_type k=0; k<a.data.size();++k) nf+=(av=std::abs(a.data[k]))*av;
     return sqrt(nf);
 }
 
diff --git a/libs/minsearch.hpp b/libs/minsearch.hpp
index aa5c9db7..e4875d1b 100644
--- a/libs/minsearch.hpp
+++ b/libs/minsearch.hpp
@@ -523,7 +523,7 @@ template<class FCLASS> void ls_brent(
             et=e;
             e=d;
                                                         
-            if ((abs(p)>=fabs(0.5*q*et) || p<=q*(a-x)
+            if ((std::abs(p)>=fabs(0.5*q*et) || p<=q*(a-x)
                  || p>=q*(b-x))) goto one;
             d=p/q; u=x+d;
             if ((u-a)<t2 || (b-u) <t2) d=(xm-x>=0?fabs(t1):-fabs(t1));
diff --git a/libs/tbdefs.hpp b/libs/tbdefs.hpp
index 437dc3cb..eb6a00d5 100644
--- a/libs/tbdefs.hpp
+++ b/libs/tbdefs.hpp
@@ -256,13 +256,13 @@ public:
             if (nstep[i]>=maxstep) { fmaxstep_reached=true; if (flags[i] & ichk_sufficient) return true;  else continue; }
             if (nstep[i]==0) { rt=false; continue; }
             if (nstep[i]==1 && (flags[i] & ichk_change)) { rt=false; continue; }
-            if (flags[i] & ichk_change) d=abs(oval[i]-val[i]);
-            else d=abs(val[i]-target[i]);
+            if (flags[i] & ichk_change) d=std::abs(oval[i]-val[i]);
+            else d=std::abs(val[i]-target[i]);
             
             if (flags[i] & ichk_relative)
             {
-                if ((flags[i] &ichk_change) && abs(val[i])>0. ) d*=1/abs(val[i]);
-                else if (abs(target[i])>0. ) d*=1./abs(target[i]);
+                if ((flags[i] &ichk_change) && std::abs(val[i])>0. ) d*=1/std::abs(val[i]);
+                else if (std::abs(target[i])>0. ) d*=1./std::abs(target[i]);
             }
             if (d>thresh[i] && !(flags[i] & ichk_sufficient)) rt=false;
             if (d<thresh[i] && (flags[i] & ichk_sufficient)) { return true;}
diff --git a/tools/dimred.cpp b/tools/dimred.cpp
index 6855212b..d591611d 100644
--- a/tools/dimred.cpp
+++ b/tools/dimred.cpp
@@ -258,7 +258,7 @@ int main(int argc, char**argv)
            {
                Dij=mdsopts.metric->dist(&mpoints(i,0),&mpoints(j,0),D); 
                dij=neuclid.dist(&iteropts.ipoints(i,0),&iteropts.ipoints(j,0),d);
-               iteropts.dweights(i,j)=iteropts.dweights(j,i)=pow(abs(fhd.f(Dij)-fld.f(dij)),2.0)/pow(abs(iteropts.tfunH.f(Dij)-dij),2.0);
+               iteropts.dweights(i,j)=iteropts.dweights(j,i)=pow(std::abs(fhd.f(Dij)-fld.f(dij)),2.0)/pow(std::abs(iteropts.tfunH.f(Dij)-dij),2.0);
            }
        std::cerr<<" matrix transfer weights have been built\n";
     }
-- 
2.11.0

peterbjorgensen avatar Jan 04 '17 12:01 peterbjorgensen

hi guys, I am running into the same issue with ambiguous abs(), using compiler g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

It worked fine with g++ 4.9 (the previous one I tried)

g++  -g -O3 -ftracer -floop-optimize -funroll-loops  -I../libs/    -c -o libminsearch.o libminsearch.cpp
In file included from libminsearch.cpp:8:0:
minsearch.hpp: In function ‘void toolbox::ls_brent(toolbox::Vec2Lin<FCLASS>&, const double&, const double&, const double&, double&, double&, const toolbox::LineSearchOpts&)’:
minsearch.hpp:526:23: error: call of overloaded ‘abs(double&)’ is ambiguous
             if ((abs(p)>=fabs(0.5*q*et) || p<=q*(a-x)
                       ^
In file included from /usr/include/c++/6/cstdlib:75:0,
                 from /usr/include/c++/6/bits/stl_algo.h:59,
                 from /usr/include/c++/6/algorithm:62,
                 from /usr/include/c++/6/valarray:38,
                 from tbdefs.hpp:17,
                 from libminsearch.cpp:7:
/usr/include/stdlib.h:735:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
                 from /usr/include/c++/6/algorithm:62,
                 from /usr/include/c++/6/valarray:38,
                 from tbdefs.hpp:17,
                 from libminsearch.cpp:7:
/usr/include/c++/6/cstdlib:185:3: note: candidate: __int128 std::abs(__int128)
   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
   ^~~
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~
In file included from /usr/include/c++/6/valarray:37:0,
                 from tbdefs.hpp:17,
                 from libminsearch.cpp:7:
/usr/include/c++/6/cmath:95:3: note: candidate: constexpr long double std::abs(long double)
   abs(long double __x)
   ^~~
/usr/include/c++/6/cmath:91:3: note: candidate: constexpr float std::abs(float)
   abs(float __x)
   ^~~
/usr/include/c++/6/cmath:85:3: note: candidate: constexpr double std::abs(double)
   abs(double __x)
   ^~~
In file included from libminsearch.cpp:7:0:
tbdefs.hpp:50:15: note: candidate: double abs(const double&)
 inline double abs(const double& g) {return fabs(g);}
               ^~~
<builtin>: recipe for target 'libminsearch.o' failed
make[1]: *** [libminsearch.o] Error 1

gabor1 avatar Sep 24 '18 15:09 gabor1