Skip to content

Commit

Permalink
Remove Protocol Buffers support.
Browse files Browse the repository at this point in the history
Change-Id: I451c543c82cdfb566736aab94d836abcfb5c689d
  • Loading branch information
sandwichmaker committed Jun 24, 2013
1 parent 5d00bf4 commit 79d9353
Show file tree
Hide file tree
Showing 25 changed files with 288 additions and 995 deletions.
17 changes: 0 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -514,23 +514,6 @@ IF (BUILD_ANDROID)
ADD_DEFINITIONS(-DCERES_WORK_AROUND_ANDROID_NDK_COMPILER_BUG)
ENDIF (BUILD_ANDROID)

# Protocol buffers
OPTION(PROTOBUF
"Enable protocol buffers support."
ON)

IF (PROTOBUF)
FIND_PACKAGE(Protobuf)
IF (PROTOBUF_FOUND)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/internal)
ELSE (PROTOBUF_FOUND)
ADD_DEFINITIONS(-DCERES_NO_PROTOCOL_BUFFERS)
ENDIF (PROTOBUF_FOUND)
ELSE (PROTOBUF)
ADD_DEFINITIONS(-DCERES_NO_PROTOCOL_BUFFERS)
ENDIF (PROTOBUF)

OPTION(DISABLE_TR1
"Don't use TR1. This replaces some hash tables with sets. Slower."
OFF)
Expand Down
3 changes: 1 addition & 2 deletions android/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,4 @@ cmake $CERES_SOURCE_ROOT \
-DBUILD_ANDROID=ON \
-DSUITESPARSE=OFF \
-DGFLAGS=OFF \
-DCXSPARSE=OFF \
-DPROTOBUF=OFF
-DCXSPARSE=OFF
Binary file removed data/problem-6-1384-000.lsqp
Binary file not shown.
14 changes: 0 additions & 14 deletions docs/source/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ SuiteSparse. We recommend either `OpenBLAS
atlas.sourceforge.net/>`_, both of which ship with BLAS and LAPACK
routines.

8. `protobuf <http://code.google.com/p/protobuf/>`_ is used for
serializing and deserializing linear least squares problems to
disk. This is useful for debugging and testing. It is an optional
dependency and without it some of the tests will be disabled.

.. _section-linux:

Building on Linux
Expand Down Expand Up @@ -91,8 +86,6 @@ platform. Start by installing all the dependencies.
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse
sudo apt-get install libsuitesparse-dev
# protobuf
sudo apt-get install libprotobuf-dev
We are now ready to build and test Ceres.

Expand Down Expand Up @@ -189,8 +182,6 @@ framework.
brew install eigen
# SuiteSparse and CXSparse
brew install suite-sparse
# protobuf
brew install protobuf
We are now ready to build and test Ceres.
Expand Down Expand Up @@ -296,11 +287,6 @@ It is possible to reduce the libraries needed to build Ceres and
customize the build process by passing appropriate flags to
``CMake``. Use these flags only if you really know what you are doing.

#. ``-DPROTOBUF=OFF``: ``protobuf`` is a large and complicated
dependency. If you do not care for the tests that depend on it and
the logging support it enables, you can use this flag to turn it
off.

#. ``-DSUITESPARSE=OFF``: By default, Ceres will link to
``SuiteSparse`` if all its dependencies are present. Use this flag
to build Ceres without ``SuiteSparse``. This will also disable
Expand Down
9 changes: 0 additions & 9 deletions docs/source/solving.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1205,15 +1205,6 @@ elimination group [LiSaad]_.
printed as dense vectors. This should only be used for small
problems.

* ``PROTOBUF`` Write out the linear least squares problem to the
directory pointed to by
:member:`Solver::Options::trust_region_problem_dump_directory` as
a protocol buffer. ``linear_least_squares_problems.h/cc``
contains routines for loading these problems. For details on the
on disk format used, see ``matrix.proto``. The files are named
``ceres_solver_iteration_???.bin``. This requires that ``protobuf`` be
linked into Ceres Solver.

