vnl_copy.cxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_copy.cxx
2 //:
3 // \file
4 // \author fsm
5 
6 #include <complex>
7 #include <cassert>
8 #include <vnl/vnl_vector.h>
9 #include <vnl/vnl_matrix.h>
10 #include <vnl/vnl_diag_matrix.h>
11 
12 //-------------------------------------------------------------------
13 
14 template <class S, class T>
15 void vnl_copy(S const * const src, T *const dst, const unsigned n)
16 {
17  for (unsigned int i=0; i<n; ++i)
18  dst[i] = T(src[i]);
19 }
20 
21 template <class S, class T>
22 void vnl_copy(S const &src, T &dst)
23 {
24  assert(src.size() == dst.size());
25  vnl_copy(src.begin(), dst.begin(), src.size());
26 }
27 
28 //------------------------------------------------------------------------
29 
30 // C arrays
31 #define VNL_COPY_INSTANTIATE0(S, T) \
32 template void VNL_EXPORT vnl_copy(S const * const, T * const, const unsigned )
33 
34 VNL_COPY_INSTANTIATE0(float, double);
35 VNL_COPY_INSTANTIATE0(double, float);
36 VNL_COPY_INSTANTIATE0(double, long double);
37 #ifndef __hppa // assembler bug on HP?
38 VNL_COPY_INSTANTIATE0(long double, double);
39 #endif
40 
41 #define vnl_copy_macro(S, D) \
42 template <> \
43 VNL_EXPORT void vnl_copy(std::complex<S> const * const src, std::complex<D> * const dst, const unsigned n) \
44 { \
45  for (unsigned int i=0; i<n; ++i) \
46  dst[i] = std::complex<D>((D)std::real(src[i]), (D)std::imag(src[i])); \
47 }
48 
49 vnl_copy_macro(float, double);
50 vnl_copy_macro(double, float);
51 vnl_copy_macro(double, long double);
52 vnl_copy_macro(long double, double);
53 #undef vnl_copy_macro
54 
55 #define vnl_copy_dumb(S) \
56 template <> \
57 VNL_EXPORT void vnl_copy(S const * const src, S *const dst, const unsigned n) \
58 { \
59  for (unsigned int i=0; i<n; ++i) \
60  dst[i] = src[i]; \
61 }
62 
63 vnl_copy_dumb(float);
64 vnl_copy_dumb(double);
65 #undef vnl_copy_dumb
66 
67 // vnl_* containers
68 #define VNL_COPY_INSTANTIATE(S, T) \
69 template VNL_EXPORT void vnl_copy(vnl_vector<S > const &, vnl_vector<T > &); \
70 template VNL_EXPORT void vnl_copy(vnl_matrix<S > const &, vnl_matrix<T > &); \
71 template VNL_EXPORT void vnl_copy(vnl_diag_matrix<S > const &, vnl_diag_matrix<T > &)
72 
73 VNL_COPY_INSTANTIATE(float, float);
74 VNL_COPY_INSTANTIATE(double, double);
75 
76 #define VNL_COPY_INSTANTIATE_twoway(S, T) \
77 VNL_COPY_INSTANTIATE(S, T); \
78 VNL_COPY_INSTANTIATE(T, S)
79 
80 VNL_COPY_INSTANTIATE_twoway(float, double);
81 VNL_COPY_INSTANTIATE_twoway(std::complex<float>, std::complex<double>);
82 #ifndef __hppa // assembler bug on HP?
83 VNL_COPY_INSTANTIATE_twoway(double, long double);
84 VNL_COPY_INSTANTIATE_twoway(std::complex<double>, std::complex<long double>);
85 #endif
An ordinary mathematical matrix.
VNL_EXPORT void vnl_copy(S const *const src, T *const dst, const unsigned n)
Easy conversion between vectors and matrices templated over different types.
Definition: vnl_copy.cxx:15
#define vnl_copy_macro(S, D)
Definition: vnl_copy.cxx:41
#define VNL_COPY_INSTANTIATE0(S, T)
Definition: vnl_copy.cxx:31
#define VNL_COPY_INSTANTIATE_twoway(S, T)
Definition: vnl_copy.cxx:76
#define VNL_COPY_INSTANTIATE(S, T)
Definition: vnl_copy.cxx:68
#define vnl_copy_dumb(S)
Definition: vnl_copy.cxx:55
Contains class for diagonal matrices.