14 #ifndef L_CPP_INT_VECTOR_WRAP_H
15 #define L_CPP_INT_VECTOR_WRAP_H
39 #include "l/l_debug.h"
40 #include "l/l_int_vector.h"
41 #include "l/l_sys_io.h"
42 #include "l/l_sys_lib.h"
49 #ifdef KJB_HAVE_BST_SERIAL
50 #include <boost/serialization/access.hpp>
53 #include <boost/concept_check.hpp>
85 #ifdef KJB_HAVE_BST_SERIAL
86 friend class boost::serialization::access;
130 void throw_bad_bounds(
int )
const;
146 template<
typename InputIterator_>
147 void m_initialize_dispatch(InputIterator_ begin_,
148 InputIterator_ end_, std::input_iterator_tag);
156 template<
typename ForwardIterator_>
157 void m_initialize_dispatch(ForwardIterator_ begin_, ForwardIterator_ end_, std::forward_iterator_tag)
159 const size_type n = std::distance(begin_, end_);
160 m_ensure_capacity(n);
162 m_vector->length = n;
164 std::copy(begin_, end_, this->
begin());
181 ETX( kjb_c::get_target_int_vector(&m_vector,
length) );
197 ETX( kjb_c::get_target_int_vector(&m_vector, static_cast<int>(length)) );
213 ETX( kjb_c::get_target_int_vector(&m_vector, static_cast<int>(length)) );
225 ETX( kjb_c::get_initialized_int_vector(&m_vector, length, num) );
237 ETX( kjb_c::get_target_int_vector(&m_vector, length) );
238 std::copy( data, data + length, m_vector -> elements );
268 : m_vector( vec_ptr )
273 ETX( kjb_c::get_target_int_vector(&m_vector, 0) );
310 ETX( kjb_c::copy_int_vector(&m_vector, &vec_ref) );
340 ETX( kjb_c::copy_int_vector(&m_vector, vec_ref.m_vector) );
361 template<
typename InputIterator_>
365 ETX( kjb_c::get_target_int_vector(&m_vector, 8) );
366 m_vector->length = 0;
368 typedef typename std::iterator_traits<InputIterator_>::
369 iterator_category IterCategory_;
370 m_initialize_dispatch(begin_, end_, IterCategory_());
382 kjb_c::free_int_vector(m_vector);
393 return m_vector ->
length;
428 return iterator(m_vector->elements);
448 return iterator(m_vector->elements + m_vector->length);
509 m_ensure_capacity(capacity);
562 if ( m_vector != &vec_ref )
565 ETX( kjb_c::copy_int_vector(&m_vector, &vec_ref) );
644 return m_vector -> elements[
i ];
658 return m_vector -> elements[
i ];
698 throw_bad_bounds( i );
749 template<
typename InputIterator>
750 void insert(
iterator position, InputIterator begin_, InputIterator end_);
780 m_vector->length = 0;
833 m_ensure_capacity(m_vector->length + 1);
836 KJB(
ASSERT(m_vector->length <= m_vector->max_length));
837 m_vector->elements[m_vector->length - 1] =
x;
860 ETX(kjb_c::write_row_int_vector( m_vector, filename ));
875 ETX(kjb_c::write_col_int_vector_with_header( m_vector, filename ));
888 void write(
const char* filename = 0 )
const
911 ETX( kjb_c::ow_multiply_int_vector_by_int_scalar(m_vector, op2) );
953 ETX( kjb_c::ow_add_int_vectors(m_vector, op2.m_vector) );
976 ETX( kjb_c::ow_subtract_int_vectors(m_vector, op2.m_vector) );
1020 return kjb_c::min_int_vector_element(m_vector);
1050 "Int_vector is empty; min is undefined" );
1052 if ( 0 == min_index )
1059 *min_index = kjb_c::get_min_int_vector_element(m_vector, &min_val);
1071 return kjb_c::max_int_vector_element(m_vector);
1101 "Int_vector is empty; max is undefined" );
1103 if ( 0 == max_index )
1110 *max_index = kjb_c::get_max_int_vector_element(m_vector, &max_val);
1152 return kjb_c::int_vector_magnitude(m_vector);
1163 return kjb_c::sum_int_vector_squared_elements(m_vector);
1169 void serialize(boost::archive::text_iarchive &ar,
const unsigned int version);
1170 void serialize(boost::archive::text_oarchive &ar,
const unsigned int version);
1181 template<
typename InputIterator_>
1182 void Int_vector::m_initialize_dispatch
1184 InputIterator_ begin_,
1185 InputIterator_ end_,
1186 std::input_iterator_tag
1189 for(; begin_ != end_; ++begin_)
1197 template<
typename InputIterator>
1201 InputIterator begin_,
1207 m_ensure_capacity(m_vector->length + N);
1209 m_vector->length += N;
1212 for(rit = rbegin(); rit.base() != position; rit++)
1218 InputIterator src_it = begin_;
1219 for(; src_it != end_; src_it++)
1221 *dest_it++ = *src_it;
1255 kjb_c::Int_vector* outvec = 0;
1256 ETX_2( kjb_c::copy_int_vector_section(&outvec,
1257 iv.
get_c_vector(), begin,
length),
"Failure in create_vector_from_vector_section : allocation error or bad indices");
1280 Int_vector
operator*(
const Int_vector& op1,
const Int_matrix& op2);
1290 Int_vector
operator*(
const Int_matrix& op1,
const Int_vector& op2 );
1375 std::ostream&
operator<<(std::ostream& out,
const Int_vector&
m);
1416 return !(op1 == op2);
1470 bool operator<(
const Int_vector& op1,
const Int_vector &op2);
1478 return (op1 < op2) || (op1 == op2);
1487 return !(op1 < op2) && !(op1 == op2);
1496 return !(op1 < op2);
1547 Int_vector
cross(
const Int_vector& op1,
const Int_vector& op2);
reverse_iterator rend()
Definition: l_int_vector.h:486
const_reference front() const
Returns the first element of the vector.
Definition: l_int_vector.h:800
Int_vector & randomize(int length)
Clobber current vector; resize and fill with random values.
Definition: l_int_vector.cpp:160
double vector_distance(const Int_vector &op1, const Int_vector &op2)
Compute the Euclidian distance between two vectors.
Definition: l_int_vector.h:1569
Int_vector cross(const Int_vector &op1, const Int_vector &op2)
Compute cross product of op1 and op2.
Definition: l_int_vector.cpp:381
#define ETX(a)
Definition: l_exception.h:67
double vector_distance_squared(const Int_vector &op1, const Int_vector &op2)
Compute the square of the Euclidian distance between two vectors.
Definition: l_int_vector.h:1581
Int_vector & operator+=(const Int_vector &op2)
Add vector to self, in-place, e.g., v += delta_v.
Definition: l_int_vector.h:950
int difference_type
Definition: l_int_vector.h:117
void push_back(Value_type x)
inserts an element at the back of the vector in amortized constant time.
Definition: l_int_vector.h:831
Int_vector & divide(Value_type op2)
Scalar integer division of self, in-place, just like v /= 2.
Definition: l_int_vector.h:939
void write_col(const char *filename=0) const
Write vector as a column to a file, or to standard output.
Definition: l_int_vector.h:872
Int_vector create_random_int_vector(int length)
Construct a vector with random contents.
Definition: l_int_vector.h:1237
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
int * pointer
Definition: l_int_vector.h:105
Int_vector(Impl_type *vec_ptr)
Conversion ctor: claim ownership of an existing int vector pointer (i.e., make a shallow copy)...
Definition: l_int_vector.h:267
int value_type
Definition: l_int_vector.h:104
value_type * iterator
Definition: l_int_vector.h:112
This class implements matrices, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_matrix.h:71
Int_vector Vec_type
the associated vector type
Definition: l_int_vector.h:100
Int_matrix::Value_type max_abs_difference(const Int_matrix &op1, const Int_matrix &op2)
Find the largest difference between two matrices.
Definition: l_int_matrix.h:1364
Value_type min(int *min_index) const
Find minimum element in the vector, both its value and index.
Definition: l_int_vector.h:1044
Int_vector & negate()
Negate self, in-place, just like v *= (-1).
Definition: l_int_vector.h:996
kjb_c::Int_vector Impl_type
the underlying implementation
Definition: l_int_vector.h:98
#define KJB(x)
Definition: l_util.h:9
const_iterator end() const
Definition: l_int_vector.h:456
Int_vector & operator=(const Int_vector &src)
Assignment operator: assign from a kjb::Int_vector, a C++ object.
Definition: l_int_vector.h:580
int Value_type
data type of the elements
Definition: l_int_vector.h:97
bool operator<(const Face_detection &f1, const Face_detection &f2)
Compares to boxes using middle of box. Needed because we have associated containers of these...
Definition: d_facecom.cpp:147
int & reference
Definition: l_int_vector.h:107
Image operator-(const Image &im1, const Image &im2)
Subtract two images.
Definition: i_image.h:843
#define KJB_THROW(ex)
Definition: l_exception.h:46
#define ASSERT(condition, message)
Definition: Assert.h:45
bool operator>=(const Int_vector &op1, const Int_vector &op2)
Test lexicographic ordering between vectors.
Definition: l_int_vector.h:1494
void write(const char *filename=0) const
Write vector to a file, or to standard output.
Definition: l_int_vector.h:888
const_reverse_iterator rend() const
Definition: l_int_vector.h:496
void clear()
delete all elements from vector
Definition: l_int_vector.h:778
size_t length(const C &cner)
Counts the total number of elements in a 2D STL-style container.
Definition: l_util.h:17
Object thrown when a function cannot generate a valid result.
Definition: l_exception.h:516
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: l_int_vector.h:399
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
reference back()
Returns the last element of the vector.
Definition: l_int_vector.h:810
iterator end()
Definition: l_int_vector.h:446
Value_type(* Mapper)(Value_type)
element transformer fun
Definition: l_int_vector.h:101
Value_type operator()(int i) const
Fortran-style vector subscript, e.g., A(10), to get an rvalue.
Definition: l_int_vector.h:681
std::reverse_iterator< iterator > reverse_iterator
Definition: l_int_vector.h:114
void check_bounds(int i) const
Test whether a subscript is valid, throw an exception if not.
Definition: l_int_vector.h:693
Int_vector & operator/=(Value_type op2)
Scalar integer division of self, in-place.
Definition: l_int_vector.cpp:304
Int_vector & resize(int new_length, Value_type pad=Value_type(0))
Resize vector, retaining previous values.
Definition: l_int_vector.cpp:147
void write_row(const char *filename=0) const
Write vector as a row to a file, or to standard output.
Definition: l_int_vector.h:857
Int_vector & operator*=(Value_type op2)
Scalar multiply self, in-place, e.g., v *= 6.
Definition: l_int_vector.h:908
bool empty() const
Returns true iff size is zero. Required to comply with stl Container concept.
Definition: l_int_vector.h:415
Int_vector(unsigned long length)
Allocate vector of given length; contents are uninitialized.
Definition: l_int_vector.h:209
Int_vector(const Impl_type &vec_ref)
Ctor copies contents (i.e., deep copy) of an existing vector.
Definition: l_int_vector.h:306
std::reverse_iterator< const_iterator > const_reverse_iterator
const Iterator type
Definition: l_int_vector.h:115
reference front()
Returns the first element of the vector.
Definition: l_int_vector.h:789
x
Definition: APPgetLargeConnectedEdges.m:100
Vec_type & mapcar(Mapper)
Transform the elements of a vector.
Definition: l_int_vector.cpp:323
This class implements vectors, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_vector.h:83
Int_vector & add(const Int_vector &op2)
Add vector to self, in-place, just like v += delta_v.
Definition: l_int_vector.h:962
bool operator>(const Int_vector &op1, const Int_vector &op2)
Test lexicographic ordering between vectors.
Definition: l_int_vector.h:1485
Value_type min() const
Return the value of the minimum element in the vector.
Definition: l_int_vector.h:1017
Value_type & operator()(int i)
Fortran-style vector subscript, e.g., A(10), to get an lvalue.
Definition: l_int_vector.h:668
const value_type * const_iterator
Definition: l_int_vector.h:113
Int_vector(unsigned length)
Allocate vector of given length; contents are uninitialized.
Definition: l_int_vector.h:193
std::ofstream & operator<<(std::ofstream &out, const Quaternion &q)
Definition: turntable_camera.cpp:77
Image operator/(const Image &op1, double op2)
Scale an image in channel space, yielding a new image.
Definition: i_image.h:825
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
bool operator!=(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1274
int size_type
Definition: l_int_vector.h:116
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
iterator insert(iterator position, value_type t)
A copy of t is inserted before position.
Int_vector & subtract(const Int_vector &op2)
Subtract vector from self, in-place, just like v -= delta_v.
Definition: l_int_vector.h:985
bool operator==(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for exact equality between two matrices.
Definition: l_int_matrix.cpp:218
Int_vector create_vector_from_vector_section(const Int_vector &iv, int begin, int length)
Construct a vector by deep-copying a section of another vector.
Definition: l_int_vector.h:1252
#define ETX_2(a, msg)
Definition: l_exception.h:78
kjb::Int_matrix hat() const
Construct an "equivalent" skew-symmetric matrix from 3-vector.
Definition: l_int_vector.cpp:337
reverse_iterator rbegin()
Definition: l_int_vector.h:466
Value_type max() const
Return the value of the maximum element in the vector.
Definition: l_int_vector.h:1068
Int_vector(const Int_vector &vec_ref)
Copy ctor – calls the kjb_c function to copy an int vector.
Definition: l_int_vector.h:336
Int_vector & multiply(Value_type op2)
Scalar multiply self, in-place, just like v *= 6.
Definition: l_int_vector.h:920
Value_type max(int *max_index) const
Find maximum element in the vector, both its value and index.
Definition: l_int_vector.h:1095
Int_vector(int length, const Value_type *data)
Initialize from an array of int, of given length.
Definition: l_int_vector.h:233
Int_vector(const std::vector< int > &src)
Conversion ctor: Create from stl-style vector.
Definition: l_int_vector.h:287
Value_type at(int i) const
Safely subscript vector, e.g., A.at(10), to get an rvalue.
Definition: l_int_vector.h:723
size_type max_size() const
Maximum size vector can ever have. Currently defined as INT_MAX.
Definition: l_int_vector.h:407
void swap(Int_vector &other)
Swap the representations of two vectors.
Definition: l_int_vector.h:620
const_iterator begin() const
Definition: l_int_vector.h:436
const_reference back() const
Returns the last element of the vector.
Definition: l_int_vector.h:821
double norm2(const Int_vector &op1)
Compute l2-norm of vector.
Definition: l_int_vector.h:1558
Int_matrix Mat_type
the associated matrix type
Definition: l_int_vector.h:99
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
iterator erase(iterator position)
erase element at position and shift all elements after p up by 1.
Value_type operator[](int i) const
Subscript vector like a C array, e.g., A[10], returning an rvalue.
Definition: l_int_vector.h:655
Int_vector & operator-=(const Int_vector &op2)
Subtract vector from self, in-place, e.g., v -= delta_v.
Definition: l_int_vector.h:973
const Impl_type * get_c_vector() const
Get const pointer to the underlying kjb_c::Int_vector C struct.
Definition: l_int_vector.h:597
Int_vector & cross_with(const Int_vector &op2)
Compute (in place) cross product of this vector and op2.
Definition: l_int_vector.cpp:364
iterator begin()
Definition: l_int_vector.h:426
int const_reference
Definition: l_int_vector.h:108
void pop_back()
Returns the last element of the vector.
Definition: l_int_vector.h:845
long int dot(const Int_vector &op1, const Int_vector &op2)
Returns dot product of this and op2.
Definition: l_int_vector.h:1532
int get_length() const
Return the length of the vector.
Definition: l_int_vector.h:390
for m
Definition: APPgetLargeConnectedEdges.m:64
Support for error handling exception classes in libKJB.
Impl_type * get_underlying_representation_with_guilt()
Get pointer to the underlying kjb_c::Vector C struct.
Definition: l_int_vector.h:610
void reserve(int capacity)
Definition: l_int_vector.h:507
const_reverse_iterator rbegin() const
Definition: l_int_vector.h:476
const int * const_pointer
Definition: l_int_vector.h:106
Value_type & operator[](int i)
Subscript vector like a C array, e.g., A[10], returning an lvalue.
Definition: l_int_vector.h:641
Value_type & at(int i)
Safely subscript vector, e.g., A.at(10), to get an lvalue.
Definition: l_int_vector.h:709
bool operator<=(const Int_vector &op1, const Int_vector &op2)
Test lexicographic ordering between vectors.
Definition: l_int_vector.h:1476
Int_vector(int length, Value_type num)
Allocate vector of given length; initialize all elts to 'num'.
Definition: l_int_vector.h:221
Int_vector(InputIterator_ begin_, InputIterator_ end_)
"Range constructor"
Definition: l_int_vector.h:362
Gsl_Vector operator*(double scalar, const Gsl_Vector &vector)
multiply scalar and vector, scalar written on the left side
Definition: gsl_vector.h:661
Int_vector & operator=(const Impl_type &vec_ref)
Assignment operator: assign from a kjb_c::Int_vector, a C struct.
Definition: l_int_vector.h:560
double magnitude() const
Return this vector's magnitude.
Definition: l_int_vector.h:1149
Int_vector & randomize()
Clobber current vector contents with random values.
Definition: l_int_vector.h:531
Int_vector(int length=0)
Allocate vector of given length; contents are uninitialized.
Definition: l_int_vector.h:177
~Int_vector()
Destructor – which just calls the KJB destructor.
Definition: l_int_vector.h:379
long int magnitude_squared() const
Return this vector's squared magnitude.
Definition: l_int_vector.h:1160