@@ -650,6 +650,138 @@ module ArrayMatrix: AbstractMatrix =
650650 end
651651
652652
653+ module SparseVector : AbstractVector =
654+ functor (A : RatOps ) ->
655+ struct
656+ include ConvenienceOps (A )
657+
658+ type t = {
659+ entries : (int * A .t ) list ;
660+ len : int
661+ }[@@ deriving eq , ord , hash ]
662+
663+ let show v =
664+ failwith " TODO"
665+
666+ let keep_vals v n =
667+ let rec keep_vals_vec v n =
668+ match v with
669+ | x ::xs -> if fst x > n then [] else x::(keep_vals_vec xs n)
670+ | [] -> []
671+ in
672+ if n > = v.len then v else (* could be left out but maybe performance??*)
673+ {entries = keep_vals_vec v.entries n; len= n}
674+
675+ let remove_val v n =
676+ let dec_idx v =
677+ List. map (fun (a ,b ) -> (a-1 , b)) v
678+ in
679+ let rec remove_val_vec v n =
680+ match v with
681+ | x ::xs ->
682+ if fst x = n then dec_idx xs else
683+ if fst x > n then dec_idx (x::xs) else
684+ x::(remove_val_vec xs n)
685+ | [] -> []
686+ in
687+ if n > = v.len then v else (* could be left out but maybe performance??*)
688+ {entries = remove_val_vec v.entries n; len = v.len - 1 }
689+
690+ let set_val v n m =
691+ failwith " TODO"
692+
693+ let set_val_with v n m =
694+ failwith " TODO"
695+
696+ let insert_val n m t =
697+ failwith " TODO"
698+
699+ let apply_with_c f m v =
700+ failwith " TODO"
701+
702+ let apply_with_c_with f m v =
703+ failwith " TODO"
704+
705+ let zero_vec n =
706+ failwith " TODO"
707+
708+ let nth v n =
709+ failwith " TODO"
710+
711+ let length v =
712+ failwith " TODO"
713+
714+ let map2 f v v' =
715+ failwith " TODO"
716+
717+ let map2_with f v v' =
718+ failwith " TODO"
719+
720+ let findi f v =
721+ failwith " TODO"
722+
723+ let map f v =
724+ failwith " TODO"
725+
726+ let map_with f v =
727+ failwith " TODO"
728+
729+ let compare_length_with v n =
730+ failwith " TODO"
731+
732+ let of_list l =
733+ failwith " TODO"
734+
735+ let to_list v =
736+ failwith " TODO"
737+
738+ let filteri f v =
739+ failwith " TODO"
740+
741+ let append v v' =
742+ failwith " TODO"
743+
744+ let exists f v =
745+ failwith " TODO"
746+
747+ let rev v =
748+ failwith " TODO"
749+
750+ let rev_with v =
751+ failwith " TODO"
752+
753+ let map2i f v v' =
754+ failwith " TODO"
755+
756+ let map2i_with f v v' =
757+ failwith " TODO"
758+
759+ let mapi f v =
760+ failwith " TODO"
761+
762+ let mapi_with f v =
763+ failwith " TODO"
764+
765+ let find2i f v v' =
766+ failwith " TODO"
767+
768+ let to_array v =
769+ failwith " TODO"
770+
771+ let of_array a =
772+ failwith " TODO"
773+
774+ let copy v = v
775+
776+ let of_sparse_list ls col_count =
777+ failwith " TODO"
778+
779+ let to_sparse_list v =
780+ failwith " TODO"
781+
782+ end
783+
784+
653785(* * Sparse matrix implementation.
654786 It provides a normalization function to reduce a matrix into reduced row echelon form.
655787 Operations exploit that the input matrix/matrices are in reduced row echelon form already. *)
@@ -689,14 +821,9 @@ module SparseMatrix: AbstractMatrix =
689821 timing_wrap " copy" (copy) m
690822
691823 let add_empty_columns m (cols : int enumerable ) =
692- let colsL = Array. to_list( cols) in
824+ let colsL = List. sort ( fun a b -> a - b) ( Array. to_list cols) in
693825 let emptyT = A. zero in
694826 let rec list_of_all_before_index idx cols =
695- (* This should return two arrays
696- all the idices before idx and all those after, but I'm not sure if inclusive or not
697- e.g. list_of_all_before_index 3 [1,2,3,4] = ([1,2], [3,4]) or = ([1,2,3], [4])
698- right now its of the first form!
699- *)
700827 match cols with
701828 | x ::xs ->
702829 if x < idx
0 commit comments