Skip to content

Commit 23164ce

Browse files
sparseVector stumb
1 parent dbc0fdc commit 23164ce

File tree

1 file changed

+133
-6
lines changed

1 file changed

+133
-6
lines changed

src/cdomains/vectorMatrix.ml

Lines changed: 133 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,138 @@ module ArrayMatrix: AbstractMatrix =
630630
end
631631

632632

633+
module SparseVector: AbstractVector =
634+
functor (A: RatOps) ->
635+
struct
636+
include ConvenienceOps (A)
637+
638+
type t = {
639+
entries: (int * A.t) list ;
640+
len: int
641+
}[@@deriving eq, ord, hash]
642+
643+
let show v =
644+
failwith "TODO"
645+
646+
let keep_vals v n =
647+
let rec keep_vals_vec v n =
648+
match v with
649+
| x::xs -> if fst x > n then [] else x::(keep_vals_vec xs n)
650+
| [] -> []
651+
in
652+
if n >= v.len then v else (*could be left out but maybe performance??*)
653+
{entries = keep_vals_vec v.entries n; len=n}
654+
655+
let remove_val v n =
656+
let dec_idx v =
657+
List.map (fun (a,b) -> (a-1, b)) v
658+
in
659+
let rec remove_val_vec v n =
660+
match v with
661+
| x::xs ->
662+
if fst x = n then dec_idx xs else
663+
if fst x > n then dec_idx (x::xs) else
664+
x::(remove_val_vec xs n)
665+
| [] -> []
666+
in
667+
if n >= v.len then v else (*could be left out but maybe performance??*)
668+
{entries = remove_val_vec v.entries n; len = v.len - 1}
669+
670+
let set_val v n m =
671+
failwith "TODO"
672+
673+
let set_val_with v n m =
674+
failwith "TODO"
675+
676+
let insert_val n m t =
677+
failwith "TODO"
678+
679+
let apply_with_c f m v =
680+
failwith "TODO"
681+
682+
let apply_with_c_with f m v =
683+
failwith "TODO"
684+
685+
let zero_vec n =
686+
failwith "TODO"
687+
688+
let nth v n =
689+
failwith "TODO"
690+
691+
let length v =
692+
failwith "TODO"
693+
694+
let map2 f v v' =
695+
failwith "TODO"
696+
697+
let map2_with f v v' =
698+
failwith "TODO"
699+
700+
let findi f v =
701+
failwith "TODO"
702+
703+
let map f v =
704+
failwith "TODO"
705+
706+
let map_with f v =
707+
failwith "TODO"
708+
709+
let compare_length_with v n =
710+
failwith "TODO"
711+
712+
let of_list l =
713+
failwith "TODO"
714+
715+
let to_list v =
716+
failwith "TODO"
717+
718+
let filteri f v =
719+
failwith "TODO"
720+
721+
let append v v' =
722+
failwith "TODO"
723+
724+
let exists f v =
725+
failwith "TODO"
726+
727+
let rev v =
728+
failwith "TODO"
729+
730+
let rev_with v =
731+
failwith "TODO"
732+
733+
let map2i f v v' =
734+
failwith "TODO"
735+
736+
let map2i_with f v v' =
737+
failwith "TODO"
738+
739+
let mapi f v =
740+
failwith "TODO"
741+
742+
let mapi_with f v =
743+
failwith "TODO"
744+
745+
let find2i f v v' =
746+
failwith "TODO"
747+
748+
let to_array v =
749+
failwith "TODO"
750+
751+
let of_array a =
752+
failwith "TODO"
753+
754+
let copy v = v
755+
756+
let of_sparse_list ls col_count =
757+
failwith "TODO"
758+
759+
let to_sparse_list v =
760+
failwith "TODO"
761+
762+
end
763+
764+
633765
(** Sparse matrix implementation.
634766
It provides a normalization function to reduce a matrix into reduced row echelon form.
635767
Operations exploit that the input matrix/matrices are in reduced row echelon form already. *)
@@ -669,14 +801,9 @@ module SparseMatrix: AbstractMatrix =
669801
timing_wrap "copy" (copy) m
670802

671803
let add_empty_columns m (cols : int enumerable) =
672-
let colsL = Array.to_list(cols) in
804+
let colsL = List.sort (fun a b -> a-b) (Array.to_list cols) in
673805
let emptyT = A.zero in
674806
let rec list_of_all_before_index idx cols =
675-
(*This should return two arrays
676-
all the idices before idx and all those after, but I'm not sure if inclusive or not
677-
e.g. list_of_all_before_index 3 [1,2,3,4] = ([1,2], [3,4]) or = ([1,2,3], [4])
678-
right now its of the first form!
679-
*)
680807
match cols with
681808
| x::xs ->
682809
if x < idx

0 commit comments

Comments
 (0)