evlib 0.8.6

Event Camera Data Processing Library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
//! Polars-first geometric transformation augmentations for event camera data
//!
//! This module provides geometric transformation functionality using Polars DataFrames
//! and LazyFrames for maximum performance and memory efficiency. All operations
//! work directly with Polars expressions and avoid unnecessary conversions.
//!
//! # Philosophy
//!
//! This implementation follows a strict Polars-first approach:
//! - Input: LazyFrame (from events_to_dataframe)
//! - Processing: Polars expressions and transformations
//! - Output: LazyFrame (convertible to Vec<Event>/numpy only when needed)
//!
//! # Performance Benefits
//!
//! - Lazy evaluation: Operations are optimized and executed only when needed
//! - Vectorized operations: All transformations use SIMD-optimized Polars operations
//! - Memory efficiency: No intermediate Vec<Event> allocations
//! - Query optimization: Polars optimizes the entire augmentation pipeline
//!
//! # Transformations
//!
//! - Horizontal flip (left-right)
//! - Vertical flip (up-down)
//! - Polarity flip
//!
//! # Example
//!
//! ```rust
//! use polars::prelude::*;
//! use evlib::ev_augmentation::geometric_transforms::*;
//!
//! // Convert events to LazyFrame once
//! let events_df = events_to_dataframe(&events)?.lazy();
//!
//! // Apply geometric transformations with Polars expressions
//! let config = GeometricTransformAugmentation::new(640, 480)
//!     .with_flip_lr_probability(0.5)
//!     .with_flip_polarity_probability(0.3);
//! let transformed = apply_geometric_transforms(events_df, &config)?;
//! ```

use crate::ev_augmentation::{AugmentationError, AugmentationResult, Validatable};
// Removed: use crate::{Event, Events}; - legacy types no longer exist
use rand::{Rng, SeedableRng};
#[cfg(unix)]
use tracing::{debug, info, instrument};

#[cfg(not(unix))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(unix))]
macro_rules! info {
    ($($args:tt)*) => {};
}

#[cfg(not(unix))]
macro_rules! warn {
    ($($args:tt)*) => {
        eprintln!("[WARN] {}", format!($($args)*))
    };
}

#[cfg(not(unix))]
macro_rules! trace {
    ($($args:tt)*) => {};
}

#[cfg(not(unix))]
macro_rules! error {
    ($($args:tt)*) => {
        eprintln!("[ERROR] {}", format!($($args)*))
    };
}

#[cfg(not(unix))]
macro_rules! instrument {
    ($($args:tt)*) => {};
}

use polars::prelude::*;

// Polars column names for event data consistency
pub const COL_X: &str = "x";
pub const COL_Y: &str = "y";
pub const COL_T: &str = "t";
pub const COL_POLARITY: &str = "polarity";

/// Geometric transform augmentation configuration
///
/// Applies geometric transformations to events with specified probabilities:
/// - Horizontal flip (left-right)
/// - Vertical flip (up-down)
/// - Polarity flip
///
/// # Example
///
/// ```rust
/// use evlib::ev_augmentation::GeometricTransformAugmentation;
///
/// // Create geometric transforms with 50% probability each
/// let transforms = GeometricTransformAugmentation::new(0.5, 0.5, 0.3, 640, 480);
/// ```
#[derive(Debug, Clone)]
pub struct GeometricTransformAugmentation {
    /// Probability of horizontal flip (0-1)
    pub flip_lr_prob: f64,
    /// Probability of vertical flip (0-1)
    pub flip_ud_prob: f64,
    /// Probability of polarity flip (0-1)
    pub flip_polarity_prob: f64,
    /// Sensor width in pixels
    pub sensor_width: u16,
    /// Sensor height in pixels
    pub sensor_height: u16,
    /// Random seed for reproducibility
    pub seed: Option<u64>,
}

impl GeometricTransformAugmentation {
    /// Create new geometric transform augmentation with default probabilities (all 0.0)
    ///
    /// # Arguments
    ///
    /// * `sensor_width` - Sensor width in pixels
    /// * `sensor_height` - Sensor height in pixels
    pub fn new(sensor_width: u16, sensor_height: u16) -> Self {
        Self {
            flip_lr_prob: 0.0,
            flip_ud_prob: 0.0,
            flip_polarity_prob: 0.0,
            sensor_width,
            sensor_height,
            seed: None,
        }
    }

