use qudit_core::ParamInfo;
use qudit_expr::ExpressionId;
use qudit_expr::GenerationShape;
use qudit_expr::index::IndexDirection;
use qudit_expr::index::TensorIndex;
#[derive(Debug, Clone)]
pub struct QuditTensor {
pub indices: Vec<TensorIndex>,
pub expression: ExpressionId,
pub param_info: ParamInfo,
}
impl QuditTensor {
pub fn new(indices: Vec<TensorIndex>, expression: ExpressionId, param_info: ParamInfo) -> Self {
QuditTensor {
indices,
expression,
param_info,
}
}
pub fn num_indices(&self) -> usize {
self.indices.len()
}
pub fn shape(&self) -> GenerationShape {
(&self.indices).into()
}
pub fn batch_indices(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Batch => Some(index.index_id()),
_ => None,
})
.collect()
}
pub fn output_indices(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Output => Some(index.index_id()),
_ => None,
})
.collect()
}
pub fn input_indices(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Input => Some(index.index_id()),
_ => None,
})
.collect()
}
pub fn batch_sizes(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Batch => Some(index.index_size()),
_ => None,
})
.collect()
}
pub fn output_sizes(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Output => Some(index.index_size()),
_ => None,
})
.collect()
}
pub fn input_sizes(&self) -> Vec<usize> {
self.indices
.iter()
.filter_map(|index| match index.direction() {
IndexDirection::Input => Some(index.index_size()),
_ => None,
})
.collect()
}
pub fn rank(&self) -> usize {
self.indices.len()
}
}