use std::marker::PhantomData;
use burn::prelude::Backend;
use burn::tensor::activation::log_softmax;
use burn::tensor::Tensor as BTensor;
use glowstick::cmp::Greater;
use glowstick::{num::Unsigned, Shape};
use crate::Tensor;
#[macro_export]
macro_rules! log_softmax {
[$t:expr,$i:ty] => {{
use $crate::op::log_softmax::LogSoftmax;
($t, std::marker::PhantomData::<$i>).log_softmax()
}};
[$t:expr,$i:ty,$($is:ty),+] => {{
$crate::log_softmax![$crate::log_softmax![$t,$i],$($is),+]
}};
}
pub trait LogSoftmax {
type Out;
fn log_softmax(self) -> Self::Out;
}
impl<B, S, const N: usize, Dim> LogSoftmax for (Tensor<BTensor<B, N>, S>, PhantomData<Dim>)
where
B: Backend,
S: Shape,
Dim: Unsigned,
(<S as Shape>::Rank, Dim): Greater,
{
type Out = Tensor<BTensor<B, N>, S>;
fn log_softmax(self) -> Self::Out {
Tensor(
log_softmax(self.0.into_inner(), <Dim as Unsigned>::USIZE),
PhantomData,
)
}
}