* ``TEXTFILE`` Write out the linear least squares problem to the
directory pointed to by
:member:`Solver::Options::trust_region_problem_dump_directory` as
Expand Down
7 changes: 0 additions & 7 deletions include/ceres/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,6 @@ enum DumpFormatType {
// for small problems.
CONSOLE,

// Write out the linear least squares problem to the directory
// pointed to by Solver::Options::lsqp_dump_directory as a protocol
// buffer. linear_least_squares_problems.h/cc contains routines for
// loading these problems. For details on the on disk format used,
// see matrix.proto. The files are named lm_iteration_???.lsqp.
PROTOBUF,

// Write out the linear least squares problem to the directory
// pointed to by Solver::Options::lsqp_dump_directory as text files
// which can be read into MATLAB/Octave. The Jacobian is dumped as a
Expand Down
10 changes: 0 additions & 10 deletions internal/ceres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
SET(LIB_SUFFIX "64")
ENDIF ()

If (PROTOBUF_FOUND)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS matrix.proto)
ENDIF (PROTOBUF_FOUND)

# Also depend on the header files so that they appear in IDEs.
FILE(GLOB CERES_INTERNAL_HDRS *.h)

Expand Down Expand Up @@ -186,13 +182,7 @@ IF (OPENMP_FOUND)
ENDIF (NOT MSVC)
ENDIF (OPENMP_FOUND)

IF (PROTOBUF_FOUND)
LIST(APPEND CERES_LIBRARY_DEPENDENCIES ${PROTOBUF_LIBRARY})
ENDIF (PROTOBUF_FOUND)

SET(CERES_LIBRARY_SOURCE
${PROTO_SRCS}
${PROTO_HDRS}
${CERES_INTERNAL_SRC}
${CERES_INTERNAL_HDRS}
${CERES_INTERNAL_SCHUR_FILES})
Expand Down
41 changes: 0 additions & 41 deletions internal/ceres/block_sparse_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "ceres/blas.h"
#include "ceres/block_structure.h"
#include "ceres/internal/eigen.h"
#include "ceres/matrix_proto.h"
#include "ceres/triplet_sparse_matrix.h"
#include "glog/logging.h"

