shugeo 1bb3ae4b03
Shugeo unordered map (#256)
* Refactored usage of std::map to std::unordered_map instead.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Eliminated crash with wrong ShapeDescriptor hash.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Eliminated crash with TadDescriptor hash.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Refactored Stash hash.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Refactored hashes.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Refactored TadDescriptor hash and top_k mapping.

* Refactored hashes for ShapeDescriptor and TadDescriptor classes.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Refactored hash for ConstantDescriptor and ShapeDescriptor classes.

Signed-off-by: shugeo <sgazeos@gmail.com>

* Fixed map using with cuda platform.

Signed-off-by: shugeo <sgazeos@gmail.com>

* - few rearrangements for hash functions
- shared openblas allowed

Signed-off-by: raver119 <raver119@gmail.com>

* exports

Signed-off-by: raver119 <raver119@gmail.com>

* exports

Signed-off-by: raver119 <raver119@gmail.com>

* Stash reverted to std::map

Signed-off-by: raver119@gmail.com <raver119@gmail.com>

* Added additional test.

Signed-off-by: shugeo <sgazeos@gmail.com>

* different maps for different compilers

Signed-off-by: raver119 <raver119@gmail.com>

* missing include

Signed-off-by: raver119 <raver119@gmail.com>

* fix the leak

Signed-off-by: raver119 <raver119@gmail.com>

Co-authored-by: raver119 <raver119@gmail.com>
2020-02-24 07:51:01 +03:00

89 lines
2.5 KiB
C++

/*******************************************************************************
* 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 <NDArray.h>
#include "testlayers.h"
#include <graph/Stash.h>
using namespace nd4j;
using namespace nd4j::graph;
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);
ASSERT_FALSE(stash.checkStash(2, "alpha"));
ASSERT_FALSE(stash.checkStash(2, "beta"));
ASSERT_FALSE(stash.checkStash(2, "cappa"));
ASSERT_TRUE(alpha == stash.extractArray(1, "alpha"));
ASSERT_TRUE(beta == stash.extractArray(1, "beta"));
ASSERT_TRUE(cappa == stash.extractArray(1, "cappa"));
}
#endif //LIBND4J_STASHTESTS_H