Changeset ec544e for src/graph


Ignore:
Timestamp:
04/14/11 15:30:13 (2 years ago)
Author:
Tiago de Paula Peixoto <tiago@…>
Branches:
master, python3
Children:
5cbf85
Parents:
b311b0
git-author:
Tiago de Paula Peixoto <tiago@…> (04/14/11 14:56:39)
git-committer:
Tiago de Paula Peixoto <tiago@…> (04/14/11 15:30:13)
Message:
Fix bug in histogram with bin list of size 2

This also changes the semantics of of bin list of size 2, and also
simplifies the histogram code slightly.
Location:
src/graph
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/graph/histogram.hh

    r011d7b rec544e  
    5959        for (size_t j = 0; j < Dim; ++j) 
    6060        { 
    61             if (_bins[j].size() < 2) 
    62                 throw std::range_error("invalid bin edge number < 2!"); 
     61            if (_bins[j].size() < 1) 
     62                throw std::range_error("invalid bin edge number < 1!"); 
    6363 
    6464            _data_range[j] = std::make_pair(0, 0); 
    65  
    66             // detect whether the given bins are of constant width, for faster 
    67             // binning 
    68             _const_width[j] = true; 
    6965            value_type delta = _bins[j][1] - _bins[j][0]; 
    70             for (size_t i = 2; i < _bins[j].size(); ++i) 
    71             { 
    72                 value_type d = _bins[j][i] - _bins[j][i-1]; 
    73                 if (delta != d) 
    74                     _const_width[j] = false; 
    75             } 
    76  
    77             if (_const_width[j]) 
    78             { 
    79                 if (_bins[j].size() > 2) 
    80                 { 
     66 
     67            if (_bins[j].size() == 2) 
     68            { 
     69                _data_range[j] = std::make_pair(_bins[j][0], _bins[j][0]); 
     70                delta = _bins[j][1]; 
     71                _const_width[j] = true; 
     72            } 
     73            else 
     74            { 
     75                // detect whether the given bins are of constant width, for faster 
     76                // binning 
     77                _const_width[j] = true; 
     78                for (size_t i = 2; i < _bins[j].size(); ++i) 
     79                { 
     80                    value_type d = _bins[j][i] - _bins[j][i-1]; 
     81                    if (delta != d) 
     82                        _const_width[j] = false; 
     83                } 
     84 
     85                if (_const_width[j]) 
    8186                    _data_range[j] = std::make_pair(_bins[j].front(), 
    8287                                                    _bins[j].back()); 
    83                     new_shape[j] = _bins[j].size() - 1; 
    84                 } 
    85                 else 
    86                 { 
    87                     _data_range[j] = std::make_pair(_bins[j].front(), 
    88                                                     _bins[j].front()); 
    89                     new_shape[j] = 1; 
    90                 } 
    91                 if (delta == 0) 
    92                     throw std::range_error("invalid bin size of zero!"); 
    93             } 
    94             else 
    95             { 
    96                 new_shape[j] = _bins[j].size() - 1; 
    97             } 
     88            } 
     89            if (delta == 0) 
     90                throw std::range_error("invalid bin size of zero!"); 
     91 
     92            new_shape[j] = _bins[j].size() - 1; 
    9893        } 
    9994        _counts.resize(new_shape); 
     
    107102            if (_const_width[i]) 
    108103            { 
    109                 if (_data_range[i].first != _data_range[i].second && 
    110                     (v[i] < _data_range[i].first || 
    111                      v[i] > _data_range[i].second)) 
    112                     return; // out of bounds 
    113                 value_type delta = _bins[i][1] - _bins[i][0]; 
     104                value_type delta; 
     105 
     106                if (_data_range[i].first == _data_range[i].second) 
     107                { 
     108                    delta = _bins[i][1]; 
     109 
     110                    if (v[i] < _data_range[i].first) 
     111                        return; // out of bounds 
     112                } 
     113                else 
     114                { 
     115                    delta = _bins[i][1] - _bins[i][0]; 
     116 
     117                    if (v[i] < _data_range[i].first || 
     118                        v[i] >= _data_range[i].second) 
     119                        return; // out of bounds 
     120                } 
     121                 
    114122                bin[i] = (v[i] - _data_range[i].first) / delta; 
    115123                if (bin[i] >= _counts.shape()[i]) // modify shape 
  • src/graph/stats/graph_histograms.cc

    r6758e8 rec544e  
    3636    run_action<>()(gi, get_histogram<VertexHistogramFiller>(hist, bins, 
    3737                                                            ret_bins), 
    38                    scalar_selectors())(degree_selector(deg)); 
     38         scalar_selectors())(degree_selector(deg)); 
    3939    return python::make_tuple(hist, ret_bins); 
    4040} 
  • src/graph/stats/graph_histograms.hh

    r6758e8 rec544e  
    3636public: 
    3737    template <class Graph, class DegreeSelector, class Hist> 
    38     void operator()(Graph& g, typename graph_traits<Graph>::vertex_descriptor v, 
     38    void operator()(const Graph& g, 
     39                    typename graph_traits<Graph>::vertex_descriptor v, 
    3940                    DegreeSelector& deg, Hist& hist) 
    4041    { 
     
    4950public: 
    5051    template <class Graph, class EdgeProperty, class Hist> 
    51     void operator()(Graph& g, typename graph_traits<Graph>::vertex_descriptor v, 
     52    void operator()(const Graph& g, 
     53                    typename graph_traits<Graph>::vertex_descriptor v, 
    5254                    EdgeProperty& eprop, Hist& hist) 
    5355    { 
     
    7274 
    7375    template <class Graph, class DegreeSelector> 
    74     void operator()(Graph& g, DegreeSelector deg) const 
     76    void operator()(const Graph& g, DegreeSelector deg) const 
    7577    { 
    7678        typedef typename DegreeSelector::value_type value_type; 
Note: See TracChangeset for help on using the changeset viewer.