This is what it should look like:
>> | 1 | 2 | 3 |
>> ----------------
>> 1 | 0 | A | B |
>> ----------------
>> 2 | A | 0 | C |
>> ----------------
>> 3 | B | C | 0 |
>> ----------------
>
> Perhaps I'm misapprehending the issue, but why isn't the following
> sufficient:
>
> (defn transpose [matrix]
> (vec (apply map vector m)))
>
> (transpose
> [[1 2]
> [3 4]])
>
> [[1 3]
> [2 4]]
So transposing it is not enough. I need the part above the main diagonal to be 'transposed' and put underneath the main diagonal. Maybe I wasn't as clear as I hoped. Let me restate the issue.
Currently I'm doing this in 2 stages, basically generating a matrix of refs, then copying the upper half into the lower half. The problem is that I want to do this in 1 function, but the code that I posted earlier can't do this, because the map basically has to refer to the matrix that it's trying to build up. I tried doing it like this:
(apply vector (map (fn [i]
(apply vector (map (fn [j] (cond
(= i j) nil
(< i j) (ref somevalue)
(> i j) (nth (nth matrix j) i))) n))) n))))))
But as you'd expect all values under the main diagonal get set to nil, because those 2 nth's are referring to positions in the matrix that hasn't been set yet.
So currently I got it working by basically repeating the above code. It's ugly and inefficient, and I'm wondering whether it can be done more efficiently.
As for performance, I don't actually intend do do any matrix operations on it, just lookups.
- Tiemo.