Mercurial > octave
changeset 22846:e827d2c089f4
use F77_INT instead of octave_idx_type for liboctave Quad and lu classes
* Quad.cc, lu.cc, lu.h: Use F77_INT instead of octave_idx_type for
interfacing with Fortran.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 29 Nov 2016 10:33:06 -0500 |
parents | 7bb977866f55 |
children | 8fb0b766f61a |
files | liboctave/numeric/Quad.cc liboctave/numeric/lu.cc liboctave/numeric/lu.h |
diffstat | 3 files changed, 273 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/numeric/Quad.cc Tue Nov 29 00:37:20 2016 -0500 +++ b/liboctave/numeric/Quad.cc Tue Nov 29 10:33:06 2016 -0500 @@ -38,8 +38,8 @@ // function, and the user wants us to quit. int quad_integration_error = 0; -typedef octave_idx_type (*quad_fcn_ptr) (double*, int&, double*); -typedef octave_idx_type (*quad_float_fcn_ptr) (float*, int&, float*); +typedef F77_INT (*quad_fcn_ptr) (double*, int&, double*); +typedef F77_INT (*quad_float_fcn_ptr) (float*, int&, float*); extern "C" { @@ -76,7 +76,7 @@ F77_INT*, F77_REAL*); } -static octave_idx_type +static F77_INT user_function (double *x, int& ierr, double *result) { BEGIN_INTERRUPT_WITH_EXCEPTIONS; @@ -105,7 +105,7 @@ return 0; } -static octave_idx_type +static F77_INT float_user_function (float *x, int& ierr, float *result) { BEGIN_INTERRUPT_WITH_EXCEPTIONS; @@ -126,29 +126,40 @@ DefQuad::do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) { - octave_idx_type npts = singularities.numel () + 2; + F77_INT npts = to_f77_int (singularities.numel () + 2); double *points = singularities.fortran_vec (); double result = 0.0; - octave_idx_type leniw = 183*npts - 122; - Array<octave_idx_type> iwork (dim_vector (leniw, 1)); - octave_idx_type *piwork = iwork.fortran_vec (); + F77_INT leniw = 183*npts - 122; + Array<F77_INT> iwork (dim_vector (leniw, 1)); + F77_INT *piwork = iwork.fortran_vec (); - octave_idx_type lenw = 2*leniw - npts; + F77_INT lenw = 2*leniw - npts; Array<double> work (dim_vector (lenw, 1)); double *pwork = work.fortran_vec (); user_fcn = f; - octave_idx_type last; + F77_INT last; double abs_tol = absolute_tolerance (); double rel_tol = relative_tolerance (); + // NEVAL and IER are output only parameters and F77_INT can not be a + // wider type than octave_idx_type so we can create local variables + // here that are the correct type for the Fortran subroutine and then + // copy them to the function parameters without needing to preserve + // and pass the values to the Fortran subroutine. + + F77_INT xneval, xier; + F77_XFCN (dqagp, DQAGP, (user_function, lower_limit, upper_limit, npts, points, abs_tol, rel_tol, result, - abserr, neval, ier, leniw, lenw, last, + abserr, xneval, xier, leniw, lenw, last, piwork, pwork)); + neval = xneval; + ier = xier; + return result; } @@ -164,18 +175,18 @@ { double result = 0.0; - octave_idx_type leniw = 128; - Array<octave_idx_type> iwork (dim_vector (leniw, 1)); - octave_idx_type *piwork = iwork.fortran_vec (); + F77_INT leniw = 128; + Array<F77_INT> iwork (dim_vector (leniw, 1)); + F77_INT *piwork = iwork.fortran_vec (); - octave_idx_type lenw = 8*leniw; + F77_INT lenw = 8*leniw; Array<double> work (dim_vector (lenw, 1)); double *pwork = work.fortran_vec (); user_fcn = f; - octave_idx_type last; + F77_INT last; - octave_idx_type inf; + F77_INT inf; switch (type) { case bound_to_inf: @@ -198,10 +209,21 @@ double abs_tol = absolute_tolerance (); double rel_tol = relative_tolerance (); + // NEVAL and IER are output only parameters and F77_INT can not be a + // wider type than octave_idx_type so we can create local variables + // here that are the correct type for the Fortran subroutine and then + // copy them to the function parameters without needing to preserve + // and pass the values to the Fortran subroutine. + + F77_INT xneval, xier; + F77_XFCN (dqagi, DQAGI, (user_function, bound, inf, abs_tol, rel_tol, - result, abserr, neval, ier, leniw, lenw, + result, abserr, xneval, xier, leniw, lenw, last, piwork, pwork)); + neval = xneval; + ier = xier; + return result; } @@ -221,29 +243,40 @@ FloatDefQuad::do_integrate (octave_idx_type& ier, octave_idx_type& neval, float& abserr) { - octave_idx_type npts = singularities.numel () + 2; + F77_INT npts = to_f77_int (singularities.numel () + 2); float *points = singularities.fortran_vec (); float result = 0.0; - octave_idx_type leniw = 183*npts - 122; - Array<octave_idx_type> iwork (dim_vector (leniw, 1)); - octave_idx_type *piwork = iwork.fortran_vec (); + F77_INT leniw = 183*npts - 122; + Array<F77_INT> iwork (dim_vector (leniw, 1)); + F77_INT *piwork = iwork.fortran_vec (); - octave_idx_type lenw = 2*leniw - npts; + F77_INT lenw = 2*leniw - npts; Array<float> work (dim_vector (lenw, 1)); float *pwork = work.fortran_vec (); float_user_fcn = ff; - octave_idx_type last; + F77_INT last; float abs_tol = single_precision_absolute_tolerance (); float rel_tol = single_precision_relative_tolerance (); + // NEVAL and IER are output only parameters and F77_INT can not be a + // wider type than octave_idx_type so we can create local variables + // here that are the correct type for the Fortran subroutine and then + // copy them to the function parameters without needing to preserve + // and pass the values to the Fortran subroutine. + + F77_INT xneval, xier; + F77_XFCN (qagp, QAGP, (float_user_function, lower_limit, upper_limit, npts, points, abs_tol, rel_tol, result, - abserr, neval, ier, leniw, lenw, last, + abserr, xneval, xier, leniw, lenw, last, piwork, pwork)); + neval = xneval; + ier = xier; + return result; } @@ -259,18 +292,18 @@ { float result = 0.0; - octave_idx_type leniw = 128; - Array<octave_idx_type> iwork (dim_vector (leniw, 1)); - octave_idx_type *piwork = iwork.fortran_vec (); + F77_INT leniw = 128; + Array<F77_INT> iwork (dim_vector (leniw, 1)); + F77_INT *piwork = iwork.fortran_vec (); - octave_idx_type lenw = 8*leniw; + F77_INT lenw = 8*leniw; Array<float> work (dim_vector (lenw, 1)); float *pwork = work.fortran_vec (); float_user_fcn = ff; - octave_idx_type last; + F77_INT last; - octave_idx_type inf; + F77_INT inf; switch (type) { case bound_to_inf: @@ -293,10 +326,21 @@ float abs_tol = single_precision_absolute_tolerance (); float rel_tol = single_precision_relative_tolerance (); + // NEVAL and IER are output only parameters and F77_INT can not be a + // wider type than octave_idx_type so we can create local variables + // here that are the correct type for the Fortran subroutine and then + // copy them to the function parameters without needing to preserve + // and pass the values to the Fortran subroutine. + + F77_INT xneval, xier; + F77_XFCN (qagi, QAGI, (float_user_function, bound, inf, abs_tol, rel_tol, - result, abserr, neval, ier, leniw, lenw, + result, abserr, xneval, xier, leniw, lenw, last, piwork, pwork)); + neval = xneval; + ier = xier; + return result; }
--- a/liboctave/numeric/lu.cc Tue Nov 29 00:37:20 2016 -0500 +++ b/liboctave/numeric/lu.cc Tue Nov 29 10:33:06 2016 -0500 @@ -78,7 +78,7 @@ if (packed ()) { octave_idx_type a_nr = a_fact.rows (); - octave_idx_type a_nc = a_fact.cols (); + octave_idx_type a_nc = a_fact.columns (); octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); T l (a_nr, mn, ELT_T (0.0)); @@ -105,7 +105,7 @@ if (packed ()) { octave_idx_type a_nr = a_fact.rows (); - octave_idx_type a_nc = a_fact.cols (); + octave_idx_type a_nc = a_fact.columns (); octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); T u (mn, a_nc, ELT_T (0.0)); @@ -252,21 +252,21 @@ template <> lu<Matrix>::lu (const Matrix& a) { - octave_idx_type a_nr = a.rows (); - octave_idx_type a_nc = a.cols (); - octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); + F77_INT a_nr = to_f77_int (a.rows ()); + F77_INT a_nc = to_f77_int (a.columns ()); + F77_INT mn = (a_nr < a_nc ? a_nr : a_nc); ipvt.resize (dim_vector (mn, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); + F77_INT *pipvt = ipvt.fortran_vec (); a_fact = a; double *tmp_data = a_fact.fortran_vec (); - octave_idx_type info = 0; + F77_INT info = 0; F77_XFCN (dgetrf, DGETRF, (a_nr, a_nc, tmp_data, a_nr, pipvt, info)); - for (octave_idx_type i = 0; i < mn; i++) + for (F77_INT i = 0; i < mn; i++) pipvt[i] -= 1; } @@ -282,11 +282,14 @@ Matrix& l = l_fact; Matrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); ColumnVector utmp = u; @@ -305,14 +308,20 @@ Matrix& l = l_fact; Matrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (volatile F77_INT i = 0; i < u_nc; i++) { ColumnVector utmp = u.column (i); ColumnVector vtmp = v.column (i); @@ -332,22 +341,25 @@ Matrix& l = l_fact; Matrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); ColumnVector utmp = u; ColumnVector vtmp = v; OCTAVE_LOCAL_BUFFER (double, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, ipvt.fortran_vec (), utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } template <> @@ -360,16 +372,22 @@ Matrix& l = l_fact; Matrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); OCTAVE_LOCAL_BUFFER (double, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile F77_INT i = 0; i < u_nc; i++) { ColumnVector utmp = u.column (i); ColumnVector vtmp = v.column (i); @@ -378,7 +396,7 @@ ipvt.fortran_vec (), utmp.data (), vtmp.data (), w)); } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #endif @@ -386,21 +404,21 @@ template <> lu<FloatMatrix>::lu (const FloatMatrix& a) { - octave_idx_type a_nr = a.rows (); - octave_idx_type a_nc = a.cols (); - octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); + F77_INT a_nr = to_f77_int (a.rows ()); + F77_INT a_nc = to_f77_int (a.columns ()); + F77_INT mn = (a_nr < a_nc ? a_nr : a_nc); ipvt.resize (dim_vector (mn, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); + F77_INT *pipvt = ipvt.fortran_vec (); a_fact = a; float *tmp_data = a_fact.fortran_vec (); - octave_idx_type info = 0; + F77_INT info = 0; F77_XFCN (sgetrf, SGETRF, (a_nr, a_nc, tmp_data, a_nr, pipvt, info)); - for (octave_idx_type i = 0; i < mn; i++) + for (F77_INT i = 0; i < mn; i++) pipvt[i] -= 1; } @@ -416,11 +434,14 @@ FloatMatrix& l = l_fact; FloatMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); FloatColumnVector utmp = u; @@ -440,14 +461,20 @@ FloatMatrix& l = l_fact; FloatMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (volatile F77_INT i = 0; i < u_nc; i++) { FloatColumnVector utmp = u.column (i); FloatColumnVector vtmp = v.column (i); @@ -468,22 +495,25 @@ FloatMatrix& l = l_fact; FloatMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); FloatColumnVector utmp = u; FloatColumnVector vtmp = v; OCTAVE_LOCAL_BUFFER (float, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, ipvt.fortran_vec (), utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } template <> @@ -496,16 +526,22 @@ FloatMatrix& l = l_fact; FloatMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); OCTAVE_LOCAL_BUFFER (float, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile F77_INT i = 0; i < u_nc; i++) { FloatColumnVector utmp = u.column (i); FloatColumnVector vtmp = v.column (i); @@ -514,7 +550,7 @@ ipvt.fortran_vec (), utmp.data (), vtmp.data (), w)); } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #endif @@ -522,22 +558,22 @@ template <> lu<ComplexMatrix>::lu (const ComplexMatrix& a) { - octave_idx_type a_nr = a.rows (); - octave_idx_type a_nc = a.cols (); - octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); + F77_INT a_nr = to_f77_int (a.rows ()); + F77_INT a_nc = to_f77_int (a.columns ()); + F77_INT mn = (a_nr < a_nc ? a_nr : a_nc); ipvt.resize (dim_vector (mn, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); + F77_INT *pipvt = ipvt.fortran_vec (); a_fact = a; Complex *tmp_data = a_fact.fortran_vec (); - octave_idx_type info = 0; + F77_INT info = 0; F77_XFCN (zgetrf, ZGETRF, (a_nr, a_nc, F77_DBLE_CMPLX_ARG (tmp_data), a_nr, pipvt, info)); - for (octave_idx_type i = 0; i < mn; i++) + for (F77_INT i = 0; i < mn; i++) pipvt[i] -= 1; } @@ -554,11 +590,14 @@ ComplexMatrix& l = l_fact; ComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); ComplexColumnVector utmp = u; @@ -579,14 +618,20 @@ ComplexMatrix& l = l_fact; ComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (volatile F77_INT i = 0; i < u_nc; i++) { ComplexColumnVector utmp = u.column (i); ComplexColumnVector vtmp = v.column (i); @@ -608,23 +653,26 @@ ComplexMatrix& l = l_fact; ComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); ComplexColumnVector utmp = u; ComplexColumnVector vtmp = v; OCTAVE_LOCAL_BUFFER (Complex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment F77_XFCN (zlup1up, ZLUP1UP, (m, n, F77_DBLE_CMPLX_ARG (l.fortran_vec ()), m, F77_DBLE_CMPLX_ARG (r.fortran_vec ()), k, ipvt.fortran_vec (), F77_CONST_DBLE_CMPLX_ARG (utmp.data ()), F77_CONST_DBLE_CMPLX_ARG (vtmp.data ()), F77_DBLE_CMPLX_ARG (w))); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } template <> @@ -637,16 +685,22 @@ ComplexMatrix& l = l_fact; ComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); OCTAVE_LOCAL_BUFFER (Complex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile F77_INT i = 0; i < u_nc; i++) { ComplexColumnVector utmp = u.column (i); ComplexColumnVector vtmp = v.column (i); @@ -656,7 +710,7 @@ F77_CONST_DBLE_CMPLX_ARG (utmp.data ()), F77_CONST_DBLE_CMPLX_ARG (vtmp.data ()), F77_DBLE_CMPLX_ARG (w))); } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #endif @@ -664,22 +718,22 @@ template <> lu<FloatComplexMatrix>::lu (const FloatComplexMatrix& a) { - octave_idx_type a_nr = a.rows (); - octave_idx_type a_nc = a.cols (); - octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); + F77_INT a_nr = to_f77_int (a.rows ()); + F77_INT a_nc = to_f77_int (a.columns ()); + F77_INT mn = (a_nr < a_nc ? a_nr : a_nc); ipvt.resize (dim_vector (mn, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); + F77_INT *pipvt = ipvt.fortran_vec (); a_fact = a; FloatComplex *tmp_data = a_fact.fortran_vec (); - octave_idx_type info = 0; + F77_INT info = 0; F77_XFCN (cgetrf, CGETRF, (a_nr, a_nc, F77_CMPLX_ARG (tmp_data), a_nr, pipvt, info)); - for (octave_idx_type i = 0; i < mn; i++) + for (F77_INT i = 0; i < mn; i++) pipvt[i] -= 1; } @@ -696,20 +750,21 @@ FloatComplexMatrix& l = l_fact; FloatComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); + + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); - if (u.numel () == m && v.numel () == n) - { - FloatComplexColumnVector utmp = u; - FloatComplexColumnVector vtmp = v; - F77_XFCN (clu1up, CLU1UP, (m, n, F77_CMPLX_ARG (l.fortran_vec ()), m, - F77_CMPLX_ARG (r.fortran_vec ()), k, - F77_CMPLX_ARG (utmp.fortran_vec ()), F77_CMPLX_ARG (vtmp.fortran_vec ()))); - } - else + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + FloatComplexColumnVector utmp = u; + FloatComplexColumnVector vtmp = v; + F77_XFCN (clu1up, CLU1UP, (m, n, F77_CMPLX_ARG (l.fortran_vec ()), m, + F77_CMPLX_ARG (r.fortran_vec ()), k, + F77_CMPLX_ARG (utmp.fortran_vec ()), F77_CMPLX_ARG (vtmp.fortran_vec ()))); } template <> @@ -723,14 +778,20 @@ FloatComplexMatrix& l = l_fact; FloatComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (volatile F77_INT i = 0; i < u_nc; i++) { FloatComplexColumnVector utmp = u.column (i); FloatComplexColumnVector vtmp = v.column (i); @@ -751,23 +812,26 @@ FloatComplexMatrix& l = l_fact; FloatComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.numel () != m || v.numel () != n) + F77_INT u_nel = to_f77_int (u.numel ()); + F77_INT v_nel = to_f77_int (v.numel ()); + + if (u_nel != m || v_nel != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); FloatComplexColumnVector utmp = u; FloatComplexColumnVector vtmp = v; OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment F77_XFCN (clup1up, CLUP1UP, (m, n, F77_CMPLX_ARG (l.fortran_vec ()), m, F77_CMPLX_ARG (r.fortran_vec ()), k, ipvt.fortran_vec (), F77_CONST_CMPLX_ARG (utmp.data ()), F77_CONST_CMPLX_ARG (vtmp.data ()), F77_CMPLX_ARG (w))); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } template <> @@ -781,16 +845,22 @@ FloatComplexMatrix& l = l_fact; FloatComplexMatrix& r = a_fact; - octave_idx_type m = l.rows (); - octave_idx_type n = r.columns (); - octave_idx_type k = l.columns (); + F77_INT m = to_f77_int (l.rows ()); + F77_INT n = to_f77_int (r.columns ()); + F77_INT k = to_f77_int (l.columns ()); - if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + F77_INT u_nr = to_f77_int (u.rows ()); + F77_INT u_nc = to_f77_int (u.columns ()); + + F77_INT v_nr = to_f77_int (v.rows ()); + F77_INT v_nc = to_f77_int (v.columns ()); + + if (u_nr != m || v_nr != n || u_nc != v_nc) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) + for (F77_INT i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile F77_INT i = 0; i < u_nc; i++) { FloatComplexColumnVector utmp = u.column (i); FloatComplexColumnVector vtmp = v.column (i); @@ -800,7 +870,7 @@ F77_CONST_CMPLX_ARG (utmp.data ()), F77_CONST_CMPLX_ARG (vtmp.data ()), F77_CMPLX_ARG (w))); } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + for (F77_INT i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #endif
--- a/liboctave/numeric/lu.h Tue Nov 29 00:37:20 2016 -0500 +++ b/liboctave/numeric/lu.h Tue Nov 29 10:33:06 2016 -0500 @@ -91,12 +91,16 @@ protected: + // The result of getp is passed to other Octave Matrix + // fucntions, so we use octave_idx_type. Array<octave_idx_type> getp (void) const; T a_fact; T l_fact; - Array<octave_idx_type> ipvt; + // This is internal storage that is passed to Fortran, so we + // need a Fortran INTEGER. + Array<octave_f77_int_type> ipvt; }; } }