【数值特性库】入口文件

数值特性库入口文件为lib.rs。该文件定义一系列数字特性的trait(特征),这些特性可以被不同的数字类型实现,从而提供一套通用的数值操作方法。下面是对代码中关键部分的解释:

一、基础设置

  • #![doc(html_root_url = “https://docs.rs/num-traits/0.2”)]:指定了文档的根URL,用于在线文档生成。
  • #![deny(unconditional_recursion)]:禁止无条件递归,这是一种编译时检查,防止无限递归。
  • #![no_std]:表明这个crate不依赖Rust标准库,使其可以在没有标准库的环境(如裸机或嵌入式系统)中使用。

二、条件编译

  • #[cfg(feature = “std”)]:当启用std特性时,编译这部分代码。这通常用于在有无标准库支持时提供不同的实现。

三、引入依赖

  • 引入了Rust核心库中的一些基本功能,如格式化(fmt)、包装类型(Wrapping)、基本的算术操作(Add, Div, Mul, Rem, Sub等)及其赋值操作(AddAssign, DivAssign, MulAssign, RemAssign, SubAssign)。

四、公开的特性

  • 通过pub use语句,公开了库中定义的一系列特性(traits)和常量,使得外部可以直接通过这些路径访问它们。例如,Bounded用于表示有边界的数字类型,Float和FloatConst提供了浮点数的操作和常量,NumCast用于类型转换等。

五、核心trait定义:

  • Num:定义了数值类型的基础特性,包括比较、基本数值操作、字符串转换等。
  • NumOps:为实现了基本算术运算符(+, -, *, /, %)的类型自动实现。
  • NumRef和RefNum:提供了对引用类型数值操作的支持。
  • NumAssignOps:为实现了赋值运算符(如+=, -=)的类型自动实现。

六、宏和模块:

  • 通过#[macro_use]引入了宏定义(在macros模块中),这些宏可能用于简化代码或提供额外的功能。
  • 定义了多个模块(如bounds, cast, float, identities, int, ops, pow, real, sign),每个模块都负责特定的数值操作或特性。

七、总结及源码

整体而言,这段代码定义了一个丰富的数字特性库,为Rust中的数值类型提供了一套通用的接口和操作方法。通过实现这些trait,不同的数值类型可以享受到这些通用操作带来的便利,同时也为开发者提供了一种灵活的方式来处理不同类型的数值。源码如下:

