cavis/libnd4j/tests_cpu/layers_tests/StashTests.cpp

89 lines
2.5 KiB
C++
Raw Normal View History

2019-06-06 14:21:15 +02:00
/*******************************************************************************
* Copyright (c) 2015-2018 Skymind, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
//
// @author raver119@gmail.com
//
#ifndef LIBND4J_STASHTESTS_H
#define LIBND4J_STASHTESTS_H
#include <array/NDArray.h>
2019-06-06 14:21:15 +02:00
#include "testlayers.h"
#include <graph/Stash.h>
using namespace sd;
using namespace sd::graph;
2019-06-06 14:21:15 +02:00
class StashTests : public testing::Test {
public:
};
TEST_F(StashTests, BasicTests_1) {
Stash stash;
auto alpha = NDArrayFactory::create_<float>('c',{5, 5});
alpha->assign(1.0);
auto beta = NDArrayFactory::create_<float>('c',{5, 5});
beta->assign(2.0);
auto cappa = NDArrayFactory::create_<float>('c',{5, 5});
cappa->assign(3.0);
stash.storeArray(1, "alpha", alpha);
stash.storeArray(2, "alpha", beta);
stash.storeArray(3, "cappa", cappa);
ASSERT_TRUE(stash.checkStash(1, "alpha"));
ASSERT_TRUE(stash.checkStash(2, "alpha"));
ASSERT_TRUE(stash.checkStash(3, "cappa"));
ASSERT_FALSE(stash.checkStash(3, "alpha"));
ASSERT_FALSE(stash.checkStash(2, "beta"));
ASSERT_FALSE(stash.checkStash(1, "cappa"));
}
TEST_F(StashTests, BasicTests_2) {
Stash stash;
auto alpha = NDArrayFactory::create_<float>('c',{5, 5});
alpha->assign(1.0);
auto beta = NDArrayFactory::create_<float>('c',{5, 5});
beta->assign(2.0);
auto cappa = NDArrayFactory::create_<float>('c',{5, 5});
cappa->assign(3.0);
stash.storeArray(1, "alpha", alpha);
stash.storeArray(1, "beta", beta);
stash.storeArray(1, "cappa", cappa);
2019-06-06 14:21:15 +02:00
ASSERT_FALSE(stash.checkStash(2, "alpha"));
ASSERT_FALSE(stash.checkStash(2, "beta"));
ASSERT_FALSE(stash.checkStash(2, "cappa"));
2019-06-06 14:21:15 +02:00
ASSERT_TRUE(alpha == stash.extractArray(1, "alpha"));
ASSERT_TRUE(beta == stash.extractArray(1, "beta"));
ASSERT_TRUE(cappa == stash.extractArray(1, "cappa"));
2019-06-06 14:21:15 +02:00
}
#endif //LIBND4J_STASHTESTS_H