Files
rustytorch/crates/models/rtx-vision/tests/view_operation_test.rs
T
2026-03-04 00:08:42 +00:00

29 lines
886 B
Rust

//! TDD tests for view/reshape operations
//! These tests define expected behavior for tensor reshaping
use rtx_tensor::{Device, Tensor};
#[test]
fn test_tensor_view_with_inferred_dimension() {
// In PyTorch, -1 means "infer this dimension"
// In Rust with usize, we need a different approach
// Option 1: Use 0 to mean "infer"
// Option 2: Calculate the dimension explicitly
// Option 3: Use a special constant
let device = Device::cpu();
let tensor = Tensor::zeros(&[2, 3, 4], &device).unwrap();
// If we want to reshape to [2, -1], that means [2, 12]
// We need to calculate: total_elements / first_dim = 24 / 2 = 12
let total_elements = 2 * 3 * 4;
let first_dim = 2;
let inferred_dim = total_elements / first_dim;
// The actual view call would be:
// tensor.view(&[2, inferred_dim])
assert_eq!(inferred_dim, 12);
}