octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seg fault with test_sparse.m


From: David Bateman
Subject: Re: Seg fault with test_sparse.m
Date: Tue, 22 Aug 2006 09:33:49 +0200
User-agent: Mozilla Thunderbird 1.0.6-7.6.20060mdk (X11/20050322)

Joe Koski wrote:

>David,
>
>I applied the patches, and now "make check" shows no errors in test_sparse:
>
>test_sparse.m .......................................... PASS 1176/1176
>
>  
>
John,

Given that Joe has given the go ahead to the attached patch, can you
apply it?

Regards
David


2006-08-22  David Bateman  <address@hidden>

    * sparse-xpow.cc: Replace all uses of pow by std::pow.
    (elem_pow): Simplify for two sparse matrices arguments.

2006-08-22  David Bateman  <address@hidden>

    * build_sparse_tests.sh: Don't force conversion to sparse boolean
    return type for string mapper functions.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./src/sparse-xpow.cc.orig   2006-08-21 11:13:58.814062855 +0200
--- ./src/sparse-xpow.cc        2006-08-19 14:56:37.361913728 +0200
***************
*** 249,255 ****
          for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             result (i, j) = pow (atmp, b(i,j));
            }
        }
  
--- 249,255 ----
          for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             result (i, j) = std::pow (atmp, b(i,j));
            }
        }
  
***************
*** 264,270 ****
          for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             result (i, j) = pow (a, b(i,j));
            }
        }
  
--- 264,270 ----
          for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             result (i, j) = std::pow (a, b(i,j));
            }
        }
  
***************
*** 289,295 ****
        for (octave_idx_type i = 0; i < nr; i++)
        {
          OCTAVE_QUIT;
!         result (i, j) = pow (atmp, b(i,j));
        }
      }
  
--- 289,295 ----
        for (octave_idx_type i = 0; i < nr; i++)
        {
          OCTAVE_QUIT;
!         result (i, j) = std::pow (atmp, b(i,j));
        }
      }
  
***************
*** 315,321 ****
  
        if (static_cast<int> (b) != b && a.any_element_is_negative ())
        {
!         ComplexMatrix result (nr, nc, Complex (pow (0.0, b)));
  
          // FIXME -- avoid apparent GNU libm bug by
          // converting A and B to complex instead of just A.
--- 315,321 ----
  
        if (static_cast<int> (b) != b && a.any_element_is_negative ())
        {
!         ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b)));
  
          // FIXME -- avoid apparent GNU libm bug by
          // converting A and B to complex instead of just A.
***************
*** 328,347 ****
              
                Complex atmp (a.data (i));
                
!               result (a.ridx(i), j) = pow (atmp, btmp);
              }
  
          retval = octave_value (result);
        }
        else
        {
!         Matrix result (nr, nc, (pow (0.0, b)));
  
          for (octave_idx_type j = 0; j < nc; j++)
            for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
              {
                OCTAVE_QUIT;
!               result (a.ridx(i), j) = pow (a.data (i), b);
              }
  
          retval = octave_value (result);
--- 328,347 ----
              
                Complex atmp (a.data (i));
                
!               result (a.ridx(i), j) = std::pow (atmp, btmp);
              }
  
          retval = octave_value (result);
        }
        else
        {
!         Matrix result (nr, nc, (std::pow (0.0, b)));
  
          for (octave_idx_type j = 0; j < nc; j++)
            for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
              {
                OCTAVE_QUIT;
!               result (a.ridx(i), j) = std::pow (a.data (i), b);
              }
  
          retval = octave_value (result);
***************
*** 361,367 ****
          Complex atmp (a.data (i));
          Complex btmp (b);
  
!         result.data (i) = pow (atmp, btmp);
        }
  
        result.maybe_compress (true);
--- 361,367 ----
          Complex atmp (a.data (i));
          Complex btmp (b);
  
!         result.data (i) = std::pow (atmp, btmp);
        }
  
        result.maybe_compress (true);
***************
*** 375,381 ****
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = pow (a.data (i), b);
        }
  
        result.maybe_compress (true);
--- 375,381 ----
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = std::pow (a.data (i), b);
        }
  
        result.maybe_compress (true);
***************
*** 406,480 ****
  
    int convert_to_complex = 0;
    for (octave_idx_type j = 0; j < nc; j++)
!     for (octave_idx_type i = 0; i < nr; i++)
        {
!       OCTAVE_QUIT;
!       double atmp = a (i, j);
!       double btmp = b (i, j);
!       if (atmp < 0.0 && static_cast<int> (btmp) != btmp)
          {
!           convert_to_complex = 1;
!           goto done;
          }
        }
  
  done:
  
