use crate::tensor::*;
use crate::units::*;
use crate::tensor::element::*;
use std::marker::PhantomData;
pub type Scalar<E: TensorElement, D> = Tensor<E, D, 1, 1, 1>;
impl<E: TensorElement, D> Scalar<E, D> {
pub const EPSILON: Scalar<E, D> = Scalar::default([E::EPSILON]);
pub fn from<U: Unit<Dimension = D>>(value: E) -> Self {
Scalar::new::<U>([value])
}
pub fn raw(&self) -> E {
self.data()[0]
}
pub fn raw_as<T: From<E>>(&self) -> T {
T::from(self.raw())
}
pub fn mag(&self) -> Scalar<f64, D> {
Scalar::default([self.raw().mag()])
}
}
impl<E: TensorElement, D> Scalar<E, D> {
pub fn epsilon(&self) -> Self {
Self::EPSILON
}
}
pub trait ToScalar<E: TensorElement> {
fn scalar<U: Unit>(&self) -> Scalar<E, U::Dimension>;
}
impl<E: TensorElement> ToScalar<E> for E {
fn scalar<U: Unit>(&self) -> Scalar<E, U::Dimension> {
Scalar::new::<U>([*self])
}
}