use patch for num-complex & refactor

This commit is contained in:
zyansheep 2022-07-17 16:51:20 -04:00
parent f66b690fe8
commit 525bc63de2
9 changed files with 51 additions and 46 deletions

View File

@ -52,8 +52,8 @@ convert-glam020 = [ "glam020" ]
## `serde-serialize`. ## `serde-serialize`.
serde-serialize-no-std = [ "serde", "num-complex/serde" ] serde-serialize-no-std = [ "serde", "num-complex/serde" ]
serde-serialize = [ "serde-serialize-no-std", "serde/std" ] serde-serialize = [ "serde-serialize-no-std", "serde/std" ]
rkyv-serialize-no-std = [ "rkyv", "rkyv_wrappers" ] rkyv-serialize-no-std = [ "rkyv", "rkyv_wrappers", "num-complex/rkyv" ]
rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std", "rkyv/validation", "bytecheck" ] rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std", "rkyv/validation", "bytecheck", "num-complex/bytecheck" ]
# Randomness # Randomness
## To use rand in a #[no-std] environment, enable the ## To use rand in a #[no-std] environment, enable the
@ -71,15 +71,15 @@ nalgebra-macros = { version = "0.1", path = "nalgebra-macros", optional = true }
typenum = "1.12" typenum = "1.12"
rand-package = { package = "rand", version = "0.8", optional = true, default-features = false } rand-package = { package = "rand", version = "0.8", optional = true, default-features = false }
num-traits = { version = "0.2", default-features = false } num-traits = { version = "0.2", default-features = false }
num-complex = { version = "0.4", git = "https://github.com/zyansheep/num-complex", default-features = false } # { version = "0.4", default-features = false } num-complex = { version = "0.4", default-features = false }
num-rational = { version = "0.4", default-features = false } num-rational = { version = "0.4", default-features = false }
approx = { version = "0.5", default-features = false } approx = { version = "0.5", default-features = false }
simba = { version = "0.7.0", default-features = false } simba = { version = "0.7", default-features = false }
alga = { version = "0.9", default-features = false, optional = true } alga = { version = "0.9", default-features = false, optional = true }
rand_distr = { version = "0.4", default-features = false, optional = true } rand_distr = { version = "0.4", default-features = false, optional = true }
matrixmultiply = { version = "0.3", optional = true } matrixmultiply = { version = "0.3", optional = true }
serde = { version = "1.0", default-features = false, features = [ "derive" ], optional = true } serde = { version = "1.0", default-features = false, features = [ "derive" ], optional = true }
rkyv = { version = "0.7", optional = true } rkyv = { version = "0.7", default-features = false, optional = true }
rkyv_wrappers = { git = "https://github.com/rkyv/rkyv_contrib", optional = true } rkyv_wrappers = { git = "https://github.com/rkyv/rkyv_contrib", optional = true }
bytecheck = { version = "~0.6.1", optional = true } bytecheck = { version = "~0.6.1", optional = true }
mint = { version = "0.5", optional = true } mint = { version = "0.5", optional = true }
@ -134,3 +134,5 @@ lto = true
# Enable certain features when building docs for docs.rs # Enable certain features when building docs for docs.rs
features = [ "proptest-support", "compare", "macros", "rand" ] features = [ "proptest-support", "compare", "macros", "rand" ]
[patch.crates-io]
num-complex = { git = "https://github.com/zyansheep/num-complex" }

View File

@ -27,6 +27,7 @@ use std::mem;
/// A array-based statically sized matrix data storage. /// A array-based statically sized matrix data storage.
#[repr(transparent)] #[repr(transparent)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
@ -38,7 +39,6 @@ use std::mem;
") ")
) )
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]); pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]);

View File

@ -13,11 +13,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// Dim of dynamically-sized algebraic entities. /// Dim of dynamically-sized algebraic entities.
#[derive(Clone, Copy, Eq, PartialEq, Debug)] #[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr(
feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct Dynamic { pub struct Dynamic {
value: usize, value: usize,
@ -203,11 +198,6 @@ dim_ops!(
); );
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct Const<const R: usize>; pub struct Const<const R: usize>;

View File

@ -155,6 +155,7 @@ pub type MatrixCross<T, R1, C1, R2, C2> =
/// some concrete types for `T` and a compatible data storage type `S`). /// some concrete types for `T` and a compatible data storage type `S`).
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(Archive, rkyv::Serialize, rkyv::Deserialize), derive(Archive, rkyv::Serialize, rkyv::Deserialize),
@ -167,7 +168,6 @@ pub type MatrixCross<T, R1, C1, R2, C2> =
") ")
) )
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct Matrix<T, R, C, S> { pub struct Matrix<T, R, C, S> {
/// The data storage that contains all the matrix components. Disappointed? /// The data storage that contains all the matrix components. Disappointed?

View File

@ -21,6 +21,7 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF
/// in their documentation, read their dedicated pages directly. /// in their documentation, read their dedicated pages directly.
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, Hash, Copy)] #[derive(Clone, Hash, Copy)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
@ -31,7 +32,6 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF
") ")
) )
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
// #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] // #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct Unit<T> { pub struct Unit<T> {
pub(crate) value: T, pub(crate) value: T,

View File

