2020-01-04 11:27:50 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2019 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
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "testlayers.h"
|
|
|
|
#include <ops/declarable/CustomOperations.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <array/NDArray.h>
|
2020-01-04 11:27:50 +01:00
|
|
|
#include <ops/ops.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <helpers/GradCheck.h>
|
2020-01-04 11:27:50 +01:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
using namespace sd;
|
2020-01-04 11:27:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DeclarableOpsTests19 : public testing::Test {
|
|
|
|
public:
|
|
|
|
|
|
|
|
DeclarableOpsTests19() {
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2020-02-02 21:14:00 +01:00
|
|
|
};
|
|
|
|
|
2020-04-10 16:57:02 +02:00
|
|
|
TEST_F(DeclarableOpsTests19, test_matmul_ccc) {
|
|
|
|
auto x = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto e = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto z = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
|
|
|
|
z.assign(100.f);
|
|
|
|
e.assign(110.f);
|
|
|
|
x.assign(1.0f);
|
|
|
|
y.assign(1.0f);
|
|
|
|
|
|
|
|
sd::ops::matmul op;
|
|
|
|
auto status = op.execute({&x, &y}, {&z}, {1.0, 1.0});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
|
|
|
|
ASSERT_EQ(e, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeclarableOpsTests19, test_matmul_fcf) {
|
|
|
|
auto x = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto e = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto z = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
|
|
|
|
z.assign(100.f);
|
|
|
|
e.assign(110.f);
|
|
|
|
x.assign(1.0f);
|
|
|
|
y.assign(1.0f);
|
|
|
|
|
|
|
|
sd::ops::matmul op;
|
|
|
|
auto status = op.execute({&x, &y}, {&z}, {1.0, 1.0});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
|
|
|
|
ASSERT_EQ(e, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeclarableOpsTests19, test_matmul_cff) {
|
|
|
|
auto x = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto e = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto z = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
|
|
|
|
z.assign(100.f);
|
|
|
|
e.assign(110.f);
|
|
|
|
x.assign(1.0f);
|
|
|
|
y.assign(1.0f);
|
|
|
|
|
|
|
|
sd::ops::matmul op;
|
|
|
|
auto status = op.execute({&x, &y}, {&z}, {1.0, 1.0});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
|
|
|
|
ASSERT_EQ(e, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(DeclarableOpsTests19, test_matmul_ccf) {
|
|
|
|
auto x = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('c', {10, 10});
|
|
|
|
auto e = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto z = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
|
|
|
|
z.assign(100.f);
|
|
|
|
e.assign(110.f);
|
|
|
|
x.assign(1.0f);
|
|
|
|
y.assign(1.0f);
|
|
|
|
|
|
|
|
sd::ops::matmul op;
|
|
|
|
auto status = op.execute({&x, &y}, {&z}, {1.0, 1.0});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
|
|
|
|
ASSERT_EQ(e, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeclarableOpsTests19, test_matmul_fff) {
|
|
|
|
auto x = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto y = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto e = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
auto z = NDArrayFactory::create<float>('f', {10, 10});
|
|
|
|
|
|
|
|
z.assign(100.f);
|
|
|
|
e.assign(110.f);
|
|
|
|
x.assign(1.0f);
|
|
|
|
y.assign(1.0f);
|
|
|
|
|
|
|
|
sd::ops::matmul op;
|
|
|
|
auto status = op.execute({&x, &y}, {&z}, {1.0, 1.0});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
|
|
|
|
ASSERT_EQ(e, z);
|
|
|
|
}
|
|
|
|
|
2020-02-02 21:14:00 +01:00
|
|
|
TEST_F(DeclarableOpsTests19, test_conv1d_bp_1) {
|
|
|
|
/*
|
|
|
|
DynamicCustomOp op = DynamicCustomOp.builder("conv1d_bp")
|
|
|
|
.addInputs(
|
|
|
|
Nd4j.create(DataType.FLOAT, 2,2,12),
|
|
|
|
Nd4j.create(DataType.FLOAT, 3,2,3),
|
|
|
|
Nd4j.create(DataType.FLOAT, 2,3,6)
|
|
|
|
)
|
|
|
|
.addOutputs(
|
|
|
|
Nd4j.create(DataType.FLOAT, 2,2,12),
|
|
|
|
Nd4j.create(DataType.FLOAT, 3,2,3))
|
|
|
|
.addIntegerArguments(3,2,0,1,2,0)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Nd4j.exec(op);
|
|
|
|
*/
|
|
|
|
|
|
|
|
auto t = NDArrayFactory::create<float>('c', {2, 2, 12});
|
|
|
|
auto u = NDArrayFactory::create<float>('c', {3, 2, 3});
|
|
|
|
auto v = NDArrayFactory::create<float>('c', {2, 3, 6});
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::ops::conv1d_bp op;
|
2020-02-02 21:14:00 +01:00
|
|
|
auto result = op.evaluate({&t, &u, &v}, {3, 2, 0, 1, 2,0});
|
2020-03-10 05:42:50 +01:00
|
|
|
ASSERT_EQ(Status::OK(), result.status());
|
2020-02-02 21:14:00 +01:00
|
|
|
|
2020-02-14 14:20:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeclarableOpsTests19, test_squeeze_1) {
|
|
|
|
auto x = NDArrayFactory::create<double>('c', {3, 4, 1});
|
|
|
|
auto e = NDArrayFactory::create<double>('c', {3, 4});
|
|
|
|
int axis = 2;
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::ops::squeeze op;
|
2020-02-14 14:20:31 +01:00
|
|
|
auto status = op.execute({&x}, {&e}, {axis});
|
|
|
|
ASSERT_EQ(Status::OK(), status);
|
2020-04-10 16:57:02 +02:00
|
|
|
}
|