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
|
|
|
|
//
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <array/NDArray.h>
|
|
|
|
#include <array/NDArrayList.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include "testlayers.h"
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
using namespace sd;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
class NDArrayListTests : public testing::Test {
|
|
|
|
public:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(NDArrayListTests, BasicTests_1) {
|
|
|
|
NDArrayList list(false);
|
|
|
|
|
|
|
|
auto x = NDArrayFactory::create<float>('c', {1, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('c', {1, 10});
|
|
|
|
|
2019-12-20 20:35:39 +01:00
|
|
|
ASSERT_EQ(ND4J_STATUS_OK, list.write(1, new NDArray(x.dup())));
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
//ASSERT_EQ(ND4J_STATUS_DOUBLE_WRITE, list.write(1, &y));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NDArrayListTests, BasicTests_2) {
|
|
|
|
NDArrayList list(false);
|
|
|
|
|
|
|
|
auto x = NDArrayFactory::create<float>('c', {1, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('c', {1, 7});
|
|
|
|
|
2019-12-20 20:35:39 +01:00
|
|
|
ASSERT_EQ(ND4J_STATUS_OK, list.write(1, new NDArray(x.dup())));
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(ND4J_STATUS_BAD_INPUT, list.write(0, &y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(NDArrayListTests, Test_Stack_UnStack_1) {
|
|
|
|
auto input = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
input.linspace(1);
|
|
|
|
|
|
|
|
NDArrayList list(false);
|
|
|
|
|
|
|
|
list.unstack(&input, 0);
|
|
|
|
|
|
|
|
ASSERT_EQ(10, list.elements());
|
|
|
|
|
2019-12-20 20:35:39 +01:00
|
|
|
auto array = list.stack();
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
ASSERT_TRUE(input.isSameShape(array));
|
|
|
|
|
|
|
|
ASSERT_TRUE(input.equalsTo(array));
|
|
|
|
|
|
|
|
delete array;
|
|
|
|
}
|