!   octave_idx_type nel = 0;
!   for (octave_idx_type j = 0; j < nc; j++) 
!     for (octave_idx_type i = 0; i < nr; i++)
!       if (!(a.elem (i, j) == 0. && b.elem (i, j) != 0.))
!       nel++;
  
    if (convert_to_complex)
      {
!       SparseComplexMatrix complex_result (nr, nc, nel);
  
-       octave_idx_type ii = 0;
-       complex_result.cidx(0) = 0;
        for (octave_idx_type j = 0; j < nc; j++)
        {
!         for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             Complex atmp (a (i, j));
!             Complex btmp (b (i, j));
!             Complex tmp =  pow (atmp, btmp);
!             if (tmp != 0.)
!               {
!                 complex_result.data (ii) = tmp;
!                 complex_result.ridx (ii++) = i;
!               }
            }
-         complex_result.cidx (j+1) = ii;
        }
!       complex_result.maybe_compress ();
! 
        retval = complex_result;
      }
    else
      {
!       SparseMatrix result (nr, nc, nel);
!       octave_idx_type ii = 0;
  
-       result.cidx (0) = 0;
        for (octave_idx_type j = 0; j < nc; j++)
        {
!         for (octave_idx_type i = 0; i < nr; i++)
            {
              OCTAVE_QUIT;
!             double tmp = pow (a (i, j), b (i, j));
!             if (tmp != 0.)
!               {
!                 result.data (ii) = tmp;
!                 result.ridx (ii++) = i;
!               }
            }
-         result.cidx (j+1) = ii;
        }
! 
!       result.maybe_compress ();
! 
        retval = result;
      }
  
--- 406,461 ----
  
    int convert_to_complex = 0;
    for (octave_idx_type j = 0; j < nc; j++)
!     for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
        {
!       if (a.data(i) < 0.0)
          {
!           double btmp = b (a.ridx(i), j);
!           if (static_cast<int> (btmp) != btmp)
!             {
!               convert_to_complex = 1;
!               goto done;
!             }
          }
        }
  
  done:
  
!   // This is a dumb operator for sparse matrices anyway, and there is
!   // no sensible way to handle the 0.^0 versus the 0.^x cases. Therefore
!   // allocate a full matrix filled for the 0.^0 case and shrink it later
!   // as needed
  
    if (convert_to_complex)
      {
!       SparseComplexMatrix complex_result (nr, nc, Complex(1.0, 0.0));
  
        for (octave_idx_type j = 0; j < nc; j++)
        {
!         for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
            {
              OCTAVE_QUIT;
!             complex_result.xelem(a.ridx(i), j) =
!               std::pow (Complex(a.data(i)), Complex(b(a.ridx(i), j)));
            }
        }
!       complex_result.maybe_compress (true);
        retval = complex_result;
      }
    else
      {
!       SparseMatrix result (nr, nc, 1.0);
  
        for (octave_idx_type j = 0; j < nc; j++)
        {
!         for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
            {
              OCTAVE_QUIT;
!             result.xelem(a.ridx(i), j) = std::pow (a.data(i), 
!                                                    b (a.ridx(i), j));
            }
        }
!       result.maybe_compress (true);
        retval = result;
      }
  
***************
*** 498,504 ****
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = pow (Complex (a.data (i)), b);
        }
    
        result.maybe_compress (true);
--- 479,485 ----
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = std::pow (Complex (a.data (i)), b);
        }
    
        result.maybe_compress (true);
***************
*** 525,556 ****
        return octave_value ();
      }
  
!   octave_idx_type nel = 0;
!   for (octave_idx_type j = 0; j < nc; j++) 
!     for (octave_idx_type i = 0; i < nr; i++)
!       if (!(a.elem (i, j) == 0. && b.elem (i, j) != 0.))
!       nel++;
! 
!   SparseComplexMatrix result (nr, nc, nel);
!   octave_idx_type ii = 0;
! 
!   result.cidx(0) = 0;
    for (octave_idx_type j = 0; j < nc; j++)
      {
!       for (octave_idx_type i = 0; i < nr; i++)
        {
          OCTAVE_QUIT;
!         Complex tmp = pow (Complex (a (i, j)), b (i, j));
!         if (tmp != 0.)
!           {
!             result.data (ii) = tmp; 
!             result.ridx (ii++) = i; 
!           }
        }
-       result.cidx (j+1) = ii;
      }
  
!   result.maybe_compress ();
  
    return result;
  }
--- 506,522 ----
        return octave_value ();
      }
  
!   SparseComplexMatrix result (nr, nc, Complex(1.0, 0.0));
    for (octave_idx_type j = 0; j < nc; j++)
      {
!       for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
        {
          OCTAVE_QUIT;
!         result.xelem(a.ridx(i), j) = std::pow (a.data(i), b (a.ridx(i), j));
        }
      }
  