@ -66,6 +66,7 @@ use crate::geometry::{AbstractRotation, Point, Translation};
Owned<T, Const<D>>: Deserialize<'de>, Owned<T, Const<D>>: Deserialize<'de>,
T: Scalar")) T: Scalar"))
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
@ -78,7 +79,6 @@ use crate::geometry::{AbstractRotation, Point, Translation};
") ")
) )
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
pub struct Isometry<T, R, const D: usize> { pub struct Isometry<T, R, const D: usize> {
/// The pure rotational part of this isometry. /// The pure rotational part of this isometry.
pub rotation: R, pub rotation: R,

View File

@ -36,11 +36,20 @@ use std::mem::MaybeUninit;
/// of said transformations for details. /// of said transformations for details.
#[repr(C)] #[repr(C)]
#[derive(Clone)] #[derive(Clone)]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
archive(
as = "OPoint<T::Archived, D>",
bound(archive = "
T: rkyv::Archive,
T::Archived: Scalar,
OVector<T, D>: rkyv::Archive<Archived = OVector<T::Archived, D>>,
DefaultAllocator: Allocator<T::Archived, D>,
")
)
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
pub struct OPoint<T: Scalar, D: DimName> pub struct OPoint<T: Scalar, D: DimName>
where where
DefaultAllocator: Allocator<T, D>, DefaultAllocator: Allocator<T, D>,

View File

@ -34,6 +34,7 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation};
DefaultAllocator: Allocator<T, Const<D>>, DefaultAllocator: Allocator<T, Const<D>>,
Owned<T, Const<D>>: Deserialize<'de>")) Owned<T, Const<D>>: Deserialize<'de>"))
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
#[cfg_attr( #[cfg_attr(
feature = "rkyv-serialize-no-std", feature = "rkyv-serialize-no-std",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
@ -46,7 +47,6 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation};
") ")
) )
)] )]
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
pub struct Similarity<T, R, const D: usize> { pub struct Similarity<T, R, const D: usize> {
/// The part of this similarity that does not include the scaling factor. /// The part of this similarity that does not include the scaling factor.
pub isometry: Isometry<T, R, D>, pub isometry: Isometry<T, R, D>,

View File

@ -8,7 +8,7 @@ use na::{
use rand; use rand;
use rkyv::{Archive, Deserialize, Infallible, Serialize}; use rkyv::{Archive, Deserialize, Infallible, Serialize};
macro_rules! test_rkyv_archived_impls( macro_rules! test_rkyv_same_type(
($($test: ident, $ty: ident);* $(;)*) => {$( ($($test: ident, $ty: ident);* $(;)*) => {$(
#[test] #[test]
fn $test() { fn $test() {
@ -16,44 +16,48 @@ macro_rules! test_rkyv_archived_impls(
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap(); let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap();
let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap(); let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap();
// Compare archived and non-archived
assert_eq!(archived, &value); assert_eq!(archived, &value);
// Make sure Debug implementations are the same for Archived and non-Archived versions.
assert_eq!(format!("{:?}", value), format!("{:?}", archived)); assert_eq!(format!("{:?}", value), format!("{:?}", archived));
} }
)*} )*}
); );
macro_rules! test_rkyv( macro_rules! test_rkyv_diff_type(
($($test: ident, $ty: ident);* $(;)*) => {$( ($($test: ident, $ty: ident);* $(;)*) => {$(
#[test] #[test]
fn $test() { fn $test() {
let value: $ty<f32> = rand::random(); let value: $ty<String> = Default::default();
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap(); let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap();
let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap(); let archived = rkyv::check_archived_root::<$ty<String>>(&bytes[..]).unwrap();
let deserialized: $ty<f32> = archived.deserialize(&mut Infallible).unwrap(); let deserialized: $ty<String> = archived.deserialize(&mut Infallible).unwrap();
assert_eq!(deserialized, value); assert_eq!(deserialized, value);
} }
)*} )*}
); );
test_rkyv_archived_impls!( // Tests to make sure
rkyv_matrix3x4, Matrix3x4; test_rkyv_same_type!(
rkyv_same_type_matrix3x4, Matrix3x4;
rkyv_same_type_point3, Point3;
rkyv_same_type_translation3, Translation3;
rkyv_same_type_rotation3, Rotation3;
rkyv_same_type_isometry3, Isometry3;
rkyv_same_type_isometry_matrix3, IsometryMatrix3;
rkyv_same_type_similarity3, Similarity3;
rkyv_same_type_similarity_matrix3, SimilarityMatrix3;
rkyv_same_type_quaternion, Quaternion;
rkyv_same_type_point2, Point2;
rkyv_same_type_translation2, Translation2;
rkyv_same_type_rotation2, Rotation2;
rkyv_same_type_isometry2, Isometry2;
rkyv_same_type_isometry_matrix2, IsometryMatrix2;
rkyv_same_type_similarity2, Similarity2;
rkyv_same_type_similarity_matrix2, SimilarityMatrix2;
); );
test_rkyv!( test_rkyv_diff_type! {
// rkyv_point3, Point3; rkyv_diff_type_matrix3x4, Matrix3x4;
rkyv_translation3, Translation3; }
/* rkyv_rotation3, Rotation3;
rkyv_isometry3, Isometry3;
rkyv_isometry_matrix3, IsometryMatrix3;
rkyv_similarity3, Similarity3;
rkyv_similarity_matrix3, SimilarityMatrix3;
rkyv_quaternion, Quaternion; */
// rkyv_point2, Point2;
rkyv_translation2, Translation2;
/* rkyv_rotation2, Rotation2;
rkyv_isometry2, Isometry2;
rkyv_isometry_matrix2, IsometryMatrix2;
rkyv_similarity2, Similarity2;
rkyv_similarity_matrix2, SimilarityMatrix2; */
);