Skip to content

Commit

Permalink
Updating ceres headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainer Kuemmerle committed Jun 27, 2012
1 parent 119f8ea commit 979699c
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 43 deletions.
24 changes: 10 additions & 14 deletions EXTERNAL/ceres/fixed_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,9 @@
#define CERES_PUBLIC_INTERNAL_FIXED_ARRAY_H_

#include <cstddef>
#include <Eigen/Core>

#if defined(_MSC_VER)
#define CERES_ALIGN_ATTRIBUTE(n) __declspec(align(n))
#define CERES_ALIGN_OF(T) __alignof(T)
typedef int ssize_t;
#elif defined(__GNUC__)
#define CERES_ALIGN_ATTRIBUTE(n) __attribute__((aligned(n)))
#define CERES_ALIGN_OF(T) __alignof(T)
#endif

#include "Eigen/Core"
#include "manual_constructor.h"
#include "macros.h"

namespace ceres {
namespace internal {
Expand Down Expand Up @@ -77,6 +68,12 @@ namespace internal {
// Non-POD types will be default-initialized just like regular vectors or
// arrays.

#if defined(_WIN64)
typedef __int64 ssize_t;
#elif defined(_WIN32)
typedef __int32 ssize_t;
#endif

template <typename T, ssize_t inline_elements = -1>
class FixedArray {
public:
Expand Down Expand Up @@ -137,7 +134,7 @@ class FixedArray {
// of this code will be broken.
struct InnerContainer {
T element;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

// How many elements should we store inline?
Expand All @@ -156,7 +153,7 @@ class FixedArray {

// Allocate some space, not an array of elements of type T, so that we can
// skip calling the T constructors and destructors for space we never use.
CERES_ALIGN_ATTRIBUTE(16) ManualConstructor<InnerContainer> inline_space_[kInlineElements];
ManualConstructor<InnerContainer> CERES_ALIGN_ATTRIBUTE(16) inline_space_[kInlineElements];
};

// Implementation details follow
Expand All @@ -167,7 +164,6 @@ inline FixedArray<T, S>::FixedArray(typename FixedArray<T, S>::size_type n)
array_((n <= kInlineElements
? reinterpret_cast<InnerContainer*>(inline_space_)
: new InnerContainer[n])) {

// Construct only the elements actually used.
if (array_ == reinterpret_cast<InnerContainer*>(inline_space_)) {
for (size_type i = 0; i != size_; ++i) {
Expand Down
65 changes: 65 additions & 0 deletions EXTERNAL/ceres/fpclassify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Ceres Solver - A fast non-linear least squares minimizer
// Copyright 2012 Google Inc. All rights reserved.
// http://code.google.com/p/ceres-solver/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Author: [email protected] (Keir Mierle)
//
// Portable floating point classification. The names are picked such that they
// do not collide with macros. For example, "isnan" in C99 is a macro and hence
// does not respect namespaces.
//
// TODO(keir): Finish porting!

#ifndef CERES_PUBLIC_FPCLASSIFY_H_
#define CERES_PUBLIC_FPCLASSIFY_H_

#if defined(_MSC_VER)
#include <float.h>
#endif

namespace ceres {

#if defined(_MSC_VER)
inline bool IsFinite (double x) { return _finite(x); }
inline bool IsInfinite(double x) { return !_finite(x) && !_isnan(x); }
inline bool IsNaN (double x) { return _isnan(x); }
inline bool IsNormal (double x) {
int classification = _fpclass(x);
return classification == _FPCLASS_NN ||
classification == _FPCLASS_PN;
}
#else
// TODO(keir): Test the "else" with more platforms.
inline bool IsFinite (double x) { return std::isfinite(x); }
inline bool IsInfinite(double x) { return std::isinf(x); }
inline bool IsNaN (double x) { return std::isnan(x); }
inline bool IsNormal (double x) { return std::isnormal(x); }
#endif

} // namespace ceres

#endif // CERES_PUBLIC_FPCLASSIFY_H_
50 changes: 25 additions & 25 deletions EXTERNAL/ceres/jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
#include <string>

#include "Eigen/Core"
#include "fpclassify.h"

namespace ceres {

Expand Down Expand Up @@ -401,12 +402,6 @@ inline double cos (double x) { return std::cos(x); }
inline double acos (double x) { return std::acos(x); }
inline double sin (double x) { return std::sin(x); }
inline double asin (double x) { return std::asin(x); }
#ifndef _MSC_VER
inline bool isfinite(double x) { return std::isfinite(x); }
inline bool isinf (double x) { return std::isinf(x); }
inline bool isnan (double x) { return std::isnan(x); }
inline bool isnormal(double x) { return std::isnormal(x); }
#endif
inline double pow (double x, double y) { return std::pow(x, y); }
inline double atan2(double y, double x) { return std::atan2(y, x); }

Expand Down Expand Up @@ -484,22 +479,23 @@ Jet<T, N> asin(const Jet<T, N>& f) {
}

// Jet Classification. It is not clear what the appropriate semantics are for
// these classifications. This picks that isfinite and isnormal are "all"
// operations, i.e. all elements of the jet must be finite for the jet itself to
// be finite (or normal). For isnan and isinf, the answer is less clear. This
// takes a "any" approach for isnan and isinf such that if any part of a jet is
// nan or inf, then the entire jet is nan or inf. This leads to strange
// situations like a jet can be both isinf and isnan, but in practice the "any"
// semantics are the most useful for e.g. checking that derivatives are sane.
// these classifications. This picks that IsFinite and isnormal are "all"
// operations, i.e. all elements of the jet must be finite for the jet itself
// to be finite (or normal). For IsNaN and IsInfinite, the answer is less
// clear. This takes a "any" approach for IsNaN and IsInfinite such that if any
// part of a jet is nan or inf, then the entire jet is nan or inf. This leads
// to strange situations like a jet can be both IsInfinite and IsNaN, but in
// practice the "any" semantics are the most useful for e.g. checking that
// derivatives are sane.

// The jet is finite if all parts of the jet are finite.
template <typename T, int N> inline
bool isfinite(const Jet<T, N>& f) {
if (!isfinite(f.a)) {
bool IsFinite(const Jet<T, N>& f) {
if (!IsFinite(f.a)) {
return false;
}
for (int i = 0; i < N; ++i) {
if (!isfinite(f.v[i])) {
if (!IsFinite(f.v[i])) {
return false;
}
}
Expand All @@ -508,12 +504,12 @@ bool isfinite(const Jet<T, N>& f) {

// The jet is infinite if any part of the jet is infinite.
template <typename T, int N> inline
bool isinf(const Jet<T, N>& f) {
if (isinf(f.a)) {
bool IsInfinite(const Jet<T, N>& f) {
if (IsInfinite(f.a)) {
return true;
}
for (int i = 0; i < N; i++) {
if (isinf(f.v[i])) {
if (IsInfinite(f.v[i])) {
return true;
}
}
Expand All @@ -522,12 +518,12 @@ bool isinf(const Jet<T, N>& f) {

// The jet is NaN if any part of the jet is NaN.
template <typename T, int N> inline
bool isnan(const Jet<T, N>& f) {
if (isnan(f.a)) {
bool IsNaN(const Jet<T, N>& f) {
if (IsNaN(f.a)) {
return true;
}
for (int i = 0; i < N; ++i) {
if (isnan(f.v[i])) {
if (IsNaN(f.v[i])) {
return true;
}
}
Expand All @@ -536,12 +532,12 @@ bool isnan(const Jet<T, N>& f) {

// The jet is normal if all parts of the jet are normal.
template <typename T, int N> inline
bool isnormal(const Jet<T, N>& f) {
if (!isnormal(f.a)) {
bool IsNormal(const Jet<T, N>& f) {
if (!IsNormal(f.a)) {
return false;
}
for (int i = 0; i < N; ++i) {
if (!isnormal(f.v[i])) {
if (!IsNormal(f.v[i])) {
return false;
}
}
Expand Down Expand Up @@ -654,6 +650,10 @@ struct NumTraits<ceres::Jet<T, N> > {
typedef ceres::Jet<T, N> NonInteger;
typedef ceres::Jet<T, N> Nested;

static typename ceres::Jet<T, N> dummy_precision() {
return ceres::Jet<T, N>(1e-12);
}

enum {
IsComplex = 0,
IsInteger = 0,
Expand Down
Loading

0 comments on commit 979699c

Please sign in to comment.