unitforge 0.4.1__tar.gz → 0.4.3__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 (100) hide show
  1. unitforge-0.4.3/.gitlab-ci.yml +137 -0
  2. {unitforge-0.4.1 → unitforge-0.4.3}/Cargo.lock +21 -38
  3. {unitforge-0.4.1 → unitforge-0.4.3}/Cargo.toml +17 -8
  4. {unitforge-0.4.1 → unitforge-0.4.3}/PKG-INFO +3 -1
  5. {unitforge-0.4.1 → unitforge-0.4.3}/Readme.md +2 -2
  6. {unitforge-0.4.1 → unitforge-0.4.3}/install_hooks.sh +0 -0
  7. unitforge-0.4.3/src/errors.rs +159 -0
  8. unitforge-0.4.3/src/impl_macros.rs +1457 -0
  9. unitforge-0.4.3/src/internal.rs +264 -0
  10. {unitforge-0.4.1 → unitforge-0.4.3}/src/lib.rs +79 -2
  11. {unitforge-0.4.1 → unitforge-0.4.3}/src/prelude.rs +24 -3
  12. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/acceleration.rs +15 -9
  13. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/angle.rs +21 -9
  14. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/angular_acceleration.rs +12 -6
  15. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/angular_velocity.rs +12 -6
  16. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/area.rs +20 -14
  17. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/area_of_moment.rs +10 -4
  18. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/charge.rs +11 -5
  19. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/compliance.rs +10 -4
  20. unitforge-0.4.3/src/quantities/density.rs +128 -0
  21. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/distance.rs +35 -29
  22. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force.rs +20 -14
  23. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_area.rs +10 -4
  24. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_distance.rs +25 -20
  25. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_div_distance_power_four.rs +11 -5
  26. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_per_volume.rs +11 -5
  27. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_stress.rs +10 -4
  28. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/force_volume.rs +10 -4
  29. unitforge-0.4.3/src/quantities/frequency.rs +77 -0
  30. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/inverse_angle.rs +10 -4
  31. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/inverse_area.rs +10 -4
  32. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/inverse_distance.rs +20 -14
  33. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/inverse_stress.rs +10 -4
  34. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/mass.rs +34 -39
  35. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/mass_per_distance.rs +10 -4
  36. unitforge-0.4.3/src/quantities/molar_mass.rs +38 -0
  37. unitforge-0.4.3/src/quantities/pressure_rate.rs +47 -0
  38. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/rotational_stiffness.rs +11 -5
  39. unitforge-0.4.3/src/quantities/specific_gas_constant.rs +39 -0
  40. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/stiffness.rs +13 -7
  41. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/strain.rs +14 -9
  42. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/stress.rs +15 -9
  43. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/stress_squared.rs +10 -4
  44. unitforge-0.4.3/src/quantities/temperature.rs +38 -0
  45. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/time.rs +30 -13
  46. unitforge-0.4.3/src/quantities/universal_gas_constant.rs +41 -0
  47. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/velocity.rs +15 -9
  48. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/velocity_squared.rs +17 -5
  49. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/voltage.rs +14 -8
  50. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities/volume.rs +20 -14
  51. {unitforge-0.4.1 → unitforge-0.4.3}/src/quantities.template.rs +82 -87
  52. {unitforge-0.4.1 → unitforge-0.4.3}/src/relations.rs +8 -2
  53. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/bindings/matrix3_py.template.rs +12 -10
  54. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/bindings/vector3_py.template.rs +3 -3
  55. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/matrix2.rs +20 -9
  56. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/matrix2x3.rs +16 -5
  57. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/matrix3.rs +25 -12
  58. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/matrix3x2.rs +16 -5
  59. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/vector2.rs +18 -8
  60. {unitforge-0.4.1 → unitforge-0.4.3}/src/small_linalg/vector3.rs +19 -12
  61. {unitforge-0.4.1 → unitforge-0.4.3}/test.sh +124 -18
  62. {unitforge-0.4.1 → unitforge-0.4.3}/tests/matrix2.rs +3 -0
  63. {unitforge-0.4.1 → unitforge-0.4.3}/tests/matrix2x3.rs +10 -2
  64. {unitforge-0.4.1 → unitforge-0.4.3}/tests/matrix3.rs +11 -2
  65. {unitforge-0.4.1 → unitforge-0.4.3}/tests/matrix3x2.rs +10 -2
  66. {unitforge-0.4.1 → unitforge-0.4.3}/tests/ndarray_dot.rs +2 -0
  67. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantities.rs +215 -18
  68. unitforge-0.4.3/tests/quantity_core/constants.rs +109 -0
  69. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/construction.rs +2 -0
  70. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/metadata.rs +20 -2
  71. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/normalization.rs +1 -1
  72. unitforge-0.4.3/tests/quantity_core/plain_storage.rs +34 -0
  73. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/relations.rs +13 -5
  74. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/runtime_quantity.rs +13 -5
  75. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/scalar_edges.rs +4 -0
  76. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core.rs +6 -0
  77. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_serde.rs +40 -3
  78. {unitforge-0.4.1 → unitforge-0.4.3}/tests/small_linalg_edge_cases.rs +56 -9
  79. {unitforge-0.4.1 → unitforge-0.4.3}/tests/small_linalg_interfaces.rs +2 -2
  80. {unitforge-0.4.1 → unitforge-0.4.3}/tests/vector2.rs +18 -3
  81. {unitforge-0.4.1 → unitforge-0.4.3}/tests/vector3.rs +3 -0
  82. {unitforge-0.4.1 → unitforge-0.4.3}/unitforge_macros/Cargo.toml +1 -1
  83. {unitforge-0.4.1 → unitforge-0.4.3}/unitforge_macros/src/lib.rs +6 -6
  84. unitforge-0.4.1/.gitlab-ci.yml +0 -43
  85. unitforge-0.4.1/python/unitforge/__init__.pyi +0 -1776
  86. unitforge-0.4.1/python/unitforge/py.typed +0 -0
  87. unitforge-0.4.1/src/impl_macros.rs +0 -1000
  88. unitforge-0.4.1/src/internal.rs +0 -55
  89. unitforge-0.4.1/src/quantities/density.rs +0 -122
  90. unitforge-0.4.1/src/quantities/mass_div_time_squared_volume.rs +0 -30
  91. {unitforge-0.4.1 → unitforge-0.4.3}/.gitignore +0 -0
  92. {unitforge-0.4.1 → unitforge-0.4.3}/Readme_py.md +0 -0
  93. {unitforge-0.4.1 → unitforge-0.4.3}/pyproject.toml +0 -0
  94. {unitforge-0.4.1 → unitforge-0.4.3}/python/unitforge/__init__.py +0 -0
  95. {unitforge-0.4.1 → unitforge-0.4.3}/scripts/generate_python_stubs.py +0 -0
  96. {unitforge-0.4.1 → unitforge-0.4.3}/tests/common/mod.rs +0 -0
  97. {unitforge-0.4.1 → unitforge-0.4.3}/tests/quantity_core/enum_iter.rs +0 -0
  98. {unitforge-0.4.1 → unitforge-0.4.3}/tests/test_quantities.py +0 -0
  99. {unitforge-0.4.1 → unitforge-0.4.3}/tests/test_small_linalg.py +0 -0
  100. {unitforge-0.4.1 → unitforge-0.4.3}/tests/typecheck/mypy_smoke.py +0 -0
