<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -103,8 +103,8 @@ unsafeGetColPerm :: (WriteVector x m, Elem e)
                  =&gt; Perm (n,p) e -&gt; Int -&gt; m (x n e)
 unsafeGetColPerm (Identity n)   j = newBasisVector n j
 unsafeGetColPerm (Perm h sigma) j
-    | h == NoTrans = newBasisVector n (P.unsafeAt sigma j)
-    | otherwise    = newBasisVector n (P.indexOf sigma j)
+    | h == NoTrans = newBasisVector n (P.indexOf sigma j)
+    | otherwise    = newBasisVector n (P.unsafeAt sigma j)
   where
     n = P.size sigma
 {-# INLINE unsafeGetColPerm #-}
@@ -153,11 +153,11 @@ unsafeDoSApplyAddPerm alpha p@(Perm h sigma) x beta y
             forM_ [0..(n-1)] $ \i -&gt;
                 let i' = P.unsafeAt sigma i in
                 case h of
-                   NoTrans -&gt; do
+                   ConjTrans -&gt; do
                         e &lt;- unsafeReadElem x i  
                         f &lt;- unsafeReadElem y i'
                         unsafeWriteElem y i' (alpha*e + f)
-                   ConjTrans  -&gt; do
+                   NoTrans  -&gt; do
                         e &lt;- unsafeReadElem x i'
                         f &lt;- unsafeReadElem y i
                         unsafeWriteElem y i (alpha*e + f)
@@ -175,9 +175,9 @@ unsafeDoSApplyAddMatPerm alpha p@(Perm h sigma) b beta c =
         forM_ [0..(m-1)] $ \i -&gt;
             let i' = P.unsafeAt sigma i in
             case h of
-                NoTrans   -&gt; unsafeAxpyVector alpha (unsafeRowView b i)
+                ConjTrans -&gt; unsafeAxpyVector alpha (unsafeRowView b i)
                                                     (unsafeRowView c i') 
-                ConjTrans -&gt; unsafeAxpyVector alpha (unsafeRowView b i') 
+                NoTrans   -&gt; unsafeAxpyVector alpha (unsafeRowView b i') 
                                                     (unsafeRowView c i)
 {-# INLINE unsafeDoSApplyAddMatPerm #-}
 </diff>
      <filename>lib/Data/Matrix/Perm.hs</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@ import Orthogonal( tests_Orthogonal )
 main :: IO ()
 main = do
     args &lt;- getArgs
-    let n = if null args then 1000 else read (head args)
+    let n = if null args then 100 else read (head args)
     
     printf &quot;\nRunnings tests for field `%s'\n&quot; field
     </diff>
      <filename>tests/Main.hs</filename>
    </modified>
    <modified>
      <diff>@@ -5,20 +5,126 @@ module Orthogonal
 import Driver
 import Monadic
 import Test.QuickCheck hiding ( vector )
-import Test.QuickCheck.BLAS( Pos(..), Nat2(..) )
+import qualified Test.QuickCheck as QC
+import Test.QuickCheck.BLAS( Index(..), Pos(..), Nat(..), Nat2(..) )
 import qualified Test.QuickCheck.BLAS as Test
 
 import Control.Monad
 
+import Data.Permute( Permute )
+import qualified Data.Permute as P
+
 import Data.Elem.BLAS
 import Data.Vector.Dense
 import Data.Vector.Dense.ST
 import Data.Matrix.Dense
 import Data.Matrix.Dense.ST
 import Data.Matrix.House
+import Data.Matrix.Perm
 import Data.Matrix.QR
 
-import Debug.Trace
+
+testPermute :: Int -&gt; Gen Permute
+testPermute n = do
+    es &lt;- QC.vector n :: Gen [Int]
+    return $ P.order n es
+
+testPerm :: Int -&gt; Gen (Perm (n,n) e)
+testPerm n = do
+    p &lt;- liftM permFromPermute $ testPermute n
+    elements [ identityPerm n, p, herm p ]
+    
+prop_perm_herm (Nat n) =
+    forAll (testPerm n) $ \p -&gt;
+        permuteFromPerm (herm p) == P.inverse (permuteFromPerm p)
+        
+prop_perm_col (Index n i) =
+    forAll (testPerm n) $ \p -&gt;
+        col p i
+        === 
+        p &lt;*&gt; (basisVector n i :: V) 
+
+prop_perm_apply_basis (Index n i) =
+    forAll (testPerm n) $ \p -&gt;
+        p &lt;*&gt; (basisVector n i :: V) 
+        === 
+        basisVector n (P.indexOf (permuteFromPerm p) i)
+
+prop_perm_herm_apply (Nat n) =
+    forAll (testPerm n)    $ \p -&gt;
+    forAll (Test.vector n) $ \(x :: V) -&gt;
+        p &lt;*&gt; herm p &lt;*&gt; x === x
+
+prop_herm_perm_apply (Nat n) =
+    forAll (testPerm n)    $ \p -&gt;
+    forAll (Test.vector n) $ \(x :: V) -&gt;
+        herm p &lt;*&gt; p &lt;*&gt; x === x
+
+prop_perm_solve (Nat n) =
+    forAll (testPerm n)    $ \p -&gt;
+    forAll (Test.vector n) $ \(x :: V) -&gt;
+        p &lt;\&gt; x === herm p &lt;*&gt; x
+
+prop_perm_applyMat_cols (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(a :: M) -&gt;
+        cols (p &lt;**&gt; a) === map (p &lt;*&gt;) (cols a)
+
+prop_perm_herm_applyMat (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(a :: M) -&gt;
+        p &lt;**&gt; herm p &lt;**&gt; a === a
+
+prop_herm_perm_applyMat (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(a :: M) -&gt;
+        herm p &lt;**&gt; p &lt;**&gt; a === a
+
+prop_perm_solveMat_cols (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(a :: M) -&gt;
+        cols (p &lt;\\&gt; a) === map (p &lt;\&gt;) (cols a)
+
+prop_perm_solveMat (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(a :: M) -&gt;
+        p &lt;\\&gt; a === herm p &lt;**&gt; a
+
+prop_perm_doSApplyVector_ alpha (Nat n) =
+    forAll (testPerm n) $ \p -&gt;
+    forAll (Test.vector n) $ \(x :: V) -&gt;
+        monadicST $ do
+            x'  &lt;- run $ unsafeThawVector x
+            x'' &lt;- run $ freezeVector x'
+            run $ doSApplyVector_ alpha p x'
+            assert $ x ~== p &lt;*&gt; (alpha *&gt; x'')
+
+prop_perm_doSApplyMatrix_ alpha (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(b :: M) -&gt;
+        monadicST $ do
+            b'  &lt;- run $ unsafeThawMatrix b
+            b'' &lt;- run $ freezeMatrix b'
+            run $ doSApplyMatrix_ alpha p b'
+            assert $ b ~== p &lt;**&gt; (alpha *&gt; b'')
+
+prop_perm_doSSolveVector alpha (Nat n) =
+    forAll (testPerm n) $ \p -&gt;
+    forAll (Test.vector n) $ \(x :: V) -&gt;
+    forAll (Test.vector n) $ \y -&gt; 
+        monadicST $ do
+            x' &lt;- run $ unsafeThawVector x
+            run $ doSSolveVector alpha p y x'
+            assert $ x ~== p &lt;\&gt; (alpha *&gt; y)
+
+prop_perm_doSSolveMatrix alpha (Nat2 (m,n)) =
+    forAll (testPerm m) $ \p -&gt;
+    forAll (Test.matrix (m,n)) $ \(b :: M) -&gt;
+    forAll (Test.matrix (m,n)) $ \c -&gt; 
+        monadicST $ do
+            b' &lt;- run $ unsafeThawMatrix b
+            run $ doSSolveMatrix alpha p c b'
+            assert $ b ~== p &lt;\\&gt; (alpha *&gt; c)
 
 prop_setReflector_snd (Pos n) = 
     monadicST $ do
@@ -96,7 +202,24 @@ prop_qrFactor_doSSolveMatrix alpha (Nat2 (n,p)) =
                 assert $ b ~== qr &lt;\\&gt; (alpha *&gt; c)
 
 tests_Orthogonal =
-    [ (&quot;snd . setReflector&quot;, mytest prop_setReflector_snd)
+    [ 
+      (&quot;perm herm&quot;, mytest prop_perm_herm)
+    , (&quot;perm col&quot;, mytest prop_perm_col)
+    , (&quot;perm apply basis&quot;, mytest prop_perm_apply_basis)
+    , (&quot;perm herm apply&quot;, mytest prop_perm_herm_apply)
+    , (&quot;herm perm apply&quot;, mytest prop_herm_perm_apply)
+    , (&quot;perm solve&quot;, mytest prop_perm_solve)
+    , (&quot;perm applyMat cols&quot;, mytest prop_perm_applyMat_cols)
+    , (&quot;perm herm applyMat&quot;, mytest prop_perm_herm_applyMat)
+    , (&quot;herm perm applyMat&quot;, mytest prop_herm_perm_applyMat)
+    , (&quot;perm solveMat cols&quot;, mytest prop_perm_solveMat_cols)
+    , (&quot;perm solveMat&quot;, mytest prop_perm_solveMat)
+    , (&quot;perm doApplyVector_&quot;, mytest prop_perm_doSApplyVector_)
+    , (&quot;perm doApplyMatrix_&quot;, mytest prop_perm_doSApplyMatrix_)
+    , (&quot;perm doSolveVector&quot;, mytest prop_perm_doSSolveVector)
+    , (&quot;perm doSolveMatrix&quot;, mytest prop_perm_doSSolveMatrix)
+    
+    , (&quot;snd . setReflector&quot;, mytest prop_setReflector_snd)
     , (&quot;fst . reflector&quot;, mytest prop_reflector_fst)
     , (&quot;reflector &lt;*&gt;&quot;, mytest prop_reflector_vector)
     , (&quot;reflector &lt;**&gt;&quot;, mytest prop_reflector_matrix)</diff>
      <filename>tests/Orthogonal.hs</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>65e96e1cbfebad34e8fdb4aaf251640971c9be50</id>
    </parent>
  </parents>
  <author>
    <name>Patrick Perry</name>
    <email>patperry@stanford.edu</email>
  </author>
  <url>http://github.com/patperry/lapack/commit/e47271400903cc1e770e19af6487518e43278204</url>
  <id>e47271400903cc1e770e19af6487518e43278204</id>
  <committed-date>2009-01-24T20:30:39-08:00</committed-date>
  <authored-date>2009-01-24T20:30:39-08:00</authored-date>
  <message>add tests for Perm and fix bugs</message>
  <tree>7fcb7b5fe20f81a9ecb2ca5e477b5726a5d80a03</tree>
  <committer>
    <name>Patrick Perry</name>
    <email>patperry@stanford.edu</email>
  </committer>
</commit>