//!为泛型准备的数字特征库 #![doc(html_root_url = "https://docs.rs/num-traits/0.2")]
#![deny(unconditional_recursion)]
#![no_std]// 需要显式地将crate引入固有的float方法。Need to explicitly bring the crate in for inherent float methods
#[cfg(feature = "std")]
extern crate std;use core::fmt;
use core::num::Wrapping;
use core::ops::{Add, Div, Mul, Rem, Sub};
use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};pub use crate::bounds::Bounded; // 1 边界特性
#[cfg(any(feature = "std", feature = "libm"))]
pub use crate::float::Float; // 2
pub use crate::float::FloatConst; // 3pub use crate::cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive}; // 4
pub use crate::identities::{one, zero, ConstOne, ConstZero, One, Zero}; // 5
pub use crate::int::PrimInt; // 6
pub use crate::ops::bytes::{FromBytes, ToBytes}; // 7
pub use crate::ops::checked::{CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr, CheckedSub,
};               // 8
pub use crate::ops::euclid::{CheckedEuclid, Euclid}; // 9
pub use crate::ops::inv::Inv; // 10
pub use crate::ops::mul_add::{MulAdd, MulAddAssign}; // 11
pub use crate::ops::saturating::{Saturating, SaturatingAdd, SaturatingMul, SaturatingSub}; // 12
pub use crate::ops::wrapping::{WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
};                           // 13
pub use crate::pow::{checked_pow, pow, Pow};  // 14
pub use crate::sign::{abs, abs_sub, signum, Signed, Unsigned};  // 15#[macro_use]
mod macros;pub mod bounds;
pub mod cast;
pub mod float;
pub mod identities;
pub mod int;
pub mod ops;
pub mod pow;
pub mod real;
pub mod sign;/// The base trait for numeric types, covering `0` and `1` values,
/// comparisons, basic numeric operations, and string conversion.
pub trait Num: PartialEq + Zero + One + NumOps {type FromStrRadixErr;/// Convert from a string and radix (typically `2..=36`).////// # Examples////// ```rust/// use num_traits::Num;////// let result = <i32 as Num>::from_str_radix("27", 10);/// assert_eq!(result, Ok(27));////// let result = <i32 as Num>::from_str_radix("foo", 10);/// assert!(result.is_err());/// ```////// # Supported radices////// The exact range of supported radices is at the discretion of each type implementation. For/// primitive integers, this is implemented by the inherent `from_str_radix` methods in the/// standard library, which **panic** if the radix is not in the range from 2 to 36. The/// implementation in this crate for primitive floats is similar.////// For third-party types, it is suggested that implementations should follow suit and at least/// accept `2..=36` without panicking, but an `Err` may be returned for any unsupported radix./// It's possible that a type might not even support the common radix 10, nor any, if string/// parsing doesn't make sense for that type.fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>;
}/// Generic trait for types implementing basic numeric operations
///
/// This is automatically implemented for types which implement the operators.
pub trait NumOps<Rhs = Self, Output = Self>:Add<Rhs, Output = Output>+ Sub<Rhs, Output = Output>+ Mul<Rhs, Output = Output>+ Div<Rhs, Output = Output>+ Rem<Rhs, Output = Output>
{
}impl<T, Rhs, Output> NumOps<Rhs, Output> for T whereT: Add<Rhs, Output = Output>+ Sub<Rhs, Output = Output>+ Mul<Rhs, Output = Output>+ Div<Rhs, Output = Output>+ Rem<Rhs, Output = Output>
{
}/// The trait for `Num` types which also implement numeric operations taking
/// the second operand by reference.
///
/// This is automatically implemented for types which implement the operators.
pub trait NumRef: Num + for<'r> NumOps<&'r Self> {}
impl<T> NumRef for T where T: Num + for<'r> NumOps<&'r T> {}/// The trait for `Num` references which implement numeric operations, taking the
/// second operand either by value or by reference.
///
/// This is automatically implemented for all types which implement the operators. It covers
/// every type implementing the operations though, regardless of it being a reference or
/// related to `Num`.
pub trait RefNum<Base>: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base> {}
impl<T, Base> RefNum<Base> for T where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base> {}/// Generic trait for types implementing numeric assignment operators (like `+=`).
///
/// This is automatically implemented for types which implement the operators.
pub trait NumAssignOps<Rhs = Self>:AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>
{
}impl<T, Rhs> NumAssignOps<Rhs> for T whereT: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>
{
}/// The trait for `Num` types which also implement assignment operators.
///
/// This is automatically implemented for types which implement the operators.
pub trait NumAssign: Num + NumAssignOps {}
impl<T> NumAssign for T where T: Num + NumAssignOps {}/// The trait for `NumAssign` types which also implement assignment operations
/// taking the second operand by reference.
///
/// This is automatically implemented for types which implement the operators.
pub trait NumAssignRef: NumAssign + for<'r> NumAssignOps<&'r Self> {}
impl<T> NumAssignRef for T where T: NumAssign + for<'r> NumAssignOps<&'r T> {}macro_rules! int_trait_impl {($name:ident for $($t:ty)*) => ($(impl $name for $t {type FromStrRadixErr = ::core::num::ParseIntError;#[inline]fn from_str_radix(s: &str, radix: u32)-> Result<Self, ::core::num::ParseIntError>{<$t>::from_str_radix(s, radix)}})*)
}
int_trait_impl!(Num for usize u8 u16 u32 u64 u128);
int_trait_impl!(Num for isize i8 i16 i32 i64 i128);impl<T: Num> Num for Wrapping<T>
whereWrapping<T>: NumOps,
{type FromStrRadixErr = T::FromStrRadixErr;fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {T::from_str_radix(str, radix).map(Wrapping)}
}#[derive(Debug)]
pub enum FloatErrorKind {Empty,Invalid,
}
// FIXME: core::num::ParseFloatError is stable in 1.0, but opaque to us,
// so there's not really any way for us to reuse it.
#[derive(Debug)]
pub struct ParseFloatError {pub kind: FloatErrorKind,
}impl fmt::Display for ParseFloatError {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {let description = match self.kind {FloatErrorKind::Empty => "cannot parse float from empty string",FloatErrorKind::Invalid => "invalid float literal",};description.fmt(f)}
}fn str_to_ascii_lower_eq_str(a: &str, b: &str) -> bool {a.len() == b.len()&& a.bytes().zip(b.bytes()).all(|(a, b)| {let a_to_ascii_lower = a | (((b'A' <= a && a <= b'Z') as u8) << 5);a_to_ascii_lower == b})
}// FIXME: The standard library from_str_radix on floats was deprecated, so we're stuck
// with this implementation ourselves until we want to make a breaking change.
// (would have to drop it from `Num` though)
macro_rules! float_trait_impl {($name:ident for $($t:ident)*) => ($(impl $name for $t {type FromStrRadixErr = ParseFloatError;fn from_str_radix(src: &str, radix: u32)-> Result<Self, Self::FromStrRadixErr>{use self::FloatErrorKind::*;use self::ParseFloatError as PFE;// Special case radix 10 to use more accurate standard library implementationif radix == 10 {return src.parse().map_err(|_| PFE {kind: if src.is_empty() { Empty } else { Invalid },});}// Special valuesif str_to_ascii_lower_eq_str(src, "inf")|| str_to_ascii_lower_eq_str(src, "infinity"){return Ok(core::$t::INFINITY);} else if str_to_ascii_lower_eq_str(src, "-inf")|| str_to_ascii_lower_eq_str(src, "-infinity"){return Ok(core::$t::NEG_INFINITY);} else if str_to_ascii_lower_eq_str(src, "nan") {return Ok(core::$t::NAN);} else if str_to_ascii_lower_eq_str(src, "-nan") {return Ok(-core::$t::NAN);}fn slice_shift_char(src: &str) -> Option<(char, &str)> {let mut chars = src.chars();Some((chars.next()?, chars.as_str()))}let (is_positive, src) =  match slice_shift_char(src) {None             => return Err(PFE { kind: Empty }),Some(('-', ""))  => return Err(PFE { kind: Empty }),Some(('-', src)) => (false, src),Some((_, _))     => (true,  src),};// The significand to accumulatelet mut sig = if is_positive { 0.0 } else { -0.0 };// Necessary to detect overflowlet mut prev_sig = sig;let mut cs = src.chars().enumerate();// Exponent prefix and exponent index offsetlet mut exp_info = None::<(char, usize)>;// Parse the integer part of the significandfor (i, c) in cs.by_ref() {match c.to_digit(radix) {Some(digit) => {// shift significand one digit leftsig *= radix as $t;// add/subtract current digit depending on signif is_positive {sig += (digit as isize) as $t;} else {sig -= (digit as isize) as $t;}// Detect overflow by comparing to last value, except// if we've not seen any non-zero digits.if prev_sig != 0.0 {if is_positive && sig <= prev_sig{ return Ok(core::$t::INFINITY); }if !is_positive && sig >= prev_sig{ return Ok(core::$t::NEG_INFINITY); }// Detect overflow by reversing the shift-and-add processif is_positive && (prev_sig != (sig - digit as $t) / radix as $t){ return Ok(core::$t::INFINITY); }if !is_positive && (prev_sig != (sig + digit as $t) / radix as $t){ return Ok(core::$t::NEG_INFINITY); }}prev_sig = sig;},None => match c {'e' | 'E' | 'p' | 'P' => {exp_info = Some((c, i + 1));break;  // start of exponent},'.' => {break;  // start of fractional part},_ => {return Err(PFE { kind: Invalid });},},}}// If we are not yet at the exponent parse the fractional// part of the significandif exp_info.is_none() {let mut power = 1.0;for (i, c) in cs.by_ref() {match c.to_digit(radix) {Some(digit) => {// Decrease power one order of magnitudepower /= radix as $t;// add/subtract current digit depending on signsig = if is_positive {sig + (digit as $t) * power} else {sig - (digit as $t) * power};// Detect overflow by comparing to last valueif is_positive && sig < prev_sig{ return Ok(core::$t::INFINITY); }if !is_positive && sig > prev_sig{ return Ok(core::$t::NEG_INFINITY); }prev_sig = sig;},None => match c {'e' | 'E' | 'p' | 'P' => {exp_info = Some((c, i + 1));break; // start of exponent},_ => {return Err(PFE { kind: Invalid });},},}}}// Parse and calculate the exponentlet exp = match exp_info {Some((c, offset)) => {let base = match c {'E' | 'e' if radix == 10 => 10.0,'P' | 'p' if radix == 16 => 2.0,_ => return Err(PFE { kind: Invalid }),};// Parse the exponent as decimal integerlet src = &src[offset..];let (is_positive, exp) = match slice_shift_char(src) {Some(('-', src)) => (false, src.parse::<usize>()),Some(('+', src)) => (true,  src.parse::<usize>()),Some((_, _))     => (true,  src.parse::<usize>()),None             => return Err(PFE { kind: Invalid }),};#[cfg(feature = "std")]fn pow(base: $t, exp: usize) -> $t {Float::powi(base, exp as i32)}// otherwise uses the generic `pow` from the rootmatch (is_positive, exp) {(true,  Ok(exp)) => pow(base, exp),(false, Ok(exp)) => 1.0 / pow(base, exp),(_, Err(_))      => return Err(PFE { kind: Invalid }),}},None => 1.0, // no exponent};Ok(sig * exp)}})*)
}
float_trait_impl!(Num for f32 f64);/// A value bounded by a minimum and a maximum
///
///  If input is less than min then this returns min.
///  If input is greater than max then this returns max.
///  Otherwise this returns input.
///
/// **Panics** in debug mode if `!(min <= max)`.
#[inline]
pub fn clamp<T: PartialOrd>(input: T, min: T, max: T) -> T {debug_assert!(min <= max, "min must be less than or equal to max");if input < min {min} else if input > max {max} else {input}
}/// A value bounded by a minimum value
///
///  If input is less than min then this returns min.
///  Otherwise this returns input.
///  `clamp_min(std::f32::NAN, 1.0)` preserves `NAN` different from `f32::min(std::f32::NAN, 1.0)`.
///
/// **Panics** in debug mode if `!(min == min)`. (This occurs if `min` is `NAN`.)
#[inline]
#[allow(clippy::eq_op)]
pub fn clamp_min<T: PartialOrd>(input: T, min: T) -> T {debug_assert!(min == min, "min must not be NAN");if input < min {min} else {input}
}/// A value bounded by a maximum value
///
///  If input is greater than max then this returns max.
///  Otherwise this returns input.
///  `clamp_max(std::f32::NAN, 1.0)` preserves `NAN` different from `f32::max(std::f32::NAN, 1.0)`.
///
/// **Panics** in debug mode if `!(max == max)`. (This occurs if `max` is `NAN`.)
#[inline]
#[allow(clippy::eq_op)]
pub fn clamp_max<T: PartialOrd>(input: T, max: T) -> T {debug_assert!(max == max, "max must not be NAN");if input > max {max} else {input}
}#[test]
fn clamp_test() {// Int testassert_eq!(1, clamp(1, -1, 2));assert_eq!(-1, clamp(-2, -1, 2));assert_eq!(2, clamp(3, -1, 2));assert_eq!(1, clamp_min(1, -1));assert_eq!(-1, clamp_min(-2, -1));assert_eq!(-1, clamp_max(1, -1));assert_eq!(-2, clamp_max(-2, -1));// Float testassert_eq!(1.0, clamp(1.0, -1.0, 2.0));assert_eq!(-1.0, clamp(-2.0, -1.0, 2.0));assert_eq!(2.0, clamp(3.0, -1.0, 2.0));assert_eq!(1.0, clamp_min(1.0, -1.0));assert_eq!(-1.0, clamp_min(-2.0, -1.0));assert_eq!(-1.0, clamp_max(1.0, -1.0));assert_eq!(-2.0, clamp_max(-2.0, -1.0));assert!(clamp(::core::f32::NAN, -1.0, 1.0).is_nan());assert!(clamp_min(::core::f32::NAN, 1.0).is_nan());assert!(clamp_max(::core::f32::NAN, 1.0).is_nan());
}#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_nan_min() {clamp(0., ::core::f32::NAN, 1.);
}#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_nan_max() {clamp(0., -1., ::core::f32::NAN);
}#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_nan_min_max() {clamp(0., ::core::f32::NAN, ::core::f32::NAN);
}#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_min_nan_min() {clamp_min(0., ::core::f32::NAN);
}#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_max_nan_max() {clamp_max(0., ::core::f32::NAN);
}#[test]
fn from_str_radix_unwrap() {// The Result error must impl Debug to allow unwrap()let i: i32 = Num::from_str_radix("0", 10).unwrap();assert_eq!(i, 0);let f: f32 = Num::from_str_radix("0.0", 10).unwrap();assert_eq!(f, 0.0);
}#[test]
fn from_str_radix_multi_byte_fail() {// Ensure parsing doesn't panic, even on invalid sign charactersassert!(f32::from_str_radix("™0.2", 10).is_err());// Even when parsing the exponent signassert!(f32::from_str_radix("0.2E™1", 10).is_err());
}#[test]
fn from_str_radix_ignore_case() {assert_eq!(f32::from_str_radix("InF", 16).unwrap(),::core::f32::INFINITY);assert_eq!(f32::from_str_radix("InfinitY", 16).unwrap(),::core::f32::INFINITY);assert_eq!(f32::from_str_radix("-InF", 8).unwrap(),::core::f32::NEG_INFINITY);assert_eq!(f32::from_str_radix("-InfinitY", 8).unwrap(),::core::f32::NEG_INFINITY);assert!(f32::from_str_radix("nAn", 4).unwrap().is_nan());assert!(f32::from_str_radix("-nAn", 4).unwrap().is_nan());
}#[test]
fn wrapping_is_num() {fn require_num<T: Num>(_: &T) {}require_num(&Wrapping(42_u32));require_num(&Wrapping(-42));
}#[test]
fn wrapping_from_str_radix() {macro_rules! test_wrapping_from_str_radix {($($t:ty)+) => {$(for &(s, r) in &[("42", 10), ("42", 2), ("-13.0", 10), ("foo", 10)] {let w = Wrapping::<$t>::from_str_radix(s, r).map(|w| w.0);assert_eq!(w, <$t as Num>::from_str_radix(s, r));})+};}test_wrapping_from_str_radix!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
}#[test]
fn check_num_ops() {fn compute<T: Num + Copy>(x: T, y: T) -> T {x * y / y % y + y - y}assert_eq!(compute(1, 2), 1)
}#[test]
fn check_numref_ops() {fn compute<T: NumRef>(x: T, y: &T) -> T {x * y / y % y + y - y}assert_eq!(compute(1, &2), 1)
}#[test]
fn check_refnum_ops() {fn compute<T: Copy>(x: &T, y: T) -> Twherefor<'a> &'a T: RefNum<T>,{&(&(&(&(x * y) / y) % y) + y) - y}assert_eq!(compute(&1, 2), 1)
}#[test]
fn check_refref_ops() {fn compute<T>(x: &T, y: &T) -> Twherefor<'a> &'a T: RefNum<T>,{&(&(&(&(x * y) / y) % y) + y) - y}assert_eq!(compute(&1, &2), 1)
}#[test]
fn check_numassign_ops() {fn compute<T: NumAssign + Copy>(mut x: T, y: T) -> T {x *= y;x /= y;x %= y;x += y;x -= y;x}assert_eq!(compute(1, 2), 1)
}#[test]
fn check_numassignref_ops() {fn compute<T: NumAssignRef + Copy>(mut x: T, y: &T) -> T {x *= y;x /= y;x %= y;x += y;x -= y;x}assert_eq!(compute(1, &2), 1)
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/64843.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

matlab绘图时设置左、右坐标轴为不同颜色

目录 一、需求描述 二、实现方法 一、需求描述 当图中存在两条曲线&#xff0c;需要对两条曲线进行分别描述时&#xff0c;应设置左、右坐标轴为不同颜色&#xff0c;并设置刻度线&#xff0c;且坐标轴颜色需要和曲线颜色相同。 二、实现方法 1.1、可以实现&#xff1a; 1…

【数据可视化复习方向】

1.数据可视化就是数据中信息的可视化 2.数据可视化主要从数据中寻找三个方面的信息&#xff1a;模式、关系和异常 3.大数据可视化分类&#xff1a;科学可视化、信息可视化、可视分析学 4.大数据可视化作用&#xff1a;记录信息、分析推理、信息传播与协同 5.可视化流程&…

「配置应用的可见性」功能使用教程

引言 对于「应用可见性」这一概念&#xff0c;可能很多开发者小伙伴还不是很熟悉。简单举一个很典型的场景例子&#xff0c;当你开发的应用需要调起第三方应用时&#xff0c;这里就涉及到应用可见性的问题了&#xff0c;如果不配置相关的应用可见性&#xff0c;则你的应用是无…

Pytorch | 从零构建ResNet对CIFAR10进行分类

Pytorch | 从零构建ResNet对CIFAR10进行分类 CIFAR10数据集ResNet核心思想网络结构创新点优点应用 ResNet结构代码详解结构代码代码详解BasicBlock 类ResNet 类ResNet18、ResNet34、ResNet50、ResNet101、ResNet152函数 训练过程和测试结果代码汇总resnet.pytrain.pytest.py 前…

安装MongoDB,环境配置

官网下载地址&#xff1a;MongoDB Shell Download | MongoDB 选择版本 安装 下载完成双击打开 点击mongodb-windows-x86_64-8.0.0-signed 选择安装地址 检查安装地址 安装成功 二.配置MongoDB数据库环境 1.找到安装好MongoDB的bin路径 复制bin路径 打开此电脑 -> 打开高级…

7.C语言 宏(Macro) 宏定义,宏函数

目录 宏定义 宏函数 1.注释事项 2.注意事项 宏(Macro)用法 常量定义 简单函数实现 类型检查 条件编译 宏函数计算参数个数 宏定义进行类型转换 宏定义进行位操作 宏定义进行断言 总结 宏定义 #include "stdio.h" #include "string.h" #incl…

基于高云GW5AT-15 FPGA的SLVS-EC桥MIPI设计方案分享

作者&#xff1a;Hello,Panda 一、设计需求 设计一个4Lanes SLVS-EC桥接到2组4lanes MIPI DPHY接口的电路模块&#xff1a; &#xff08;1&#xff09;CMOS芯片&#xff1a;IMX537-AAMJ-C&#xff0c;输出4lanes SLVS-EC 4.752Gbps Lane速率&#xff1b; &#xff08;2&…

【漏洞复现】CVE-2023-29944 Expression Injection

漏洞信息 NVD - cve-2023-29944 Metersphere v1.20.20-lts-79d354a6 is vulnerable to Remote Command Execution. The system command reverse-shell can be executed at the custom code snippet function of the metersphere system workbench. 背景介绍 MeterSphere is…

在VBA中结合正则表达式和查找功能给文档添加交叉连接

在VBA中搜索文本有两种方式可用&#xff0c;一种是利用Range.Find对象&#xff08;更常见的形式可能是Selection.Find&#xff0c;Selection是Range的子类&#xff0c;Selection.Find其实就是特殊的Range.Find&#xff09;&#xff0c;另一种方法是利用正则表达式&#xff0c;但…

AW36518芯片手册解读(3)

接前一篇文章&#xff1a;AW36518芯片手册解读&#xff08;2&#xff09; 二、详述 3. 功能描述 &#xff08;1&#xff09;上电复位 当电源电压VIN降至预定义电压VPOR&#xff08;典型值为2.0V&#xff09;以下时&#xff0c;该设备会产生复位信号以执行上电复位操作&#x…

【mysql】唯一性约束unique

文章目录 唯一性约束1. 作用2. 关键字3. 特点4. 添加唯一约束5. 关于复合唯一约束 唯一性约束 1. 作用 用来限制某个字段/某列的值不能重复。 2. 关键字 UNIQUE3. 特点 同一个表可以有多个唯一约束。唯一约束可以是某一个列的值唯一&#xff0c;也可以多个列组合的值唯一。…

实操给桌面机器人加上超拟人音色

前面我们讲了怎么用CSK6大模型开发板做一个桌面机器人充当AI语音助理&#xff0c;近期上线超拟人方案&#xff0c;不仅大模型语音最快可以1秒内回复&#xff0c;还可以让我们的桌面机器人使用超拟人音色、具备声纹识别等能力&#xff0c;本文以csk6大模型开发板为例实操怎么把超…

SYD881X RTC定时器事件在调用timeAppClockSet后会出现比较大的延迟

RTC定时器事件在调用timeAppClockSet后会出现比较大的延迟 这里RTC做了两个定时器一个是12秒,一个是185秒: #define RTCEVT_NUM ((uint8_t) 0x02)//当前定时器事件数#define RTCEVT_12S ((uint32_t) 0x0000002)//定时器1s事件 /*整分钟定时器事件&#xff0c;因为其余的…

LearnOpenGL学习(碰撞检测,粒子)

完整代码见&#xff1a;zaizai77/OpenGLTo2DGame: 基于OpenGL制作2D游戏 物体本身的数据来检测碰撞会很复杂&#xff0c;一半使用重叠在物体上的更简单的外形来检测。 AABB - AABB 碰撞 AABB代表的是轴对齐碰撞箱(Axis-aligned Bounding Box)&#xff0c;碰撞箱是指与场景基…

SwinTransformer 改进:添加SelfAttention自注意力层

目录 1. SelfAttention自注意力层 2. SwinTransformer SelfAttention 3. 代码 1. SelfAttention自注意力层 Self-Attention自注意力层是一种在神经网络中用于处理序列数据的注意力机制。它通过对输入序列中的不同位置进行关注&#xff0c;来计算每个位置与其他位置的关联程…

c++ ------语句

一、简单语句 简单语句是C中最基本的语句单元&#xff0c;通常以分号&#xff08;;&#xff09;结尾&#xff0c;用于执行一个单一的操作。常见的简单语句类型有&#xff1a; 表达式语句&#xff1a;由一个表达式后面加上分号构成&#xff0c;用于计算表达式的值或者执行具有…

【他山之石】The SVG path Syntax: An Illustrated Guide:SVG 中的 path 语法图解指南

写在前面 本文为我的自学精译专栏《CSS in Depth 2》第 086 篇文章、在介绍 CSS 的 clip-path 属性的用法时作者提到的一篇延伸阅读材料&#xff0c;以图文并茂的形式系统梳理了 SVG path 属性的方方面面。其中最为精彩的是文中列举的大量使用案例。为了方便查找&#xff0c;特…

小型 Vue 项目,该不该用 Pinia 、Vuex呢?

说到 Vue3 的状态管理&#xff0c;我们会第一时间想到 Pinia、Vuex&#xff0c;但是经过很长一段时间的 Vue3 项目开发&#xff0c;我逐渐发现&#xff0c;我们真的有必要用 Pinia、Vuex 这类的状态管理工具吗&#xff1f; 带着这样的疑惑&#xff0c;我首先是想知道一下 Pini…

c4d动画怎么导出mp4视频,c4d动画视频格式设置

宝子们&#xff0c;今天来给大家讲讲 C4D 咋导出mp4视频的方法。通过用图文教程的形式给大家展示得明明白白的&#xff0c;让你能轻松理解和掌握&#xff0c;不管是理论基础&#xff0c;还是实际操作和技能技巧&#xff0c;都能学到&#xff0c;快速入门然后提升自己哦。 c4d动…

EfficienetAD异常值检测之瓷砖表面缺陷检测(免费下载测试数据集和模型)

背景 当今制造业蓬勃发展&#xff0c;产品质量把控至关重要。从精密电子元件到大型工业板材&#xff0c;表面缺陷哪怕细微&#xff0c;都可能引发性能故障或外观瑕疵。人工目视检测耗时费力且易漏检&#xff0c;已无法适应高速生产线节奏。在此背景下&#xff0c;表面缺陷异常…