]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Check for the easy case in rank_k_approximation().
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 5 May 2013 01:11:13 +0000 (21:11 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 5 May 2013 01:11:13 +0000 (21:11 -0400)
rank_k_approximation.m

index ff42f589c7a33e0eb09f1422ea43f10317b7d46a..9883084d479b1cb71d290ceb17281e82b1d56101 100644 (file)
@@ -14,6 +14,15 @@ function Ak = rank_k_approximation(A,k)
   %
   %   - ``Ak`` -- The rank-k approximation to ``A``.
   %
+  [m,n] = size(A);
+
+  if (k >= min(m,n))
+    % We're keeping greater than or equal to the maximum number of
+    % singular values that can exist.
+    Ak = A;
+    return;
+  end
+
   [U, S, V] = svds(A, k);
   Ak = U*S*V';
 end