File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -686,6 +686,45 @@ where
686
686
. drain ( ( col_idx * self . rows ) ..( col_idx * self . rows + self . rows ) ) ;
687
687
self . cols -= 1 ;
688
688
}
689
+
690
+ pub fn remove_columns ( self , removing : & HashSet < usize > ) -> Self
691
+ where
692
+ T : Copy + Send + Sync ,
693
+ {
694
+ let cols = self . cols ( ) ;
695
+ if removing. iter ( ) . any ( |i| * i >= cols) {
696
+ panic ! ( "cannot remove out of range column" ) ;
697
+ }
698
+ let cols = cols - removing. len ( ) ;
699
+ let rows = self . rows ( ) ;
700
+ let data = vec ! [ MaybeUninit :: <T >:: uninit( ) ; cols * rows] ;
701
+ ( 0 ..self . cols ( ) )
702
+ . filter ( |x| !removing. contains ( x) )
703
+ . collect :: < Vec < _ > > ( )
704
+ . into_par_iter ( )
705
+ . enumerate ( )
706
+ . for_each ( |( n, o) | {
707
+ let s = unsafe {
708
+ std:: slice:: from_raw_parts_mut (
709
+ data. as_ptr ( ) . add ( n * self . rows ) . cast :: < T > ( ) . cast_mut ( ) ,
710
+ self . rows ,
711
+ )
712
+ } ;
713
+ s. copy_from_slice ( self . col ( o) )
714
+ } ) ;
715
+ OwnedMatrix {
716
+ rows,
717
+ cols,
718
+ colnames : self . colnames . map ( |c| {
719
+ c. into_iter ( )
720
+ . enumerate ( )
721
+ . filter ( |( i, _) | !removing. contains ( i) )
722
+ . map ( |( _, x) | x)
723
+ . collect ( )
724
+ } ) ,
725
+ data : unsafe { std:: mem:: transmute ( data) } ,
726
+ }
727
+ }
689
728
}
690
729
691
730
impl OwnedMatrix < f64 > {
You can’t perform that action at this time.
0 commit comments