Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.14.1] - 2026-07-24
### Added
- Added `into_dimensionality` and `into_dyn` for quantities of arrays. [#119](https://github.com/itt-ustutt/quantity/pull/119)

## [0.14.0] - 2026-06-14
### Packaging
- Updated `nalgebra` dependency to 0.35.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quantity"
version = "0.14.0"
version = "0.14.1"
authors = [
"Philipp Rehner <prehner@ethz.ch>",
"Gernot Bauer <bauer@itt.uni-stuttgart.de>",
Expand Down
4 changes: 2 additions & 2 deletions si-units/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ impl SINumber {
format!(
"{}\\,{}",
float_to_latex(value),
&unit_to_latex(symbols, exponents, Some(prefix))
unit_to_latex(symbols, exponents, Some(prefix))
)
} else {
format!("{}\\,{}", float_to_latex(self.value), &self.unit.to_latex())
format!("{}\\,{}", float_to_latex(self.value), self.unit.to_latex())
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/array.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::Quantity;
use ndarray::iter::LanesMut;
use ndarray::{
Array, Array1, ArrayBase, ArrayView, Axis, Data, DataMut, Dimension, NdIndex, RemoveAxis,
ShapeBuilder,
Array, Array1, ArrayBase, ArrayView, Axis, Data, DataMut, Dimension, IxDyn, NdIndex,
RemoveAxis, ShapeBuilder, ShapeError,
};
use num_traits::Zero;
use std::iter::FromIterator;
Expand Down Expand Up @@ -159,6 +159,21 @@ impl<T, S: Data<Elem = T>, U, D: Dimension> Quantity<ArrayBase<S, D>, U> {
Quantity::new(self.0.insert_axis(axis))
}

/// Convert an array or array view to another with the same type, but different dimensionality
/// type. Errors if the dimensions don't agree (the number of axes must match).
pub fn into_dimensionality<D2>(self) -> Result<Quantity<ArrayBase<S, D2>, U>, ShapeError>
where
D2: Dimension,
{
self.0.into_dimensionality().map(Quantity::new)
}

/// Convert any array or array view to a dynamic dimensional array or
/// array view (respectively).
pub fn into_dyn(self) -> Quantity<ArrayBase<S, IxDyn>, U> {
Quantity::new(self.0.into_dyn())
}

/// Return the element at `index`.
///
/// The `Index` trait can not be implemented, because a new instance has to be created,
Expand Down
Loading