22 #ifndef _vctFastCopy_h
23 #define _vctFastCopy_h
46 template <
class _vector1Type,
class _vector2Type>
48 const _vector2Type & vector2)
50 return (vector1.size() == vector2.size());
53 template <
class _container1Type,
class _container2Type>
55 const _container2Type & container2)
57 return (container1.sizes() == container2.sizes());
60 template <
class _vector1Type,
class _vector2Type>
62 const _vector2Type & vector2)
64 return ((vector1.stride() == 1) && (vector2.stride() == 1));
68 template <
class _matrix1Type,
class _matrix2Type>
70 const _matrix2Type & matrix2)
74 (matrix1.IsCompact() && matrix2.IsCompact()
75 && (matrix1.strides() == matrix2.strides()))
78 ((matrix1.row_stride() == 1) && matrix2.row_stride() == 1)
81 ((matrix1.col_stride() == 1) && matrix2.col_stride() == 1));
84 template <
class _nArray1Type,
class _nArray2Type>
86 const _nArray2Type & nArray2)
88 return (nArray1.IsCompact() && nArray2.IsCompact()
89 && (nArray1.strides() == nArray2.strides()));
97 template <
class _vector1Type,
class _vector2Type>
99 const _vector2Type & vector2)
100 throw(std::runtime_error)
103 cmnThrow(std::runtime_error(
"vctFastCopy: Vector sizes mismatch"));
107 template <
class _container1Type,
class _container2Type>
109 const _container2Type & container2)
110 throw(std::runtime_error)
113 cmnThrow(std::runtime_error(
"vctFastCopy: Container sizes mismatch"));
128 template <
class _vector1Type,
class _vector2Type>
130 const _vector2Type & vector2)
132 return (!cmnRequiresDeepCopy<typename _vector1Type::value_type>()
133 && !cmnRequiresDeepCopy<typename _vector2Type::value_type>()
138 template <
class _matrix1Type,
class _matrix2Type>
140 const _matrix2Type & matrix2)
142 return (!cmnRequiresDeepCopy<typename _matrix1Type::value_type>()
143 && !cmnRequiresDeepCopy<typename _matrix2Type::value_type>()
148 template <
class _nArray1Type,
class _nArray2Type>
150 const _nArray2Type & nArray2)
152 return (!cmnRequiresDeepCopy<typename _nArray1Type::value_type>()
153 && !cmnRequiresDeepCopy<typename _nArray2Type::value_type>()
164 template <
class _destinationVectorType,
class _sourceVectorType>
165 inline static bool VectorCopy(_destinationVectorType & destination,
166 const _sourceVectorType & source,
167 bool performSafetyChecks)
169 typedef _sourceVectorType SourceVectorType;
170 typedef typename SourceVectorType::value_type value_type;
172 if (performSafetyChecks) {
181 memcpy(destination.Pointer(), source.Pointer(), source.size() *
sizeof(value_type));
211 template <
class _destinationMatrixType,
class _sourceMatrixType>
212 inline static bool MatrixCopy(_destinationMatrixType & destination,
213 const _sourceMatrixType & source,
214 bool performSafetyChecks)
216 typedef _sourceMatrixType SourceMatrixType;
217 typedef typename SourceMatrixType::value_type value_type;
219 if (performSafetyChecks) {
229 if (destination.IsCompact() && source.IsCompact()) {
230 memcpy(destination.Pointer(), source.Pointer(), source.size() *
sizeof(value_type));
233 typedef _destinationMatrixType DestinationMatrixType;
234 typedef _sourceMatrixType SourceMatrixType;
239 typedef typename DestinationMatrixType::pointer DestinationPointerType;
240 typedef typename SourceMatrixType::const_pointer SourcePointerType;
242 const size_type rows = destination.rows();
243 const size_type cols = destination.cols();
245 DestinationPointerType destinationPointer = destination.Pointer();
246 SourcePointerType sourcePointer = source.Pointer();
248 const stride_type destinationRowStride = destination.row_stride();
249 const stride_type sourceRowStride = source.row_stride();
250 const stride_type destinationColStride = destination.col_stride();
251 const stride_type sourceColStride = source.col_stride();
254 if ((destinationColStride == 1) && (sourceColStride == 1)) {
256 const size_type sizeOfRow = cols *
sizeof(value_type);
258 const DestinationPointerType destinationRowEnd = destinationPointer + rows * destinationRowStride;
261 destinationPointer != destinationRowEnd;
262 destinationPointer += destinationRowStride, sourcePointer += sourceRowStride) {
263 memcpy(destinationPointer, sourcePointer, sizeOfRow);
268 const size_type sizeOfCol = rows *
sizeof(value_type);
269 const DestinationPointerType destinationColEnd = destinationPointer + cols * destinationColStride;
272 destinationPointer != destinationColEnd;
273 destinationPointer += destinationColStride, sourcePointer += sourceColStride) {
274 memcpy(destinationPointer, sourcePointer, sizeOfCol);
287 template <
class _destinationNArrayType,
class _sourceNArrayType>
288 inline static bool NArrayCopy(_destinationNArrayType & destination,
289 const _sourceNArrayType & source,
290 bool performSafetyChecks)
292 typedef _sourceNArrayType SourceNArrayType;
293 typedef typename SourceNArrayType::value_type value_type;
295 if (performSafetyChecks) {
304 memcpy(destination.Pointer(), source.Pointer(), source.size() *
sizeof(value_type));
310 #endif // _vctFastCopy_h
static bool ContainerSizesCompatible(const _container1Type &container1, const _container2Type &container2)
Definition: vctFastCopy.h:54
static void ThrowUnlessValidVectorSizes(const _vector1Type &vector1, const _vector2Type &vector2)
Definition: vctFastCopy.h:98
Portability across compilers and operating systems tools.
static bool NArrayCopyCompatible(const _nArray1Type &nArray1, const _nArray2Type &nArray2)
Definition: vctFastCopy.h:149
static bool VectorCopy(_destinationVectorType &destination, const _sourceVectorType &source, bool performSafetyChecks)
Definition: vctFastCopy.h:165
size_t size_type
Definition: vctContainerTraits.h:35
static const bool PerformChecks
Definition: vctFastCopy.h:123
static bool VectorStrideCompatible(const _vector1Type &vector1, const _vector2Type &vector2)
Definition: vctFastCopy.h:61
static bool MatrixCopy(_destinationMatrixType &destination, const _sourceMatrixType &source, bool performSafetyChecks)
Definition: vctFastCopy.h:212
static bool MatrixCopyCompatible(const _matrix1Type &matrix1, const _matrix2Type &matrix2)
Definition: vctFastCopy.h:139
static const bool SkipChecks
Definition: vctFastCopy.h:122
static bool MatrixStridesCompatible(const _matrix1Type &matrix1, const _matrix2Type &matrix2)
Definition: vctFastCopy.h:69
Container class for fast copy related methods.
Definition: vctFastCopy.h:40
#define cmnThrow(a)
Definition: MinimalCmn.h:4
static void ThrowUnlessValidContainerSizes(const _container1Type &container1, const _container2Type &container2)
Definition: vctFastCopy.h:108
static bool NArrayStridesCompatible(const _nArray1Type &nArray1, const _nArray2Type &nArray2)
Definition: vctFastCopy.h:85
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
static bool VectorSizeCompatible(const _vector1Type &vector1, const _vector2Type &vector2)
Definition: vctFastCopy.h:47
static bool VectorCopyCompatible(const _vector1Type &vector1, const _vector2Type &vector2)
Definition: vctFastCopy.h:129
Declaration of the template function cmnThrow.
static bool NArrayCopy(_destinationNArrayType &destination, const _sourceNArrayType &source, bool performSafetyChecks)
Definition: vctFastCopy.h:288
Declaration of cmnRequiresDeepCopy.