    /// Set horizontal flip probability
    pub fn with_flip_lr_probability(mut self, prob: f64) -> Self {
        self.flip_lr_prob = prob;
        self
    }

    /// Set vertical flip probability
    pub fn with_flip_ud_probability(mut self, prob: f64) -> Self {
        self.flip_ud_prob = prob;
        self
    }

    /// Set polarity flip probability
    pub fn with_flip_polarity_probability(mut self, prob: f64) -> Self {
        self.flip_polarity_prob = prob;
        self
    }

    /// Set random seed for reproducibility
    pub fn with_seed(mut self, seed: u64) -> Self {
        self.seed = Some(seed);
        self
    }

    /// Get description of this augmentation
    pub fn description(&self) -> String {
        format!(
            "flip_lr={:.2}, flip_ud={:.2}, flip_pol={:.2}, size={}x{}",
            self.flip_lr_prob,
            self.flip_ud_prob,
            self.flip_polarity_prob,
            self.sensor_width,
            self.sensor_height
        )
    }

    /// Check if any transformations are enabled
    pub fn is_enabled(&self) -> bool {
        self.flip_lr_prob > 0.0 || self.flip_ud_prob > 0.0 || self.flip_polarity_prob > 0.0
    }

    /// Apply geometric transforms directly to DataFrame (recommended approach)
    ///
    /// This is the high-performance DataFrame-native method that should be used
    /// instead of the legacy Vec<Event> approach when possible.
    ///
    /// # Arguments
    ///
    /// * `df` - Input LazyFrame containing event data
    ///
    /// # Returns
    ///
    /// Transformed LazyFrame with geometric transforms applied
    pub fn apply_to_dataframe(&self, df: LazyFrame) -> PolarsResult<LazyFrame> {
        apply_geometric_transforms(df, self)
    }

    /// Apply geometric transforms directly to DataFrame and return DataFrame
    ///
    /// Convenience method that applies transforms and collects the result.
    ///
    /// # Arguments
    ///
    /// * `df` - Input DataFrame containing event data
    ///
    /// # Returns
    ///
    /// Transformed DataFrame with geometric transforms applied
    pub fn apply_to_dataframe_eager(&self, df: DataFrame) -> PolarsResult<DataFrame> {
        apply_geometric_transforms(df.lazy(), self)?.collect()
    }
}

impl Validatable for GeometricTransformAugmentation {
    fn validate(&self) -> AugmentationResult<()> {
        if !(0.0..=1.0).contains(&self.flip_lr_prob) {
            return Err(AugmentationError::InvalidProbability(self.flip_lr_prob));
        }
        if !(0.0..=1.0).contains(&self.flip_ud_prob) {
            return Err(AugmentationError::InvalidProbability(self.flip_ud_prob));
        }
        if !(0.0..=1.0).contains(&self.flip_polarity_prob) {
            return Err(AugmentationError::InvalidProbability(
                self.flip_polarity_prob,
            ));
        }
        if self.sensor_width == 0 || self.sensor_height == 0 {
            return Err(AugmentationError::InvalidSensorSize(
                self.sensor_width,
                self.sensor_height,
            ));
        }
        Ok(())
    }
}

// impl SingleAugmentation for GeometricTransformAugmentation {
//     #[cfg_attr(unix, instrument(skip(events), level = "debug"))]
//     fn apply(&self, events: &Events) -> AugmentationResult<Events> {
//         // Legacy Vec<Event> interface - convert to DataFrame and back
//         // This is for backward compatibility only
//         #[cfg(unix)]
//         tracing::warn!("Using legacy Vec<Event> interface - consider using LazyFrame directly for better performance");
//         #[cfg(not(unix))]
//         eprintln!("[WARN] Using legacy Vec<Event> interface - consider using LazyFrame directly for better performance");
//
//         {
//             let df = crate::events_to_dataframe(events)
//                 .map_err(|e| {
//                     AugmentationError::ProcessingError(format!(
//                         "DataFrame conversion failed: {}",
//                         e
//                     ))
//                 })?
//                 .lazy();
//
//             let transformed_df = self.apply_to_dataframe(df).map_err(|e| {
//                 AugmentationError::ProcessingError(format!("Polars transformation failed: {}", e))
//             })?;
//
//             // Convert back to Vec<Event> - this is inefficient but maintains compatibility
//             let result_df = transformed_df.collect().map_err(|e| {
//                 AugmentationError::ProcessingError(format!("LazyFrame collection failed: {}", e))
//             })?;
//
//             // Convert DataFrame back to Events
//             dataframe_to_events(&result_df)
//         }
//
//         #[cfg(not(feature = "polars"))]
//         {
//             geometric_transforms(events, self)
//         }
//     }
//
//     fn description(&self) -> String {
//         self.description()
//     }
// }

