unitforge 0.3.15__tar.gz → 0.3.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {unitforge-0.3.15 → unitforge-0.3.16}/Cargo.lock +2 -2
  2. {unitforge-0.3.15 → unitforge-0.3.16}/Cargo.toml +2 -2
  3. {unitforge-0.3.15 → unitforge-0.3.16}/PKG-INFO +1 -1
  4. {unitforge-0.3.15 → unitforge-0.3.16}/src/impl_macros.rs +5 -28
  5. {unitforge-0.3.15 → unitforge-0.3.16}/src/tests/quantity_unit_tests.rs +0 -16
  6. {unitforge-0.3.15 → unitforge-0.3.16}/unitforge_macros/Cargo.toml +1 -1
  7. {unitforge-0.3.15 → unitforge-0.3.16}/unitforge_macros/src/lib.rs +11 -8
  8. {unitforge-0.3.15 → unitforge-0.3.16}/.gitignore +0 -0
  9. {unitforge-0.3.15 → unitforge-0.3.16}/.gitlab-ci.yml +0 -0
  10. {unitforge-0.3.15 → unitforge-0.3.16}/Readme.md +0 -0
  11. {unitforge-0.3.15 → unitforge-0.3.16}/Readme_py.md +0 -0
  12. {unitforge-0.3.15 → unitforge-0.3.16}/pyproject.toml +0 -0
  13. {unitforge-0.3.15 → unitforge-0.3.16}/python/unitforge/__init__.py +0 -0
  14. {unitforge-0.3.15 → unitforge-0.3.16}/scripts/generate_python_stubs.py +0 -0
  15. {unitforge-0.3.15 → unitforge-0.3.16}/src/lib.rs +0 -0
  16. {unitforge-0.3.15 → unitforge-0.3.16}/src/prelude.rs +0 -0
  17. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/acceleration.rs +0 -0
  18. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/angle.rs +0 -0
  19. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/angular_acceleration.rs +0 -0
  20. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/angular_velocity.rs +0 -0
  21. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/area.rs +0 -0
  22. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/area_of_moment.rs +0 -0
  23. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/charge.rs +0 -0
  24. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/compliance.rs +0 -0
  25. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/density.rs +0 -0
  26. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/distance.rs +0 -0
  27. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force.rs +0 -0
  28. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_area.rs +0 -0
  29. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_distance.rs +0 -0
  30. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_div_distance_power_four.rs +0 -0
  31. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_per_volume.rs +0 -0
  32. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_stress.rs +0 -0
  33. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/force_volume.rs +0 -0
  34. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/inverse_area.rs +0 -0
  35. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/inverse_distance.rs +0 -0
  36. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/inverse_stress.rs +0 -0
  37. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/mass.rs +0 -0
  38. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/mass_div_time_squared_volume.rs +0 -0
  39. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/mass_per_distance.rs +0 -0
  40. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/rotational_stiffness.rs +0 -0
  41. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/stiffness.rs +0 -0
  42. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/strain.rs +0 -0
  43. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/stress.rs +0 -0
  44. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/stress_squared.rs +0 -0
  45. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/time.rs +0 -0
  46. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/velocity.rs +0 -0
  47. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/velocity_squared.rs +0 -0
  48. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/voltage.rs +0 -0
  49. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities/volume.rs +0 -0
  50. {unitforge-0.3.15 → unitforge-0.3.16}/src/quantities.template.rs +0 -0
  51. {unitforge-0.3.15 → unitforge-0.3.16}/src/relations.rs +0 -0
  52. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/bindings/matrix3_py.template.rs +0 -0
  53. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/bindings/vector3_py.template.rs +0 -0
  54. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/matrix2.rs +0 -0
  55. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/matrix2x3.rs +0 -0
  56. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/matrix3.rs +0 -0
  57. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/matrix3x2.rs +0 -0
  58. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/vector2.rs +0 -0
  59. {unitforge-0.3.15 → unitforge-0.3.16}/src/small_linalg/vector3.rs +0 -0
  60. {unitforge-0.3.15 → unitforge-0.3.16}/src/tests/serde_tests.rs +0 -0
  61. {unitforge-0.3.15 → unitforge-0.3.16}/tests/matrix2.rs +0 -0
  62. {unitforge-0.3.15 → unitforge-0.3.16}/tests/matrix2x3.rs +0 -0
  63. {unitforge-0.3.15 → unitforge-0.3.16}/tests/matrix3.rs +0 -0
  64. {unitforge-0.3.15 → unitforge-0.3.16}/tests/matrix3x2.rs +0 -0
  65. {unitforge-0.3.15 → unitforge-0.3.16}/tests/ndarray_dot.rs +0 -0
  66. {unitforge-0.3.15 → unitforge-0.3.16}/tests/quantities.rs +0 -0
  67. {unitforge-0.3.15 → unitforge-0.3.16}/tests/small_linalg_interfaces.rs +0 -0
  68. {unitforge-0.3.15 → unitforge-0.3.16}/tests/test_quantities.py +0 -0
  69. {unitforge-0.3.15 → unitforge-0.3.16}/tests/test_small_linalg.py +0 -0
  70. {unitforge-0.3.15 → unitforge-0.3.16}/tests/typecheck/mypy_smoke.py +0 -0
  71. {unitforge-0.3.15 → unitforge-0.3.16}/tests/vector2.rs +0 -0
  72. {unitforge-0.3.15 → unitforge-0.3.16}/tests/vector3.rs +0 -0
