hbf / miniball

Fast computation of the smallest enclosing ball of a point set, in low or moderately high dimensions.
133 stars 41 forks source link

Compilation problems on g++ 4.7 and 4.5 on SUSE Linux 12.2 and 11.3, respectively #3

Closed hbf closed 11 years ago

hbf commented 11 years ago

Hi,

I have been trying to get your miniball library to work, and fixed some compiler and linux related issues, see the attached patches.

However, even now the provided example.C doesn't seem to produce reasonable result. I have tried with two compiler versions and different optimization levels (g++ 4.7 and 4.5 on SUSE Linux 12.2 and 11.3, respectively) and varying data and dimension sizes. It always results in "Radius = -nan" [1].

Any idea what I might be doing wrong?

Best Regards

1: Example output

$ ./example.bin 1234 8
====================================================
Seb example
====================================================
Starting computation...
====================================================
Running time: 0.002999s
Radius = -nan
=====================================================
Solution errors (relative to radius, nonsquared)
 final QR inconsistency     : 0
 minimal convex coefficient : positive
 maximal overlength         : -nan
 maximal underlength        : nan
=====================================================

Patch 1:


Errors:
  sqr -> sqrt
  Seb_Debug.C -> Seb_debug.C

Warnings:
  signed/unsigned
  uninitialized variable
  initialization order

---
 cpp/main/Seb.C     |   10 +++++-----
 cpp/main/Subspan.C |    6 +++---
 cpp/test/example.C |    4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/cpp/main/Seb.C b/cpp/main/Seb.C
