Commit c118dcb6 authored by Davis King's avatar Davis King

Made resizable_tensor construction and assignment from matrices automatically

set the size of the tensor.
parent 087f9f17
...@@ -267,6 +267,15 @@ namespace dlib ...@@ -267,6 +267,15 @@ namespace dlib
) )
{} {}
template <typename EXP>
resizable_tensor(
const matrix_exp<EXP>& item
)
{
set_size(item.nr(), item.nc());
*this = item;
}
explicit resizable_tensor( explicit resizable_tensor(
long n_, long k_ = 1, long nr_ = 1, long nc_ = 1 long n_, long k_ = 1, long nr_ = 1, long nc_ = 1
) )
...@@ -319,12 +328,34 @@ namespace dlib ...@@ -319,12 +328,34 @@ namespace dlib
} }
template <typename EXP> template <typename EXP>
resizable_tensor& operator= (const matrix_exp<EXP>& item) resizable_tensor& operator= (
const matrix_exp<EXP>& item
)
{ {
set_size(item.nr(), item.nc());
tensor::operator=(item); tensor::operator=(item);
return *this; return *this;
} }
template <typename EXP>
resizable_tensor& operator+= (
const matrix_exp<EXP>& item
)
{
set_size(item.nr(), item.nc());
tensor::operator+=(item);
return *this;
}
template <typename EXP>
resizable_tensor& operator-= (
const matrix_exp<EXP>& item
)
{
set_size(item.nr(), item.nc());
tensor::operator-=(item);
return *this;
}
void set_size( void set_size(
long n_, long k_ = 1, long nr_ = 1, long nc_ = 1 long n_, long k_ = 1, long nr_ = 1, long nc_ = 1
......
...@@ -412,6 +412,22 @@ namespace dlib ...@@ -412,6 +412,22 @@ namespace dlib
- #nc() == 0 - #nc() == 0
!*/ !*/
template <typename EXP>
resizable_tensor(
const matrix_exp<EXP>& item
);
/*!
requires
- item contains float values
ensures
- #num_samples() == item.nr()
- #k() == item.nc()
- #nr() == 1
- #nc() == 1
- Assigns item to *this tensor by performing:
set_ptrm(host(), num_samples(), k()*nr()*nc()) = item;
!*/
explicit resizable_tensor( explicit resizable_tensor(
long n_, long k_ = 1, long nr_ = 1, long nc_ = 1 long n_, long k_ = 1, long nr_ = 1, long nc_ = 1
); );
...@@ -470,6 +486,54 @@ namespace dlib ...@@ -470,6 +486,54 @@ namespace dlib
- #nr() == nr_ - #nr() == nr_
- #nc() == nc_ - #nc() == nc_
!*/ !*/
template <typename EXP>
resizable_tensor& operator= (
const matrix_exp<EXP>& item
);
/*!
requires
- item contains float values
ensures
- #num_samples() == item.nr()
- #k() == item.nc()
- #nr() == 1
- #nc() == 1
- Assigns item to *this tensor by performing:
set_ptrm(host(), num_samples(), k()*nr()*nc()) = item;
!*/
template <typename EXP>
resizable_tensor& operator+= (
const matrix_exp<EXP>& item
);
/*!
requires
- item contains float values
ensures
- #num_samples() == item.nr()
- #k() == item.nc()
- #nr() == 1
- #nc() == 1
- Adds item to *this tensor by performing:
set_ptrm(host(), num_samples(), k()*nr()*nc()) += item;
!*/
template <typename EXP>
resizable_tensor& operator-= (
const matrix_exp<EXP>& item
);
/*!
requires
- item contains float values
ensures
- #num_samples() == item.nr()
- #k() == item.nc()
- #nr() == 1
- #nc() == 1
- Subtracts item from *this tensor by performing:
set_ptrm(host(), num_samples(), k()*nr()*nc()) -= item;
!*/
}; };
void serialize(const tensor& item, std::ostream& out); void serialize(const tensor& item, std::ostream& out);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment