Commit e83ca135 authored by Jason Rhinelander's avatar Jason Rhinelander
Browse files

Major Matrix fixes

linear-update-test from creativity was showing various failings around
copying, blocks, and moving.  This commit hunts down the various
problems and fixes them.
parent 58b6717a
......@@ -58,6 +58,9 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -DERIS_DEBUG")
find_package(Threads REQUIRED)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_library(eris SHARED ${eris_src})
set_target_properties(eris PROPERTIES
......
......@@ -19,6 +19,13 @@ implementations.
The library name, Eris, is the name of the Greek goddess of chaos.
## Requirements
- [boost](http://www.boost.org/) for compilation; only the Math component is
needed.
- A C++ compiler supporting the C++11 standard, such as
[clang](http://clang.llvm.org/) (3.3+) or [g++](https://gcc.gnu.org/) (4.9+)
## Compiling
To compile on a unix-like system, create a new build directory somewhere, then
......
......@@ -52,8 +52,9 @@ GRAPHICAL_HIERARCHY = YES
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
#ENABLE_PREPROCESSING = YES
#MACRO_EXPANSION = YES
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
PREDEFINED = DOXYGEN_SHOULD_SEE_THIS
#SKIP_FUNCTION_MACROS = NO
#---------------------------------------------------------------------------
......
This diff is collapsed.
......@@ -24,7 +24,7 @@ namespace matrix {
class MatrixImpl {
public:
/// Ref is an alias for std::shared_ptr<MatrixImpl> for convenience.
using Ref = std::unique_ptr<MatrixImpl>;
using Ref = std::shared_ptr<MatrixImpl>;
/// Default virtual destructor
virtual ~MatrixImpl() = default;
......
......@@ -2,7 +2,7 @@
namespace eris { namespace matrix {
#define NULLIMPL_THROW { throw std::logic_error("Error: NullImpl matrix implementation cannot be used for Matrix operations!"); }
#define NULLIMPL_THROW { throw std::logic_error("Error: Attempt to use null (default-constructed) matrix via " + std::string(__func__)); }
/** Null matrix implementation. The implementation simply throws exceptions if attempted to be used
* in any way. The only thing that doesn't throw an exception is calling rows() or cols(): both
......@@ -16,6 +16,8 @@ class NullImpl : public MatrixImpl {
virtual unsigned int cols() const override { return 0; }
/// Returns true
virtual bool null() const override { return true; }
/// Returns a new NullImpl object
virtual Ref clone() const override { return Ref(static_cast<MatrixImpl*>(new NullImpl)); }
// Hide everything here from doxygen; these are really methods that shouldn't ever be
// called.
/// \cond
......
......@@ -4,6 +4,7 @@
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <eris/Matrix.hpp>
#include <eris/matrix/EigenImpl.hpp>
......@@ -50,6 +51,13 @@ class User {
}
};
void printCol(const Vector &v) {
std::cout << "vector': " << v.transpose() << "\n";
}
void printRow(const RowVector &v) {
std::cout << "row vector: " << v << "\n";
}
int main() {
Eigen::MatrixXd start = Eigen::MatrixXd::Zero(5, 2);
......@@ -162,4 +170,48 @@ int main() {
double z3 = row * row.transpose();
std::cout << "z2: " << z2 << ", z3: " << z3 << "\n";
class FooBar {
public:
FooBar(const Matrix &dummy)
: m(dummy.createVector(3, 0)) {}
Matrix m;
};
Matrix factory = Matrix::create<EigenImpl>(0, 0);
std::map<int, FooBar> foomap;
foomap.emplace(1, FooBar(factory));
Matrix nullmat;
Matrix copynull(nullmat);
Vector vec1 = factory.createVector(10);
Vector vec2 = factory.createVector(10);
PRINT(vec1.transpose());
PRINT(vec2.transpose());
vec2 = vec1;
PRINT(vec2.transpose());
for (int i = 0; i < 10; i++) vec2[i] = i;
PRINT(vec2.transpose());
PRINT(vec1.transpose());
vec1.head(3) = vec2.tail(3);
PRINT(vec1.transpose());
Matrix vec1h = vec1.tail(3); //block(7, 0, 3);
vec1h = vec2.tail(3);
PRINT(vec1h.transpose());
PRINT(vec1.transpose());
printCol(vec1h);
const Vector vec3 = vec2;
std::cout << "here goes\n";
Vector vec4 = vec3.head(4).copy();
std::cout << "is it const: " << vec4.constant() << ", block: " << vec4.block() << "\n";
vec4[1] = 777;
PRINT(vec4.transpose());
PRINT(vec3.transpose());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment