Added transpose

This commit is contained in:
Anthony Scemama 2020-12-16 12:03:20 +01:00
parent 51b1d0d002
commit b7add6b2b6
2 changed files with 20 additions and 5 deletions

View File

@ -68,12 +68,21 @@ let col_inplace t j =
Mat.col t j
|> Vector.of_bigarray_inplace
(*
let col t j =
Mat.col t j
|> Vector.of_bigarray
*)
let transpose t =
Mat.transpose_copy t
let transpose_inplace t =
let mat = to_bigarray_inplace t in
let d1 = dim1 t in
let d2 = dim2 t in
assert (d1 = d2);
for j=1 to d1 do
for i=1 to (j-1) do
let ij, ji = mat.{i,j}, mat.{j,i} in
mat.{i,j} <- ji;
mat.{j,i} <- ij
done;
done
let to_col_vecs t =
Mat.to_col_vecs t

View File

@ -129,6 +129,12 @@ val col: ('a,'b) t -> int -> 'a Vector.t
val col_inplace: ('a,'b) t -> int -> 'a Vector.t
(** Returns a column of the matrix as a vector *)
val transpose: ('a,'b) t -> ('b,'a) t
(** Returns the transposed matrix *)
val transpose_inplace: ('a,'a) t -> unit
(** Transposes the matrix in place. *)
val detri: ('a,'b) t -> ('a,'b) t
(** Takes an upper-triangular matrix, and makes it a symmetric matrix
by mirroring the defined triangle along the diagonal. *)