2008-02-29 10:55:53 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-02-29 10:55:53 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-02-02 14:21:35 +00:00
|
|
|
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2013-08-10 19:13:46 +02:00
|
|
|
// Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
|
2008-02-29 10:55:53 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// 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
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-02-29 10:55:53 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_MATRIXSTORAGE_H
|
|
|
|
|
#define EIGEN_MATRIXSTORAGE_H
|
|
|
|
|
|
2010-12-25 17:01:01 -05:00
|
|
|
#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
2017-02-17 14:10:57 +01:00
|
|
|
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) \
|
|
|
|
|
X; \
|
|
|
|
|
EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
|
2010-02-09 20:32:48 +01:00
|
|
|
#else
|
2017-02-17 14:10:57 +01:00
|
|
|
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
|
2010-02-09 20:32:48 +01:00
|
|
|
#endif
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2022-12-14 17:05:37 +00:00
|
|
|
template <typename T, int Size>
|
2024-10-21 17:10:15 +00:00
|
|
|
struct check_static_allocation_size {
|
2022-12-14 17:05:37 +00:00
|
|
|
#if EIGEN_STACK_ALLOCATION_LIMIT
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG)
|
2022-12-14 17:05:37 +00:00
|
|
|
#endif
|
2009-10-05 10:11:11 -04:00
|
|
|
};
|
2009-01-04 15:26:32 +00:00
|
|
|
|
2013-01-22 22:59:09 +01:00
|
|
|
#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
2009-10-05 10:11:11 -04:00
|
|
|
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
|
|
|
|
|
#else
|
|
|
|
|
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
2023-03-21 16:50:23 +00:00
|
|
|
eigen_assert((internal::is_constant_evaluated() || (std::uintptr_t(array) & (sizemask)) == 0) && \
|
2009-10-05 10:11:11 -04:00
|
|
|
"this assertion is explained here: " \
|
2013-01-22 22:59:09 +01:00
|
|
|
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
2009-10-05 10:11:11 -04:00
|
|
|
" **** READ THIS WEB PAGE !!! ****");
|
|
|
|
|
#endif
|
2009-01-09 21:28:53 +00:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
/** \internal
|
|
|
|
|
* Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned:
|
|
|
|
|
* to 16 bytes boundary if the total size is a multiple of 16 bytes.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T, int Size, int MatrixOrArrayOptions,
|
|
|
|
|
int Alignment = (MatrixOrArrayOptions & DontAlign) ? 0 : compute_default_alignment<T, Size>::value>
|
|
|
|
|
struct plain_array : check_static_allocation_size<T, Size> {
|
|
|
|
|
EIGEN_ALIGN_TO_BOUNDARY(Alignment) T array[Size];
|
|
|
|
|
#if defined(EIGEN_NO_DEBUG) || defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
|
|
|
|
|
#else
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment - 1); }
|
|
|
|
|
#endif
|
2015-03-13 21:15:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T, int Size, int MatrixOrArrayOptions>
|
2024-10-21 17:10:15 +00:00
|
|
|
struct plain_array<T, Size, MatrixOrArrayOptions, 0> : check_static_allocation_size<T, Size> {
|
|
|
|
|
T array[Size];
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
|
|
|
|
|
};
|
2015-03-13 21:15:50 +01:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
template <typename T, int MatrixOrArrayOptions, int Alignment>
|
|
|
|
|
struct plain_array<T, 0, MatrixOrArrayOptions, Alignment> {
|
|
|
|
|
T array[1];
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
|
2015-03-13 21:15:50 +01:00
|
|
|
};
|
|
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
// this class is intended to be inherited by DenseStorage to take advantage of empty base optimization
|
|
|
|
|
template <int Rows, int Cols>
|
|
|
|
|
struct DenseStorageIndices {
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices() = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(Index /*rows*/, Index /*cols*/) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * Cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void set(Index /*rows*/, Index /*cols*/) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorageIndices& /*other*/) noexcept {}
|
|
|
|
|
};
|
|
|
|
|
template <int Rows>
|
|
|
|
|
struct DenseStorageIndices<Rows, Dynamic> {
|
|
|
|
|
Index m_cols;
|
2015-03-13 21:15:50 +01:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices() : m_cols(0) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index /*rows*/, Index cols) : m_cols(cols) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return Rows * m_cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index /*rows*/, Index cols) { m_cols = cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& other) noexcept {
|
|
|
|
|
numext::swap(m_cols, other.m_cols);
|
2015-03-13 21:15:50 +01:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
};
|
|
|
|
|
template <int Cols>
|
|
|
|
|
struct DenseStorageIndices<Dynamic, Cols> {
|
|
|
|
|
Index m_rows;
|
2015-03-13 21:15:50 +01:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices() : m_rows(0) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index rows, Index /*cols*/) : m_rows(rows) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_rows; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_rows * Cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index rows, Index /*cols*/) { m_rows = rows; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& other) noexcept {
|
|
|
|
|
numext::swap(m_rows, other.m_rows);
|
2015-03-13 21:15:50 +01:00
|
|
|
}
|
|
|
|
|
};
|
2024-10-21 17:10:15 +00:00
|
|
|
template <>
|
|
|
|
|
struct DenseStorageIndices<Dynamic, Dynamic> {
|
|
|
|
|
Index m_rows;
|
|
|
|
|
Index m_cols;
|
2015-03-13 21:15:50 +01:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices() : m_rows(0), m_cols(0) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(const DenseStorageIndices&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorageIndices& operator=(DenseStorageIndices&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorageIndices(Index rows, Index cols) : m_rows(rows), m_cols(cols) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_rows; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_rows * m_cols; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set(Index rows, Index cols) {
|
|
|
|
|
m_rows = rows;
|
|
|
|
|
m_cols = cols;
|
2012-07-17 22:15:42 +01:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseStorageIndices& other) noexcept {
|
|
|
|
|
numext::swap(m_rows, other.m_rows);
|
|
|
|
|
numext::swap(m_cols, other.m_cols);
|
2012-07-17 22:15:42 +01:00
|
|
|
}
|
2009-01-04 15:26:32 +00:00
|
|
|
};
|
|
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
template <int Size, int Rows, int Cols>
|
|
|
|
|
struct use_trivial_ctors {
|
|
|
|
|
static constexpr bool value = (Size >= 0) && (Rows >= 0) && (Cols >= 0) && (Size == Rows * Cols);
|
2021-04-21 15:45:31 -07:00
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
} // end namespace internal
|
|
|
|
|
|
2008-03-15 11:05:38 +00:00
|
|
|
/** \internal
|
2008-02-29 10:55:53 +00:00
|
|
|
*
|
2010-10-20 09:34:13 -04:00
|
|
|
* \class DenseStorage
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2008-02-29 10:55:53 +00:00
|
|
|
*
|
2008-03-15 11:05:38 +00:00
|
|
|
* \brief Stores the data of a matrix
|
2008-02-29 10:55:53 +00:00
|
|
|
*
|
|
|
|
|
* This class stores the data of fixed-size, dynamic-size or mixed matrices
|
|
|
|
|
* in a way as compact as possible.
|
|
|
|
|
*
|
|
|
|
|
* \sa Matrix
|
|
|
|
|
*/
|
2024-10-21 17:10:15 +00:00
|
|
|
template <typename T, int Size, int Rows, int Cols, int Options,
|
|
|
|
|
bool Trivial = internal::use_trivial_ctors<Size, Rows, Cols>::value>
|
2021-08-04 22:41:52 +00:00
|
|
|
class DenseStorage;
|
2008-02-29 10:55:53 +00:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
// fixed-size storage with fixed dimensions
|
|
|
|
|
template <typename T, int Size, int Rows, int Cols, int Options>
|
|
|
|
|
class DenseStorage<T, Size, Rows, Cols, Options, true> : internal::DenseStorageIndices<Rows, Cols> {
|
|
|
|
|
using Base = internal::DenseStorageIndices<Rows, Cols>;
|
|
|
|
|
|
|
|
|
|
internal::plain_array<T, Size, Options> m_data;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2008-02-29 10:55:53 +00:00
|
|
|
public:
|
2024-10-21 17:10:15 +00:00
|
|
|
using Base::cols;
|
|
|
|
|
using Base::rows;
|
|
|
|
|
#ifndef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorage() = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage&) = default;
|
2021-06-30 04:27:51 +00:00
|
|
|
#else
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorage() { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size) }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage& other)
|
|
|
|
|
: Base(other), m_data(other.m_data) {
|
|
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
|
|
|
|
|
}
|
2021-06-30 04:27:51 +00:00
|
|
|
#endif
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index size, Index rows, Index cols) : Base(rows, cols) {
|
2017-02-20 10:14:21 +01:00
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
2015-04-17 11:36:21 +02:00
|
|
|
EIGEN_UNUSED_VARIABLE(size);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage& other) {
|
|
|
|
|
numext::swap(m_data, other.m_data);
|
|
|
|
|
Base::swap(other);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
|
2022-10-27 20:33:35 +00:00
|
|
|
};
|
2024-10-21 17:10:15 +00:00
|
|
|
// fixed-size storage with dynamic dimensions
|
|
|
|
|
template <typename T, int Size, int Rows, int Cols, int Options>
|
|
|
|
|
class DenseStorage<T, Size, Rows, Cols, Options, false> : internal::DenseStorageIndices<Rows, Cols> {
|
|
|
|
|
using Base = internal::DenseStorageIndices<Rows, Cols>;
|
2011-06-24 13:47:11 +01:00
|
|
|
|
2024-10-21 17:10:15 +00:00
|
|
|
internal::plain_array<T, Size, Options> m_data;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2022-10-27 20:33:35 +00:00
|
|
|
public:
|
2024-10-21 17:10:15 +00:00
|
|
|
using Base::cols;
|
|
|
|
|
using Base::rows;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseStorage() = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage& other) : Base(other), m_data() {
|
|
|
|
|
Index size = other.size();
|
|
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
|
|
|
|
internal::smart_copy(other.m_data.array, other.m_data.array + size, m_data.array);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&& other) : Base(other), m_data() {
|
|
|
|
|
Index size = other.size();
|
|
|
|
|
internal::smart_move(other.m_data.array, other.m_data.array + size, m_data.array);
|
|
|
|
|
other.resize(Size, 0, 0);
|
2022-10-27 20:33:35 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage& other) {
|
|
|
|
|
Base::set(other.rows(), other.cols());
|
|
|
|
|
Index size = other.size();
|
|
|
|
|
internal::smart_copy(other.m_data.array, other.m_data.array + size, m_data.array);
|
2022-10-27 20:33:35 +00:00
|
|
|
return *this;
|
|
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&& other) {
|
|
|
|
|
Base::set(other.rows(), other.cols());
|
|
|
|
|
Index size = other.size();
|
|
|
|
|
internal::smart_move(other.m_data.array, other.m_data.array + size, m_data.array);
|
|
|
|
|
other.resize(Size, 0, 0);
|
2021-03-08 12:39:11 -05:00
|
|
|
return *this;
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index size, Index rows, Index cols) : Base(rows, cols) {
|
|
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
|
|
|
|
EIGEN_UNUSED_VARIABLE(size);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage& other) {
|
|
|
|
|
Index thisSize = this->size();
|
|
|
|
|
Index otherSize = other.size();
|
|
|
|
|
Index commonSize = numext::mini(thisSize, otherSize);
|
|
|
|
|
std::swap_ranges(m_data.array, m_data.array + commonSize, other.m_data.array);
|
|
|
|
|
if (thisSize > otherSize)
|
|
|
|
|
internal::smart_move(m_data.array + commonSize, m_data.array + thisSize, other.m_data.array + commonSize);
|
|
|
|
|
else if (otherSize > thisSize)
|
|
|
|
|
internal::smart_move(other.m_data.array + commonSize, other.m_data.array + otherSize, m_data.array + commonSize);
|
|
|
|
|
Base::swap(other);
|
|
|
|
|
}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
|
|
|
|
}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
|
|
|
|
}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
|
2008-02-29 10:55:53 +00:00
|
|
|
};
|
2024-10-21 17:10:15 +00:00
|
|
|
// null matrix specialization
|
|
|
|
|
template <typename T, int Rows, int Cols, int Options>
|
|
|
|
|
class DenseStorage<T, 0, Rows, Cols, Options, true> : internal::DenseStorageIndices<Rows, Cols> {
|
|
|
|
|
using Base = internal::DenseStorageIndices<Rows, Cols>;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2008-02-29 10:55:53 +00:00
|
|
|
public:
|
2024-10-21 17:10:15 +00:00
|
|
|
using Base::cols;
|
|
|
|
|
using Base::rows;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage() = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&&) = default;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index /*size*/, Index rows, Index cols)
|
|
|
|
|
: Base(rows, cols) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage& other) noexcept { Base::swap(other); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
|
|
|
|
}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index cols) {
|
|
|
|
|
Base::set(rows, cols);
|
|
|
|
|
}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return nullptr; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return nullptr; }
|
2008-02-29 10:55:53 +00:00
|
|
|
};
|
2024-10-21 17:10:15 +00:00
|
|
|
// dynamic matrix specialization
|
|
|
|
|
template <typename T, int Rows, int Cols, int Options>
|
|
|
|
|
class DenseStorage<T, Dynamic, Rows, Cols, Options, false> : internal::DenseStorageIndices<Rows, Cols> {
|
|
|
|
|
using Base = internal::DenseStorageIndices<Rows, Cols>;
|
|
|
|
|
static constexpr int Size = Dynamic;
|
|
|
|
|
static constexpr bool Align = (Options & DontAlign) == 0;
|
2008-02-29 10:55:53 +00:00
|
|
|
|
|
|
|
|
T* m_data;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2008-02-29 10:55:53 +00:00
|
|
|
public:
|
2024-10-21 17:10:15 +00:00
|
|
|
using Base::cols;
|
|
|
|
|
using Base::rows;
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage() : m_data(nullptr) {}
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage& other)
|
|
|
|
|
: Base(other), m_data(internal::conditional_aligned_new_auto<T, Align>(other.size())) {
|
|
|
|
|
Index size = other.size();
|
2015-07-22 12:29:18 +02:00
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
2024-10-21 17:10:15 +00:00
|
|
|
internal::smart_copy(other.m_data, other.m_data + size, m_data);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&& other) noexcept
|
|
|
|
|
: Base(other), m_data(other.m_data) {
|
|
|
|
|
other.set(0, 0);
|
2013-08-02 19:59:43 +02:00
|
|
|
other.m_data = nullptr;
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage& other) {
|
|
|
|
|
Base::set(other.rows(), other.cols());
|
|
|
|
|
Index size = other.size();
|
|
|
|
|
m_data = internal::conditional_aligned_new_auto<T, Align>(size);
|
2021-08-04 22:41:52 +00:00
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
2024-10-21 17:10:15 +00:00
|
|
|
internal::smart_copy(other.m_data, other.m_data + size, m_data);
|
2015-07-22 12:29:18 +02:00
|
|
|
return *this;
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&& other) noexcept {
|
|
|
|
|
this->swap(other);
|
2013-08-10 19:13:46 +02:00
|
|
|
return *this;
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index size, Index rows, Index cols)
|
|
|
|
|
: Base(rows, cols), m_data(internal::conditional_aligned_new_auto<T, Align>(size)) {
|
2021-08-04 22:41:52 +00:00
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2021-08-04 22:41:52 +00:00
|
|
|
EIGEN_DEVICE_FUNC ~DenseStorage() {
|
2024-10-21 17:10:15 +00:00
|
|
|
Index size = this->size();
|
|
|
|
|
internal::conditional_aligned_delete_auto<T, Align>(m_data, size);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage& other) noexcept {
|
2018-06-11 18:33:24 +02:00
|
|
|
numext::swap(m_data, other.m_data);
|
2024-10-21 17:10:15 +00:00
|
|
|
Base::swap(other);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index size, Index rows, Index cols) {
|
|
|
|
|
Index oldSize = this->size();
|
|
|
|
|
m_data = internal::conditional_aligned_realloc_new_auto<T, Align>(m_data, size, oldSize);
|
|
|
|
|
Base::set(rows, cols);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index size, Index rows, Index cols) {
|
|
|
|
|
Index oldSize = this->size();
|
|
|
|
|
if (size != oldSize) {
|
|
|
|
|
internal::conditional_aligned_delete_auto<T, Align>(m_data, oldSize);
|
2018-10-07 21:55:59 +02:00
|
|
|
if (size > 0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
|
2024-10-21 17:10:15 +00:00
|
|
|
{
|
|
|
|
|
m_data = internal::conditional_aligned_new_auto<T, Align>(size);
|
|
|
|
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
|
|
|
|
} else
|
|
|
|
|
m_data = nullptr;
|
2009-06-03 16:47:38 +02:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
Base::set(rows, cols);
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2024-10-21 17:10:15 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data; }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data; }
|
2009-06-03 16:47:38 +02:00
|
|
|
};
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2008-02-29 10:55:53 +00:00
|
|
|
#endif // EIGEN_MATRIX_H
|