Changeset 1658 for trunk/test_more


Ignore:
Timestamp:
Mar 3, 2010 11:42:54 AM (10 years ago)
Author:
bradbell
Message:

/home/bradbell/cppad/trunk: Fix bool packed bug in case where set size is a multiple of n_bit.

spars_jacobian.cpp: add test for case where set size is a multiple of n_bit.
*/makefile.in: update makefile.am version corresponding to this file.
whats_new_10.omh: user's view of the changes.
sparse_pack.hpp: avoid accessing of end of data_ vector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/sparse_jacobian.cpp

    r1558 r1658  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-09 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-10 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    259259        return ok;
    260260}
     261
     262bool multiple_of_n_bit()
     263{       bool ok = true;
     264        using CppAD::AD;
     265        using CppAD::vector;
     266        size_t i, j;
     267
     268        // should be the same as the corresponding typedef in
     269        // cppad/local/sparse_pack.hpp
     270        typedef size_t Pack;
     271
     272        // number of bits per packed value
     273        size_t n_bit = std::numeric_limits<Pack>::digits;
     274
     275        // check case where number of variables is equal to n_bit
     276        vector< AD<double> > x(n_bit);
     277        vector< AD<double> > y(n_bit);
     278
     279        // create an AD function with domain and range dimension equal to n_bit
     280        CppAD::Independent(x);
     281        for(i = 0; i < n_bit; i++)
     282                y[i] = x[n_bit - i - 1];
     283        CppAD::ADFun<double> f(x, y);
     284
     285        // Jacobian sparsity patterns
     286        vector<bool> r(n_bit * n_bit);
     287        vector<bool> s(n_bit * n_bit);
     288        for(i = 0; i < n_bit; i++)
     289        {       for(j = 0; j < n_bit; j++)
     290                        r[ i * n_bit + j ] = (i == j);
     291        }
     292        s = f.ForSparseJac(n_bit, r);
     293
     294        // check the result
     295        for(i = 0; i < n_bit; i++)
     296        {       for(j = 0; j < n_bit; j++)
     297                {       if( i == n_bit - j - 1 )
     298                                ok = ok & s[ i * n_bit + j ];
     299                        else    ok = ok & (! s[i * n_bit + j] );
     300                }
     301        }
     302
     303        return ok;
     304}
    261305} // End empty namespace
    262306# include <vector>
     
    291335        // ok &= reverse_set< std::valarray<double>, std_valarray_set >();
    292336        // ---------------------------------------------------------------
    293         return ok;
    294 }
     337        //
     338        ok &= multiple_of_n_bit();
     339        return ok;
     340}
Note: See TracChangeset for help on using the changeset viewer.