// /// Apply geometric transforms to events
// ///
// /// # Arguments
// ///
// /// * `events` - Input events
// /// * `config` - Geometric transform configuration
// ///
// /// # Returns
// ///
// /// * `AugmentationResult<Events>` - Transformed events
// #[cfg_attr(unix, instrument(skip(events), level = "debug"))]
// pub fn geometric_transforms(
//     events: &Events,
//     config: &GeometricTransformAugmentation,
// ) -> AugmentationResult<Events> {
//     let start_time = std::time::Instant::now();
//
//     if events.is_empty() {
//         debug!("No events to transform");
//         return Ok(Vec::new());
//     }
//
//     // Validate configuration
//     config.validate()?;
//
//     // If no transformations are enabled, return original events
//     if !config.is_enabled() {
//         debug!("No geometric transformations enabled");
//         return Ok(events.clone());
//     }
//
//     // Initialize RNG
//     let mut rng = if let Some(seed) = config.seed {
//         rand::rngs::StdRng::seed_from_u64(seed)
//     } else {
//         rand::rngs::StdRng::from_entropy()
//     };
//
//     // Determine which transformations to apply (once for entire sequence)
//     let apply_flip_lr = rng.gen::<f64>() < config.flip_lr_prob;
//     let apply_flip_ud = rng.gen::<f64>() < config.flip_ud_prob;
//     let apply_flip_polarity = rng.gen::<f64>() < config.flip_polarity_prob;
//
//     debug!(
//         "Applying transformations: flip_lr={}, flip_ud={}, flip_polarity={}",
//         apply_flip_lr, apply_flip_ud, apply_flip_polarity
//     );
//
//     // Apply transformations to all events
//     let mut transformed_events = Vec::with_capacity(events.len());
//
//     for event in events {
//         let mut new_x = event.x;
//         let mut new_y = event.y;
//         let mut new_polarity = event.polarity;
//
//         // Apply horizontal flip: x_new = sensor_width - 1 - x_old
//         if apply_flip_lr {
//             new_x = config
//                 .sensor_width
//                 .saturating_sub(1)
//                 .saturating_sub(event.x);
//         }
//
//         // Apply vertical flip: y_new = sensor_height - 1 - y_old
//         if apply_flip_ud {
//             new_y = config
//                 .sensor_height
//                 .saturating_sub(1)
//                 .saturating_sub(event.y);
//         }
//
//         // Apply polarity reversal: polarity_new = !polarity_old
//         if apply_flip_polarity {
//             new_polarity = !event.polarity;
//         }
//
//         // Create transformed event (timestamp remains unchanged)
//         let transformed_event = Event {
//             t: event.t,
//             x: new_x,
//             y: new_y,
//             polarity: new_polarity,
//         };
//
//         transformed_events.push(transformed_event);
//     }
//
//     let processing_time = start_time.elapsed().as_secs_f64();
//
//     info!(
//         "Geometric transforms applied: {} events transformed in {:.3}s (LR={}, UD={}, Pol={})",
//         events.len(),
//         processing_time,
//         apply_flip_lr,
//         apply_flip_ud,
//         apply_flip_polarity
//     );
//
//     Ok(transformed_events)
// }

