当前位置: 首页 > news >正文

【数值特性库】入口文件

数值特性库入口文件为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)
}

相关文章:

【数值特性库】入口文件

数值特性库入口文件为lib.rs。该文件定义一系列数字特性的trait&#xff08;特征&#xff09;&#xff0c;这些特性可以被不同的数字类型实现&#xff0c;从而提供一套通用的数值操作方法。下面是对代码中关键部分的解释&#xff1a; 一、基础设置 #![doc(html_root_url “h…...

企业微信客户管理工具

软件下载 点击这里下载软件 使用指南 查看操作演示视频 点击这里观看视频教程 安装与注意事项 排除防病毒程序干扰(本程序无病毒&#xff0c;请放心使用).避免快捷键冲突(确保 CtrlA 等快捷键无其他程序占用). 操作流程 手动启动企业微信&#xff0c;打开“添加客户”界面…...

Unity 碎片化空间的产生和优化

文章目录 产生1. 动态内存分配2. 磁盘文件操作3. 内存池和对象池4. 数据结构导致的碎片5. 操作系统的内存管理6. 应用程序设计不当 碎片化空间的优化方案 产生 碎片化空间通常指内存或磁盘中的一种分配不连续、难以利用的现象&#xff0c;主要由以下原因产生&#xff1a; 1. …...

音视频学习(二十七):SRT协议

SRT&#xff08;Secure Reliable Transport&#xff09;是一种开源的网络传输协议&#xff0c;专为实时音视频数据传输设计&#xff0c;具有低延迟、高可靠性和安全性等特点。 核心功能 SRT协议旨在解决实时音视频传输中的网络抖动、丢包、延迟和安全问题&#xff0c;提供以下…...

【Canvas与艺术】红色3号桌球

【注】 此图立体感还差点&#xff0c;以后改进吧。 【成图】 120*120的png图标&#xff1a; 大小图&#xff1a; 【代码】 <!DOCTYPE html> <html lang"utf-8"> <meta http-equiv"Content-Type" content"text/html; charsetutf-8&q…...

2024-12-20 iframe嵌套与postMessage传值

iframe嵌套与postMessage传值 在Web开发中&#xff0c;iframe嵌套和postMessage传值是两个常用的技术&#xff0c;它们各自具有独特的用途和优势。本文将对这两项技术进行详细解析&#xff0c;并通过实例展示其使用方法。 一、iframe嵌套 什么是iframe嵌套&#xff1f; ifram…...

MFC 应用程序语言切换

在开发多语言支持的 MFC 应用程序时&#xff0c;如何实现动态语言切换是一个常见的问题。在本文中&#xff0c;我们将介绍两种实现语言切换的方式&#xff0c;并讨论其优缺点。同时&#xff0c;我们还会介绍如何通过保存配置文件来记住用户的语言选择&#xff0c;以及如何在程序…...

与您的数据对话: 用人工智能驱动的对象存储变革医疗保健

MinIO 的提示 API 现在是 AIStor 的一部分。MinIO 的创建是为了支持海量数据集&#xff0c;包括超过 EB 级的工作负载&#xff0c;解决内存、网络、复制和负载均衡方面的挑战&#xff0c;而 AIStor 的创建是为了建立在这些功能之上并解决我们客户的 AI 使用案例。作为 AIStor 的…...

WIN10拖入文件到桌面,文件自动移动到左上角,导致桌面文件错乱

1.先打开文件管理器。 2.点击如下图所示的“选项”。 3.我用红笔标记的这个框&#xff0c;把勾去掉...

JavaSE——绘图入门

一、Java绘图坐标体系 下图说明了Java坐标系&#xff0c;坐标原地位于左上角&#xff0c;以像素为单位。在Java坐标系中&#xff0c;第一个是x坐标&#xff0c;表示当前位置为水平方向&#xff0c;距离坐标原点x个像素&#xff1b;第二个是y坐标&#xff0c;表示当前位置为垂直…...

electron-vite打包后图标不生效问题

在electron-builder.yml中&#xff0c;通过icon配置自己的图标&#xff0c;以下是正确代码 win:executableName: 名称icon: build/icon.ico nsis:artifactName: ${name}-${version}.${ext}shortcutName: ${productName}uninstallDisplayName: ${productName}createDesktopShor…...

【MySQL】Linux使用C语言连接安装

&#x1f4e2;博客主页&#xff1a;https://blog.csdn.net/2301_779549673 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01; &#x1f4e2;本文由 JohnKi 原创&#xff0c;首发于 CSDN&#x1f649; &#x1f4e2;未来很长&#…...

Linux计算时间差

Linux计算时间差 1、Linux计算时间差2、时间差的应用 1、Linux计算时间差 在Linux中&#xff0c;计算时间差通常是为了统计、监控或调试。时间差可以用来衡量任务执行的时间&#xff0c;或者两个事件之间的间隔。例如&#xff0c;响应时间、执行时间、定时任务与延时处理等 以…...

onlyoffice连接器 二次开发 合同等制式模板化技术开发方案【三】

一、期望效果 目前曹瑞版本onlyoffice已经实现&#xff1a;书签模式 和 控件模式&#xff0c;用以支持该方案。 【图1】字段绑定 【图2】模板发起 【图3】接入表单 思路讲解&#xff1a; 业务系统开发中通常希望能够通过绑定form字段给word&#xff0c;从而达到双向同步效果&am…...

【论文研读】U-DiTs:在U型扩散Transformer中引入下采样Token,以更低计算成本超越DiT-XL/2

推荐理由 这篇论文提出了一种新的U型扩散Transformer模型&#xff08;U-DiT&#xff09;&#xff0c;该模型通过对自注意力机制中的查询、键和值进行下采样&#xff0c;有效减少了计算冗余&#xff0c;同时提高了性能。论文中的研究不仅包含理论分析和实验验证&#xff0c;还展…...

2009 ~ 2019 年 408【计算机网络】大题解析

2009 年 路由算法&#xff08;9’&#xff09; 讲解视频推荐&#xff1a;【BOK408真题讲解-2009年&#xff08;催更就退网版&#xff09;】 某网络拓扑如下图所示&#xff0c;路由器 R1 通过接口 E1 、E2 分别连接局域网 1 、局域网 2 &#xff0c;通过接口 L0 连接路由器 R2 &…...

.net core在linux导出excel,System.Drawing.Common is not supported on this platform

使用框架 .NET7 导出组件 Aspose.Cells for .NET 5.3.1 asp.net core mvc 如果使用Aspose.Cells导出excel时&#xff0c;报错 &#xff1a; System.Drawing.Common is not supported on this platform 平台特定实现&#xff1a; 对于Windows平台&#xff0c;System.Drawing.C…...

ExcelVBA编程输出ColorIndex与对应颜色色谱

标题 ExcelVBA编程输出ColorIndex与对应颜色色谱 正文 解决问题编程输出ColorIndex与对应色谱共56&#xff0c;打算分4纵列输出&#xff0c;标题是ColorIndex,Color,Name 1. 解释VBA中的ColorIndex属性 在VBA&#xff08;Visual Basic for Applications&#xff09;中&#xff…...

3.使用SD卡挂载petalinux根文件系统

前言 说明为什么使用SD卡挂载petalinux根文件系统如何使用SD卡挂载根文件系统 配置根文件写入类型制作SD分区格式化SD卡将工程目录下的rootfs.tar.gz解压到SD EXT4分区 为什么使用SD卡挂载petalinux根文件系统 Petalinux 默认的根文件系统类型是 INITRAMFS&#xff0c;不能…...

Java反射学习(1)(Java的“反射“机制、Class类对象的实例化方式)

目录 一、Java的"反射"机制。 &#xff08;1&#xff09;生活中的"反射"例子。 &#xff08;2&#xff09;Java的"反射"机制。 1、Java程序中"反射"的基本介绍。 2、"反射"机制图解介绍。 3、"反射"常见的应用场景…...

paimon中的Tag

TAG 在传统数仓场景中&#xff0c;从传统数据库中导入的事实表数据一般是全量导入&#xff0c;按天分区每天都存储一份全量数据&#xff0c;paimon对此提供了Tag机制&#xff0c;创建TAG时&#xff0c;会对当前数据做一份全量快照&#xff0c;在之后对表的数据进行更新也不会影…...

使用Vue创建前后端分离项目的过程(前端部分)

前端使用Vue.js作为前端开发框架&#xff0c;使用Vue CLI3脚手架搭建项目&#xff0c;使用axios作为HTTP库与后端API交互&#xff0c;使用Vue-router实现前端路由的定义、跳转以及参数的传递等&#xff0c;使用vuex进行数据状态管理&#xff0c;后端使用Node.jsexpress&#xf…...

4、交换机IP接口功能

这一篇是讲端口的功能的&#xff0c;应该放在路由前面的&#xff0c;不过关联不大&#xff0c;就这个顺序也行 1、DHCP功能 作用&#xff1a;交换机端口的DHCP功能可以使网络中的设备&#xff08;计算机、打印机等等&#xff09;能够自动的获取IP地址或其它网络参数&#xff0…...

java 选择排序,涵盖工作原理、算法分析、实现细节、优缺点以及一些实际应用场景

选择排序的详细解析 更深入地探讨选择排序的各个方面&#xff0c;包括其工作原理、算法分析、实现细节、优缺点以及一些实际应用场景。 动画演示 1. 基本概念 选择排序是一种简单的比较排序算法。它的核心思想是将数组分为两个部分&#xff1a;已排序部分和未排序部分。每…...

基于springboot+vue实现的医院急诊(病房)管理系统 (源码+L文+ppt)4-122

摘要 医院急诊&#xff08;病房&#xff09;管理系统旨在优化患者的就诊流程&#xff0c;提高医疗效率和服务质量。该系统通过电子化患者信息、实时床位监控和智能调度等功能&#xff0c;确保急诊患者能够快速得到必要治疗&#xff0c;同时协助医护人员高效管理病房资源。系统…...

前端模块化

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言1.概述1.1什么是模块化1.2为什么要使用模块化 2.有哪些模块化规范3.CommonJS3.1导入3.1.1正常导入3.1.2解构导入 3.2导出3.2.1exports导出3.2.2module.exports导…...

​在VMware虚拟机上设置Ubuntu与主机共享文件夹​

‌在VMware虚拟机上设置Ubuntu与主机共享文件夹的步骤如下‌&#xff1a; ‌主机共享文件夹的设置‌&#xff1a;首先&#xff0c;在主机上选择一个磁盘分区创建一个文件夹&#xff0c;并设置其共享属性。右键点击该文件夹&#xff0c;选择“属性”&#xff0c;然后在“共享”选…...

无线信道常识(符号与多径、窄带与宽带)

符号长度与时延扩展 符号长度&#xff1a; 符号长度是指一个符号&#xff08;即一个信息单元&#xff09;在传输过程中所占用的时间。符号长度通常与系统的带宽和调制方式有关。例如&#xff0c;在GSM系统中&#xff0c;符号长度大约为 5μs。 时延扩展&#xff1a; 时延扩展是…...

人工智能 (AI) 模型的数据泄露问题

目录 1. 数据泄露:2. 模型泄露:3. 社会工程学攻击:参考文献:其他资源: 人工智能 (AI) 模型的数据泄露问题指的是模型训练过程中&#xff0c;训练数据的信息被泄露到模型输出中&#xff0c;导致模型对未见过的数据产生偏差或错误预测。这种泄露可能来自多个方面&#xff0c;包括…...

uniapp Vue3 语法实现浏览器中音频录制、停止、保存、播放、转码、实时音频输出

一、引言 在现代 Web 应用开发中,音频处理功能变得越来越重要。本文将详细介绍如何使用 uniapp 结合 Vue3 语法在浏览器环境中实现音频录制、停止、保存、播放、转码以及实时音频输出等一系列功能。通过深入剖析代码结构和功能实现细节,帮助读者全面理解和掌握相关技术,以便…...

OSPF的基本配置

基本原理图 1. 要求&#xff1a; R1-3为区域0&#xff0c;R3-R4为区域1&#xff1b;其中r3的环回也在区域0。R1,R2也各有一个环回 R1-R3 R3为DR设备&#xff0c;没有BDR R4环回地址以固定&#xff0c;其他所有网段使用192.168.1.0/24进行合理的分配 R4环回不能宣告&#xff0…...

【Flutter_Web】Flutter编译Web第二篇(webview篇):flutter_inappwebview如何改造方法,变成web之后数据如何交互

前言 欢迎来到第二篇文章&#xff0c;这也是第二个难题&#xff0c;就是原有的移动端本身一些页面H5的形式去呈现&#xff08;webview&#xff09;&#xff0c;例如某些需要动态更换内容的页面&#xff0c;某些活动页面、支付页面&#xff0c;不仅仅做页面呈现&#xff0c;还包…...

【游戏中orika完成一个Entity的复制及其Entity异步落地的实现】 1.ctrl+shift+a是飞书下的截图 2.落地实现

一、orika工具使用 1)工具类 package com.xinyue.game.utils;import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.impl.DefaultMapperFactory;/*** author 王广帅* since 2022/2/8 22:37*/ public class XyBeanCopyUtil {private static MapperFactory mappe…...

全局JDK环境和ES自带的JDK混用导致的ES集群创建失败

es配置安全集群es使用的自带的jdk环境&#xff0c;如果服务器全局在有jdk的配置。会导致秘钥解析出问题。各种问题异常密钥解析异常。 错误日志1&#xff1a; [2024-12-20T17:10:44,700][WARN ][o.e.c.c.ClusterFormationFailureHelper] [es-node1] master not discovered yet…...

vmime.net_4.dll详解:它是什么,有何用途?

在.NET开发环境中&#xff0c;DLL&#xff08;Dynamic Link Library&#xff0c;动态链接库&#xff09;文件扮演着至关重要的角色。它们封装了代码和资源&#xff0c;使得多个应用程序可以共享这些功能&#xff0c;从而提高开发效率和代码复用性。本文将详细介绍vmime.net_4.d…...

K8s 节点 NotReady 后 Pod的变化

NotReady 后 Pod的变化 当Kubernetes&#xff08;K8s&#xff09;节点进入NotReady状态时&#xff0c;该节点将无法接收新的Pod调度&#xff0c;这可能会影响服务的可用性。以下是节点变为NotReady后&#xff0c;其上Pod状态可能发生的一些情况和细节&#xff1a; Pod状态变为…...

使用 esrally race 测试 Elasticsearch 性能:实践指南

在 Elasticsearch 性能优化和容量规划中&#xff0c;使用 esrally 进行基准测试是官方推荐的方式。通过 esrally race 命令&#xff0c;您可以针对不同的数据集与挑战类型&#xff0c;对 Elasticsearch 集群进行精确的性能评估。本文将简要介绍常用的数据集与挑战类型&#xff…...

对象、函数、原型之间的关系

在 JavaScript 中&#xff0c;对象、函数 和 原型 是三者紧密联系的核心概念。它们共同构成了 JavaScript 中面向对象编程的基石&#xff0c;并通过原型链实现了继承与代码复用。本文将从对象、函数、原型的基础概念到它们之间的关系进行详细的讲解&#xff0c;帮助你理解 Java…...

Showrunner AI技术浅析(二):大型语言模型

1. GPT-3模型架构详解 GPT-3是基于Transformer架构的预训练语言模型&#xff0c;由OpenAI开发。其核心思想是通过自注意力机制&#xff08;Self-Attention&#xff09;处理输入序列&#xff0c;并生成自然语言文本。 1.1 Transformer架构基础 Transformer架构由Vaswani等人在…...

Web安全攻防入门教程——hvv行动详解

Web安全攻防入门教程 Web安全攻防是指在Web应用程序的开发、部署和运行过程中&#xff0c;保护Web应用免受攻击和恶意行为的技术与策略。这个领域不仅涉及防御措施的实现&#xff0c;还包括通过渗透测试、漏洞挖掘和模拟攻击来识别潜在的安全问题。 本教程将带你入门Web安全攻防…...

买卖股票的最佳时机 - 合集

************* C 买卖股票问题合集 ************* Since I have finished some stocks problems. I wanna make a list of the stocks to figure out the similarities. Here is the storks topucs list, from easy to hard: 121. 买卖股票的最佳时机 - 力扣&#xff08;L…...

gitlab window如何设置ssh

在GitLab中设置SSH需要以下步骤&#xff1a; 在GitLab账户中&#xff0c;导航到“用户设置”下的“SSH密钥”部分。 生成SSH密钥对&#xff08;如果你还没有的话&#xff09;。在Windows上&#xff0c;你可以使用ssh-keygen命令来生成密钥。 在命令提示符或PowerShell中运行以…...

go配置文件

https://github.com/spf13/viper viper golang中常用的配置文件工具为viper库&#xff0c;是一个第三方库。viper功能&#xff1a; 解析JSON、TOML、YAML、HCL等格式的配置文件。监听配置文件的变化(WatchConfig)&#xff0c;不需要重启程序就可以读到最新的值。...

深度学习之超分辨率算法——SRGAN

更新版本 实现了生成对抗网络在超分辨率上的使用 更新了损失函数&#xff0c;增加先验函数 SRresnet实现 import torch import torchvision from torch import nnclass ConvBlock(nn.Module):def __init__(self, kernel_size3, stride1, n_inchannels64):super(ConvBlock…...

GIT命令使用手册(详细实用版)

一、git常用操作参考 第一次提交完整步骤&#xff1a; 1.git init; 2.git add . 3.git commit -m "初始化" 4.git remote add origin https://github.com/githubusername/demo.git 5.git pull origin master 6.git push -u origin master&#xff08;使用-u选项可以将…...

数据分析实战—IMDB电影数据分析

1.实战内容 1.加载数据到movies_df&#xff0c;输出前5行&#xff0c;输出movies_df.info(),movies_df.describe() # &#xff08;1&#xff09;加载数据集&#xff0c;输出前5行 #导入库 import pandas as pd import numpy as np import matplotlib import matplotlib.pyplo…...

【SQL/MySQL 如何使用三种触发器】SQL语句实例演示

触发器介绍 – 触发器是与表有关的数据库对象&#xff0c;指在insert/update/delete之前(BEFORE)或之后(AFTER)&#xff0c;触发并执行触发器中定义的SQL语句集合。 – 使用别名OLD和NEW来引用触发器中发生变化的记录内容&#xff0c;这与其他的数据库是相似的。现在触发器还只…...

社区团购管理系统(源码+数据库)

355.基于SpringBoot的社区团购管理系统&#xff0c;系统包含两种角色&#xff1a;管理员、用户,系统分为前台和后台两大模块&#xff0c;主要功能如下 二、项目技术 编程语言&#xff1a;Java 数据库&#xff1a;MySQL 项目管理工具&#xff1a;Maven 前端技术&#xff1a;Vue …...

时钟分频模块

实现时钟的二分频&#xff0c;四分频 1.时钟分频模块&#xff1a; module clk_div(input clk, //50Mhzinput rst_n,input [15:0] lcd_id,output reg lcd_pclk);reg clk_25m; reg clk_12_5m; reg …...

linux ipmitool配置机器的BMC(服务器管理后台)

前置&#xff1a;mgnt口和网卡1连接入内网&#xff0c;并分配静态ip 1. 安装 ipmitool Debian/Ubuntu: sudo apt-get update sudo apt-get install ipmitool CentOS/RHEL: sudo yum install ipmitool2. 配置 BMC 的 IP 地址 #打印当前ipmi 地址配置信息。 ipmitool lan p…...