Allow empty matrices to be resized.

This commit is contained in:
Antonio Sánchez 2022-10-27 20:33:35 +00:00 committed by Rasmus Munk Larsen
parent 886aad1361
commit c5b896c5a3

View File

@ -247,9 +247,11 @@ template<typename T, int Size, int Rows_, int Cols_, int Options_> class DenseSt
};
// null matrix
template<typename T, int Rows_, int Cols_, int Options_> class DenseStorage<T, 0, Rows_, Cols_, Options_>
template<typename T, int Rows_, int Cols_, int Options_>
class DenseStorage<T, 0, Rows_, Cols_, Options_>
{
public:
static_assert(Rows_ * Cols_ == 0, "The fixed number of rows times columns must equal the storage size.");
EIGEN_DEVICE_FUNC DenseStorage() {}
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {}
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {}
@ -265,17 +267,107 @@ template<typename T, int Rows_, int Cols_, int Options_> class DenseStorage<T, 0
};
// more specializations for null matrices; these are necessary to resolve ambiguities
template<typename T, int Options_> class DenseStorage<T, 0, Dynamic, Dynamic, Options_>
: public DenseStorage<T, 0, 0, 0, Options_> { };
template<typename T, int Options_>
class DenseStorage<T, 0, Dynamic, Dynamic, Options_> {
Index m_rows;
Index m_cols;
public:
EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {}
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_rows(other.m_rows), m_cols(other.m_cols) {}
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) {
m_rows = other.m_rows;
m_cols = other.m_cols;
return *this;
}
EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {
eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
numext::swap(m_rows,other.m_rows);
numext::swap(m_cols,other.m_cols);
}
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT {return m_rows;}
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT {return m_cols;}
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) {
m_rows = rows;
m_cols = cols;
eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) {
m_rows = rows;
m_cols = cols;
eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC const T *data() const { return nullptr; }
EIGEN_DEVICE_FUNC T *data() { return nullptr; }
};
template<typename T, int Rows_, int Options_> class DenseStorage<T, 0, Rows_, Dynamic, Options_>
: public DenseStorage<T, 0, 0, 0, Options_> { };
template<typename T, int Rows_, int Options_>
class DenseStorage<T, 0, Rows_, Dynamic, Options_> {
Index m_cols;
public:
EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {}
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_cols(other.m_cols) {}
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) {
m_cols = other.m_cols;
return *this;
}
EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {
eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
numext::swap(m_cols, other.m_cols);
}
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return Rows_;}
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) {
m_cols = cols;
eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) {
m_cols = cols;
eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC const T *data() const { return nullptr; }
EIGEN_DEVICE_FUNC T *data() { return nullptr; }
};
template<typename T, int Cols_, int Options_> class DenseStorage<T, 0, Dynamic, Cols_, Options_>
: public DenseStorage<T, 0, 0, 0, Options_> { };
template<typename T, int Cols_, int Options_>
class DenseStorage<T, 0, Dynamic, Cols_, Options_> {
Index m_rows;
public:
EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {}
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_rows(other.m_rows) {}
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) {
m_rows = other.m_rows;
return *this;
}
EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {
eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
numext::swap(m_rows, other.m_rows);
}
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return Cols_;}
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) {
m_rows = rows;
eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) {
m_rows = rows;
eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size.");
}
EIGEN_DEVICE_FUNC const T *data() const { return nullptr; }
EIGEN_DEVICE_FUNC T *data() { return nullptr; }
};
// dynamic-size matrix with fixed-size storage
template<typename T, int Size, int Options_> class DenseStorage<T, Size, Dynamic, Dynamic, Options_>
template<typename T, int Size, int Options_>
class DenseStorage<T, Size, Dynamic, Dynamic, Options_>
{
internal::plain_array<T,Size,Options_> m_data;
Index m_rows;
@ -315,7 +407,8 @@ template<typename T, int Size, int Options_> class DenseStorage<T, Size, Dynamic
};
// dynamic-size matrix with fixed-size storage and fixed width
template<typename T, int Size, int Cols_, int Options_> class DenseStorage<T, Size, Dynamic, Cols_, Options_>
template<typename T, int Size, int Cols_, int Options_>
class DenseStorage<T, Size, Dynamic, Cols_, Options_>
{
internal::plain_array<T,Size,Options_> m_data;
Index m_rows;
@ -353,7 +446,8 @@ template<typename T, int Size, int Cols_, int Options_> class DenseStorage<T, Si
};
// dynamic-size matrix with fixed-size storage and fixed height
template<typename T, int Size, int Rows_, int Options_> class DenseStorage<T, Size, Rows_, Dynamic, Options_>
template<typename T, int Size, int Rows_, int Options_>
class DenseStorage<T, Size, Rows_, Dynamic, Options_>
{
internal::plain_array<T,Size,Options_> m_data;
Index m_cols;
@ -389,7 +483,8 @@ template<typename T, int Size, int Rows_, int Options_> class DenseStorage<T, Si
};
// purely dynamic matrix.
template<typename T, int Options_> class DenseStorage<T, Dynamic, Dynamic, Dynamic, Options_>
template<typename T, int Options_>
class DenseStorage<T, Dynamic, Dynamic, Dynamic, Options_>
{
T *m_data;
Index m_rows;
@ -473,8 +568,8 @@ template<typename T, int Options_> class DenseStorage<T, Dynamic, Dynamic, Dynam
};
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
template<typename T, int Rows_, int Options_> class DenseStorage<T, Dynamic, Rows_, Dynamic, Options_>
{
template<typename T, int Rows_, int Options_>
class DenseStorage<T, Dynamic, Rows_, Dynamic, Options_> {
T *m_data;
Index m_cols;
public:
@ -547,7 +642,8 @@ template<typename T, int Rows_, int Options_> class DenseStorage<T, Dynamic, Row
};
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
template<typename T, int Cols_, int Options_> class DenseStorage<T, Dynamic, Dynamic, Cols_, Options_>
template<typename T, int Cols_, int Options_>
class DenseStorage<T, Dynamic, Dynamic, Cols_, Options_>
{
T *m_data;
Index m_rows;