#[doc(hidden)]
#[macro_export]
macro_rules! tensor_traits {
($Type:ident) => {
impl<Element> $crate::math::tensor::AsRefTensor for $Type<Vec<Element>> {
type Element = Element;
type Container = Vec<Element>;
fn as_tensor(&self) -> &Tensor<Self::Container> {
&self.tensor
}
}
impl<Element> $crate::math::tensor::AsRefTensor
for $Type<fftw::array::AlignedVec<Element>>
{
type Element = Element;
type Container = fftw::array::AlignedVec<Element>;
fn as_tensor(&self) -> &Tensor<Self::Container> {
&self.tensor
}
}
impl<Element> $crate::math::tensor::AsRefTensor for $Type<[Element; 1]> {
type Element = Element;
type Container = [Element; 1];
fn as_tensor(&self) -> &Tensor<Self::Container> {
&self.tensor
}
}
impl<'a, Element> $crate::math::tensor::AsRefTensor for $Type<&'a [Element]> {
type Element = Element;
type Container = &'a [Element];
fn as_tensor(&self) -> &Tensor<Self::Container> {
&self.tensor
}
}
impl<'a, Element> $crate::math::tensor::AsRefTensor for $Type<&'a mut [Element]> {
type Element = Element;
type Container = &'a mut [Element];
fn as_tensor(&self) -> &Tensor<Self::Container> {
&self.tensor
}
}
impl<Element> $crate::math::tensor::AsMutTensor for $Type<Vec<Element>> {
type Element = Element;
type Container = Vec<Element>;
fn as_mut_tensor(
&mut self,
) -> &mut Tensor<<Self as $crate::math::tensor::AsMutTensor>::Container> {
&mut self.tensor
}
}
impl<Element> $crate::math::tensor::AsMutTensor for $Type<[Element; 1]> {
type Element = Element;
type Container = [Element; 1];
fn as_mut_tensor(
&mut self,
) -> &mut Tensor<<Self as $crate::math::tensor::AsMutTensor>::Container> {
&mut self.tensor
}
}
impl<Element> $crate::math::tensor::AsMutTensor
for $Type<fftw::array::AlignedVec<Element>>
{
type Element = Element;
type Container = fftw::array::AlignedVec<Element>;
fn as_mut_tensor(
&mut self,
) -> &mut Tensor<<Self as $crate::math::tensor::AsMutTensor>::Container> {
&mut self.tensor
}
}
impl<'a, Element> $crate::math::tensor::AsMutTensor for $Type<&'a mut [Element]> {
type Element = Element;
type Container = &'a mut [Element];
fn as_mut_tensor(
&mut self,
) -> &mut Tensor<<Self as $crate::math::tensor::AsMutTensor>::Container> {
&mut self.tensor
}
}
impl<Element> $crate::math::tensor::IntoTensor for $Type<Vec<Element>> {
type Element = Element;
type Container = Vec<Element>;
fn into_tensor(self) -> Tensor<Self::Container> {
self.tensor
}
}
impl<Element> $crate::math::tensor::IntoTensor for $Type<fftw::array::AlignedVec<Element>> {
type Element = Element;
type Container = fftw::array::AlignedVec<Element>;
fn into_tensor(self) -> Tensor<Self::Container> {
self.tensor
}
}
impl<Element> $crate::math::tensor::IntoTensor for $Type<[Element; 1]> {
type Element = Element;
type Container = [Element; 1];
fn into_tensor(self) -> Tensor<Self::Container> {
self.tensor
}
}
impl<'a, Element> $crate::math::tensor::IntoTensor for $Type<&'a [Element]> {
type Element = Element;
type Container = &'a [Element];
fn into_tensor(self) -> Tensor<Self::Container> {
self.tensor
}
}
impl<'a, Element> $crate::math::tensor::IntoTensor for $Type<&'a mut [Element]> {
type Element = Element;
type Container = &'a mut [Element];
fn into_tensor(self) -> Tensor<Self::Container> {
self.tensor
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! current_func_path {
() => {{
fn name<T>(_any: T) -> &'static str {
std::any::type_name::<T>()
}
fn t() {}
let output = name(t);
&output[..output.len() - 3]
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! ck_dim_eq {
($tensor_size: expr => $($size: expr),* ) => {
let func = $crate::current_func_path!();
$(
debug_assert!(
$tensor_size == $size,
"Called operation {} on tensors of incompatible size. {} (={:?}) does not equals \
{} (={:?}).",
func,
stringify!($size),
$size,
stringify!($tensor_size),
$tensor_size
);
)*
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! ck_dim_div {
($tensor_size: expr => $($size: expr),* ) => {
$(
let func = $crate::current_func_path!();
debug_assert!(
$tensor_size % $size == 0,
"Called operation {} on tensors of incompatible size. {} (={:?}) does not divide \
{} (={:?})",
func,
stringify!($size),
$size,
stringify!($tensor_size),
$tensor_size
);
)*
};
}
#[cfg(test)]
mod tests;
mod errors;
pub use errors::*;
#[allow(clippy::module_inception)]
mod tensor;
pub use tensor::*;
mod as_slice;
pub use as_slice::*;
mod as_element;
pub use as_element::*;
mod as_tensor;
pub use as_tensor::*;
mod into_tensor;
pub use into_tensor::*;