Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Added .copy(...) to cppmat::tiny, cppmat::cartesian2d, cppmat::cartes…
Browse files Browse the repository at this point in the history
…ian3d (syntax the same as map)
  • Loading branch information
tdegeus committed Mar 27, 2018
1 parent 01e44e6 commit 83bdce7
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/cppmat/tensor2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,58 @@ template<class X> inline void tensor2s<X>::map(X *D) { m_data = D; }
template<class X> inline void tensor2d<X>::map(X *D) { m_data = D; }
template<class X> inline void vector <X>::map(X *D) { m_data = D; }

// =================================================================================================
// copy from external pointer
// =================================================================================================

template<class X>
inline void tensor4 <X>::copy(const X *D)
{
std::copy(D, D+16, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2 <X>::copy(const X *D)
{
std::copy(D, D+4, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2s<X>::copy(const X *D)
{
std::copy(D, D+3, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2d<X>::copy(const X *D)
{
std::copy(D, D+2, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void vector <X>::copy(const X *D)
{
std::copy(D, D+2, &m_container[0]);

m_data = &m_container[0];
}

// =================================================================================================
// cast to different class / type
// =================================================================================================
Expand Down
15 changes: 15 additions & 0 deletions src/cppmat/tensor2.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class tensor4
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down Expand Up @@ -145,6 +148,9 @@ class tensor2
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -260,6 +266,9 @@ class tensor2s
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -375,6 +384,9 @@ class tensor2d
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -486,6 +498,9 @@ class vector
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down
52 changes: 52 additions & 0 deletions src/cppmat/tensor3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,58 @@ template<class X> inline void tensor2s<X>::map(X *D) { m_data = D; }
template<class X> inline void tensor2d<X>::map(X *D) { m_data = D; }
template<class X> inline void vector <X>::map(X *D) { m_data = D; }

// =================================================================================================
// copy from external pointer
// =================================================================================================

template<class X>
inline void tensor4 <X>::copy(const X *D)
{
std::copy(D, D+81, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2 <X>::copy(const X *D)
{
std::copy(D, D+9, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2s<X>::copy(const X *D)
{
std::copy(D, D+6, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void tensor2d<X>::copy(const X *D)
{
std::copy(D, D+3, &m_container[0]);

m_data = &m_container[0];
}

// -------------------------------------------------------------------------------------------------

template<class X>
inline void vector <X>::copy(const X *D)
{
std::copy(D, D+3, &m_container[0]);

m_data = &m_container[0];
}

// =================================================================================================
// cast to different class / type
// =================================================================================================
Expand Down
15 changes: 15 additions & 0 deletions src/cppmat/tensor3.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class tensor4
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down Expand Up @@ -145,6 +148,9 @@ class tensor2
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -260,6 +266,9 @@ class tensor2s
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -375,6 +384,9 @@ class tensor2d
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// cast into another object
template<class U> U cast() const;

Expand Down Expand Up @@ -486,6 +498,9 @@ class vector
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down
12 changes: 12 additions & 0 deletions src/cppmat/tiny_matrix2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ inline void matrix2<X,m,n>::map(X *D)
m_data = D;
}

// =================================================================================================
// copy from external pointer
// =================================================================================================

template<class X, size_t m, size_t n>
inline void matrix2<X,m,n>::copy(const X *D)
{
std::copy(D, D+m_size, &m_container[0]);

m_data = &m_container[0];
}

// =================================================================================================
// get dimensions
// =================================================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/cppmat/tiny_matrix2.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class matrix2
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down
12 changes: 12 additions & 0 deletions src/cppmat/tiny_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ inline void vector<X,n>::map(X *D)
m_data = D;
}

// =================================================================================================
// copy from external pointer
// =================================================================================================

template<class X, size_t n>
inline void vector<X,n>::copy(const X *D)
{
std::copy(D, D+m_size, &m_container[0]);

m_data = &m_container[0];
}

// =================================================================================================
// get dimensions
// =================================================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/cppmat/tiny_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class vector
// map external pointer
void map(X *D);

// copy from external point
void copy(const X *D);

// get dimensions
size_t size() const;
size_t ndim() const;
Expand Down

0 comments on commit 83bdce7

Please sign in to comment.