diff libinterp/corefcn/__ichol__.cc @ 23099:d44537a50f4b

__ilu__ and __ichol__: use liboctave functions instead of feval (bug #50105) * __ichol__.cc(__ichol0__, __icholt__): Remove parameter checking, as it is done in ichol.m, all input arguments must be given. Replace feval calls to "tril" by "Ftril". * __ichol__.cc(__icholt__): Replace feval "norm" calls for column-wise l1-Norm by liboctave's "xcolnorms". * __ilu__.cc(__ilu0__, __iluc__, __ilutp__): Remove parameter checking, as it is done in ilu.m, all input arguments must be given. Replace feval calls to "tril" and "triu" by "Ftril" and "Ftriu". Replace feval calls to "speye" by using SparseMatrix constructor calls. Replace feval "norm" calls for column-wise l2-Norm by liboctave's "xcolnorms" and for row-wise l2-Norm by "xrownorms". * ilu.m: Avoid undefined values for "ilutp" and one return value. Refactor tests for "ilutp". Added xtest, where failure was just commented out.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Fri, 27 Jan 2017 16:39:15 +0100
parents ef4d915df748
children 092078913d54
line wrap: on
line diff
--- a/libinterp/corefcn/__ichol__.cc	Thu Jan 26 23:46:47 2017 -0500
+++ b/libinterp/corefcn/__ichol__.cc	Fri Jan 27 16:39:15 2017 +0100
@@ -1,7 +1,7 @@
 /*
 
-Copyright (C) 2014-2016 Eduardo Ramos Fernández <eduradical951@gmail.com>
-Copyright (C) 2013-2016 Kai T. Ohlhus <k.ohlhus@gmail.com>
+Copyright (C) 2014-2017 Eduardo Ramos Fernández <eduradical951@gmail.com>
+Copyright (C) 2013-2017 Kai T. Ohlhus <k.ohlhus@gmail.com>
 
 This file is part of Octave.
 
@@ -26,10 +26,12 @@
 #endif
 
 #include "oct-locbuf.h"
+#include "oct-norm.h"
 
 #include "defun.h"
 #include "error.h"
-#include "parse.h"
+
+#include "builtin-defun-decls.h"
 
 // Secondary functions for complex and real case used in ichol algorithms.
 Complex ichol_mult_complex (Complex a, Complex b)
@@ -181,37 +183,31 @@
 
 DEFUN (__ichol0__, args, ,
        doc: /* -*- texinfo -*-
-@deftypefn  {} {@var{L} =} __ichol0__ (@var{A})
-@deftypefnx {} {@var{L} =} __ichol0__ (@var{A}, @var{michol})
+@deftypefn {} {@var{L} =} __ichol0__ (@var{A}, @var{michol})
 Undocumented internal function.
 @end deftypefn */)
 {
-  std::string michol = "off";
-  if (args.length ())
-    michol = args(1).string_value ();
+  if (args.length () != 2)
+    print_usage ();
+
+  std::string michol = args(1).string_value ();
 
   // In ICHOL0 algorithm the zero-pattern of the input matrix is preserved
   // so its structure does not change during the algorithm.  The same input
   // matrix is used to build the output matrix due to that fact.
-  octave_value_list arg_list;
   if (! args(0).is_complex_type ())
     {
-      SparseMatrix sm = args(0).sparse_matrix_value ();
-      arg_list.append (sm);
-      sm = octave::feval ("tril", arg_list)(0).sparse_matrix_value ();
+      SparseMatrix sm = Ftril (args(0))(0).sparse_matrix_value ();
       ichol_0 <SparseMatrix, double, ichol_mult_real,
                ichol_checkpivot_real> (sm, michol);
-
       return ovl (sm);
     }
   else
     {
-      SparseComplexMatrix sm = args(0).sparse_complex_matrix_value ();
-      arg_list.append (sm);
-      sm = octave::feval ("tril", arg_list)(0).sparse_complex_matrix_value ();
+      SparseComplexMatrix sm =
+        Ftril (args(0))(0).sparse_complex_matrix_value ();
       ichol_0 <SparseComplexMatrix, Complex, ichol_mult_complex,
                ichol_checkpivot_complex> (sm, michol);
-
       return ovl (sm);
     }
 }
@@ -416,55 +412,32 @@
 
 DEFUN (__icholt__, args, ,
        doc: /* -*- texinfo -*-
-@deftypefn  {} {@var{L} =} __icholt__ (@var{A})
-@deftypefnx {} {@var{L} =} __icholt__ (@var{A}, @var{droptol})
-@deftypefnx {} {@var{L} =} __icholt__ (@var{A}, @var{droptol}, @var{michol})
+@deftypefn {} {@var{L} =} __icholt__ (@var{A}, @var{droptol}, @var{michol})
 Undocumented internal function.
 @end deftypefn */)
 {
-  int nargin = args.length ();
-  // Default values of parameters
-  std::string michol = "off";
-  double droptol = 0;
+  if (args.length () != 3)
+    print_usage ();
 
-  // Don't repeat input validation of arguments done in ichol.m
-  if (nargin >= 2)
-    droptol = args(1).double_value ();
+  double droptol = args(1).double_value ();
+  std::string michol = args(2).string_value ();
 
-  if (nargin == 3)
-    michol = args(2).string_value ();
-
-  octave_value_list arg_list;
   if (! args(0).is_complex_type ())
     {
-      Array <double> cols_norm;
       SparseMatrix L;
-      arg_list.append (args(0).sparse_matrix_value ());
-      SparseMatrix sm_l =
-        octave::feval ("tril", arg_list)(0).sparse_matrix_value ();
-      arg_list(0) = sm_l;
-      arg_list(1) = 1;
-      arg_list(2) = "cols";
-      cols_norm = octave::feval ("norm", arg_list)(0).vector_value ();
-      arg_list.clear ();
+      SparseMatrix sm_l = Ftril (args(0))(0).sparse_matrix_value ();
       ichol_t <SparseMatrix,
                double, ichol_mult_real, ichol_checkpivot_real>
-               (sm_l, L, cols_norm.fortran_vec (), droptol, michol);
+               (sm_l, L, xcolnorms (sm_l, 1).fortran_vec (), droptol, michol);
 
       return ovl (L);
     }
   else
     {
-      Array <Complex> cols_norm;
       SparseComplexMatrix L;
-      arg_list.append (args(0).sparse_complex_matrix_value ());
       SparseComplexMatrix sm_l =
-        octave::feval ("tril", arg_list)(0).sparse_complex_matrix_value ();
-      arg_list(0) = sm_l;
-      arg_list(1) = 1;
-      arg_list(2) = "cols";
-      cols_norm = octave::feval ("norm", arg_list)(0).complex_vector_value ();
-      arg_list.clear ();
+        Ftril (args(0))(0).sparse_complex_matrix_value ();
+      Array <Complex> cols_norm = xcolnorms (sm_l, 1);
       ichol_t <SparseComplexMatrix,
                Complex, ichol_mult_complex, ichol_checkpivot_complex>
                (sm_l, L, cols_norm.fortran_vec (),