mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-12 19:20:36 +08:00
Added copy constructor and assignment to DenseStorage.
Required by the standard even when its not used but elided. Added a test for DenseStorage copying and assignment.
This commit is contained in:
parent
8a89ba9275
commit
e4acd6e2fd
@ -3,7 +3,7 @@
|
||||
//
|
||||
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
||||
// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
|
||||
// Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
@ -264,6 +264,22 @@ template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynam
|
||||
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
|
||||
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows), m_cols(nbCols)
|
||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||
DenseStorage(const DenseStorage& other)
|
||||
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*other.m_cols))
|
||||
, m_rows(other.m_rows)
|
||||
, m_cols(other.m_cols)
|
||||
{
|
||||
internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
|
||||
}
|
||||
DenseStorage& operator=(const DenseStorage& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
DenseStorage tmp(other);
|
||||
this->swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
||||
DenseStorage(DenseStorage&& other)
|
||||
: m_data(std::move(other.m_data))
|
||||
@ -308,9 +324,6 @@ template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynam
|
||||
}
|
||||
const T *data() const { return m_data; }
|
||||
T *data() { return m_data; }
|
||||
private:
|
||||
DenseStorage(const DenseStorage&);
|
||||
DenseStorage& operator=(const DenseStorage&);
|
||||
};
|
||||
|
||||
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
|
||||
@ -323,6 +336,21 @@ template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Ro
|
||||
DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
|
||||
DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(nbCols)
|
||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||
DenseStorage(const DenseStorage& other)
|
||||
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(_Rows*other.m_cols))
|
||||
, m_cols(other.m_cols)
|
||||
{
|
||||
internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data);
|
||||
}
|
||||
DenseStorage& operator=(const DenseStorage& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
DenseStorage tmp(other);
|
||||
this->swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
||||
DenseStorage(DenseStorage&& other)
|
||||
: m_data(std::move(other.m_data))
|
||||
@ -362,9 +390,6 @@ template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Ro
|
||||
}
|
||||
const T *data() const { return m_data; }
|
||||
T *data() { return m_data; }
|
||||
private:
|
||||
DenseStorage(const DenseStorage&);
|
||||
DenseStorage& operator=(const DenseStorage&);
|
||||
};
|
||||
|
||||
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
|
||||
@ -377,6 +402,21 @@ template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dyn
|
||||
DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
|
||||
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows)
|
||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||
DenseStorage(const DenseStorage& other)
|
||||
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*_Cols))
|
||||
, m_rows(other.m_rows)
|
||||
{
|
||||
internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data);
|
||||
}
|
||||
DenseStorage& operator=(const DenseStorage& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
DenseStorage tmp(other);
|
||||
this->swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
||||
DenseStorage(DenseStorage&& other)
|
||||
: m_data(std::move(other.m_data))
|
||||
@ -416,9 +456,6 @@ template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dyn
|
||||
}
|
||||
const T *data() const { return m_data; }
|
||||
T *data() { return m_data; }
|
||||
private:
|
||||
DenseStorage(const DenseStorage&);
|
||||
DenseStorage& operator=(const DenseStorage&);
|
||||
};
|
||||
|
||||
} // end namespace Eigen
|
||||
|
@ -225,6 +225,7 @@ ei_add_test(prec_inverse_4x4)
|
||||
ei_add_test(vectorwiseop)
|
||||
ei_add_test(special_numbers)
|
||||
ei_add_test(rvalue_types)
|
||||
ei_add_test(dense_storage)
|
||||
|
||||
ei_add_test(simplicial_cholesky)
|
||||
ei_add_test(conjugate_gradient)
|
||||
|
91
test/dense_storage.cpp
Normal file
91
test/dense_storage.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// Alternatively, you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License and a copy of the GNU General Public License along with
|
||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
template <typename T, int Rows, int Cols>
|
||||
void dense_storage_copy()
|
||||
{
|
||||
static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
|
||||
typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
|
||||
|
||||
const int rows = (Rows==Dynamic) ? 4 : Rows;
|
||||
const int cols = (Cols==Dynamic) ? 3 : Cols;
|
||||
const int size = rows*cols;
|
||||
DenseStorageType reference(size, rows, cols);
|
||||
T* raw_reference = reference.data();
|
||||
for (int i=0; i<size; ++i)
|
||||
raw_reference[i] = static_cast<T>(i);
|
||||
|
||||
DenseStorageType copied_reference(reference);
|
||||
const T* raw_copied_reference = copied_reference.data();
|
||||
for (int i=0; i<size; ++i)
|
||||
VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
|
||||
}
|
||||
|
||||
template <typename T, int Rows, int Cols>
|
||||
void dense_storage_assignment()
|
||||
{
|
||||
static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
|
||||
typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
|
||||
|
||||
const int rows = (Rows==Dynamic) ? 4 : Rows;
|
||||
const int cols = (Cols==Dynamic) ? 3 : Cols;
|
||||
const int size = rows*cols;
|
||||
DenseStorageType reference(size, rows, cols);
|
||||
T* raw_reference = reference.data();
|
||||
for (int i=0; i<size; ++i)
|
||||
raw_reference[i] = static_cast<T>(i);
|
||||
|
||||
DenseStorageType copied_reference;
|
||||
copied_reference = reference;
|
||||
const T* raw_copied_reference = copied_reference.data();
|
||||
for (int i=0; i<size; ++i)
|
||||
VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
|
||||
}
|
||||
|
||||
void test_dense_storage()
|
||||
{
|
||||
dense_storage_copy<int,Dynamic,Dynamic>();
|
||||
dense_storage_copy<int,Dynamic,3>();
|
||||
dense_storage_copy<int,4,Dynamic>();
|
||||
dense_storage_copy<int,4,3>();
|
||||
|
||||
dense_storage_copy<float,Dynamic,Dynamic>();
|
||||
dense_storage_copy<float,Dynamic,3>();
|
||||
dense_storage_copy<float,4,Dynamic>();
|
||||
dense_storage_copy<float,4,3>();
|
||||
|
||||
dense_storage_assignment<int,Dynamic,Dynamic>();
|
||||
dense_storage_assignment<int,Dynamic,3>();
|
||||
dense_storage_assignment<int,4,Dynamic>();
|
||||
dense_storage_assignment<int,4,3>();
|
||||
|
||||
dense_storage_assignment<float,Dynamic,Dynamic>();
|
||||
dense_storage_assignment<float,Dynamic,3>();
|
||||
dense_storage_assignment<float,4,Dynamic>();
|
||||
dense_storage_assignment<float,4,3>();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user