2015-02-07 22:04:18 +01:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
|
|
|
//
|
|
|
|
|
// 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/.
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_SPARSE_REF_H
|
|
|
|
|
#define EIGEN_SPARSE_REF_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2015-06-09 23:11:24 +02:00
|
|
|
enum {
|
2015-12-30 16:04:24 +01:00
|
|
|
StandardCompressedFormat =
|
|
|
|
|
2 /**< used by Ref<SparseMatrix> to specify whether the input storage must be in standard compressed form */
|
2015-06-09 23:11:24 +02:00
|
|
|
};
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
class SparseRefBase;
|
2015-10-21 09:47:43 +02:00
|
|
|
|
2022-01-10 20:53:29 +00:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options_, typename StrideType_>
|
|
|
|
|
struct traits<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
|
2015-02-07 22:04:18 +01:00
|
|
|
: public traits<SparseMatrix<MatScalar, MatOptions, MatIndex>> {
|
|
|
|
|
typedef SparseMatrix<MatScalar, MatOptions, MatIndex> PlainObjectType;
|
2015-10-21 09:47:43 +02:00
|
|
|
enum { Options = Options_, Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit };
|
2015-02-07 22:04:18 +01:00
|
|
|
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
struct match {
|
|
|
|
|
enum {
|
|
|
|
|
StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime ||
|
|
|
|
|
((PlainObjectType::Flags & RowMajorBit) == (Derived::Flags & RowMajorBit)),
|
|
|
|
|
MatchAtCompileTime = (Derived::Flags & CompressedAccessBit) && StorageOrderMatch
|
|
|
|
|
};
|
2022-03-16 16:43:40 +00:00
|
|
|
typedef std::conditional_t<MatchAtCompileTime, internal::true_type, internal::false_type> type;
|
2015-02-07 22:04:18 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-10 20:53:29 +00:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options_, typename StrideType_>
|
|
|
|
|
struct traits<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
|
|
|
|
|
: public traits<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>> {
|
2015-02-07 22:04:18 +01:00
|
|
|
enum {
|
2015-02-09 10:23:45 +01:00
|
|
|
Flags =
|
|
|
|
|
(traits<SparseMatrix<MatScalar, MatOptions, MatIndex>>::Flags | CompressedAccessBit | NestByRefBit) & ~LvalueBit
|
2015-02-07 22:04:18 +01:00
|
|
|
};
|
|
|
|
|
};
|
2015-10-21 09:47:43 +02:00
|
|
|
|
2022-01-10 20:53:29 +00:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options_, typename StrideType_>
|
|
|
|
|
struct traits<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
|
2015-10-21 09:47:43 +02:00
|
|
|
: public traits<SparseVector<MatScalar, MatOptions, MatIndex>> {
|
|
|
|
|
typedef SparseVector<MatScalar, MatOptions, MatIndex> PlainObjectType;
|
|
|
|
|
enum { Options = Options_, Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit };
|
|
|
|
|
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
struct match {
|
|
|
|
|
enum { MatchAtCompileTime = (Derived::Flags & CompressedAccessBit) && Derived::IsVectorAtCompileTime };
|
2022-03-16 16:43:40 +00:00
|
|
|
typedef std::conditional_t<MatchAtCompileTime, internal::true_type, internal::false_type> type;
|
2015-10-21 09:47:43 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-10 20:53:29 +00:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options_, typename StrideType_>
|
|
|
|
|
struct traits<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>>
|
|
|
|
|
: public traits<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options_, StrideType_>> {
|
2015-10-21 09:47:43 +02:00
|
|
|
enum {
|
|
|
|
|
Flags =
|
|
|
|
|
(traits<SparseVector<MatScalar, MatOptions, MatIndex>>::Flags | CompressedAccessBit | NestByRefBit) & ~LvalueBit
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename Derived>
|
|
|
|
|
struct traits<SparseRefBase<Derived>> : public traits<Derived> {};
|
|
|
|
|
|
|
|
|
|
template <typename Derived>
|
2016-01-03 21:56:30 +01:00
|
|
|
class SparseRefBase : public SparseMapBase<Derived> {
|
2023-11-29 11:12:48 +00:00
|
|
|
public:
|
2015-02-07 22:04:18 +01:00
|
|
|
typedef SparseMapBase<Derived> Base;
|
2015-10-08 22:06:49 +02:00
|
|
|
EIGEN_SPARSE_PUBLIC_INTERFACE(SparseRefBase)
|
2015-02-07 22:04:18 +01:00
|
|
|
|
|
|
|
|
SparseRefBase()
|
|
|
|
|
: Base(RowsAtCompileTime == Dynamic ? 0 : RowsAtCompileTime, ColsAtCompileTime == Dynamic ? 0 : ColsAtCompileTime,
|
|
|
|
|
0, 0, 0, 0, 0) {}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
template <typename Expression>
|
|
|
|
|
void construct(Expression& expr) {
|
2015-10-06 15:09:04 +02:00
|
|
|
if (expr.outerIndexPtr() == 0)
|
2022-03-08 20:43:22 +00:00
|
|
|
internal::construct_at<Base>(this, expr.size(), expr.nonZeros(), expr.innerIndexPtr(), expr.valuePtr());
|
2015-10-06 15:09:04 +02:00
|
|
|
else
|
2022-03-08 20:43:22 +00:00
|
|
|
internal::construct_at<Base>(this, expr.rows(), expr.cols(), expr.nonZeros(), expr.outerIndexPtr(),
|
|
|
|
|
expr.innerIndexPtr(), expr.valuePtr(), expr.innerNonZeroPtr());
|
2015-10-06 11:53:19 +02:00
|
|
|
}
|
2015-02-07 22:04:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
2015-06-09 23:11:24 +02:00
|
|
|
/**
|
2016-01-03 21:56:30 +01:00
|
|
|
* \ingroup SparseCore_Module
|
2015-06-09 23:11:24 +02:00
|
|
|
*
|
|
|
|
|
* \brief A sparse matrix expression referencing an existing sparse expression
|
|
|
|
|
*
|
2016-01-03 21:56:30 +01:00
|
|
|
* \tparam SparseMatrixType the equivalent sparse matrix type of the referenced data, it must be a template instance of
|
2015-06-09 23:11:24 +02:00
|
|
|
* class SparseMatrix. \tparam Options specifies whether the a standard compressed format is required \c Options is \c
|
|
|
|
|
* #StandardCompressedFormat, or \c 0. The default is \c 0.
|
|
|
|
|
*
|
|
|
|
|
* \sa class Ref
|
|
|
|
|
*/
|
2016-01-03 21:56:30 +01:00
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
class Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>
|
|
|
|
|
: public internal::SparseRefBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
2016-01-03 21:56:30 +01:00
|
|
|
#else
|
|
|
|
|
template <typename SparseMatrixType, int Options>
|
|
|
|
|
class Ref<SparseMatrixType, Options>
|
|
|
|
|
: public SparseMapBase<Derived, WriteAccessors> // yes, that's weird to use Derived here, but that works!
|
|
|
|
|
#endif
|
2015-02-07 22:04:18 +01:00
|
|
|
{
|
|
|
|
|
typedef SparseMatrix<MatScalar, MatOptions, MatIndex> PlainObjectType;
|
|
|
|
|
typedef internal::traits<Ref> Traits;
|
|
|
|
|
template <int OtherOptions>
|
|
|
|
|
inline Ref(const SparseMatrix<MatScalar, OtherOptions, MatIndex>& expr);
|
|
|
|
|
template <int OtherOptions>
|
2021-11-19 15:58:04 +00:00
|
|
|
inline Ref(const Map<SparseMatrix<MatScalar, OtherOptions, MatIndex>>& expr);
|
|
|
|
|
|
2016-01-03 21:56:30 +01:00
|
|
|
public:
|
2015-02-07 22:04:18 +01:00
|
|
|
typedef internal::SparseRefBase<Ref> Base;
|
|
|
|
|
EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
template <int OtherOptions>
|
|
|
|
|
inline Ref(SparseMatrix<MatScalar, OtherOptions, MatIndex>& expr) {
|
|
|
|
|
EIGEN_STATIC_ASSERT(
|
|
|
|
|
bool(Traits::template match<SparseMatrix<MatScalar, OtherOptions, MatIndex>>::MatchAtCompileTime),
|
|
|
|
|
STORAGE_LAYOUT_DOES_NOT_MATCH);
|
|
|
|
|
eigen_assert(((Options & int(StandardCompressedFormat)) == 0) || (expr.isCompressed()));
|
|
|
|
|
Base::construct(expr.derived());
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2015-02-07 22:04:18 +01:00
|
|
|
|
|
|
|
|
template <int OtherOptions>
|
|
|
|
|
inline Ref(Map<SparseMatrix<MatScalar, OtherOptions, MatIndex>>& expr) {
|
2015-10-08 22:06:49 +02:00
|
|
|
EIGEN_STATIC_ASSERT(
|
|
|
|
|
bool(Traits::template match<SparseMatrix<MatScalar, OtherOptions, MatIndex>>::MatchAtCompileTime),
|
|
|
|
|
STORAGE_LAYOUT_DOES_NOT_MATCH);
|
|
|
|
|
eigen_assert(((Options & int(StandardCompressedFormat)) == 0) || (expr.isCompressed()));
|
2015-02-07 22:04:18 +01:00
|
|
|
Base::construct(expr.derived());
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2015-02-07 22:04:18 +01:00
|
|
|
|
|
|
|
|
template <typename Derived>
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const SparseCompressedBase<Derived>& expr)
|
|
|
|
|
#else
|
2015-02-07 22:04:18 +01:00
|
|
|
/** Implicit constructor from any sparse expression (2D matrix or 1D vector) */
|
|
|
|
|
template <typename Derived>
|
2015-10-21 09:47:43 +02:00
|
|
|
inline Ref(SparseCompressedBase<Derived>& expr)
|
2023-11-29 11:12:48 +00:00
|
|
|
#endif
|
|
|
|
|
{
|
2015-02-07 22:04:18 +01:00
|
|
|
EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
|
|
|
|
|
EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
|
|
|
|
|
eigen_assert(((Options & int(StandardCompressedFormat)) == 0) || (expr.isCompressed()));
|
|
|
|
|
Base::construct(expr.const_cast_derived());
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
};
|
2015-02-07 22:04:18 +01:00
|
|
|
|
2016-12-05 16:59:30 +01:00
|
|
|
// this is the const ref version
|
|
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
2015-02-07 22:04:18 +01:00
|
|
|
class Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>
|
2015-10-21 09:47:43 +02:00
|
|
|
: public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>> {
|
|
|
|
|
typedef SparseMatrix<MatScalar, MatOptions, MatIndex> TPlainObjectType;
|
|
|
|
|
typedef internal::traits<Ref> Traits;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
|
|
|
|
public:
|
2016-12-05 16:59:30 +01:00
|
|
|
typedef internal::SparseRefBase<Ref> Base;
|
|
|
|
|
EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename Derived>
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) {
|
2015-02-07 22:04:18 +01:00
|
|
|
construct(expr.derived(), typename Traits::template match<Derived>::type());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const Ref& other) : Base(other), m_hasCopy(false) {
|
2015-02-07 22:04:18 +01:00
|
|
|
// copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 16:59:30 +01:00
|
|
|
template <typename OtherRef>
|
|
|
|
|
inline Ref(const RefBase<OtherRef>& other) : m_hasCopy(false) {
|
2022-03-08 20:43:22 +00:00
|
|
|
construct(other.derived(), typename Traits::template match<OtherRef>::type());
|
2016-12-05 16:59:30 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-09 23:11:24 +02:00
|
|
|
~Ref() {
|
|
|
|
|
if (m_hasCopy) {
|
2022-03-08 20:43:22 +00:00
|
|
|
internal::destroy_at(reinterpret_cast<TPlainObjectType*>(&m_storage));
|
2015-02-07 22:04:18 +01:00
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2015-02-07 22:04:18 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
template <typename Expression>
|
|
|
|
|
void construct(const Expression& expr, internal::true_type) {
|
|
|
|
|
if ((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) {
|
2022-03-08 20:43:22 +00:00
|
|
|
TPlainObjectType* obj = internal::construct_at(reinterpret_cast<TPlainObjectType*>(&m_storage), expr);
|
2016-12-05 16:59:30 +01:00
|
|
|
m_hasCopy = true;
|
2015-10-06 11:57:03 +02:00
|
|
|
Base::construct(*obj);
|
2023-11-29 11:12:48 +00:00
|
|
|
} else {
|
2015-06-09 23:11:24 +02:00
|
|
|
Base::construct(expr);
|
2015-02-07 22:04:18 +01:00
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2015-02-07 22:04:18 +01:00
|
|
|
|
2019-11-07 14:34:06 +00:00
|
|
|
template <typename Expression>
|
|
|
|
|
void construct(const Expression& expr, internal::false_type) {
|
|
|
|
|
TPlainObjectType* obj = internal::construct_at(reinterpret_cast<TPlainObjectType*>(&m_storage), expr);
|
2016-12-05 16:59:30 +01:00
|
|
|
m_hasCopy = true;
|
2015-02-07 22:04:18 +01:00
|
|
|
Base::construct(*obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-11-07 14:34:06 +00:00
|
|
|
typename internal::aligned_storage<sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
|
2016-12-05 16:59:30 +01:00
|
|
|
bool m_hasCopy;
|
2023-11-29 11:12:48 +00:00
|
|
|
};
|
2015-10-21 09:47:43 +02:00
|
|
|
|
|
|
|
|
/**
|
2016-01-03 21:56:30 +01:00
|
|
|
* \ingroup SparseCore_Module
|
2015-10-21 09:47:43 +02:00
|
|
|
*
|
|
|
|
|
* \brief A sparse vector expression referencing an existing sparse vector expression
|
|
|
|
|
*
|
2016-01-03 21:56:30 +01:00
|
|
|
* \tparam SparseVectorType the equivalent sparse vector type of the referenced data, it must be a template instance of
|
|
|
|
|
* class SparseVector.
|
2015-10-21 09:47:43 +02:00
|
|
|
*
|
|
|
|
|
* \sa class Ref
|
|
|
|
|
*/
|
2016-01-03 21:56:30 +01:00
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
2015-10-21 09:47:43 +02:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
class Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>
|
|
|
|
|
: public internal::SparseRefBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
2016-01-03 21:56:30 +01:00
|
|
|
#else
|
|
|
|
|
template <typename SparseVectorType>
|
|
|
|
|
class Ref<SparseVectorType> : public SparseMapBase<Derived, WriteAccessors>
|
|
|
|
|
#endif
|
2015-10-21 09:47:43 +02:00
|
|
|
{
|
|
|
|
|
typedef SparseVector<MatScalar, MatOptions, MatIndex> PlainObjectType;
|
|
|
|
|
typedef internal::traits<Ref> Traits;
|
|
|
|
|
template <int OtherOptions>
|
|
|
|
|
inline Ref(const SparseVector<MatScalar, OtherOptions, MatIndex>& expr);
|
|
|
|
|
|
2016-01-03 21:56:30 +01:00
|
|
|
public:
|
2015-10-21 09:47:43 +02:00
|
|
|
typedef internal::SparseRefBase<Ref> Base;
|
|
|
|
|
EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
template <int OtherOptions>
|
|
|
|
|
inline Ref(SparseVector<MatScalar, OtherOptions, MatIndex>& expr) {
|
|
|
|
|
EIGEN_STATIC_ASSERT(
|
|
|
|
|
bool(Traits::template match<SparseVector<MatScalar, OtherOptions, MatIndex>>::MatchAtCompileTime),
|
|
|
|
|
STORAGE_LAYOUT_DOES_NOT_MATCH);
|
|
|
|
|
Base::construct(expr.derived());
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2015-10-21 09:47:43 +02:00
|
|
|
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
inline Ref(const SparseCompressedBase<Derived>& expr)
|
2023-11-29 11:12:48 +00:00
|
|
|
#else
|
2016-01-03 21:56:30 +01:00
|
|
|
/** Implicit constructor from any 1D sparse vector expression */
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename Derived>
|
2015-10-21 09:47:43 +02:00
|
|
|
inline Ref(SparseCompressedBase<Derived>& expr)
|
2023-11-29 11:12:48 +00:00
|
|
|
#endif
|
|
|
|
|
{
|
2015-10-21 09:47:43 +02:00
|
|
|
EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
|
|
|
|
|
EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
|
|
|
|
|
Base::construct(expr.const_cast_derived());
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
|
|
|
|
};
|
2015-10-21 09:47:43 +02:00
|
|
|
|
|
|
|
|
// this is the const ref version
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
2015-10-21 09:47:43 +02:00
|
|
|
class Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>
|
|
|
|
|
: public internal::SparseRefBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>> {
|
|
|
|
|
typedef SparseVector<MatScalar, MatOptions, MatIndex> TPlainObjectType;
|
|
|
|
|
typedef internal::traits<Ref> Traits;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
|
|
|
|
public:
|
2015-10-21 09:47:43 +02:00
|
|
|
typedef internal::SparseRefBase<Ref> Base;
|
|
|
|
|
EIGEN_SPARSE_PUBLIC_INTERFACE(Ref)
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2015-10-21 09:47:43 +02:00
|
|
|
template <typename Derived>
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) {
|
2015-10-21 09:47:43 +02:00
|
|
|
construct(expr.derived(), typename Traits::template match<Derived>::type());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const Ref& other) : Base(other), m_hasCopy(false) {
|
2015-10-21 09:47:43 +02:00
|
|
|
// copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OtherRef>
|
2016-12-05 16:59:30 +01:00
|
|
|
inline Ref(const RefBase<OtherRef>& other) : m_hasCopy(false) {
|
2015-10-21 09:47:43 +02:00
|
|
|
construct(other.derived(), typename Traits::template match<OtherRef>::type());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 16:59:30 +01:00
|
|
|
~Ref() {
|
|
|
|
|
if (m_hasCopy) {
|
2022-03-08 20:43:22 +00:00
|
|
|
internal::destroy_at(reinterpret_cast<TPlainObjectType*>(&m_storage));
|
2016-12-05 16:59:30 +01:00
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
}
|
2016-12-05 16:59:30 +01:00
|
|
|
|
2015-10-21 09:47:43 +02:00
|
|
|
protected:
|
|
|
|
|
template <typename Expression>
|
|
|
|
|
void construct(const Expression& expr, internal::true_type) {
|
|
|
|
|
Base::construct(expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Expression>
|
|
|
|
|
void construct(const Expression& expr, internal::false_type) {
|
2022-03-08 20:43:22 +00:00
|
|
|
TPlainObjectType* obj = internal::construct_at(reinterpret_cast<TPlainObjectType*>(&m_storage), expr);
|
2016-12-05 16:59:30 +01:00
|
|
|
m_hasCopy = true;
|
2015-10-21 09:47:43 +02:00
|
|
|
Base::construct(*obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-11-07 14:34:06 +00:00
|
|
|
typename internal::aligned_storage<sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage;
|
2016-12-05 16:59:30 +01:00
|
|
|
bool m_hasCopy;
|
2015-10-21 09:47:43 +02:00
|
|
|
};
|
|
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
namespace internal {
|
|
|
|
|
|
2015-10-21 13:48:15 +02:00
|
|
|
// FIXME shall we introduce a general evaluatior_ref that we can specialize for any sparse object once, and thus remove
|
|
|
|
|
// this copy-pasta thing...
|
|
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
struct evaluator<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
|
|
|
|
: evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
|
|
|
|
|
typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> Base;
|
2022-01-10 20:53:29 +00:00
|
|
|
typedef Ref<SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
|
2015-02-07 22:04:18 +01:00
|
|
|
evaluator() : Base() {}
|
|
|
|
|
explicit evaluator(const XprType& mat) : Base(mat) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
struct evaluator<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
|
|
|
|
: evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
|
|
|
|
|
typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType>>>
|
|
|
|
|
Base;
|
2022-01-10 20:53:29 +00:00
|
|
|
typedef Ref<const SparseMatrix<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
|
2015-02-07 22:04:18 +01:00
|
|
|
evaluator() : Base() {}
|
|
|
|
|
explicit evaluator(const XprType& mat) : Base(mat) {}
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-21 09:47:43 +02:00
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
struct evaluator<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
|
|
|
|
: evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
|
|
|
|
|
typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> Base;
|
|
|
|
|
typedef Ref<SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
|
|
|
|
|
evaluator() : Base() {}
|
|
|
|
|
explicit evaluator(const XprType& mat) : Base(mat) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>
|
|
|
|
|
struct evaluator<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>
|
|
|
|
|
: evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>> {
|
|
|
|
|
typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType>>>
|
|
|
|
|
Base;
|
|
|
|
|
typedef Ref<const SparseVector<MatScalar, MatOptions, MatIndex>, Options, StrideType> XprType;
|
|
|
|
|
evaluator() : Base() {}
|
|
|
|
|
explicit evaluator(const XprType& mat) : Base(mat) {}
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-07 22:04:18 +01:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
|
|
|
|
#endif // EIGEN_SPARSE_REF_H
|