!   result.maybe_compress (true);
  
    return result;
  }
***************
*** 571,579 ****
          OCTAVE_QUIT;
          double btmp = b (i, j);
          if (xisint (btmp))
!           result (i, j) = pow (a, static_cast<int> (btmp));
          else
!           result (i, j) = pow (a, btmp);
        }
      }
  
--- 537,545 ----
          OCTAVE_QUIT;
          double btmp = b (i, j);
          if (xisint (btmp))
!           result (i, j) = std::pow (a, static_cast<int> (btmp));
          else
!           result (i, j) = std::pow (a, btmp);
        }
      }
  
***************
*** 592,598 ****
      for (octave_idx_type i = 0; i < nr; i++)
        {
        OCTAVE_QUIT;
!       result (i, j) = pow (a, b (i, j));
        }
  
    return result;
--- 558,564 ----
      for (octave_idx_type i = 0; i < nr; i++)
        {
        OCTAVE_QUIT;
!       result (i, j) = std::pow (a, b (i, j));
        }
  
    return result;
***************
*** 609,615 ****
        octave_idx_type nr = a.rows ();
        octave_idx_type nc = a.cols ();
  
!       ComplexMatrix result (nr, nc, Complex (pow (0.0, b)));
  
        if (xisint (b))
        {
--- 575,581 ----
        octave_idx_type nr = a.rows ();
        octave_idx_type nc = a.cols ();
  
!       ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b)));
  
        if (xisint (b))
        {
***************
*** 618,624 ****
              {
                OCTAVE_QUIT;
                result (a.ridx(i), j) = 
!                 pow (a.data (i), static_cast<int> (b));
              }
        }
        else
--- 584,590 ----
              {
                OCTAVE_QUIT;
                result (a.ridx(i), j) = 
!                 std::pow (a.data (i), static_cast<int> (b));
              }
        }
        else
***************
*** 627,633 ****
            for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
              {
                OCTAVE_QUIT;
!               result (a.ridx(i), j) = pow (a.data (i), b);
              }
        }  
  
--- 593,599 ----
            for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
              {
                OCTAVE_QUIT;
!               result (a.ridx(i), j) = std::pow (a.data (i), b);
              }
        }  
  
***************
*** 644,650 ****
          for (octave_idx_type i = 0; i < nz; i++)
            {
              OCTAVE_QUIT;
!             result.data (i) = pow (a.data (i), static_cast<int> (b));
            }
        }
        else
--- 610,616 ----
          for (octave_idx_type i = 0; i < nz; i++)
            {
              OCTAVE_QUIT;
!             result.data (i) = std::pow (a.data (i), static_cast<int> (b));
            }
        }
        else
***************
*** 652,658 ****
          for (octave_idx_type i = 0; i < nz; i++)
            {
              OCTAVE_QUIT;
!             result.data (i) = pow (a.data (i), b);
            }
        }  
  
--- 618,624 ----
          for (octave_idx_type i = 0; i < nz; i++)
            {
              OCTAVE_QUIT;
!             result.data (i) = std::pow (a.data (i), b);
            }
        }  
  
***************
*** 680,717 ****
        return octave_value ();
      }
  
!   octave_idx_type nel = 0;
!   for (octave_idx_type j = 0; j < nc; j++) 
!     for (octave_idx_type i = 0; i < nr; i++)
!       if (!(a.elem (i, j) == 0. && b.elem (i, j) != 0.))
!       nel++;
! 
!   SparseComplexMatrix result (nr, nc, nel);
!   octave_idx_type ii = 0;
! 
!   result.cidx (0) = 0;
    for (octave_idx_type j = 0; j < nc; j++)
      {
!       for (octave_idx_type i = 0; i < nr; i++)
        {
          OCTAVE_QUIT;
!         double btmp = b (i, j);
          Complex tmp;
  
          if (xisint (btmp))
!           tmp = pow (a (i, j), static_cast<int> (btmp));
          else
!           tmp = pow (a (i, j), btmp);
!         if (tmp != 0.)
!           {
!             result.data (ii) = tmp; 
!             result.ridx (ii++) = i; 
!           }
        }
-       result.cidx (j+1) = ii;
      }
  
!   result.maybe_compress ();
  
    return result;
  }
--- 646,669 ----
        return octave_value ();
      }
  
!   SparseComplexMatrix result (nr, nc, Complex(1.0, 0.0));
    for (octave_idx_type j = 0; j < nc; j++)
      {
!       for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
        {
          OCTAVE_QUIT;
!         double btmp = b (a.ridx(i), j);
          Complex tmp;
  
          if (xisint (btmp))
!           result.xelem(a.ridx(i), j) = std::pow (a.data (i), 
!                                             static_cast<int> (btmp));
          else
!           result.xelem(a.ridx(i), j) = std::pow (a.data (i), btmp);
        }
      }
  
