14 #ifndef L_CPP_INT_MATRIX_WRAP_H
15 #define L_CPP_INT_MATRIX_WRAP_H
37 #include "l/l_int_matrix.h"
38 #include "l/l_int_mat_io.h"
44 #ifdef KJB_HAVE_BST_SERIAL
45 #include <boost/serialization/access.hpp>
73 #ifdef KJB_HAVE_BST_SERIAL
74 friend class boost::serialization::access;
103 void compute_row_col(
122 void compute_row_col_carefully(
136 compute_row_col( index, row, col );
140 void throw_bad_bounds(
int row_ix,
int col_ix )
const;
155 ETX( kjb_c::get_target_int_matrix( &m_matrix, 0, 0 ) );
167 ETX( kjb_c::get_target_int_matrix( &m_matrix, rows, cols ) );
180 Int_matrix m( static_cast<int>( rows ), static_cast<int>( cols ) );
194 Int_matrix m( static_cast<int>( rows ), static_cast<int>( cols ), val );
208 Int_matrix m( static_cast<int>( rows ), static_cast<int>( cols ) );
222 Int_matrix m( static_cast<int>( rows ), static_cast<int>( cols ), val );
235 ETX( kjb_c::get_initialized_int_matrix( &m_matrix, rows, cols, num ) );
272 : m_matrix( mat_ptr )
277 ETX( kjb_c::get_target_int_matrix( &m_matrix, 0, 0 ) );
300 ETX( kjb_c::copy_int_matrix( &m_matrix, &mat_ref ) );
320 ETX( kjb_c::copy_int_matrix( &m_matrix, mat_ref.m_matrix ) );
329 kjb_c::free_int_matrix( m_matrix );
362 ETX( kjb_c::get_zero_int_matrix( &m_matrix, num_rows, num_cols ) );
427 if ( m_matrix != &mat_ref )
430 ETX( kjb_c::copy_int_matrix( &m_matrix, &mat_ref ) );
473 return m_matrix -> num_rows;
484 return m_matrix -> num_cols;
529 return m_matrix->elements;
552 ETX(kjb_c::get_target_int_matrix(&m_matrix, new_rows, new_cols));
565 kjb_c::Int_matrix* result = 0;
566 ETX(kjb_c::get_int_transpose( &result, m_matrix ) );
592 throw_bad_bounds( row, col );
640 compute_row_col( i, &row, &col );
656 compute_row_col( i, &row, &col );
673 return m_matrix -> elements[ row ][ col ];
689 return m_matrix -> elements[ row ][ col ];
702 compute_row_col_carefully( i, &row, &col );
717 compute_row_col_carefully( i, &row, &col );
773 template <
class Generic_vector>
774 void set_row(
int row,
const Generic_vector& v);
781 template <
class Iterator>
782 void set_row(
int row, Iterator begin, Iterator end);
790 template <
class Generic_vector>
791 void set_col(
int col,
const Generic_vector& v);
798 template <
class Iterator>
799 void set_col(
int col, Iterator begin, Iterator end);
812 int write(
const char* filename = 0 )
const
815 return kjb_c::write_int_matrix( m_matrix, filename );
839 ETX(multiply_int_matrices(&m_matrix, m_matrix, op2.m_matrix));
867 ETX(kjb_c::ow_multiply_int_matrix_by_int_scalar(m_matrix, op2));
917 ETX(kjb_c::ow_add_int_matrices(m_matrix, op2.m_matrix));
940 ETX(kjb_c::ow_subtract_int_matrices(m_matrix, op2.m_matrix));
982 template<
class Archive>
983 void serialize(Archive &ar,
const unsigned int version)
995 template <
class Generic_vector>
999 using namespace boost;
1000 BOOST_CONCEPT_ASSERT((Container<Generic_vector>));
1002 typedef typename Generic_vector::value_type Vector_value_type;
1003 BOOST_CONCEPT_ASSERT((Convertible<Vector_value_type, Value_type>));
1005 set_row(row, v.begin(), v.end());
1010 template <
class Iterator>
1013 Iterator it = begin;
1037 template <
class Generic_vector>
1041 using namespace boost;
1042 BOOST_CONCEPT_ASSERT((Container<Generic_vector>));
1044 typedef typename Generic_vector::value_type Vector_value_type;
1045 BOOST_CONCEPT_ASSERT((Convertible<Vector_value_type, Value_type>));
1047 set_col(col, v.begin(), v.end());
1052 template <
class Iterator>
1055 Iterator it = begin;
1092 kjb_c::Int_matrix* result = 0;
1093 ETX( kjb_c::get_int_identity_matrix( &result, rank ) );
1106 kjb_c::Int_matrix* result = 0;
1107 ETX( kjb_c::get_zero_int_matrix( &result, rows, columns ) );
1277 return !(op1 == op2);
1290 return !(op1 == op2);
1333 kjb_c::Int_matrix* kjb_matrix = 0;
1347 kjb_c::Int_matrix* result = 0;
1388 return kjb_c::min_int_matrix_element(mat.
get_c_matrix());
1400 return kjb_c::max_int_matrix_element(mat.
get_c_matrix());
Int_matrix create_row_matrix(const Int_matrix::Vec_type &vec)
Construct a one-row matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:105
Int_matrix & operator=(const Int_matrix &src)
Assign contents from a kjb::Int_matrix, a C++ object.
Definition: l_int_matrix.h:446
Value_type & operator[](int i)
Subscript matrix like a one-dimensional C array, e.g., A[10], using row-major ordering, and returning an lvalue.
Definition: l_int_matrix.h:608
#define ETX(a)
Definition: l_exception.h:67
void set_row(int row, const Generic_vector &v)
Replace a row of the matrix with the given vector.
Definition: l_int_matrix.h:996
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
kjb_c::Int_matrix Impl_type
the underlying implementation
Definition: l_int_matrix.h:85
Value_type at(int i) const
Access matrix like a one-dimensional array, using row-major ordering, and returning an rvalue...
Definition: l_int_matrix.h:713
Value_type(* Mapper)(Value_type)
element transformer fun
Definition: l_int_matrix.h:88
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
Mat_type & mapcar(Mapper)
Transform the elements of a matrix.
Definition: l_int_matrix.cpp:252
This class implements matrices, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_matrix.h:71
Value_type at(int row, int col) const
Access matrix with bounds checking and return an rvalue.
Definition: l_int_matrix.h:739
Int_matrix(unsigned long rows, unsigned long cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: l_int_matrix.h:204
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
Int_matrix create_diagonal_matrix(const Int_matrix::Vec_type &diagonal)
Construct a one-row matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:118
Int_matrix Mat_type
the associated matrix type
Definition: l_int_matrix.h:86
Int_matrix & operator*=(const Int_matrix &op2)
Compute product of this matrix (on the left) and another, and replace this matrix with the result...
Definition: l_int_matrix.h:836
Int_matrix & multiply(const Int_matrix &op2)
Compute product of this matrix (on the left) and another, and replace this matrix with the result...
Definition: l_int_matrix.h:853
~Int_matrix()
Definition: l_int_matrix.h:326
Int_matrix & operator-=(const Int_matrix &op2)
Subtract another matrix from this matrix, in place.
Definition: l_int_matrix.h:937
int Size_type
Definition: l_int_matrix.h:84
Int_matrix & subtract(const Int_matrix &op2)
Subtract another matrix from this matrix, in place.
Definition: l_int_matrix.h:949
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
Int_matrix(const Int_matrix &mat_ref)
Copy ctor.
Definition: l_int_matrix.h:316
Int_matrix transpose()
Transpose this matrix, in-place.
Definition: l_int_matrix.h:562
Int_matrix create_column_matrix(const Int_matrix::Vec_type &vec)
Construct a one-column matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:127
void check_bounds(int row, int col) const
Test whether the given row and column indices are valid.
Definition: l_int_matrix.h:586
Value_type ** ptr_to_storage_area() const
Access a pointer to the underlying implementation, use with care.
Definition: l_int_matrix.h:523
Int_matrix(int rows, int cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: l_int_matrix.h:163
Value_type operator()(int row, int col) const
Access matrix like a Fortran or MATLAB two-dimensional array, e.g., A(2,4), and return an rvalue...
Definition: l_int_matrix.h:686
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
int Value_type
data type of the elements
Definition: l_int_matrix.h:83
Int_matrix & zero_out(int num_rows, int num_cols)
Resize matrix, replace contents with the identity matrix.
Definition: l_int_matrix.h:359
void kjb_serialize(Archive &ar, KJB_readable_writable &obj, const unsigned int version)
Definition: l_serialization.h:170
Int_matrix & operator/=(Int_matrix::Value_type op2)
Perform integer division on each entry in the matrix by a scalar value.
Definition: l_int_matrix.cpp:192
Value_type & at(int row, int col)
Access matrix with bounds checking and return an lvalue.
Definition: l_int_matrix.h:727
Value_type & operator()(int row, int col)
Access matrix like a Fortran or MATLAB two-dimensional array, e.g., A(2,4), and return an lvalue...
Definition: l_int_matrix.h:670
Value_type operator()(int i) const
MATLAB-style one-dimensional subscript of matrix, e.g., A(10), using row-major ordering, and returning an rvalue.
Definition: l_int_matrix.h:652
Vec_type get_row(int row) const
Return a specified row of this matrix, in the form of an Int_vector.
Definition: l_int_matrix.cpp:168
void set_col(int col, const Generic_vector &v)
Replace a column of the matrix with the given vector. "vector" can be any collection of values conver...
Definition: l_int_matrix.h:1038
Int_matrix & realloc(int new_rows, int new_cols)
Resize this matrix, discarding previous values (faster than resize, because storage is reused) ...
Definition: l_int_matrix.h:548
Int_matrix matrix_transpose(const Int_matrix &op1)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1331
kjb_c::Pixel abs(const kjb_c::Pixel &p)
Take the channel-wise absolute value of a kjb_c::Pixel.
Definition: i_pixel.h:354
Impl_type * get_underlying_representation_with_guilt()
Get pointer to the underlying kjb_c::Matrix C struct.
Definition: l_int_matrix.h:516
Int_vector Vec_type
the associated vector type
Definition: l_int_matrix.h:87
void swap(Int_matrix &other)
Swap the representations of two matrices.
Definition: l_int_matrix.h:459
Value_type & operator()(int i)
MATLAB-style one-dimensional subscript of matrix, e.g., A(10), using row-major ordering, and returning an lvalue.
Definition: l_int_matrix.h:636
This class implements vectors, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_vector.h:83
Int_matrix(int rows, int cols, Value_type num)
Ctor builds a matrix of specified size, all entries set to num.
Definition: l_int_matrix.h:231
Int_matrix & zero_out()
Clobber contents of matrix with zeroes.
Definition: l_int_matrix.h:387
Int_matrix & multiply(Value_type op2)
Multiply this matrix by a scalar, in place.
Definition: l_int_matrix.h:876
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_matrix & divide(Int_matrix::Value_type op2)
Perform integer division on each entry in the matrix by a scalar value.
Definition: l_int_matrix.h:903
const Impl_type * get_c_matrix() const
Get const pointer to the underlying kjb_c::Int_matrix C struct.
Definition: l_int_matrix.h:504
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
Int_matrix(const Impl_type &mat_ref)
Ctor copies contents (i.e., a deep copy) of an existing C-struct matrix.
Definition: l_int_matrix.h:296
int get_length() const
Return the number of elements in the matrix.
Definition: l_int_matrix.h:493
Int_matrix(unsigned rows, unsigned cols, Value_type val)
Ctor builds a matrix of specified number of rows and columns.
Definition: l_int_matrix.h:190
Int_matrix create_identity_int_matrix(int rank)
Construct an identity matrix of specified rank.
Definition: l_int_matrix.h:1089
Int_matrix & resize(int new_rows, int new_cols, Value_type pad=Value_type(0))
Resize this matrix, retaining previous values.
Definition: l_int_matrix.cpp:140
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
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_matrix(unsigned long rows, unsigned long cols, Value_type val)
Ctor builds a matrix of specified number of rows and columns.
Definition: l_int_matrix.h:218
Int_matrix & operator+=(const Int_matrix &op2)
Add, in place, a matrix to this matrix.
Definition: l_int_matrix.h:914
Int_matrix::Value_type min(const Int_matrix &mat)
Return the minimum value in this matrix.
Definition: l_int_matrix.h:1385
Value_type & at(int i)
Access matrix like a one-dimensional array, using row-major ordering, and returning an lvalue...
Definition: l_int_matrix.h:698
Value_type operator[](int i) const
Subscript matrix like a one-dimensional C array, e.g., A[10], using row-major ordering, and returning an rvalue.
Definition: l_int_matrix.h:622
int get_num_rows() const
Return the number of rows in the matrix.
Definition: l_int_matrix.h:470
Int_matrix & operator=(const Impl_type &mat_ref)
Clone of zero_out(int,int)
Definition: l_int_matrix.h:425
Int_matrix(unsigned rows, unsigned cols)
Ctor builds a matrix of specified number of rows and columns.
Definition: l_int_matrix.h:176
Int_matrix()
Default ctor builds a matrix of zero rows, zero columns.
Definition: l_int_matrix.h:151
int get_num_cols() const
Return the number of columns in the matrix.
Definition: l_int_matrix.h:481
Int_matrix(Impl_type *mat_ptr)
Conversion ctor: claim ownership of an existing int matrix pointer (i.e., make a shallow copy)...
Definition: l_int_matrix.h:271
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Vec_type get_col(int col) const
Return a specified column of this matrix, in the form of an Int_vector.
Definition: l_int_matrix.cpp:177
for m
Definition: APPgetLargeConnectedEdges.m:64
Support for error handling exception classes in libKJB.
Int_matrix & zero_out(int rows)
Resize matrix to be square, and clobber contents with zeroes.
Definition: l_int_matrix.h:374
Definition for the Int_vector class, a thin wrapper on the KJB Int_vector struct and its related func...
Int_matrix & negate()
Transform this matrix into the additive inverse of its former value, in place.
Definition: l_int_matrix.h:961
Int_matrix create_zero_int_matrix(int rows, int columns)
Construct a zero matrix of specified size.
Definition: l_int_matrix.h:1103
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 write(const char *filename=0) const
Writes the matrix contents to a file specified by name.
Definition: l_int_matrix.h:812
Int_matrix & add(const Int_matrix &op2)
Add, in place, a matrix to this matrix.
Definition: l_int_matrix.h:926