/// Apply geometric transforms using Polars expressions
///
/// This is the main geometric transformation function that works entirely with Polars
/// operations for maximum performance. It applies probabilistic transforms using
/// vectorized operations.
///
/// # Arguments
///
/// * `df` - Input LazyFrame containing event data
/// * `config` - Geometric transformation configuration
///
/// # Returns
///
/// Transformed LazyFrame with geometric transforms applied
///
/// # Example
///
/// ```rust
/// use polars::prelude::*;
/// use evlib::ev_augmentation::geometric_transforms::*;
///
/// let events_df = events_to_dataframe(&events)?.lazy();
/// let config = GeometricTransformAugmentation::new(640, 480)
///     .with_flip_lr_probability(0.5);
/// let transformed = apply_geometric_transforms(events_df, &config)?;
/// ```
#[cfg_attr(unix, instrument(skip(df), level = "debug"))]
pub fn apply_geometric_transforms(
    df: LazyFrame,
    config: &GeometricTransformAugmentation,
) -> PolarsResult<LazyFrame> {
    debug!("Applying geometric transforms with Polars: {:?}", config);

    // If no transformations are enabled, return original DataFrame
    if !config.is_enabled() {
        debug!("No geometric transformations enabled");
        return Ok(df);
    }

    // Initialize RNG
    let mut rng = if let Some(seed) = config.seed {
        rand::rngs::StdRng::seed_from_u64(seed)
    } else {
        rand::rngs::StdRng::from_entropy()
    };

    // Determine which transformations to apply (once for entire sequence)
    let apply_flip_lr = rng.gen::<f64>() < config.flip_lr_prob;
    let apply_flip_ud = rng.gen::<f64>() < config.flip_ud_prob;
    let apply_flip_polarity = rng.gen::<f64>() < config.flip_polarity_prob;

    debug!(
        "Polars transformations: flip_lr={}, flip_ud={}, flip_polarity={}",
        apply_flip_lr, apply_flip_ud, apply_flip_polarity
    );

    info!(
        "Applying geometric transforms: LR={}, UD={}, Pol={}",
        apply_flip_lr, apply_flip_ud, apply_flip_polarity
    );

    let mut result_df = df;

    // Apply horizontal flip transformation: x_new = sensor_width - 1 - x_old
    if apply_flip_lr {
        result_df = result_df
            .with_columns([(lit(config.sensor_width as i64 - 1) - col(COL_X)).alias(COL_X)]);
    }

    // Apply vertical flip transformation: y_new = sensor_height - 1 - y_old
    if apply_flip_ud {
        result_df = result_df
            .with_columns([(lit(config.sensor_height as i64 - 1) - col(COL_Y)).alias(COL_Y)]);
    }

    // Apply polarity reversal transformation: polarity_new = !polarity_old (1 - polarity)
    if apply_flip_polarity {
        result_df = result_df.with_columns([(lit(1) - col(COL_POLARITY)).alias(COL_POLARITY)]);
    }

    Ok(result_df)
}

/// Legacy Polars function for backward compatibility
pub fn apply_geometric_transforms_polars(
    df: LazyFrame,
    config: &GeometricTransformAugmentation,
) -> PolarsResult<LazyFrame> {
    apply_geometric_transforms(df, config)
}

/// Apply geometric transforms directly to LazyFrame - DataFrame-native convenience functions
///
/// These functions apply geometric transformations directly to a LazyFrame for optimal performance.
/// Use these instead of the legacy Vec<Event> versions when possible.
pub fn apply_flip_lr_df(df: LazyFrame, sensor_width: u16) -> PolarsResult<LazyFrame> {
    let config =
        GeometricTransformAugmentation::new(sensor_width, 480).with_flip_lr_probability(1.0);
    apply_geometric_transforms(df, &config)
}

pub fn apply_flip_ud_df(df: LazyFrame, sensor_height: u16) -> PolarsResult<LazyFrame> {
    let config =
        GeometricTransformAugmentation::new(640, sensor_height).with_flip_ud_probability(1.0);
    apply_geometric_transforms(df, &config)
}

pub fn apply_flip_polarity_df(df: LazyFrame) -> PolarsResult<LazyFrame> {
    let config = GeometricTransformAugmentation::new(640, 480).with_flip_polarity_probability(1.0);
    apply_geometric_transforms(df, &config)
}

