Skip to content

Commit f810c3d

Browse files
GardevoirXLuthaf
andcommitted
Add function to check that Quantity match the expected layout
Co-Authored-By: Guillaume Fraux <guillaume.fraux@epfl.ch>
1 parent 75ef3ca commit f810c3d

21 files changed

Lines changed: 4768 additions & 123 deletions

docs/src/quantities/mass.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ following metadata:
3737
- the ``"mass"`` quantity must not have any components
3838

3939
* - properties
40-
- ``"mass``
40+
- ``"mass"``
4141
- The ``"mass"`` quantity must have a single property dimension named
4242
``"mass"``, with a single entry set to ``0``.
4343

docs/src/quantities/non_conservative.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ and must have the following metadata:
133133
* - keys
134134
- ``"_"``
135135
- the keys must have a single dimension named ``"_"``, with a single entry
136-
set to ``0``. The ``"non_conservative_force"`` quantity is always
136+
set to ``0``. The ``"non_conservative_stress"`` quantity is always
137137
represented as a :py:class:`metatensor.torch.TensorMap` with a single
138138
block.
139139

docs/src/quantities/velocity.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ following metadata:
3636
* - components
3737
- ``"xyz"``
3838
- The ``"velocity"`` quantity must have a single component dimension named
39-
``"xyz"``, with three entries set to ``0``, ``1``, and ``2``. The position
39+
``"xyz"``, with three entries set to ``0``, ``1``, and ``2``. The velocity
4040
is always a 3D vector, and the order of the components is ``x, y, z``.
4141

4242
* - properties

metatomic-core/src/kernels/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ pub struct ReferenceValue<T> {
8181
pub(crate) metal: OnceLock<(metal::MetalBuffer, StridedNDIndex)>,
8282
}
8383

84+
impl std::fmt::Debug for ReferenceValue<i32> {
85+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86+
f.debug_struct("ReferenceValue")
87+
.field("cpu", &self.cpu)
88+
.finish()
89+
}
90+
}
91+
8492
impl<T> ReferenceValue<T> {
8593
pub(crate) fn new(cpu: ArrayD<T>) -> Self {
8694
Self {

metatomic-core/src/metadata.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Write;
33

44
use json::JsonValue;
55

6+
use crate::metadata::DType::Float32;
67
use crate::{Error, Quantity};
78
use crate::units::validate_unit;
89

@@ -459,6 +460,16 @@ pub enum DType {
459460
Float64,
460461
}
461462

463+
impl std::fmt::Display for DType {
464+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
465+
if *self == Float32 {
466+
write!(f, "float32")
467+
} else {
468+
write!(f, "float64")
469+
}
470+
}
471+
}
472+
462473
impl From<DType> for JsonValue {
463474
fn from(value: DType) -> Self {
464475
match value {

0 commit comments

Comments
 (0)