@@ -0,0 +1,137 @@
1
+ image: "rust:latest"
2
+
3
+ stages:
4
+ - lint
5
+ - test
6
+ - python
7
+
8
+ variables:
9
+ CARGO_TERM_COLOR: always
10
+ PIP_DISABLE_PIP_VERSION_CHECK: "1"
11
+
12
+ .default_rust:
13
+ before_script:
14
+ - rustc --version
15
+ - cargo --version
16
+
17
+ .default_python:
18
+ before_script:
19
+ - apt-get update
20
+ - apt-get install -y python3 python3-venv python3-dev pkg-config
21
+ - python3 --version
22
+
23
+ # --------------------
24
+ # LINT
25
+ # --------------------
26
+
27
+ lint:
28
+ stage: lint
29
+ extends: .default_rust
30
+ script:
31
+ - ./test.sh lint-base
32
+ allow_failure: true
33
+
34
+ lint_serde:
35
+ stage: lint
36
+ extends: .default_rust
37
+ script:
38
+ - ./test.sh lint-serde
39
+ allow_failure: true
40
+
41
+ lint_strum:
42
+ stage: lint
43
+ extends: .default_rust
44
+ script:
45
+ - ./test.sh lint-strum
46
+ allow_failure: true
47
+
48
+ lint_pyo3:
49
+ stage: lint
50
+ extends: .default_rust
51
+ script:
52
+ - ./test.sh lint-pyo3
53
+ allow_failure: true
54
+
55
+ # --------------------
56
+ # RUST TESTS
57
+ # --------------------
58
+
59
+ test_base:
60
+ stage: test
61
+ extends: .default_rust
62
+ script:
63
+ - ./test.sh test-base
64
+
65
+ test_serde:
66
+ stage: test
67
+ extends: .default_rust
68
+ script:
69
+ - ./test.sh test-serde
70
+
71
+ test_strum:
72
+ stage: test
73
+ extends: .default_rust
74
+ script:
75
+ - ./test.sh test-strum
76
+
77
+ test_no_ndarray:
78
+ stage: test
79
+ extends: .default_rust
80
+ script:
81
+ - ./test.sh test-no-ndarray
82
+
83
+ test_serde_no_ndarray:
84
+ stage: test
85
+ extends: .default_rust
86
+ script:
87
+ - ./test.sh test-serde-no-ndarray
88
+
89
+ test_strum_no_ndarray:
90
+ stage: test
91
+ extends: .default_rust
92
+ script:
93
+ - ./test.sh test-strum-no-ndarray
94
+
95
+ test_plain_f64:
96
+ stage: test
97
+ extends: .default_rust
98
+ script:
99
+ - ./test.sh test-plain-f64
100
+
101
+ test_plain_f64_serde:
102
+ stage: test
103
+ extends: .default_rust
104
+ script:
105
+ - ./test.sh test-plain-f64-serde
106
+
107
+ test_plain_f32:
108
+ stage: test
109
+ extends: .default_rust
110
+ script:
111
+ - ./test.sh test-plain-f32
112
+
113
+ test_plain_f32_serde:
114
+ stage: test
115
+ extends: .default_rust
116
+ script:
117
+ - ./test.sh test-plain-f32-serde
118
+
119
+ # --------------------
120
+ # PYTHON / PYO3
121
+ # --------------------
122
+
123
+ test_pyo3:
124
+ stage: python
125
+ extends:
126
+ - .default_rust
127
+ - .default_python
128
+ script:
129
+ - ./test.sh test-pyo3
130
+
131
+ typecheck_pyo3:
132
+ stage: python
133
+ extends:
134
+ - .default_rust
135
+ - .default_python
136
+ script:
137
+ - ./test.sh typecheck-pyo3
@@ -23,12 +23,6 @@ version = "0.5.0"
23
23
  source = "registry+https://github.com/rust-lang/crates.io-index"