// /// Helper function to convert DataFrame back to Events (for legacy compatibility)
// fn dataframe_to_events(df: &DataFrame) -> AugmentationResult<Events> {
//     let height = df.height();
//     let mut events = Vec::with_capacity(height);
//
//     let x_series = df
//         .column(COL_X)
//         .map_err(|e| AugmentationError::ProcessingError(format!("Missing x column: {}", e)))?;
//     let y_series = df
//         .column(COL_Y)
//         .map_err(|e| AugmentationError::ProcessingError(format!("Missing y column: {}", e)))?;
//     let t_series = df
//         .column(COL_T)
//         .map_err(|e| AugmentationError::ProcessingError(format!("Missing t column: {}", e)))?;
//     let p_series = df.column(COL_POLARITY).map_err(|e| {
//         AugmentationError::ProcessingError(format!("Missing polarity column: {}", e))
//     })?;
//
//     let x_values = x_series
//         .i64()
//         .map_err(|e| AugmentationError::ProcessingError(format!("X column type error: {}", e)))?;
//     let y_values = y_series
//         .i64()
//         .map_err(|e| AugmentationError::ProcessingError(format!("Y column type error: {}", e)))?;
//     let t_values = t_series
//         .f64()
//         .map_err(|e| AugmentationError::ProcessingError(format!("T column type error: {}", e)))?;
//     let p_values = p_series.i64().map_err(|e| {
//         AugmentationError::ProcessingError(format!("Polarity column type error: {}", e))
//     })?;
//
//     for i in 0..height {
//         let x = x_values
//             .get(i)
//             .ok_or_else(|| AugmentationError::ProcessingError("Missing x value".to_string()))?
//             as u16;
//         let y = y_values
//             .get(i)
//             .ok_or_else(|| AugmentationError::ProcessingError("Missing y value".to_string()))?
//             as u16;
//         let t = t_values
//             .get(i)
//             .ok_or_else(|| AugmentationError::ProcessingError("Missing t value".to_string()))?;
//         let p = p_values.get(i).ok_or_else(|| {
//             AugmentationError::ProcessingError("Missing polarity value".to_string())
//         })? > 0;
//
//         events.push(Event {
//             x,
//             y,
//             t,
//             polarity: p,
//         });
//     }
//
//     Ok(events)
// }

// #[cfg(test)]
// mod tests {
//     use super::*;
//
//     fn create_test_events() -> Events {
//         vec![
//             Event {
//                 t: 1.0,
//                 x: 100,
//                 y: 200,
//                 polarity: true,
//             },
//             Event {
//                 t: 2.0,
//                 x: 150,
//                 y: 250,
//                 polarity: false,
//             },
//         ]
//     }

#[test]
fn test_geometric_transform_creation() {
    let transform = GeometricTransformAugmentation::new(640, 480)
        .with_flip_lr_probability(0.5)
        .with_flip_ud_probability(0.5)
        .with_flip_polarity_probability(0.3);
    assert_eq!(transform.flip_lr_prob, 0.5);
    assert_eq!(transform.flip_ud_prob, 0.5);
    assert_eq!(transform.flip_polarity_prob, 0.3);
    assert_eq!(transform.sensor_width, 640);
    assert_eq!(transform.sensor_height, 480);
}

#[test]
fn test_validation() {
    // Valid configuration
    let valid_config = GeometricTransformAugmentation::new(640, 480)
        .with_flip_lr_probability(0.5)
        .with_flip_ud_probability(0.5)
        .with_flip_polarity_probability(0.3);
    assert!(valid_config.validate().is_ok());

    // Invalid probability
    let invalid_prob = GeometricTransformAugmentation::new(640, 480)
        .with_flip_lr_probability(1.5)
        .with_flip_ud_probability(0.5)
        .with_flip_polarity_probability(0.3);
    assert!(invalid_prob.validate().is_err());

    // Invalid sensor size
    let invalid_size = GeometricTransformAugmentation::new(0, 480)
        .with_flip_lr_probability(0.5)
        .with_flip_ud_probability(0.5)
        .with_flip_polarity_probability(0.3);
    assert!(invalid_size.validate().is_err());
}

// #[test]
// fn test_no_transform() {
//     let events = create_test_events();
//     let transform = GeometricTransformAugmentation::new(640, 480); // All probabilities default to 0.0
//     let result = transform.apply(&events).unwrap();
//
//     // Events should be unchanged when all probabilities are 0
//     assert_eq!(result.len(), events.len());
//     for (original, transformed) in events.iter().zip(result.iter()) {
//         assert_eq!(original.t, transformed.t);
//         assert_eq!(original.x, transformed.x);
//         assert_eq!(original.y, transformed.y);
//         assert_eq!(original.polarity, transformed.polarity);
//     }
// }

