USML
seq_log.h
1 
6 #ifndef USML_TYPES_SEQ_LOG_H
7 #define USML_TYPES_SEQ_LOG_H
8 
9 #include <usml/types/seq_vector.h>
10 
11 namespace usml {
12 namespace types {
15 
20 class USML_DECLSPEC seq_log: public seq_vector {
21 
22  typedef seq_log self_type;
23 public:
24  typedef const vector_reference<const self_type> const_closure_type;
25  typedef vector_reference<self_type> closure_type;
26 
27  //***************************************************************
28  // vritual functions
29 
30 public:
31 
41  virtual size_type find_index( value_type value ) {
42  return (size_type) max(
43  (difference_type) 0, min( (difference_type) _size-2,
44  (difference_type) floor( (value - _data(0)) / _increment(0) )));
45  }
46 
47  //***************************************************************
48  // constructors and destructors
49 
50 private:
51 
59  void initialize( value_type first, value_type increment, size_type size ) {
60  value_type v = first ;
61  for (size_type n = 0; n < size; ++n) {
62  _data[n] = v ;
63  v *= increment ;
64  if ( n > 0 ) {
65  _increment[n-1] = _data[n] - _data[n-1];
66  _increment[n] = _increment[n-1] ;
67  }
68  }
69  }
70 
71 public:
72 
74  virtual ~seq_log() {}
75 
83  seq_log( value_type first, value_type increment, size_type size ) :
84  seq_vector( size )
85  {
86  initialize( first, increment, size ) ;
87  }
88 
96  seq_log( value_type first, value_type increment, int size ) :
97  seq_vector( (size_type) size )
98  {
99  initialize( first, increment, (size_type) size ) ;
100  }
101 
112  seq_log( value_type first, value_type increment, value_type last ) :
113  seq_vector( (increment == 1.0) ? 1
114  : max((difference_type) 1, (difference_type) floor(1.0 + (log(
115  last / first) / log(increment)))) )
116  {
117  initialize( first, increment, _size ) ;
118  }
119 
125  seq_log( const seq_log & copy ) : seq_vector( copy ) {
126  }
127 
129  virtual seq_vector* clone() const {
130  return new seq_log( *this ) ;
131  }
132 
133 
134 }; // end of class
135 
137 } // end of namespace types
138 } // end of namespace usml
139 
140 #endif
BOOST_UBLAS_INLINE boost::enable_if< boost::is_convertible< T2, typename E1::value_type >, typename matrix_binary_scalar2_traits< E1, const T2, scalar_max< typename E1::value_type, T2 > >::result_type >::type max(const matrix_expression< E1 > &e1, const T2 &e2)
Maximum between a matrix and a scalar.
Definition: matrix_math.h:143
seq_log(const seq_log &copy)
Copies data from another sequence object.
Definition: seq_log.h:125
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_floor< typename E::value_type > >::result_type floor(const matrix_expression< E > &e)
Rounding elements of a matrix down to the nearest integer.
Definition: matrix_math.h:170
BOOST_UBLAS_INLINE boost::enable_if< boost::is_convertible< T2, typename E1::value_type >, typename matrix_binary_scalar2_traits< E1, const T2, scalar_min< typename E1::value_type, T2 > >::result_type >::type min(const matrix_expression< E1 > &e1, const T2 &e2)
Minimum between a matrix and a scalar.
Definition: matrix_math.h:158
vector_reference< self_type > closure_type
Definition: seq_log.h:25
seq_log(value_type first, value_type increment, value_type last)
Construct sequence using first value, increment value, and last value.
Definition: seq_log.h:112
virtual seq_vector * clone() const
Create a copy using a reference to the base class.
Definition: seq_log.h:129
Sequence defined by a logarithmically spaced grid of points.
Definition: seq_log.h:20
seq_log self_type
Definition: seq_log.h:22
const vector_reference< const self_type > const_closure_type
Definition: seq_log.h:24
virtual size_type find_index(value_type value)
Search for a value in this sequence.
Definition: seq_log.h:41
void initialize(value_type first, value_type increment, size_type size)
Construct sequence using first value, increment, and size.
Definition: seq_log.h:59
vector< value_type >::size_type size_type
Definition: seq_vector.h:44
seq_log(value_type first, value_type increment, int size)
Construct sequence using first value, increment, and size.
Definition: seq_log.h:96
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_log< typename E::value_type > >::result_type log(const matrix_expression< E > &e)
Natural logarithm of a matrix.
Definition: matrix_math.h:516
virtual ~seq_log()
Virtual destructor.
Definition: seq_log.h:74
vector< value_type >::difference_type difference_type
Definition: seq_vector.h:45
A read-only, monotonic sequence of values.
Definition: seq_vector.h:36
double value_type
Definition: seq_vector.h:43
seq_log(value_type first, value_type increment, size_type size)
Construct sequence using first value, increment, and size.
Definition: seq_log.h:83