24
24
  checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
25
25
 
26
- [[package]]
27
- name = "indoc"
28
- version = "2.0.6"
29
- source = "registry+https://github.com/rust-lang/crates.io-index"
30
- checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
31
-
32
26
  [[package]]
33
27
  name = "inventory"
34
28
  version = "0.3.20"
@@ -66,15 +60,6 @@ version = "2.7.4"
66
60
  source = "registry+https://github.com/rust-lang/crates.io-index"
67
61
  checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
68
62
 
69
- [[package]]
70
- name = "memoffset"
71
- version = "0.9.1"
72
- source = "registry+https://github.com/rust-lang/crates.io-index"
73
- checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
74
- dependencies = [
75
- "autocfg",
76
- ]
77
-
78
63
  [[package]]
79
64
  name = "ndarray"
80
65
  version = "0.16.1"
@@ -120,9 +105,9 @@ dependencies = [
120
105
 
121
106
  [[package]]
122
107
  name = "numpy"
123
- version = "0.26.0"
108
+ version = "0.28.0"
124
109
  source = "registry+https://github.com/rust-lang/crates.io-index"
125
- checksum = "9b2dba356160b54f5371b550575b78130a54718b4c6e46b3f33a6da74a27e78b"
110
+ checksum = "778da78c64ddc928ebf5ad9df5edf0789410ff3bdbf3619aed51cd789a6af1e2"
126
111
  dependencies = [
127
112
  "libc",
128
113
  "ndarray",
@@ -140,6 +125,12 @@ version = "1.21.3"
140
125
  source = "registry+https://github.com/rust-lang/crates.io-index"
141
126
  checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
142
127
 
128
+ [[package]]
129
+ name = "paste"
130
+ version = "1.0.15"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
133
+
143
134
  [[package]]
144
135
  name = "portable-atomic"
145
136
  version = "1.10.0"
@@ -166,36 +157,33 @@ dependencies = [
166
157
 
167
158
  [[package]]
168
159
  name = "pyo3"
169
- version = "0.26.0"
160
+ version = "0.28.3"
170
161
  source = "registry+https://github.com/rust-lang/crates.io-index"
171
- checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383"
162
+ checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
172
163
  dependencies = [
173
- "indoc",
174
164
  "inventory",
175
165
  "libc",
176
- "memoffset",
177
166
  "once_cell",
178
167
  "portable-atomic",
179
168
  "pyo3-build-config",
180
169
  "pyo3-ffi",
181
170
  "pyo3-macros",
182
- "unindent",
183
171
  ]
184
172
 
185
173
  [[package]]
186
174
  name = "pyo3-build-config"
187
- version = "0.26.0"
175
+ version = "0.28.3"
188
176
  source = "registry+https://github.com/rust-lang/crates.io-index"
189
- checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f"
177
+ checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
190
178
  dependencies = [
191
179
  "target-lexicon",
192
180
  ]
193
181
 
194
182
  [[package]]
195
183
  name = "pyo3-ffi"
196
- version = "0.26.0"
184
+ version = "0.28.3"
197
185
  source = "registry+https://github.com/rust-lang/crates.io-index"
198
- checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105"
186
+ checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
199
187
  dependencies = [
200
188
  "libc",
201
189
  "pyo3-build-config",
@@ -203,9 +191,9 @@ dependencies = [
203
191
 
204
192
  [[package]]
205
193
  name = "pyo3-macros"
206
- version = "0.26.0"
194
+ version = "0.28.3"
207
195
  source = "registry+https://github.com/rust-lang/crates.io-index"
208
- checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded"
196
+ checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
209
197
  dependencies = [
210
198
  "proc-macro2",
211
199
  "pyo3-macros-backend",
@@ -215,9 +203,9 @@ dependencies = [
215
203
 
216
204
  [[package]]
217
205
  name = "pyo3-macros-backend"
218
- version = "0.26.0"
206
+ version = "0.28.3"
219
207
  source = "registry+https://github.com/rust-lang/crates.io-index"
220
- checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf"
208
+ checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
221
209
  dependencies = [
222
210
  "heck",
223
211
  "proc-macro2",
@@ -361,19 +349,14 @@ version = "1.0.18"
361
349
  source = "registry+https://github.com/rust-lang/crates.io-index"
362
350
  checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
363
351
 
364
- [[package]]
365
- name = "unindent"
366
- version = "0.2.4"
367
- source = "registry+https://github.com/rust-lang/crates.io-index"
368
- checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
369
-
370
352
  [[package]]
371
353
  name = "unitforge"
372
- version = "0.4.1"
354
+ version = "0.4.3"
373
355
  dependencies = [
374
356
  "ndarray",
375
357
  "num-traits",
376
358
  "numpy",
359
+ "paste",
377
360
  "pyo3",
378
361
  "serde",
379
362
  "serde_json",
@@ -384,7 +367,7 @@ dependencies = [
384
367
 
385
368
  [[package]]
386
369
  name = "unitforge_macros"
387
- version = "0.4.1"
370
+ version = "0.4.3"
388
371
  dependencies = [
389
372
  "regex",
390
373
  ]
@@ -4,7 +4,7 @@ crate-type = ["cdylib", "rlib"]
4
4
 
5
5
  [package]
6
6
  name = "unitforge"
7
- version = "0.4.1"
7
+ version = "0.4.3"
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"
@@ -15,20 +15,29 @@ readme = "Readme.md"
15
15
  # ToDo: documentation
16
16
 
17
17
  [dependencies]
18
- ndarray = { version = "0.16" }
19
- num-traits = "0.2.19"
18
+ ndarray = { version = "0.16", optional = true }
19
+ num-traits = { version = "0.2.19", default-features = false }
20
+ paste = "1.0.15"
20
21
  serde = { version = "1", optional = true, features = ["derive"] }
21
22
  serde_json = { version = "1.0.140", optional = true }
22
- pyo3 = { version = "0.26.0", features = ["extension-module", "auto-initialize", "multiple-pymethods"], optional = true }
23
- numpy = { version = "0.26.0", optional = true }
23
+ pyo3 = { version = "0.28.3", features = ["extension-module", "auto-initialize", "multiple-pymethods"], optional = true }
24
+ numpy = { version = "0.28.0", optional = true }
24
25
  strum = { version = "0.28.0", optional = true }
25
26
  strum_macros = { version = "0.28.0", optional = true }
26
- unitforge_macros = { version = "0.4.1", path = "unitforge_macros" }
27
+ unitforge_macros = { version = "0.4.3", path = "unitforge_macros" }
27
28
 
28
29
  [features]
29
- serde = ["dep:serde", "dep:serde_json", "ndarray/serde"]
30
- pyo3 = ["dep:pyo3", "dep:numpy"]
30
+ default = []
31
+ ndarray = ["dep:ndarray"]
32
+ serde = ["dep:serde", "dep:serde_json", "ndarray?/serde"]
33
+ pyo3 = ["dep:pyo3", "dep:numpy", "ndarray"]
31
34
  strum = ["dep:strum", "dep:strum_macros"]
35
+ storage-f64 = []
36
+ storage-f32 = []
37
+ no_std = []
32
38
 
33
39
  [workspace]
34
40
  members = ["unitforge_macros"]
41
+
42
+ [profile.dev]
43
+ panic = "abort"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitforge
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -9,7 +9,9 @@ Classifier: Topic :: Scientific/Engineering :: Physics
9
9
  Requires-Dist: numpy>=2.2.0
10
10
  Summary: A library for unit and quantity consistent computations in Rust
11
11
  Keywords: units,quantities,simulation,physics
12
+ Author: Dr.Q team <info@askdrq.com>, Henrik Stromberg <henrik@askdrq.com>
12
13
  Author-email: "Dr.Q team" <info@askdrq.com>, Henrik Stromberg <henrik@askdrq.com>
14
+ License: MIT
13
15
  Requires-Python: >=3.7
14
16
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
17
  Project-URL: Repository, https://gitlab.com/henrikjstromberg/unitforge
@@ -10,9 +10,9 @@
10
10
  - **Unit conversion:** Quantities can be set or read in arbitrary units.
11
11
  - **Computing Precision** Values are stored in exponential format (f64*10^i32) to prevent floating point precision issues.
12
12
  - **Formating** Quantities are displayed with 4 significant digits and configured display unit.
13
- - **ndarray support:** Quantities may be used as inner types for `ndarray`.
13
+ - **ndarray support:** Optional `ndarray` integration with `features = ["ndarray"]`; quantities may be used as inner types for arrays.
14
14
  - **3D Vector and matrix operations:** Structs for 3D vectors and matrices are included to allow fast and unit-safe work with them.
15
- - **Serialization**: Optional support for sere using the serde feature.
15
+ - **Serialization**: Optional support for serde using `features = ["serde"]`; combine with `ndarray` for ndarray serialization support.
16
16
  - **python interface** Optional Python interface when building with flag pyo3; also available on pypi
17
17
 
18
18
  ## Contribute
File without changes
@@ -0,0 +1,159 @@
1
+ use core::fmt;
2
+
3
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
4
+ pub enum UnitforgeError {
5
+ QuantityConversion(QuantityConversionError),
6
+ QuantityOperation(QuantityOperationError),
7
+ Linalg(LinalgError),
8
+ }
9
+
10
+ pub type UnitforgeResult<T> = Result<T, UnitforgeError>;
11
+
12
+ impl fmt::Display for UnitforgeError {
13
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14
+ match self {
15
+ UnitforgeError::QuantityConversion(err) => err.fmt(f),
16
+ UnitforgeError::QuantityOperation(err) => err.fmt(f),
17
+ UnitforgeError::Linalg(err) => err.fmt(f),
18
+ }
19
+ }
20
+ }
21
+
22
+ impl From<QuantityConversionError> for UnitforgeError {
23
+ fn from(value: QuantityConversionError) -> Self {
24
+ UnitforgeError::QuantityConversion(value)
25
+ }
26
+ }
27
+
28
+ impl From<QuantityOperationError> for UnitforgeError {
29
+ fn from(value: QuantityOperationError) -> Self {
30
+ UnitforgeError::QuantityOperation(value)
31
+ }
32
+ }
33
+
34
+ impl From<LinalgError> for UnitforgeError {
35
+ fn from(value: LinalgError) -> Self {
36
+ UnitforgeError::Linalg(value)
37
+ }
38
+ }
39
+
40
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
41
+ pub enum QuantityConversionError {
42
+ InvalidQuantityUnitPair,
43
+ InvalidQuantityExtraction,
44
+ InvalidPythonQuantity,
45
+ InvalidPythonUnit,
46
+ UnknownQuantityKindId { kind_id: u32 },
47
+ UnknownUnitKindId { kind_id: u32 },
48
+ UnknownUnitVariantId { kind_id: u32, variant_id: i32 },
49
+ }
50
+
51
+ pub type QuantityConversionResult<T> = Result<T, QuantityConversionError>;
52
+
53
+ impl fmt::Display for QuantityConversionError {
54
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55
+ match self {
56
+ QuantityConversionError::InvalidQuantityUnitPair => {
57
+ write!(f, "Cannot use given pair of quantity and unit")
58
+ }
59
+ QuantityConversionError::InvalidQuantityExtraction => {
60
+ write!(f, "Cannot extract requested quantity type")
61
+ }
62
+ QuantityConversionError::InvalidPythonQuantity => {
63
+ write!(f, "Cannot interpret given value as Quantity")
64
+ }
65
+ QuantityConversionError::InvalidPythonUnit => {
66
+ write!(f, "Cannot interpret given value as Unit")
67
+ }
68
+ QuantityConversionError::UnknownQuantityKindId { kind_id } => {
69
+ write!(f, "Unknown quantity kind id: {kind_id}")
70
+ }
71
+ QuantityConversionError::UnknownUnitKindId { kind_id } => {
72
+ write!(f, "Unknown unit kind id: {kind_id}")
73
+ }
74
+ QuantityConversionError::UnknownUnitVariantId {
75
+ kind_id,
76
+ variant_id,
77
+ } => write!(
78
+ f,
79
+ "Unknown unit variant id {variant_id} for unit kind id {kind_id}"
80
+ ),
81
+ }
82
+ }
83
+ }
84
+
85
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
86
+ pub enum QuantityOperationError {
87
+ AddError,
88
+ SubError,
89
+ MulError,
90
+ DivError,
91
+ PowError,
92
+ SqrtError,
93
+ ComparisonError,
94
+ }
95
+
96
+ pub type QuantityOperationResult<T> = Result<T, QuantityOperationError>;
97
+
98
+ impl fmt::Display for QuantityOperationError {
99
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100
+ match self {
101
+ QuantityOperationError::AddError => write!(f, "Addition operation failed"),
102
+ QuantityOperationError::SubError => write!(f, "Subtraction operation failed"),
103
+ QuantityOperationError::MulError => write!(f, "Multiplication operation failed"),
104
+ QuantityOperationError::DivError => write!(f, "Division operation failed"),
105
+ QuantityOperationError::PowError => write!(f, "Power operation failed"),
106
+ QuantityOperationError::SqrtError => write!(f, "Sqrt operation failed"),
107
+ QuantityOperationError::ComparisonError => write!(f, "Comparison operation failed"),
108
+ }
109
+ }
110
+ }
111
+
112
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
113
+ pub enum LinalgShape {
114
+ Vector { len: usize },
115
+ Matrix { rows: usize, cols: usize },
116
+ }
117
+
118
+ impl fmt::Display for LinalgShape {
119
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120
+ match self {
121
+ LinalgShape::Vector { len } => write!(f, "vector length {len}"),
122
+ LinalgShape::Matrix { rows, cols } => write!(f, "matrix shape {rows}x{cols}"),
123
+ }
124
+ }
125
+ }
126
+
127
+ #[derive(Clone, Copy, Debug, Eq, PartialEq)]
128
+ pub enum LinalgError {
129
+ ShapeMismatch {
130
+ expected: LinalgShape,
131
+ actual: LinalgShape,
132
+ },
133
+ ShapeConstructionFailed,
134
+ }
135
+
136
+ pub type LinalgResult<T> = Result<T, LinalgError>;
137
+
138
+ impl fmt::Display for LinalgError {
139
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140
+ match self {
141
+ LinalgError::ShapeMismatch { expected, actual } => {
142
+ write!(f, "Shape mismatch: expected {expected}, got {actual}")
143
+ }
144
+ LinalgError::ShapeConstructionFailed => write!(f, "Shape construction failed"),
145
+ }
146
+ }
147
+ }
148
+
149
+ #[cfg(not(feature = "no_std"))]
150
+ impl std::error::Error for UnitforgeError {}
151
+
152
+ #[cfg(not(feature = "no_std"))]
153
+ impl std::error::Error for QuantityConversionError {}
154
+
155
+ #[cfg(not(feature = "no_std"))]
156
+ impl std::error::Error for QuantityOperationError {}
157
+
158
+ #[cfg(not(feature = "no_std"))]
159
+ impl std::error::Error for LinalgError {}