// #[test]
// fn test_deterministic_with_seed() {
//     let events = create_test_events();
//     let transform1 = GeometricTransformAugmentation::new(640, 480)
//         .with_flip_lr_probability(1.0)
//         .with_flip_ud_probability(1.0)
//         .with_flip_polarity_probability(1.0)
//         .with_seed(42);
//     let transform2 = GeometricTransformAugmentation::new(640, 480)
//         .with_flip_lr_probability(1.0)
//         .with_flip_ud_probability(1.0)
//         .with_flip_polarity_probability(1.0)
//         .with_seed(42);
//
//     let result1 = transform1.apply(&events).unwrap();
//     let result2 = transform2.apply(&events).unwrap();
//
//     // Results should be identical with same seed
//     assert_eq!(result1.len(), result2.len());
//     for (r1, r2) in result1.iter().zip(result2.iter()) {
//         assert_eq!(r1.t, r2.t);
//         assert_eq!(r1.x, r2.x);
//         assert_eq!(r1.y, r2.y);
//         assert_eq!(r1.polarity, r2.polarity);
//     }
// }

// #[test]
// fn test_geometric_transforms_dataframe_native() -> PolarsResult<()> {
//     use crate::events_to_dataframe;
//
//     let events = create_test_events();
//     let df = events_to_dataframe(&events)?.lazy();
//     let config = GeometricTransformAugmentation::new(640, 480).with_flip_lr_probability(1.0);
//
//     let transformed_df = config.apply_to_dataframe(df)?;
//     let result = transformed_df.collect()?;
//
//     assert_eq!(result.height(), events.len());
//
//     // Check that horizontal flip was applied: x_new = 639 - x_old
//     let original_df = events_to_dataframe(&events)?;
//     let original_x: Vec<i64> = original_df
//         .column(COL_X)?
//         .i64()?
//         .into_no_null_iter()
//         .collect();
//     let transformed_x: Vec<i64> = result.column(COL_X)?.i64()?.into_no_null_iter().collect();
//
//     for (orig_x, trans_x) in original_x.iter().zip(transformed_x.iter()) {
//         assert_eq!(*trans_x, 639 - orig_x);
//     }
//
//     Ok(())
// }

// #[test]
// fn test_apply_geometric_transforms() -> PolarsResult<()> {
//     use crate::events_to_dataframe;
//
//     let events = create_test_events();
//     let df = events_to_dataframe(&events)?.lazy();
//     let config =
//         GeometricTransformAugmentation::new(640, 480).with_flip_polarity_probability(1.0);
//
//     let transformed = apply_geometric_transforms(df, &config)?;
//     let result = transformed.collect()?;
//     assert_eq!(result.height(), events.len());
//
//     // Check polarity flip was applied
//     let original_df = events_to_dataframe(&events)?;
//     let original_pol: Vec<i64> = original_df
//         .column(COL_POLARITY)?
//         .i64()?
//         .into_no_null_iter()
//         .collect();
//     let transformed_pol: Vec<i64> = result
//         .column(COL_POLARITY)?
//         .i64()?
//         .into_no_null_iter()
//         .collect();
//
//     for (orig_p, trans_p) in original_pol.iter().zip(transformed_pol.iter()) {
//         assert_eq!(*trans_p, 1 - orig_p);
//     }
//
//     Ok(())
// }

// #[test]
// fn test_geometric_transforms_convenience_functions() -> PolarsResult<()> {
//     use crate::events_to_dataframe;
//
//     let events = create_test_events();
//     let df = events_to_dataframe(&events)?.lazy();
//
//     // Test horizontal flip
//     let flipped_lr = apply_flip_lr_df(df.clone(), 640)?;
//     let result_lr = flipped_lr.collect()?;
//     assert_eq!(result_lr.height(), events.len());
//
//     // Test vertical flip
//     let flipped_ud = apply_flip_ud_df(df.clone(), 480)?;
//     let result_ud = flipped_ud.collect()?;
//     assert_eq!(result_ud.height(), events.len());
//
//     // Test polarity flip
//     let flipped_pol = apply_flip_polarity_df(df)?;
//     let result_pol = flipped_pol.collect()?;
//     assert_eq!(result_pol.height(), events.len());
//
//     Ok(())
// }

// #[test]
// fn test_geometric_transforms_legacy_compatibility() {
//     let events = create_test_events();
//     let config = GeometricTransformAugmentation::new(640, 480).with_flip_lr_probability(1.0);
//
//     let transformed = config.apply(&events).unwrap();
//     assert_eq!(transformed.len(), events.len());
//
//     // Check that transformation was applied
//     assert_eq!(transformed[0].x, 639 - events[0].x);
// }
// }