use ::burn::tensor::backend::Backend;
use crate::base::geometry::{Command, Layout, Range};
use super::{Arguments, Contour};
pub fn contour_tensors<B: Backend>(layout: &Layout, arguments: Arguments<B>) -> Vec<Contour<B>> {
let [batch_size, sequence_length, point_count, coordinate_count] = arguments.dims();
assert!(
layout.batch() < batch_size && point_count == 2 && coordinate_count == 2,
"layout requires arguments with shape [batch, sequence, 2, 2] and an in-bounds batch index"
);
layout
.contours()
.iter()
.map(|range| {
contour(
layout.commands(range),
arguments.clone(),
layout.batch(),
range,
sequence_length,
)
})
.collect()
}
fn contour<B: Backend>(
commands: &[Command],
arguments: Arguments<B>,
batch: usize,
range: &Range,
sequence_length: usize,
) -> Contour<B> {
assert!(
!range.is_empty() && range.end() <= sequence_length && commands.len() == range.len(),
"contour ranges must be non-empty and in bounds"
);
for command in commands {
match command {
Command::Linear => {}
Command::Quadratic => {}
}
}
let arguments = arguments
.slice([batch..batch + 1, range.start()..range.end(), 0..2, 0..2])
.squeeze_dim::<3>(0);
Contour::new(commands.to_vec(), arguments)
}