@@ -369,7 +369,7 @@ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
369
369
 
370
370
  [[package]]
371
371
  name = "unitforge"
372
- version = "0.3.15"
372
+ version = "0.3.16"
373
373
  dependencies = [
374
374
  "ndarray",
375
375
  "num-traits",
@@ -384,7 +384,7 @@ dependencies = [
384
384
 
385
385
  [[package]]
386
386
  name = "unitforge_macros"
387
- version = "0.3.15"
387
+ version = "0.3.16"
388
388
  dependencies = [
389
389
  "regex",
390
390
  ]
@@ -4,7 +4,7 @@ crate-type = ["cdylib", "rlib"]
4
4
 
5
5
  [package]
6
6
  name = "unitforge"
7
- version = "0.3.15"
7
+ version = "0.3.16"
8
8
  edition = "2021"
9
9
  authors = ["Dr.Q team <info@askdrq.com>", "Henrik Stromberg <henrik@askdrq.com>"]
10
10
  description = "A library for unit and quantity consistent computations in Rust"
@@ -23,7 +23,7 @@ pyo3 = { version = "0.26.0", features = ["extension-module", "auto-initialize",
23
23
  numpy = { version = "0.26.0", optional = true }
24
24
  strum = { version = "0.28.0", optional = true }
25
25
  strum_macros = { version = "0.28.0", optional = true }
26
- unitforge_macros = { version = "0.3.15", path = "unitforge_macros" }
26
+ unitforge_macros = { version = "0.3.16", path = "unitforge_macros" }
27
27
 
28
28
  [features]
29
29
  serde = ["dep:serde", "dep:serde_json", "ndarray/serde"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitforge
3
- Version: 0.3.15
3
+ Version: 0.3.16
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -3,11 +3,11 @@ macro_rules! impl_quantity {
3
3
  ($type:ident, $unit:ident, $display_units:expr) => {
4
4
  use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
5
5
  use num_traits::Zero;
6
- use std::collections::HashSet;
7
6
  use num_traits::{Float, FromPrimitive};
8
7
  #[cfg(feature = "serde")]
9
8
  use serde::{Deserialize, Serialize};
10
9
  use std::cmp::Ordering;
10
+ use std::collections::HashSet;
11
11
  use std::fmt;
12
12
  use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
13
13
  use $crate::prelude::*;
@@ -20,8 +20,6 @@ macro_rules! impl_quantity {
20
20
  IntoPyObject, Py, PyAny, PyRef, PyResult,
21
21
  };
22
22
 
23
- #[cfg(feature = "strum")]
24
- use strum::IntoEnumIterator;
25
23
  #[cfg(feature = "strum")]
26
24
  use strum_macros::EnumIter;
27
25
  use $crate::small_linalg::{Matrix3, Vector3};
@@ -594,35 +592,14 @@ macro_rules! impl_quantity {
594
592
  }
595
593
  }
596
594
 
597
- #[cfg(feature = "strum")]
598
- impl $type {
599
- pub fn optimal_unit(
600
- &self,
601
- choices: impl Into<Option<HashSet<$unit>>>,
602
- ) -> Option<$unit> {
603
- let choices = choices.into().unwrap_or_else(|| $unit::iter().collect());
604
- let mut min_value = f64::INFINITY;
605
- let mut best_unit = None;
606
- for unit in choices {
607
- let deviation = (self.to(unit).abs() - 1.).abs();
608
- if deviation < min_value {
609
- min_value = deviation;
610
- best_unit = Some(unit);
611
- }
612
- }
613
- best_unit
614
- }
615
- }
616
-
617
- #[cfg(not(feature = "strum"))]
618
595
  impl $type {
619
596
  pub fn optimal_unit(&self, choices: HashSet<$unit>) -> Option<$unit> {
620
- let mut min_value = f64::INFINITY;
597
+ let mut min_value = i32::MAX;
621
598
  let mut best_unit = None;
622
599
  for unit in choices {
623
- let deviation = (self.to(unit).abs() - 1.).abs();
624
- if deviation < min_value {
625
- min_value = deviation;
600
+ let difference = (self.power - unit.base_per_x().1).abs();
601
+ if difference < min_value {
602
+ min_value = difference;
626
603
  best_unit = Some(unit);
627
604
  }
628
605
  }
@@ -101,22 +101,6 @@ mod tests {
101
101
  assert!((result.to(ForceStressUnit::Nsq_msq) - 6.0).abs() < 1E-12);
102
102
  }
103
103
 
104
- #[cfg(feature = "strum")]
105
- #[test]
106
- fn test_optimal_unit() {
107
- let area = Area::new(0.0001, AreaUnit::msq);
108
- let optimal_unit = area.optimal_unit(None).unwrap();
109
- assert_eq!(optimal_unit, AreaUnit::cmsq)
110
- }
111
-
112
- #[cfg(feature = "strum")]
113
- #[test]
114
- fn test_optimal_unit_with_selection_strum() {
115
- let area = Area::new(0.0001, AreaUnit::msq);
116
- let optimal_unit = area.optimal_unit(Some(vec![AreaUnit::kmsq, AreaUnit::cmsq, AreaUnit::nmsq].into_iter().collect())).unwrap();
117
- assert_eq!(optimal_unit, AreaUnit::cmsq)
118
- }
119
-
120
104
  #[test]
121
105
  fn test_optimal_unit_with_selection() {
122
106
  let area = Area::new(0.0001, AreaUnit::msq);
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "unitforge_macros"
3
- version = "0.3.15"
3
+ version = "0.3.16"
4
4
  edition = "2021"
5
5
  authors = ["Dr.Q team <info@askdrq.com>", "Henrik Stromberg <henrik@askdrq.com>"]
6
6
  description = "Proc macros for generating units, quantities, and Python bindings in unitforge"
@@ -241,7 +241,9 @@ fn parse_unit_variants(files: &[String], unit_name: &str) -> Result<Vec<String>,
241
241
  }
242
242
  }
243
243
 
244
- Err(format!("Enum {unit_name} not found in quantity source files"))
244
+ Err(format!(
245
+ "Enum {unit_name} not found in quantity source files"
246
+ ))
245
247
  }
246
248
 
247
249
  fn fnv1a32(input: &str) -> u32 {
@@ -443,12 +445,10 @@ fn write_quantity_code(
443
445
  let mut id_to_variant_match = String::new();
444
446
  for variant_name in unit_variant_list {
445
447
  let variant_id = stable_unit_variant_id(&unit_name, variant_name);
446
- variant_to_id_match += &format!(
447
- " {struct_name}Unit::{variant_name} => {variant_id},\n"
448
- );
449
- id_to_variant_match += &format!(
450
- " {variant_id} => Some({struct_name}Unit::{variant_name}),\n"
451
- );
448
+ variant_to_id_match +=
449
+ &format!(" {struct_name}Unit::{variant_name} => {variant_id},\n");
450
+ id_to_variant_match +=
451
+ &format!(" {variant_id} => Some({struct_name}Unit::{variant_name}),\n");
452
452
  }
453
453
  unit_variant_id_impls += &format!(
454
454
  "impl pyo3_capsule_api::UnitVariantId for {struct_name}Unit {{\n fn to_variant_id(self) -> i32 {{\n match self {{\n{variant_to_id_match} }}\n }}\n fn from_variant_id(variant_id: i32) -> Option<Self> {{\n match variant_id {{\n{id_to_variant_match} _ => None,\n }}\n }}\n}}\n"
@@ -559,7 +559,10 @@ fn write_quantity_code(
559
559
  .replace("// __UNIT_KIND_ID_IMPLS__", &unit_kind_id_impls)
560
560
  .replace("// __UNIT_VARIANT_ID_IMPLS__", &unit_variant_id_impls)
561
561
  .replace("// __QUANTITY_TO_REPR_MATCHES__", &quantity_to_repr_matches)
562
- .replace("// __QUANTITY_FROM_REPR_MATCHES__", &quantity_from_repr_matches)
562
+ .replace(
563
+ "// __QUANTITY_FROM_REPR_MATCHES__",
564
+ &quantity_from_repr_matches,
565
+ )
563
566
  .replace("// __UNIT_TO_REPR_MATCHES__", &unit_to_repr_matches)
564
567
  .replace("// __UNIT_FROM_REPR_MATCHES__", &unit_from_repr_matches)
565
568
  .replace("// __UNIT_TO_PYOBJECT_MATCHES__", &unit_to_pyobject_matches))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes