Your call to Array.create is placing the same physical vector in each column of the array - this matters when you are using mutation to initialize. Generally use Array.init and Array2.init to avoid this kind of aliasing. Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 

#light

let of_array2 (mat:float[,]) = 
    Array.init (Array2.length1 mat) (fun i -> 
        Array.init (Array2.length2 mat) (fun j -> 
           mat.[i,j]))

let diag n = 
  let res = Array2.zero_create n n 
  for i= 0 to (n-1) do
    res.[i,i] <- 1.0
  res


diag 3 |> of_array2

By on 11/7/2006 5:16 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper