unitforge 0.4.2__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.
- unitforge-0.4.3/.gitlab-ci.yml +137 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/Cargo.lock +9 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/Cargo.toml +15 -6
- {unitforge-0.4.2 → unitforge-0.4.3}/PKG-INFO +1 -1
- {unitforge-0.4.2 → unitforge-0.4.3}/Readme.md +2 -2
- unitforge-0.4.3/src/errors.rs +159 -0
- unitforge-0.4.3/src/impl_macros.rs +1457 -0
- unitforge-0.4.3/src/internal.rs +264 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/lib.rs +79 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/src/prelude.rs +24 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/acceleration.rs +14 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/angle.rs +20 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/angular_acceleration.rs +11 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/angular_velocity.rs +11 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/area.rs +19 -13
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/area_of_moment.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/charge.rs +10 -4
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/compliance.rs +9 -3
- unitforge-0.4.3/src/quantities/density.rs +128 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/distance.rs +34 -28
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force.rs +19 -13
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_area.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_distance.rs +24 -19
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_div_distance_power_four.rs +10 -4
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_per_volume.rs +10 -4
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_stress.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/force_volume.rs +9 -3
- unitforge-0.4.3/src/quantities/frequency.rs +77 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/inverse_angle.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/inverse_area.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/inverse_distance.rs +19 -13
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/inverse_stress.rs +9 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/mass.rs +33 -38
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/mass_per_distance.rs +9 -3
- unitforge-0.4.3/src/quantities/molar_mass.rs +38 -0
- unitforge-0.4.3/src/quantities/pressure_rate.rs +47 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/rotational_stiffness.rs +10 -4
- unitforge-0.4.3/src/quantities/specific_gas_constant.rs +39 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/stiffness.rs +12 -6
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/strain.rs +13 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/stress.rs +14 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/stress_squared.rs +9 -3
- unitforge-0.4.3/src/quantities/temperature.rs +38 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/time.rs +29 -12
- unitforge-0.4.3/src/quantities/universal_gas_constant.rs +41 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/velocity.rs +14 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/velocity_squared.rs +16 -4
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/voltage.rs +13 -7
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities/volume.rs +19 -13
- {unitforge-0.4.2 → unitforge-0.4.3}/src/quantities.template.rs +62 -76
- {unitforge-0.4.2 → unitforge-0.4.3}/src/relations.rs +8 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/bindings/matrix3_py.template.rs +2 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/bindings/vector3_py.template.rs +2 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/matrix2.rs +20 -9
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/matrix2x3.rs +16 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/matrix3.rs +25 -12
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/matrix3x2.rs +16 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/vector2.rs +18 -8
- {unitforge-0.4.2 → unitforge-0.4.3}/src/small_linalg/vector3.rs +19 -12
- {unitforge-0.4.2 → unitforge-0.4.3}/test.sh +124 -18
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/matrix2.rs +3 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/matrix2x3.rs +10 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/matrix3.rs +11 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/matrix3x2.rs +10 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/ndarray_dot.rs +2 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantities.rs +215 -18
- unitforge-0.4.3/tests/quantity_core/constants.rs +109 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/construction.rs +2 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/metadata.rs +20 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/normalization.rs +1 -1
- unitforge-0.4.3/tests/quantity_core/plain_storage.rs +34 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/relations.rs +13 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/runtime_quantity.rs +13 -5
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/scalar_edges.rs +4 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core.rs +6 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_serde.rs +40 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/small_linalg_edge_cases.rs +56 -9
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/small_linalg_interfaces.rs +2 -2
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/vector2.rs +18 -3
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/vector3.rs +3 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/unitforge_macros/Cargo.toml +1 -1
- {unitforge-0.4.2 → unitforge-0.4.3}/unitforge_macros/src/lib.rs +6 -6
- unitforge-0.4.2/.gitlab-ci.yml +0 -43
- unitforge-0.4.2/src/impl_macros.rs +0 -1000
- unitforge-0.4.2/src/internal.rs +0 -55
- unitforge-0.4.2/src/quantities/density.rs +0 -122
- unitforge-0.4.2/src/quantities/mass_div_time_squared_volume.rs +0 -30
- {unitforge-0.4.2 → unitforge-0.4.3}/.gitignore +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/Readme_py.md +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/install_hooks.sh +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/pyproject.toml +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/python/unitforge/__init__.py +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/scripts/generate_python_stubs.py +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/common/mod.rs +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/quantity_core/enum_iter.rs +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/test_quantities.py +0 -0
- {unitforge-0.4.2 → unitforge-0.4.3}/tests/test_small_linalg.py +0 -0
- {unitforge-0.4.2 → 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
|
|
@@ -125,6 +125,12 @@ version = "1.21.3"
|
|
|
125
125
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
126
126
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
127
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
|
+
|
|
128
134
|
[[package]]
|
|
129
135
|
name = "portable-atomic"
|
|
130
136
|
version = "1.10.0"
|
|
@@ -345,11 +351,12 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
|
|
345
351
|
|
|
346
352
|
[[package]]
|
|
347
353
|
name = "unitforge"
|
|
348
|
-
version = "0.4.
|
|
354
|
+
version = "0.4.3"
|
|
349
355
|
dependencies = [
|
|
350
356
|
"ndarray",
|
|
351
357
|
"num-traits",
|
|
352
358
|
"numpy",
|
|
359
|
+
"paste",
|
|
353
360
|
"pyo3",
|
|
354
361
|
"serde",
|
|
355
362
|
"serde_json",
|
|
@@ -360,7 +367,7 @@ dependencies = [
|
|
|
360
367
|
|
|
361
368
|
[[package]]
|
|
362
369
|
name = "unitforge_macros"
|
|
363
|
-
version = "0.4.
|
|
370
|
+
version = "0.4.3"
|
|
364
371
|
dependencies = [
|
|
365
372
|
"regex",
|
|
366
373
|
]
|
|
@@ -4,7 +4,7 @@ crate-type = ["cdylib", "rlib"]
|
|
|
4
4
|
|
|
5
5
|
[package]
|
|
6
6
|
name = "unitforge"
|
|
7
|
-
version = "0.4.
|
|
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
23
|
pyo3 = { version = "0.28.3", features = ["extension-module", "auto-initialize", "multiple-pymethods"], optional = true }
|
|
23
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.
|
|
27
|
+
unitforge_macros = { version = "0.4.3", path = "unitforge_macros" }
|
|
27
28
|
|
|
28
29
|
[features]
|
|
29
|
-
|
|
30
|
-
|
|
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"
|
|
@@ -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:**
|
|
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
|
|
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
|
|
@@ -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 {}
|