> > From: Amitha Perera [mailto:perera@cs.rpi.edu] > > Sent: Monday, October 07, 2002 3:18 PM > > Subject: vnl_vector_fixed_ref > > > > I'm working on separating vnl_vector and vnl_vector_fixed in the VXL > > tree, as I mailed a while ago to the vxl-maintainers list. I noticed > > that you'd committed a vnl_vector_fixed_ref class which doesn't seem > > to provide any additional functionality over vnl_vector_ref. May I > > remove it, or is there some use for it? > > > > FYI, the author is listed as "Paul P. Smyth, Vicon Motion > > Systems Ltd." > > and the comment is dated 02 May 2001.
Paul Smyth <paul.smyth@vicon.com> writes: > The rationale behind it was that I had some (fast) algorithms for > matrix/vector operations that made use of compile-time knowledge of the > vector and matrix sizes. > This was typically appropriate when trying to interpret a fixed-size > subvector within a large vector of parameters as e.g. a translation. > > As I saw it, the various types of vector possible were: (with their current > names) > - pointer to memory, plus compile-time knowledge of vector size ( T*, and enum{size}) = vnl_vector_fixed_ref > - ownership of memory, plus compile-time size = vnl_vector_fixed > - pointer to memory, plus run-time only knowledge of size (T* and size()) = vnl_vector_ref > - ownership of memory, variably sized = vnl_vector > > I had a conversation with Andrew Fitzgibbon, where he reckoned that the best > thing to do with vnl vectors etc. was to create entirely separate types, and > routines for conversion between them (possibly implicitly), rather that > trying to establish a class hierarchy, which may add too many burdens in > terms of object size for small vectors/matrices. > > Sorry - I've now found the debate on the maintaners list! > > Anyway, I believe that vector_fixed_ref is very necessary, and that you > should be able to convert from a vector_fixed to a vector_fixed_ref - say > using an as_ref() member on vector_fixed or standalone function. > And I believe that for the restructured classes, vector_fixed_ref and > vector_fixed should not be related by inheritance, as that would place an > excessive burden on the size of vector_fixed. > > ------ > Another issue - do you have a mechanism for dealing with const data safely? > { > template<typename T, int n> > vnl_vector_fixed_ref(T* i_Data); > > void MyFunction(const vnl_vector<double> & Input) > { > // take a reference to the first 3 elements of Input > vnl_vector_fixed_ref<double,3> ref(Input.begin()); > // compiler error - as making vector_fixed_ref from const > double * > } > } > > The options appear to be > 1) Make a separate class vnl_vector_fixed_ref_const > 2) Make vnl_vector_fixed_ref so it can be instantiated with > vnl_vector_fixed_ref<double,n> AND vnl_vector_fixed_ref<const double,n>, and > gives appropriate behaviour - would probably require a to_const function > which generates vnl_vector_fixed_ref<const T,n> from > vnl_vector_fixed_ref<T,n> > > ------ > Another note is that a number of routines that use vector_fixed currently > (e.g. cross_3d) should really use vector_fixed_ref as an input, because they > should be able to operate on fixed vector references as well as fixed > vectors. > > While I'm at it, has it been decided that the vnl_vector and vnl_vector_ref > classes are to remain unchanged? Because having vnl_vector as the base, and > vnl_vector_ref derived from it is a real pain in the backside. A vector > which may or may not own its own memory is a more general type than one > which does own it's own memory, and having vnl_vector as the base means that > all sorts of nastinesses can happen. Simply, a vector_ref Is-not a type of > vector. > If anything, it should be the other way round. > > void DoAssign(vnl_vector<double> & RefToMemoryIDontOwn, const vnl_vector<double> & NewContents) > { > RefToMemoryIDontOwn = NewContents; > } > > void DeleteTwice() > { > vnl_vector<double> vec1(3, 0); // size 3 - news 3*double > vnl_vector<double> vec2(4,1); // size 4 news 4 * double > vnl_vector_ref<double> ref_to_1(3,vec1.begin()); // copies pointer > DoAssign(ref_to_1, vec2); // deletes memory owned by 1, news 4 * double > // vec1 now points to deleted memory, and will crash when goes out of scope > } > > Maybe that issue isn't on your agenda - but it's a bit of a disaster. I know > that fixing this might break some code. > > --------- > Sorry for rolling all these things into one - I'd be interested to know what > you think. But please don't kill my vnl_vector_ref! > > Paul.
vnl_matrix_fixed_ref is a fixed-size vnl_matrix for which the data space has been supplied externally. This is useful for two main tasks:
(a) Treating some row-based "C" matrix as a vnl_matrix in order to perform vnl_matrix operations on it.
(b) Declaring a vnl_matrix that uses entirely stack-based storage for the matrix.
The big warning is that returning a vnl_matrix_fixed_ref pointer will free non-heap memory if deleted through a vnl_matrix pointer. This should be very difficult though, as vnl_matrix_fixed_ref objects may not be constructed using operator new. This in turn is plausible as the point is to avoid such calls.
Modifications:
27-Nov-1996 Peter Vanroose - added default constructor which allocates matrix storage
4-Jul-2003 Paul Smyth - general cleanup and rewrite; interface now as vnl_matrix_fixed
15-Aug-2003 Peter Vanroose - removed "duplicate" operator=(vnl_matrix_fixed<T,n> const&)
8-Dec-2006 Markus Moll - changed operator>> signature (to const& argument)
30-Mar-2009 Peter Vanroose - added arg_min() and arg_max()
Definition in file vnl_matrix_fixed_ref.h.
#include <vcl_cassert.h>
#include <vcl_iosfwd.h>
#include <vcl_cstring.h>
#include <vnl/vnl_matrix_fixed.h>
#include <vnl/vnl_vector_fixed.h>
#include <vnl/vnl_vector_fixed_ref.h>
#include <vnl/vnl_c_vector.h>
Go to the source code of this file.
Classes | |
| class | vnl_matrix_fixed_ref_const< T, num_rows, num_cols > |
| Fixed size stack-stored vnl_matrix. More... | |
| class | vnl_matrix_fixed_ref< T, num_rows, num_cols > |
Functions | |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator+ (const vnl_matrix_fixed_ref_const< T, m, n > &mat1, const vnl_matrix_fixed_ref_const< T, m, n > &mat2) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator+ (const vnl_matrix_fixed_ref_const< T, m, n > &mat, T s) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator+ (T s, const vnl_matrix_fixed_ref_const< T, m, n > &mat) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator- (const vnl_matrix_fixed_ref_const< T, m, n > &mat1, const vnl_matrix_fixed_ref_const< T, m, n > &mat2) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator- (const vnl_matrix_fixed_ref_const< T, m, n > &mat, T s) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator- (T s, const vnl_matrix_fixed_ref_const< T, m, n > &mat) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator * (const vnl_matrix_fixed_ref_const< T, m, n > &mat, T s) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator * (T s, const vnl_matrix_fixed_ref_const< T, m, n > &mat) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | operator/ (const vnl_matrix_fixed_ref_const< T, m, n > &mat, T s) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | element_product (const vnl_matrix_fixed_ref_const< T, m, n > &mat1, const vnl_matrix_fixed_ref_const< T, m, n > &mat2) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix_fixed< T, m, n > | element_quotient (const vnl_matrix_fixed_ref_const< T, m, n > &mat1, const vnl_matrix_fixed_ref_const< T, m, n > &mat2) |
| template<class T, unsigned M, unsigned N> | |
| vnl_vector_fixed< T, M > | vnl_matrix_fixed_mat_vec_mult (const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_vector_fixed_ref_const< T, N > &b) |
| template<class T, unsigned M, unsigned N, unsigned O> | |
| vnl_matrix_fixed< T, M, O > | vnl_matrix_fixed_mat_mat_mult (const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_matrix_fixed_ref_const< T, N, O > &b) |
| template<class T, unsigned M, unsigned N> | |
| vnl_vector_fixed< T, M > | operator * (const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_vector_fixed_ref_const< T, N > &b) |
| Multiply conformant vnl_matrix_fixed (M x N) and vector_fixed (N). | |
| template<class T, unsigned M, unsigned N, unsigned O> | |
| vnl_matrix_fixed< T, M, O > | operator * (const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_matrix_fixed_ref_const< T, N, O > &b) |
| Multiply two conformant vnl_matrix_fixed (M x N) times (N x O). | |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator+ (const vnl_matrix_fixed_ref_const< T, m, n > &a, const vnl_matrix< T > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator+ (const vnl_matrix< T > &a, const vnl_matrix_fixed_ref_const< T, m, n > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator- (const vnl_matrix_fixed_ref_const< T, m, n > &a, const vnl_matrix< T > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator- (const vnl_matrix< T > &a, const vnl_matrix_fixed_ref_const< T, m, n > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator * (const vnl_matrix_fixed_ref_const< T, m, n > &a, const vnl_matrix< T > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_matrix< T > | operator * (const vnl_matrix< T > &a, const vnl_matrix_fixed_ref_const< T, m, n > &b) |
| template<class T, unsigned m, unsigned n> | |
| vnl_vector< T > | operator * (const vnl_matrix_fixed_ref_const< T, m, n > &a, const vnl_vector< T > &b) |
| template<class T, unsigned n> | |
| vnl_vector< T > | operator * (const vnl_matrix< T > &a, const vnl_vector_fixed_ref_const< T, n > &b) |
| template<class T, unsigned m, unsigned n> | |
| vcl_ostream & | operator<< (vcl_ostream &os, vnl_matrix_fixed_ref_const< T, m, n > const &mat) |
| template<class T, unsigned m, unsigned n> | |
| vcl_istream & | operator>> (vcl_istream &is, vnl_matrix_fixed_ref< T, m, n > const &mat) |
| vnl_matrix_fixed<T,m,n> element_product | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat1, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat2 | |||
| ) | [inline] |
Definition at line 762 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> element_quotient | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat1, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat2 | |||
| ) | [inline] |
Definition at line 773 of file vnl_matrix_fixed_ref.h.
| vnl_vector<T> operator * | ( | const vnl_matrix< T > & | a, | |
| const vnl_vector_fixed_ref_const< T, n > & | b | |||
| ) | [inline] |
Definition at line 892 of file vnl_matrix_fixed_ref.h.
| vnl_vector<T> operator * | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | a, | |
| const vnl_vector< T > & | b | |||
| ) | [inline] |
Definition at line 886 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator * | ( | const vnl_matrix< T > & | a, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | b | |||
| ) | [inline] |
Definition at line 880 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator * | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | a, | |
| const vnl_matrix< T > & | b | |||
| ) | [inline] |
Definition at line 874 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed< T, M, O > operator * | ( | const vnl_matrix_fixed_ref_const< T, M, N > & | a, | |
| const vnl_matrix_fixed_ref_const< T, N, O > & | b | |||
| ) | [inline] |
Multiply two conformant vnl_matrix_fixed (M x N) times (N x O).
Definition at line 838 of file vnl_matrix_fixed_ref.h.
| vnl_vector_fixed< T, M > operator * | ( | const vnl_matrix_fixed_ref_const< T, M, N > & | a, | |
| const vnl_vector_fixed_ref_const< T, N > & | b | |||
| ) | [inline] |
Multiply conformant vnl_matrix_fixed (M x N) and vector_fixed (N).
Definition at line 829 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator * | ( | T | s, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat | |||
| ) | [inline] |
Definition at line 743 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator * | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat, | |
| T | s | |||
| ) | [inline] |
Definition at line 734 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator+ | ( | const vnl_matrix< T > & | a, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | b | |||
| ) | [inline] |
Definition at line 856 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator+ | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | a, | |
| const vnl_matrix< T > & | b | |||
| ) | [inline] |
Definition at line 850 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator+ | ( | T | s, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat | |||
| ) | [inline] |
Definition at line 698 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator+ | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat, | |
| T | s | |||
| ) | [inline] |
Definition at line 689 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator+ | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat1, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat2 | |||
| ) | [inline] |
Definition at line 680 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator- | ( | const vnl_matrix< T > & | a, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | b | |||
| ) | [inline] |
Definition at line 868 of file vnl_matrix_fixed_ref.h.
| vnl_matrix<T> operator- | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | a, | |
| const vnl_matrix< T > & | b | |||
| ) | [inline] |
Definition at line 862 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator- | ( | T | s, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat | |||
| ) | [inline] |
Definition at line 725 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator- | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat, | |
| T | s | |||
| ) | [inline] |
Definition at line 716 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator- | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat1, | |
| const vnl_matrix_fixed_ref_const< T, m, n > & | mat2 | |||
| ) | [inline] |
Definition at line 707 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T,m,n> operator/ | ( | const vnl_matrix_fixed_ref_const< T, m, n > & | mat, | |
| T | s | |||
| ) | [inline] |
Definition at line 752 of file vnl_matrix_fixed_ref.h.
| vcl_ostream& operator<< | ( | vcl_ostream & | os, | |
| vnl_matrix_fixed_ref_const< T, m, n > const & | mat | |||
| ) | [inline] |
Definition at line 902 of file vnl_matrix_fixed_ref.h.
| vcl_istream& operator>> | ( | vcl_istream & | is, | |
| vnl_matrix_fixed_ref< T, m, n > const & | mat | |||
| ) | [inline] |
Definition at line 910 of file vnl_matrix_fixed_ref.h.
| vnl_matrix_fixed<T, M, O> vnl_matrix_fixed_mat_mat_mult | ( | const vnl_matrix_fixed_ref_const< T, M, N > & | a, | |
| const vnl_matrix_fixed_ref_const< T, N, O > & | b | |||
| ) | [inline] |
Definition at line 806 of file vnl_matrix_fixed_ref.h.
| vnl_vector_fixed<T, M> vnl_matrix_fixed_mat_vec_mult | ( | const vnl_matrix_fixed_ref_const< T, M, N > & | a, | |
| const vnl_vector_fixed_ref_const< T, N > & | b | |||
| ) | [inline] |
Definition at line 788 of file vnl_matrix_fixed_ref.h.
1.5.1