Markus Mottl avatar Markus Mottl committed 8c98eb5

Improved mvec_to_array check

Comments (0)

Files changed (1)

 let mvec_of_array ar =
   let n = Array.length ar in
   let mat = create_mvec n in
-  if n <> 0 then
-    for row = 1 to n do mat.{row, 1} <- ar.(row - 1) done;
+  for row = 1 to n do mat.{row, 1} <- ar.(row - 1) done;
   mat
 
 let dim1 (mat : mat) = Array2.dim1 mat
 let dim2 (mat : mat) = Array2.dim2 mat
 
 let mvec_to_array mat =
-  let n = dim1 mat in
-  if n = 0 then [||]
+  if dim2 mat <> 1 then failwith "mvec_to_array: more than one column"
   else
-    let ar = Array.make n mat.{1, 1} in
-    for row = 2 to n do ar.(row - 1) <- mat.{row, 1} done;
-    ar
+    let n = dim1 mat in
+    if n = 0 then [||]
+    else
+      let ar = Array.make n mat.{1, 1} in
+      for row = 2 to n do ar.(row - 1) <- mat.{row, 1} done;
+      ar
 
 let from_col_vec vec = reshape_2 (genarray_of_array1 vec) (Array1.dim vec) 1
 let from_row_vec vec = reshape_2 (genarray_of_array1 vec) 1 (Array1.dim vec)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.