index 7585c52..625a595 100644
--- a/cpp/main/Seb.C
+++ b/cpp/main/Seb.C
@@ -55,8 +55,8 @@ namespace SEB_NAMESPACE {

     // find farthest point:
     radius_square = 0;
-    int farthest;
-    for (int j = 1; j < S.size(); ++j) {
+    int farthest = 1;
+    for (unsigned j = 1; j < S.size(); ++j) {
       // compute squared distance from center to S[j]:
       Float dist = 0;
       for (int i = 0; i < dim; ++i)
@@ -93,7 +93,7 @@ namespace SEB_NAMESPACE {
     support->find_affine_coefficients(center,lambdas);

     // find a non-positive coefficient:
-    int smallest;
+    int smallest = 0;
     Float minimum(1);
     for (int i=0; i<support->size(); ++i)
       if (lambdas[i] < minimum) {
@@ -128,7 +128,7 @@ namespace SEB_NAMESPACE {
     SEB_DEBUG (Float margin = 0;)

     // ... but one of the points in S might hinder us:
-    for (int j = 0; j < S.size(); ++j)
+    for (unsigned j = 0; j < S.size(); ++j)
       if (!support->is_member(j)) {

    // compute vector center_to_point from center to the point S[i]:
@@ -301,7 +301,7 @@ namespace SEB_NAMESPACE {
    min_lambda = lambdas[k];

     // all points in ball, all support points really on boundary?
-    for (int k = 0; k < S.size(); ++k) {
+    for (unsigned k = 0; k < S.size(); ++k) {

       // compare center-to-point distance with radius
       for (int i = 0; i < dim; ++i)
diff --git a/cpp/main/Subspan.C b/cpp/main/Subspan.C
index 818d480..50064bb 100644
--- a/cpp/main/Subspan.C
+++ b/cpp/main/Subspan.C
@@ -37,18 +37,18 @@ namespace SEB_NAMESPACE {
       s = 0;
     } else if (abs(b) > abs(a)) {
       const Float t = a / b;
-      s = 1 / sqrt (1 + sqr(t));
+      s = 1 / sqrt (1 + sqrt(t));
       c = s * t;
     } else {
       const Float t = b / a;
-      c = 1 / sqrt (1 + sqr(t));
+      c = 1 / sqrt (1 + sqrt(t));
       s = c * t;
     }
   }

   template<typename Float>
   Subspan<Float>::Subspan(int dim,const std::vector<Pt>& S,int index)
-    : S(S), dim(dim), membership(S.size()), members(dim+1)
+    : S(S), membership(S.size()), dim(dim), members(dim+1)
   {
     // allocate storage for Q, R, u, and w:
     Q = new Float *[dim];
diff --git a/cpp/test/example.C b/cpp/test/example.C
index 76f074b..7def936 100644
--- a/cpp/test/example.C
+++ b/cpp/test/example.C
@@ -7,7 +7,7 @@
 #include <cstdio>

 #include <Seb.h>
-#include <Seb_Debug.C> // ... only because we use Seb::Timer below
+#include <Seb_debug.C> // ... only because we use Seb::Timer below

 int main(int argn,char **argv) {
   typedef double FT;
@@ -57,7 +57,7 @@ int main(int argn,char **argv) {

   // compute the miniball:
   Miniball mb(d);
-  for (int i=0; i<S.size(); ++i)
+  for (unsigned i=0; i<S.size(); ++i)
     mb.insert(S[i].begin());

   // output:
-- 
1.7.10.4

Patch 2:


---
 cpp/main/Seb.h           |    7 ++++---
 cpp/main/Seb_configure.h |    2 +-
 cpp/main/Seb_debug.C     |    2 +-
 cpp/main/Seb_point.h     |    2 +-
 cpp/main/Subspan.h       |    4 ++--
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/cpp/main/Seb.h b/cpp/main/Seb.h
index 629abb0..ccba1d2 100644
--- a/cpp/main/Seb.h
+++ b/cpp/main/Seb.h
@@ -7,8 +7,8 @@
 #define SEB_SEB_H

 #include <vector>
-#include <Seb_configure.h>
-#include <Subspan.h>
+#include "Seb_configure.h"
+#include "Subspan.h"

 namespace SEB_NAMESPACE {

@@ -72,6 +72,7 @@ namespace SEB_NAMESPACE {
       return radius_square;
     }

+
     Coordinate_iterator center_begin()
     // Returns an iterator to the first Cartesian coordinate of the
     // center of the miniball.
@@ -157,6 +158,6 @@ namespace SEB_NAMESPACE {

 } // namespace SEB_NAMESPACE

-#include <Seb.C>
+#include "Seb.C"

 #endif // SEB_SEB_H
diff --git a/cpp/main/Seb_configure.h b/cpp/main/Seb_configure.h
index 76fde27..f00585d 100644
--- a/cpp/main/Seb_configure.h
+++ b/cpp/main/Seb_configure.h
@@ -18,7 +18,7 @@
 // #define SEB_TIMER_MODE              // enables runtime measurements
 // #define SEB_STATS_MODE              // enables statistics

-#include <Seb_debug.h>
+#include "Seb_debug.h"

 // Fixes for GCC series 2.95.  (This fix is necessary for 2.95.2 at
 // least.  But I guess it is needed for any earlier version of the 2.95
diff --git a/cpp/main/Seb_debug.C b/cpp/main/Seb_debug.C
index f7bb687..c4c7d94 100644
--- a/cpp/main/Seb_debug.C
+++ b/cpp/main/Seb_debug.C
@@ -7,7 +7,7 @@
 #include <sys/time.h>
 #include <sys/resource.h>

-#include <Seb_configure.h>
+#include "Seb_configure.h"

 namespace SEB_NAMESPACE {

diff --git a/cpp/main/Seb_point.h b/cpp/main/Seb_point.h
index ccf165b..d2444b0 100644
--- a/cpp/main/Seb_point.h
+++ b/cpp/main/Seb_point.h
@@ -7,7 +7,7 @@
 #define SEB_POINT_H

 #include <vector>
-#include <Seb_configure.h>
+#include "Seb_configure.h"

 namespace SEB_NAMESPACE {

diff --git a/cpp/main/Subspan.h b/cpp/main/Subspan.h
index 90a8caa..352b9c6 100644
--- a/cpp/main/Subspan.h
+++ b/cpp/main/Subspan.h
@@ -6,7 +6,7 @@
 #ifndef SEB_SUBSPAN_H
 #define SEB_SUBSPAN_H

-#include <Seb_point.h>
+#include "Seb_point.h"

 namespace SEB_NAMESPACE {

@@ -170,6 +170,6 @@ namespace SEB_NAMESPACE {

 } // namespace SEB_NAMESPACE

-#include <Subspan.C>
+#include "Subspan.C"

 #endif // SEB_SUBSPAN_H
-- 
1.7.10.4