源码拾贝三则

ops/2024/10/18 5:45:43/

目录

一  一种枚举类型的新型使用方式

二 Eigen库中的LDLT分解

三 Eigen中的访问者模式


一  一种枚举类型的新型使用方式

///D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xiosbase							enum _Iostate { // constants for stream states							_Statmask = 0x17							};							static constexpr _Iostate goodbit = static_cast<_Iostate>(0x0);							static constexpr _Iostate eofbit  = static_cast<_Iostate>(0x1);							static constexpr _Iostate failbit = static_cast<_Iostate>(0x2);							static constexpr _Iostate badbit  = static_cast<_Iostate>(0x4);							_NODISCARD bool __CLR_OR_THIS_CALL good() const {							return rdstate() == ios_base::goodbit;							}							_NODISCARD bool __CLR_OR_THIS_CALL eof() const {							return rdstate() & ios_base::eofbit;							}							_NODISCARD bool __CLR_OR_THIS_CALL fail() const {							return rdstate() & (ios_base::badbit | ios_base::failbit);							}							_NODISCARD bool __CLR_OR_THIS_CALL bad() const {							return rdstate() & ios_base::badbit;							}							_NODISCARD iostate __CLR_OR_THIS_CALL exceptions() const {							return _Except;							}							void __CLR_OR_THIS_CALL exceptions(iostate _Newexcept) { // set exception mask to argument							_Except = _Newexcept & _Statmask;							clear(rdstate());							}							

二 Eigen库中的LDLT分解

													
Eigen-3.4.0\Eigen\src\Cholesky\LDLT.h													
template<typename _MatrixType,int _UpLo>													
template<bool Conjugate, typename RhsType, typename DstType>													
void LDLT<_MatrixType,_UpLo>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const													
{													// dst = P b													dst = m_transpositions * rhs;													// dst = L^-1 (P b)													// dst = L^-*T (P b)													matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst);													// dst = D^-* (L^-1 P b)													// dst = D^-1 (L^-*T P b)													// more precisely, use pseudo-inverse of D (see bug 241)													using std::abs;													const typename Diagonal<const MatrixType>::RealReturnType vecD(vectorD());													// In some previous versions, tolerance was set to the max of 1/highest (or rather numeric_limits::min())													// and the maximal diagonal entry * epsilon as motivated by LAPACK's xGELSS:													// RealScalar tolerance = numext::maxi(vecD.array().abs().maxCoeff() * NumTraits<RealScalar>::epsilon(),RealScalar(1) / NumTraits<RealScalar>::highest());													// However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the highest													// diagonal element is not well justified and leads to numerical issues in some cases.													// Moreover, Lapack's xSYTRS routines use 0 for the tolerance.													// Using numeric_limits::min() gives us more robustness to denormals.													RealScalar tolerance = (std::numeric_limits<RealScalar>::min)();													for (Index i = 0; i < vecD.size(); ++i)													{													if(abs(vecD(i)) > tolerance)													dst.row(i) /= vecD(i);													else													dst.row(i).setZero();													}													// dst = L^-* (D^-* L^-1 P b)													// dst = L^-T (D^-1 L^-*T P b)													matrixL().transpose().template conjugateIf<Conjugate>().solveInPlace(dst);													// dst = P^T (L^-* D^-* L^-1 P b) = A^-1 b													// dst = P^-T (L^-T D^-1 L^-*T P b) = A^-1 b													dst = m_transpositions.transpose() * dst;													
}													
#endif													

三 Eigen中的访问者模式

Eigen-3.4.0\Eigen\src\Core\Visitor.h
template<typename Derived>
template<typename Visitor>
EIGEN_DEVICE_FUNC
void DenseBase<Derived>::visit(Visitor& visitor) const
{if(size()==0)return;typedef typename internal::visitor_evaluator<Derived> ThisEvaluator;ThisEvaluator thisEval(derived());enum {unroll =  SizeAtCompileTime != Dynamic&& SizeAtCompileTime * int(ThisEvaluator::CoeffReadCost) + (SizeAtCompileTime-1) * int(internal::functor_traits<Visitor>::Cost) <= EIGEN_UNROLLING_LIMIT};return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor);
}


http://www.ppmy.cn/ops/39232.html

相关文章

Aapache Tomcat AJP 文件包含漏洞(CVE-2020-1938)

1 漏洞描述 CVE-2020-1938 是 Apache Tomcat 中的一个严重安全漏洞&#xff0c;该漏洞涉及到 Tomcat 的 AJP&#xff08;Apache JServ Protocol&#xff09;连接器。由于 AJP 协议在处理请求时存在缺陷&#xff0c;攻击者可以利用此漏洞读取服务器上的任意文件&#xff0c;甚至…

Java自定义注解:从定义到解析,再到AOP切面与日志打印应用

目录 一、注解定义二、注解解析三、自定义注解结合AOP切面四、自定义注解用于日志打印五、区别总结六、应用场景总结 在Java开发中&#xff0c;注解是一种强大的元编程工具&#xff0c;它可以帮助我们提升代码的可读性和功能性。本文将深入探讨如何创建和使用自定义注解&#x…

vue3中实现内容溢出隐藏以及显示提示属性

使用:show-overflow-tooltip"true" <el-table :data"serviceList" style"width: 100%"><el-table-column align"center" label"序号" prop"index" width"80" fixed /><el-table-column …

recycleview和banner新闻列表轮播图

说明&#xff1a;最近碰到一个需求&#xff0c;弄一个新闻列表和轮播图&#xff0c;在首页显示&#xff0c;并且需要json解析&#xff0c;图片下载&#xff0c;轮播图和新闻列表一起滑动 ui效果图&#xff1a; 文件说明&#xff1a; step1:引用依赖包 图片下载 json解析 轮播…

TypeError: __init__() got an unexpected keyword argument ‘logger‘

TypeError: __init__() got an unexpected keyword argument logger 执行python程序报错&#xff0c;博主出现这个问题最后解决办法是通过升级python到最新版3.12解决的。记住安装python时&#xff0c;要让它帮你配置好环境变量&#xff0c;如果默认不配置的话&#xff0c;还是…

掌握Ansible命令——提高自动化运维效率

目录 一、Ansible命令 1.定义 2.组成 3.命令格式 4.选项 5.示例 二、常用命令解释 1.ansible-doc 2.ansible-galaxy 3.ansible-playbook 4.ansible-pull 5.ansible-vault 三、高频使用的命令 1.Ping主机 2.执行命令 3.安装软件包 4.管理文件 5.管理服务 6.获…

使用sqlmodel实现唯一性校验

代码&#xff1a; from sqlmodel import Field, Session, SQLModel, create_engine# 声明模型 class User(SQLModel, tableTrue):id: int | None Field(defaultNone, primary_keyTrue)# 不能为空&#xff0c;必须唯一name: str Field(nullableFalse, uniqueTrue)age: int | …

python中的数据可视化:二维直方图 hist2d()

【小白从小学Python、C、Java】 【计算机等考500强证书考研】 【Python-数据分析】 python中的数据可视化&#xff1a; 二维直方图 hist2d() 选择题 关于以下代码输出结果的说法中正确的是? import matplotlib.pyplot as plt import numpy as np x np.random.normal(0, 1, …