// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2024 Charles Schlosser // // 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_FILL_H #define EIGEN_FILL_H // IWYU pragma: private #include "./InternalHeaderCheck.h" namespace Eigen { namespace internal { template struct eigen_fill_helper : std::false_type {}; template struct eigen_fill_helper> : std::true_type {}; template struct eigen_fill_helper> : std::true_type {}; template struct eigen_fill_helper> : eigen_fill_helper {}; template struct eigen_fill_helper> : std::integral_constant::value && (Xpr::IsRowMajor ? (BlockRows == 1) : (BlockCols == 1))> {}; template struct eigen_fill_helper>> : eigen_fill_helper {}; template struct eigen_fill_helper>> : std::integral_constant::value && enum_eq_not_dynamic(OuterStride_, Xpr::InnerSizeAtCompileTime)> {}; template struct eigen_fill_helper>> : eigen_fill_helper>> {}; template struct eigen_fill_helper>> : eigen_fill_helper>> {}; template struct eigen_fill_helper>> : eigen_fill_helper>> {}; template struct eigen_fill_impl { using Scalar = typename Xpr::Scalar; using Func = scalar_constant_op; using PlainObject = typename Xpr::PlainObject; using Constant = typename PlainObject::ConstantReturnType; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void run(Xpr& dst, const Scalar& val) { const Constant src(dst.rows(), dst.cols(), val); run(dst, src); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void run(Xpr& dst, const SrcXpr& src) { call_dense_assignment_loop(dst, src, assign_op()); } }; #if EIGEN_COMP_MSVC || defined(EIGEN_GPU_COMPILE_PHASE) template struct eigen_fill_impl : eigen_fill_impl {}; #else template struct eigen_fill_impl { using Scalar = typename Xpr::Scalar; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const Scalar& val) { const Scalar val_copy = val; using std::fill_n; fill_n(dst.data(), dst.size(), val_copy); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) { resize_if_allowed(dst, src, assign_op()); const Scalar& val = src.functor()(); run(dst, val); } }; #endif template struct eigen_memset_helper { static constexpr bool value = std::is_trivially_copyable::value && eigen_fill_helper::value; }; template struct eigen_zero_impl { using Scalar = typename Xpr::Scalar; using PlainObject = typename Xpr::PlainObject; using Zero = typename PlainObject::ZeroReturnType; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void run(Xpr& dst) { const Zero src(dst.rows(), dst.cols()); run(dst, src); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void run(Xpr& dst, const SrcXpr& src) { call_dense_assignment_loop(dst, src, assign_op()); } }; template struct eigen_zero_impl { using Scalar = typename Xpr::Scalar; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst) { const std::ptrdiff_t num_bytes = dst.size() * static_cast(sizeof(Scalar)); if (num_bytes <= 0) return; void* dst_ptr = static_cast(dst.data()); #ifndef EIGEN_NO_DEBUG eigen_assert((dst_ptr != nullptr) && "null pointer dereference error!"); #endif EIGEN_USING_STD(memset); memset(dst_ptr, 0, static_cast(num_bytes)); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) { resize_if_allowed(dst, src, assign_op()); run(dst); } }; } // namespace internal } // namespace Eigen #endif // EIGEN_FILL_H