!   result.maybe_compress (true);
  
    return result;
  }
***************
*** 735,741 ****
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = pow (a.data (i), b);
        }
  
        result.maybe_compress (true);
--- 687,693 ----
        for (octave_idx_type i = 0; i < nz; i++)
        {
          OCTAVE_QUIT;
!         result.data (i) = std::pow (a.data (i), b);
        }
  
        result.maybe_compress (true);
***************
*** 762,790 ****
        return octave_value ();
      }
  
!   octave_idx_type nel = 0;
!   for (octave_idx_type j = 0; j < nc; j++) 
!     for (octave_idx_type i = 0; i < nr; i++)
!       if (!(a.elem (i, j) == 0. && b.elem (i, j) != 0.))
!       nel++;
! 
!   SparseComplexMatrix result (nr, nc, nel);
!   octave_idx_type ii = 0;
! 
!   result.cidx (0) = 0;
    for (octave_idx_type j = 0; j < nc; j++) 
      {
!       for (octave_idx_type i = 0; i < nr; i++)
        {
          OCTAVE_QUIT;
!         Complex tmp = pow (a (i, j), b (i, j));
!         if (tmp != 0.)
!           {
!             result.data (ii) = tmp;
!             result.ridx (ii++) = i;
!           }
        }
-       result.cidx (j+1) = ii;
      }
    result.maybe_compress (true);
  
--- 714,727 ----
        return octave_value ();
      }
  
!   SparseComplexMatrix result (nr, nc, Complex(1.0, 0.0));
    for (octave_idx_type j = 0; j < nc; j++) 
      {
!       for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
        {
          OCTAVE_QUIT;
!         result.xelem(a.ridx(i), j) = std::pow (a.data (i), b (a.ridx(i), j));
        }
      }
    result.maybe_compress (true);
  
*** ./test/build_sparse_tests.sh.orig   2006-08-21 11:13:39.290337888 +0200
--- ./test/build_sparse_tests.sh        2006-08-21 11:21:43.663467159 +0200
***************
*** 414,420 ****
  %! wn2s = warning ("query", "Octave:num-to-str");
  %! warning ("off", "Octave:num-to-str");
  %! if isreal(af)
! %!    assert($1(as),sparse($1(af),1))
  %! endif
  %! warning (wn2s.state, "Octave:num-to-str");
  
--- 414,424 ----
  %! wn2s = warning ("query", "Octave:num-to-str");
  %! warning ("off", "Octave:num-to-str");
  %! if isreal(af)
! %!   if ($2)
! %!     assert($1(as),sparse($1(af),1))
! %!   else
! %!     assert($1(as),$1(af))
! %!   endif
  %! endif
  %! warning (wn2s.state, "Octave:num-to-str");
  
***************
*** 466,487 ****
  
  gen_real_mapper_tests() {
  echo "%% Unary matrix tests (uses af,as)">>$TESTS
! print_real_mapper_test erf
! print_real_mapper_test erfc
! #print_real_mapper_test gamma
! print_real_mapper_test isalnum
! print_real_mapper_test isalpha
! print_real_mapper_test isascii
! print_real_mapper_test iscntrl
! print_real_mapper_test isdigit
! print_real_mapper_test isgraph
! print_real_mapper_test islower
! print_real_mapper_test isprint
! print_real_mapper_test ispunct
! print_real_mapper_test isspace
! print_real_mapper_test isupper
! print_real_mapper_test isxdigit
! #print_real_mapper_test lgamma
  
  # Specific tests for certain mapper functions
      cat >>$TESTS <<EOF
--- 470,491 ----
  
  gen_real_mapper_tests() {
  echo "%% Unary matrix tests (uses af,as)">>$TESTS
! print_real_mapper_test erf 1
! print_real_mapper_test erfc 1
! #print_real_mapper_test gamma 1
! print_real_mapper_test isalnum 0
! print_real_mapper_test isalpha 0
! print_real_mapper_test isascii 0
! print_real_mapper_test iscntrl 0
! print_real_mapper_test isdigit 0
! print_real_mapper_test isgraph 0
! print_real_mapper_test islower 0
! print_real_mapper_test isprint 0
! print_real_mapper_test ispunct 0
! print_real_mapper_test isspace 0
! print_real_mapper_test isupper 0
! print_real_mapper_test isxdigit 0
! #print_real_mapper_test lgamma 1
  
  # Specific tests for certain mapper functions
      cat >>$TESTS <<EOF

reply via email to

[Prev in Thread] Current Thread [Next in Thread]