Expand Down Expand Up @@ -82,31 +81,6 @@ BlockSparseMatrix::BlockSparseMatrix(
CHECK_NOTNULL(values_.get());
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
BlockSparseMatrix::BlockSparseMatrix(const SparseMatrixProto& outer_proto) {
CHECK(outer_proto.has_block_matrix());

const BlockSparseMatrixProto& proto = outer_proto.block_matrix();
CHECK(proto.has_num_rows());
CHECK(proto.has_num_cols());
CHECK_EQ(proto.num_nonzeros(), proto.values_size());

num_rows_ = proto.num_rows();
num_cols_ = proto.num_cols();
num_nonzeros_ = proto.num_nonzeros();

// Copy out the values into *this.
values_.reset(new double[num_nonzeros_]);
for (int i = 0; i < proto.num_nonzeros(); ++i) {
values_[i] = proto.values(i);
}

// Create the block structure according to the proto.
block_structure_.reset(new CompressedRowBlockStructure);
ProtoToBlockStructure(proto.block_structure(), block_structure_.get());
}
#endif

void BlockSparseMatrix::SetZero() {
fill(values_.get(), values_.get() + num_nonzeros_, 0.0);
}
Expand Down Expand Up @@ -243,21 +217,6 @@ const CompressedRowBlockStructure* BlockSparseMatrix::block_structure()
return block_structure_.get();
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
void BlockSparseMatrix::ToProto(SparseMatrixProto* outer_proto) const {
outer_proto->Clear();

BlockSparseMatrixProto* proto = outer_proto->mutable_block_matrix();
proto->set_num_rows(num_rows_);
proto->set_num_cols(num_cols_);
proto->set_num_nonzeros(num_nonzeros_);
for (int i = 0; i < num_nonzeros_; ++i) {
proto->add_values(values_[i]);
}
BlockStructureToProto(*block_structure_, proto->mutable_block_structure());
}
#endif

void BlockSparseMatrix::ToTextFile(FILE* file) const {
CHECK_NOTNULL(file);
for (int i = 0; i < block_structure_->rows.size(); ++i) {
Expand Down
9 changes: 0 additions & 9 deletions internal/ceres/block_sparse_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
namespace ceres {
namespace internal {

class SparseMatrixProto;
class TripletSparseMatrix;

// This class implements the SparseMatrix interface for storing and
Expand All @@ -64,11 +63,6 @@ class BlockSparseMatrix : public SparseMatrix {
// CompressedRowBlockStructure objects.
explicit BlockSparseMatrix(CompressedRowBlockStructure* block_structure);

// Construct a block sparse matrix from a protocol buffer.
#ifndef CERES_NO_PROTOCOL_BUFFERS
explicit BlockSparseMatrix(const SparseMatrixProto& proto);
#endif

BlockSparseMatrix();
virtual ~BlockSparseMatrix();

Expand All @@ -79,9 +73,6 @@ class BlockSparseMatrix : public SparseMatrix {
virtual void SquaredColumnNorm(double* x) const;
virtual void ScaleColumns(const double* scale);
virtual void ToDenseMatrix(Matrix* dense_matrix) const;
#ifndef CERES_NO_PROTOCOL_BUFFERS
virtual void ToProto(SparseMatrixProto* proto) const;
#endif
virtual void ToTextFile(FILE* file) const;

virtual int num_rows() const { return num_rows_; }
Expand Down
23 changes: 0 additions & 23 deletions internal/ceres/block_sparse_matrix_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "ceres/internal/eigen.h"
#include "ceres/internal/scoped_ptr.h"
#include "ceres/linear_least_squares_problems.h"
#include "ceres/matrix_proto.h"
#include "ceres/triplet_sparse_matrix.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -109,27 +108,5 @@ TEST_F(BlockSparseMatrixTest, ToDenseMatrixTest) {
EXPECT_LT((m_a - m_b).norm(), 1e-12);
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
TEST_F(BlockSparseMatrixTest, Serialization) {
// Roundtrip through serialization and check for equality.
SparseMatrixProto proto;
A_->ToProto(&proto);

LOG(INFO) << proto.DebugString();

BlockSparseMatrix A2(proto);

Matrix m_a;
Matrix m_b;
A_->ToDenseMatrix(&m_a);
A2.ToDenseMatrix(&m_b);

LOG(INFO) << "\n" << m_a;
LOG(INFO) << "\n" << m_b;

EXPECT_LT((m_a - m_b).norm(), 1e-12);
}
#endif

} // namespace internal
} // namespace ceres
51 changes: 0 additions & 51 deletions internal/ceres/block_structure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
// Author: sameeragarwal@google.com (Sameer Agarwal)

#include "ceres/block_structure.h"
#include "ceres/matrix_proto.h"

namespace ceres {
namespace internal {
Expand All @@ -38,55 +37,5 @@ bool CellLessThan(const Cell& lhs, const Cell& rhs) {
return (lhs.block_id < rhs.block_id);
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
void ProtoToBlockStructure(const BlockStructureProto &proto,
CompressedRowBlockStructure *block_structure) {
// Decode the column blocks.
block_structure->cols.resize(proto.cols_size());
for (int i = 0; i < proto.cols_size(); ++i) {
block_structure->cols[i].size = proto.cols(i).size();
block_structure->cols[i].position =
proto.cols(i).position();
}
// Decode the row structure.
block_structure->rows.resize(proto.rows_size());
for (int i = 0; i < proto.rows_size(); ++i) {
const CompressedRowProto &row = proto.rows(i);
block_structure->rows[i].block.size = row.block().size();
block_structure->rows[i].block.position = row.block().position();

// Copy the cells within the row.
block_structure->rows[i].cells.resize(row.cells_size());
for (int j = 0; j < row.cells_size(); ++j) {
const CellProto &cell = row.cells(j);
block_structure->rows[i].cells[j].block_id = cell.block_id();
block_structure->rows[i].cells[j].position = cell.position();
}
}
}

void BlockStructureToProto(const CompressedRowBlockStructure &block_structure,
BlockStructureProto *proto) {
// Encode the column blocks.
for (int i = 0; i < block_structure.cols.size(); ++i) {
BlockProto *block = proto->add_cols();
block->set_size(block_structure.cols[i].size);
block->set_position(block_structure.cols[i].position);
}
// Encode the row structure.
for (int i = 0; i < block_structure.rows.size(); ++i) {
CompressedRowProto *row = proto->add_rows();
BlockProto *block = row->mutable_block();
block->set_size(block_structure.rows[i].block.size);
block->set_position(block_structure.rows[i].block.position);
for (int j = 0; j < block_structure.rows[i].cells.size(); ++j) {
CellProto *cell = row->add_cells();
cell->set_block_id(block_structure.rows[i].cells[j].block_id);
cell->set_position(block_structure.rows[i].cells[j].position);
}
}
}
#endif

} // namespace internal
} // namespace ceres
7 changes: 0 additions & 7 deletions internal/ceres/compressed_row_sparse_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ class CompressedRowSparseMatrix : public SparseMatrix {
virtual const double* values() const { return &values_[0]; }
virtual double* mutable_values() { return &values_[0]; }

#ifndef CERES_NO_PROTOCOL_BUFFERS
// Dump the sparse matrix to a proto. Destroys the contents of proto.
virtual void ToProto(SparseMatrixProto* proto) const {
LOG(FATAL) << "Broken.;";
}
#endif

// Delete the bottom delta_rows.
// num_rows -= delta_rows
void DeleteRows(int delta_rows);
Expand Down
33 changes: 0 additions & 33 deletions internal/ceres/dense_sparse_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "ceres/dense_sparse_matrix.h"

#include <algorithm>
#include "ceres/matrix_proto.h"
#include "ceres/triplet_sparse_matrix.h"
#include "ceres/internal/eigen.h"
#include "ceres/internal/port.h"
Expand Down Expand Up @@ -81,22 +80,6 @@ DenseSparseMatrix::DenseSparseMatrix(const ColMajorMatrix& m)
has_diagonal_reserved_(false) {
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
DenseSparseMatrix::DenseSparseMatrix(const SparseMatrixProto& outer_proto)
: m_(Eigen::MatrixXd::Zero(
outer_proto.dense_matrix().num_rows(),
outer_proto.dense_matrix().num_cols())),
has_diagonal_appended_(false),
has_diagonal_reserved_(false) {
const DenseSparseMatrixProto& proto = outer_proto.dense_matrix();
for (int i = 0; i < m_.rows(); ++i) {
for (int j = 0; j < m_.cols(); ++j) {
m_(i, j) = proto.values(m_.cols() * i + j);
}
}
}
#endif

void DenseSparseMatrix::SetZero() {
m_.setZero();
}
Expand All @@ -122,22 +105,6 @@ void DenseSparseMatrix::ToDenseMatrix(Matrix* dense_matrix) const {
*dense_matrix = m_.block(0, 0, num_rows(), num_cols());
}

#ifndef CERES_NO_PROTOCOL_BUFFERS
void DenseSparseMatrix::ToProto(SparseMatrixProto* outer_proto) const {
CHECK(!has_diagonal_appended_) << "Not supported.";
outer_proto->Clear();
DenseSparseMatrixProto* proto = outer_proto->mutable_dense_matrix();

proto->set_num_rows(num_rows());
proto->set_num_cols(num_cols());

int num_nnz = num_nonzeros();
for (int i = 0; i < num_nnz; ++i) {
proto->add_values(m_.data()[i]);
}
}
#endif

void DenseSparseMatrix::AppendDiagonal(double *d) {
CHECK(!has_diagonal_appended_);
if (!has_diagonal_reserved_) {
Expand Down
Loading

0 comments on commit 79d9353

Please sign in to comment.