tests edit
This commit is contained in:
@@ -41,7 +41,7 @@ class Subview
|
||||
* @param begin Start index.
|
||||
* @param end End index.
|
||||
*/
|
||||
Subview(const arma::uword begin = 0, const arma::uword end = 0):
|
||||
Subview(const size_t begin = 0, const size_t end = 0):
|
||||
begin(begin),
|
||||
end(end)
|
||||
{
|
||||
@@ -58,11 +58,11 @@ class Subview
|
||||
template<typename InputType, typename OutputType>
|
||||
void Forward(InputType&& input, OutputType&& output)
|
||||
{
|
||||
|
||||
// Check if input has been selected as required.
|
||||
if ((input.n_rows != (end-begin+1)) && (end != 0))
|
||||
{
|
||||
arma::uword cols = input.n_cols;
|
||||
output = arma::mat(&input(begin), end - begin + 1, cols, false);
|
||||
output = arma::mat(&input(begin), end - begin + 1, input.n_cols, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -80,16 +80,10 @@ class Subview
|
||||
* @param g The calculated gradient.
|
||||
*/
|
||||
template<typename eT>
|
||||
void Backward(arma::Mat<eT>&& input,
|
||||
void Backward(arma::Mat<eT>&& /* input */,
|
||||
arma::Mat<eT>&& gy,
|
||||
arma::Mat<eT>&& g)
|
||||
{
|
||||
// Check if input has been selected as required.
|
||||
if ((input.n_rows != (end-begin+1)) && (end != 0))
|
||||
{
|
||||
arma::uword cols = input.n_cols;
|
||||
input = arma::mat(&input(begin), end - begin + 1, cols, false);
|
||||
}
|
||||
g = gy;
|
||||
}
|
||||
|
||||
|
||||
@@ -1813,8 +1813,38 @@ BOOST_AUTO_TEST_CASE(SimpleSubviewLayerTest)
|
||||
|
||||
// Test the Backward function.
|
||||
module.Backward(std::move(input), std::move(input), std::move(delta));
|
||||
BOOST_REQUIRE_EQUAL(accu(delta), 10);
|
||||
BOOST_REQUIRE_EQUAL(delta.n_rows, 10);
|
||||
BOOST_REQUIRE_EQUAL(accu(delta), 20);
|
||||
BOOST_REQUIRE_EQUAL(delta.n_rows, 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subview index test.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(SubviewIndexTest)
|
||||
{
|
||||
arma::mat outputEnd, outputMid, outputStart, input, delta;
|
||||
input = arma::linspace<arma::vec>(1, 20, 20);
|
||||
|
||||
// Slicing from the initial indices.
|
||||
Subview<> moduleStart(0, 9);
|
||||
arma::mat subStart = arma::linspace<arma::vec>(1, 10, 10);
|
||||
|
||||
moduleStart.Forward(std::move(input), std::move(outputStart));
|
||||
CheckMatrices(outputStart, subStart);
|
||||
|
||||
// Slicing from the mid indices.
|
||||
Subview<> moduleMid(6, 15);
|
||||
arma::mat subMid = arma::linspace<arma::vec>(7, 16, 10);
|
||||
|
||||
moduleMid.Forward(std::move(input), std::move(outputMid));
|
||||
CheckMatrices(outputMid, subMid);
|
||||
|
||||
// Slicing from the end indices.
|
||||
Subview<> moduleEnd(10, 19);
|
||||
arma::mat subEnd = arma::linspace<arma::vec>(11, 20, 10);
|
||||
|
||||
moduleEnd.Forward(std::move(input), std::move(outputEnd));
|
||||
CheckMatrices(outputEnd, subEnd);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
Reference in New Issue
Block a user