* fix pad javadoc and @see links. (#72) Signed-off-by: Robert Altena <Rob@Ra-ai.com> * [WIP] More fixes (#73) * special tests for ConstantTadHelper/ConstantShapeHelper Signed-off-by: raver119 <raver119@gmail.com> * release methods for data buffers Signed-off-by: raver119 <raver119@gmail.com> * delete temporary buffer Java side Signed-off-by: raver119 <raver119@gmail.com> * delete temporary buffer Java side Signed-off-by: raver119 <raver119@gmail.com> * delete temporary TadPack C++/Java side (#74) Signed-off-by: raver119 <raver119@gmail.com> * Zoo model TF import test updates (#75) * argLine fix, update compression_gru comment * updated comment for xception * undid but commented argLine change * updated xlnet comment * copyright headers * - new NDArray methods like()/ulike() (#77) - fix for depthwise_conv2d_bp + special test Signed-off-by: raver119 <raver119@gmail.com> * upsampling2d fix CUDA Signed-off-by: raver119 <raver119@gmail.com> * DL4J trace logging (#79) * MLN/CG trace logging for debugging Signed-off-by: AlexDBlack <blacka101@gmail.com> * Tiny tweak Signed-off-by: AlexDBlack <blacka101@gmail.com> * strided_slice_bp shape fn leak fix Signed-off-by: raver119 <raver119@gmail.com> * SameDiff fixes and naming (#78) * remove SDVariable inplace methods * import methods * npe fix in OpVal * removed SameDiff inplace ops from tests * Naming updates, moved to centralized methods in SameDiff, should use op_#:# for everything * quick fixes * javadoc * SDVariable eval with placeholders * use regex match * better matching * fix javadoc. (#76) * fix javadoc. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * replace most @see with @link s. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * 4 additional tests Signed-off-by: raver119 <raver119@gmail.com> * Various DL4J/ND4J fixes (#81) * #7954 Force refresh of UI when switching tabs on overview page Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8017 Concurrent modification exception (synchronize) fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8033 Don't initialize updater in middle of writing memory crash dump Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8208 Fix shape checks for ND4J int[] creator methods Signed-off-by: AlexDBlack <blacka101@gmail.com> * #6385 #7992 Keras import naming fixes + cleanup Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8016 Upsampling3D - add NDHWC format support Signed-off-by: AlexDBlack <blacka101@gmail.com> * Refactor NativeOps.h to export C functions * Actually export functions from NativeOps.h * Adapt the Java wrappers in ND4J generated with JavaCPP * Create C wrappers for some of the C++ classes currently used by ND4J * remove duplicate code in createBufferDetached. (#83) Signed-off-by: Robert Altena <Rob@Ra-ai.com> * Keras model import - updater lr fix (#84) * Keras model import - updater lr fix Signed-off-by: eraly <susan.eraly@gmail.com> * Keras model import - updater lr fix, cleanup Signed-off-by: eraly <susan.eraly@gmail.com> * Fix functions of OpaqueVariablesSet * SameDiff Convolution Config validation, better output methods (#82) * Conv Config validation & tests Signed-off-by: Ryan Nett <rnett@skymind.io> * stackOutputs utility method Signed-off-by: Ryan Nett <rnett@skymind.io> * use constructor for validation, support negative kernel sizes (infered from weights) Signed-off-by: Ryan Nett <rnett@skymind.io> * better output methods Signed-off-by: Ryan Nett <rnett@skymind.io> * move output to be with fit and evaluate Signed-off-by: Ryan Nett <rnett@skymind.io> * fixes Signed-off-by: Ryan Nett <rnett@skymind.io> * more fixes Signed-off-by: Ryan Nett <rnett@skymind.io> * refactor duplicate code from pad methods. (#86) * refactor duplicate code from pad methods. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * replace switch with if. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * Various ND4J/DL4J fixes and improvements (#87) * Reshape and reallocate - small fixes Signed-off-by: AlexDBlack <blacka101@gmail.com> * Reshape and reallocate - small fixes Signed-off-by: AlexDBlack <blacka101@gmail.com> * #6488 ElementWiseVertex broadcast support Signed-off-by: AlexDBlack <blacka101@gmail.com> * Constructors and broadcast supported it Transforms.max/min Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8054 ElementWiseVertex now supports broadcast inputs Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8057 Nd4j.create overload dtype fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * #7551 ND4J Shape validation fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * [WIP] Numpy boolean import (#91) * numpy bool type Signed-off-by: raver119 <raver119@gmail.com> * numpy bool java side Signed-off-by: raver119 <raver119@gmail.com> * remove create method with unused parameter. (#89) * remove create method with unused parameter. * removed more unused methods. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * removing more unused code. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * last removal of unused code. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * remove createSparse methods. (#92) Signed-off-by: Robert Altena <Rob@Ra-ai.com> * Various ND4J/DL4J fixes (#90) * Deprecate Old*Op instances Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8063 #8054 Broadcast exceptions + cleanup inplace ops Signed-off-by: AlexDBlack <blacka101@gmail.com> * Small fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * Remove bad test condition Signed-off-by: AlexDBlack <blacka101@gmail.com> * #7993 Fix shape function issue in crop_and_resize op Signed-off-by: AlexDBlack <blacka101@gmail.com> * DL4J SameDiff lambda layer fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8029 Fix for pnorm backprop math Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8038 Fix Op profiler NaN/Inf triggering + add tests (#93) Signed-off-by: AlexDBlack <blacka101@gmail.com> * createUninitializedDetached refactoring. (#94) * wip * update interface, add null implementations. * Breaking one test in a weird way. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * createUninitializedDetached refactored. Signed-off-by: Robert Altena <Rob@Ra-ai.com> * cuda build fix for issues introduced by recent refactoring Signed-off-by: raver119 <raver119@gmail.com> * [WIP] More of CUDA (#95) * initial commit Signed-off-by: raver119 <raver119@gmail.com> * Implementation of hashcode cuda helper. Working edition. * Fixed parallel test input arangements. * Fixed tests for hashcode op. * Fixed shape calculation for image:crop_and_resize op and test. * NativeOps tests. Initial test suite. * Added tests for indexReduce methods. * Added test on execBroadcast with NDArray as dimensions. * Added test on execBroadcastBool with NDArray as dimensions. * Added tests on execPairwiseTransform and execPairwiseTransofrmBool. * Added tests for execReduce with scalar results. * Added reduce tests for non-empty dims array. * Added tests for reduce3. * Added tests for execScalar. * Added tests for execSummaryStats. * - provide cpu/cuda code for batch_to_space - testing it Signed-off-by: Yurii <yurii@skymind.io> * - remove old test for batch_to_space (had wrong format and numbers were not checked) Signed-off-by: Yurii <yurii@skymind.io> * Fixed complilation errors with test. * Added test for execTransformFloat. * Added test for execTransformSame. * Added test for execTransformBool. * Added test for execTransformStrict. * Added tests for execScalar/execScalarBool with TADs. * Added test for flatten. * - provide cpu/cuda code for space_to_Batch operaion Signed-off-by: Yurii <yurii@skymind.io> * Added test for concat. * comment unnecessary stuff in s_t_b Signed-off-by: Yurii <yurii@skymind.io> * Added test for specialConcat. * Added tests for memcpy/set routines. * Fixed pullRow cuda test. * Added pullRow test. * Added average test. * - correct typo in NDArray::applyPairwiseTransform(nd4j::pairwise::BoolOps op...) Signed-off-by: Yurii <yurii@skymind.io> * - debugging and fixing cuda tests in JavaInteropTests file Signed-off-by: Yurii <yurii@skymind.io> * - correct some tests Signed-off-by: Yurii <yurii@skymind.io> * Added test for shuffle. * Fixed ops declarations. * Restored omp and added shuffle test. * Added convertTypes test. * Added tests for execRandom. Eliminated usage of RandomBuffer with NativeOps. * Added sort tests. * Added tests for execCustomOp. * - further debuging and fixing tests terminated with crash Signed-off-by: Yurii <yurii@skymind.io> * Added tests for calculateOutputShapes. * Addded Benchmarks test. * Commented benchmark tests. * change assertion Signed-off-by: raver119 <raver119@gmail.com> * Added tests for apply_sgd op. Added cpu helper for that op. * Implement cuda helper for aplly_sgd op. Fixed tests for NativeOps. * Added test for assign broadcastable. * Added tests for assign_bp op. * Added tests for axpy op. * - assign/execScalar/execTransformAny signature change - minor test fix Signed-off-by: raver119 <raver119@gmail.com> * Fixed axpy op. * meh Signed-off-by: raver119 <raver119@gmail.com> * - fix tests for nativeOps::concat Signed-off-by: Yurii <yurii@skymind.io> * sequential transform/scalar Signed-off-by: raver119 <raver119@gmail.com> * allow nested parallelism Signed-off-by: raver119 <raver119@gmail.com> * assign_bp leak fix Signed-off-by: raver119 <raver119@gmail.com> * block setRNG fix Signed-off-by: raver119 <raver119@gmail.com> * enable parallelism by default Signed-off-by: raver119 <raver119@gmail.com> * enable nested parallelism by default Signed-off-by: raver119 <raver119@gmail.com> * Added cuda implementation for row_count helper. * Added implementation for tnse gains op helper. * - take into account possible situations when input arrays are empty in reduce_ cuda stuff Signed-off-by: Yurii <yurii@skymind.io> * Implemented tsne/edge_forces op cuda-based helper. Parallelized cpu-based helper for edge_forces. * Added kernel for tsne/symmetrized op heleper. * Implementation of tsne/symmetrized op cuda helper. Working edition. * Eliminated waste printfs. * Added test for broadcastgradientargs op. * host-only fallback for empty reduce float Signed-off-by: raver119 <raver119@gmail.com> * - some tests fixes Signed-off-by: Yurii <yurii@skymind.io> * - correct the rest of reduce_ stuff Signed-off-by: Yurii <yurii@skymind.io> * - further correction of reduce_ stuff Signed-off-by: Yurii <yurii@skymind.io> * Added test for Cbow op. Also added cuda implementation for cbow helpers. * - improve code of stack operation for scalar case Signed-off-by: Yurii <yurii@skymind.io> * - provide cuda kernel for gatherND operation Signed-off-by: Yurii <yurii@skymind.io> * Implementation of cbow helpers with cuda kernels. * minor tests tweaks Signed-off-by: raver119 <raver119@gmail.com> * minor tests tweaks Signed-off-by: raver119 <raver119@gmail.com> * - further correction of cuda stuff Signed-off-by: Yurii <yurii@skymind.io> * Implementatation of cbow op helper with cuda kernels. Working edition. * Skip random testing for cudablas case. * lstmBlockCell context fix Signed-off-by: raver119 <raver119@gmail.com> * Added tests for ELU and ELU_BP ops. * Added tests for eq_scalar, gt_scalar, gte_scalar and lte_scalar ops. * Added tests for neq_scalar. * Added test for noop. * - further work on clipbynorm_bp Signed-off-by: Yurii <yurii@skymind.io> * - get rid of concat op call, use instead direct concat helper call Signed-off-by: Yurii <yurii@skymind.io> * lstmBlockCell context fix Signed-off-by: raver119 <raver119@gmail.com> * Added tests for lrelu and lrelu_bp. * Added tests for selu and selu_bp. * Fixed lrelu derivative helpers. * - some corrections in lstm Signed-off-by: Yurii <yurii@skymind.io> * operator * result shape fix Signed-off-by: raver119 <raver119@gmail.com> * - correct typo in lstmCell Signed-off-by: Yurii <yurii@skymind.io> * few tests fixed Signed-off-by: raver119 <raver119@gmail.com> * CUDA inverse broadcast bool fix Signed-off-by: raver119 <raver119@gmail.com> * disable MMAP test for CUDA Signed-off-by: raver119 <raver119@gmail.com> * BooleanOp syncToDevice Signed-off-by: raver119 <raver119@gmail.com> * meh Signed-off-by: raver119 <raver119@gmail.com> * additional data types for im2col/col2im Signed-off-by: raver119 <raver119@gmail.com> * Added test for firas_sparse op. * one more RandomBuffer test excluded Signed-off-by: raver119 <raver119@gmail.com> * Added tests for flatten op. * Added test for Floor op. * bunch of tests fixed Signed-off-by: raver119 <raver119@gmail.com> * mmulDot tests fixed Signed-off-by: raver119 <raver119@gmail.com> * more tests fixed Signed-off-by: raver119 <raver119@gmail.com> * Implemented floordiv_bp op and tests. * Fixed scalar case with cuda implementation for bds. * - work on cuda kernel for clip_by_norm backprop op is completed Signed-off-by: Yurii <yurii@skymind.io> * Eliminate cbow crach. * more tests fixed Signed-off-by: raver119 <raver119@gmail.com> * more tests fixed Signed-off-by: raver119 <raver119@gmail.com> * Eliminated abortion with batched nlp test. * more tests fixed Signed-off-by: raver119 <raver119@gmail.com> * Fixed shared flag initializing. * disabled bunch of cpu workspaces tests Signed-off-by: raver119 <raver119@gmail.com> * scalar operators fix: missing registerSpecialUse call Signed-off-by: raver119 <raver119@gmail.com> * Fixed logdet for cuda and tests. * - correct clipBynorm_bp Signed-off-by: Yurii <yurii@skymind.io> * Fixed crop_and_resize shape datatype. * - correct some mmul tests Signed-off-by: Yurii <yurii@skymind.io> * build fix Signed-off-by: raver119 <raver119@gmail.com> * exclude two methods for JNI Signed-off-by: raver119 <raver119@gmail.com> * exclude two methods for JNI Signed-off-by: raver119 <raver119@gmail.com> * exclude two methods for JNI (#97) Signed-off-by: raver119 <raver119@gmail.com> * temporary stack fix Signed-off-by: raver119 <raver119@gmail.com> * couple of legacy groups reorganized into separate compialtion units Signed-off-by: raver119 <raver119@gmail.com> * wrong include Signed-off-by: raver119 <raver119@gmail.com> * wrong include Signed-off-by: raver119 <raver119@gmail.com> * ReductionLoops_float split Signed-off-by: raver119 <raver119@gmail.com> * maximum Signed-off-by: raver119 <raver119@gmail.com> * some more rearrangements Signed-off-by: raver119 <raver119@gmail.com> * spare ifdef Signed-off-by: raver119 <raver119@gmail.com> * mirror pad Signed-off-by: raver119 <raver119@gmail.com> * - reduce_float split - mcmodel Signed-off-by: raver119 <raver119@gmail.com> * bad include fix Signed-off-by: raver119 <raver119@gmail.com> * norelax Signed-off-by: raver119 <raver119@gmail.com> * norelax Signed-off-by: raver119 <raver119@gmail.com> * norelax Signed-off-by: raver119 <raver119@gmail.com> * norelax Signed-off-by: raver119 <raver119@gmail.com> * norelax Signed-off-by: raver119 <raver119@gmail.com> * norelax gone Signed-off-by: raver119 <raver119@gmail.com> * get back sm Signed-off-by: raver119 <raver119@gmail.com> * fix couple of tests for msvc Signed-off-by: raver119 <raver119@gmail.com> * fix couple of tests for msvc Signed-off-by: raver119 <raver119@gmail.com> * compress-all Signed-off-by: raver119 <raver119@gmail.com> * reduced arch list Signed-off-by: raver119 <raver119@gmail.com> * compress-all Signed-off-by: raver119 <raver119@gmail.com> * reduced arch list Signed-off-by: raver119 <raver119@gmail.com> * all compute capabilities option for tests Signed-off-by: raver119 <raver119@gmail.com>
453 lines
14 KiB
C++
453 lines
14 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
|
|
******************************************************************************/
|
|
|
|
|
|
//
|
|
// Created by raver on 8/4/2018.
|
|
//
|
|
|
|
#include "testlayers.h"
|
|
#include <ops/declarable/CustomOperations.h>
|
|
#include <NDArray.h>
|
|
#include <ops/ops.h>
|
|
#include <GradCheck.h>
|
|
|
|
|
|
using namespace nd4j;
|
|
|
|
|
|
class DeclarableOpsTests14 : public testing::Test {
|
|
public:
|
|
|
|
DeclarableOpsTests14() {
|
|
printf("\n");
|
|
fflush(stdout);
|
|
}
|
|
};
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Validation_Edge_1) {
|
|
auto x = NDArrayFactory::create<int>('c', {2}, {2, 2});
|
|
auto exp = NDArrayFactory::create('c', {2, 2}, Environment::getInstance()->defaultFloatDataType());
|
|
exp.assign(4.0f);
|
|
|
|
nd4j::ops::fill op;
|
|
auto result = op.execute({&x}, {4.0f},{}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
ASSERT_EQ(exp, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Reshape_CF_1) {
|
|
auto x = NDArrayFactory::create<double>('f', {2, 3}, {1.0, 4.0, 2.0, 5.0, 3.0, 6.0});
|
|
auto e = NDArrayFactory::create<double>('f', {3, 2}, {1.0, 3.0, 5.0, 2.0, 4.0, 6.0});
|
|
|
|
x.printShapeInfo("x shape");
|
|
x.printBuffer("x buffr");
|
|
x.printIndexedBuffer("x indxd");
|
|
|
|
auto r = x.reshape('c', {3, 2});
|
|
r.printIndexedBuffer("r pre-s");
|
|
r.streamline('f');
|
|
|
|
nd4j::ops::reshape op;
|
|
auto result = op.execute({&x}, {}, {3, 2}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Inf_Comparison_1) {
|
|
auto x = NDArrayFactory::create<double>('c', {5}, {1, 2, 3, std::numeric_limits<double>::infinity(), 5});
|
|
auto y = NDArrayFactory::create<double>('c', {5}, {1, 2, 3, std::numeric_limits<double>::infinity(), 5});
|
|
|
|
ASSERT_EQ(x, y);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Inf_Comparison_2) {
|
|
auto x = NDArrayFactory::create<double>('c', {5}, {1, 2, 3, std::numeric_limits<double>::infinity(), 5});
|
|
auto y = NDArrayFactory::create<double>('c', {5}, {1, 2, 3, -std::numeric_limits<double>::infinity(), 5});
|
|
|
|
ASSERT_NE(x, y);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Multiply_test) {
|
|
|
|
for(int k=2;k<10;k++){
|
|
nd4j_printf("k=%d\n", k);
|
|
NDArray x = NDArrayFactory::create<double>('c', {k, 1});
|
|
NDArray y = NDArrayFactory::create<double>('c', {k});
|
|
NDArray e = NDArrayFactory::create<double>('c', {k, k});
|
|
x.assign(1.0);
|
|
y.assign(1.0);
|
|
e.assign(1.0);
|
|
|
|
nd4j::ops::multiply op;
|
|
auto result = op.execute({&x, &y}, {}, {});
|
|
auto f = result->at(0);
|
|
NDArray r = *f;
|
|
|
|
ASSERT_EQ(e, r);
|
|
ASSERT_EQ(e, *f);
|
|
|
|
delete result;
|
|
}
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_EvalReductionShape_1) {
|
|
auto x = NDArrayFactory::create<int>('c', {3}, {5, 3, 4});
|
|
auto y = NDArrayFactory::create<int>('c', {1}, {1});
|
|
auto e = NDArrayFactory::create<Nd4jLong>('c', {2}, {5, 4});
|
|
|
|
nd4j::ops::evaluate_reduction_shape op;
|
|
auto result = op.execute({&x, &y}, {}, {}, {false, false});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
z->printIndexedBuffer("Reduced shape");
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_EvalReductionShape_2) {
|
|
auto x = NDArrayFactory::create<int>('c', {3}, {5, 3, 4});
|
|
auto y = NDArrayFactory::create<int>('c', {1}, {1});
|
|
auto e = NDArrayFactory::create<Nd4jLong>('c', {3}, {5, 1, 4});
|
|
|
|
nd4j::ops::evaluate_reduction_shape op;
|
|
auto result = op.execute({&x, &y}, {}, {}, {true, false});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Reduce_Min_Small_0) {
|
|
auto x = NDArrayFactory::create<float>('c', {3, 4}, {-999.f, 0.2236f, 0.7973f, 0.0962f, 0.7231f, 0.3381f, -0.7301f, 0.9115f, -0.5094f, 0.9749f, -2.1340f, 0.6023f});
|
|
auto z = NDArrayFactory::create<float>('c', {4});
|
|
auto e = NDArrayFactory::create<float>('c', {4}, {-999.f, 0.2236f, -2.1340f, 0.0962f});
|
|
|
|
nd4j::ops::reduce_min op;
|
|
op.execute({&x}, {&z}, {}, {0}, {});
|
|
|
|
//z.printIndexedBuffer("Z");
|
|
|
|
ASSERT_EQ(e, z);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Reduce_Min_Small_1) {
|
|
auto x = NDArrayFactory::create<float>('c', {3, 4}, {-999.f, 0.2236f, 0.7973f, 0.0962f, 0.7231f, 0.3381f, -0.7301f, 0.9115f, -0.5094f, 0.9749f, -2.1340f, 0.6023f});
|
|
auto z = NDArrayFactory::create<float>('c', {3});
|
|
auto e = NDArrayFactory::create<float>('c', {3}, {-999.f, -0.7301f, -2.1340f});
|
|
|
|
nd4j::ops::reduce_min op;
|
|
op.execute({&x}, {&z}, {}, {1}, {});
|
|
|
|
//z.printIndexedBuffer("Z");
|
|
|
|
ASSERT_EQ(e, z);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_Diag_Zeros_1) {
|
|
auto x = NDArrayFactory::create<double>('c', {2}, {1, 2});
|
|
auto z = NDArrayFactory::create<double>('c', {2, 2}, {-119, -119, -119, -119});
|
|
auto exp = NDArrayFactory::create<double>('c', {2, 2}, {1, 0, 0, 2});
|
|
|
|
nd4j::ops::diag op;
|
|
auto status = op.execute({&x}, {&z}, {}, {}, {});
|
|
ASSERT_EQ(Status::OK(), status);
|
|
|
|
ASSERT_EQ(exp, z);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_scalar_broadcast_1) {
|
|
auto x = NDArrayFactory::create<float>(1.0f);
|
|
auto y = NDArrayFactory::create<float>('c', {5, 10});
|
|
auto e = NDArrayFactory::create<float>('c', {5, 10});
|
|
e.assign(1.0);
|
|
|
|
|
|
nd4j::ops::add op;
|
|
auto result = op.execute({&x, &y}, {}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
ASSERT_EQ(e, *result->at(0));
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_scalar_broadcast_2) {
|
|
auto x = NDArrayFactory::create<float>(1.0f);
|
|
auto y = NDArrayFactory::create<float>('c', {5, 10});
|
|
auto e = NDArrayFactory::create<float>('c', {5, 10});
|
|
y.assign(2.0f);
|
|
e.assign(-1.0f);
|
|
|
|
|
|
nd4j::ops::subtract op;
|
|
auto result = op.execute({&x, &y}, {}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
ASSERT_EQ(e, *result->at(0));
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_fill_1) {
|
|
auto x = NDArrayFactory::empty<int>();
|
|
auto y = NDArrayFactory::create<int>(1);
|
|
|
|
nd4j::ops::fill op;
|
|
auto result = op.execute({&x, &y}, {}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(y, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_lstmBlockCell_1) {
|
|
auto a = NDArrayFactory::create<double>('c', {1, 5}, {0.7787856f, 0.80119777f, 0.72437465f, 0.23089433f, 0.72714126f});
|
|
auto b = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto c = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto d = NDArrayFactory::create<double>('c', {8, 12}, {-0.15320599,-0.120416045,0.33126968,0.13921785,-0.32313538,-0.43956736,0.4756174,0.4335605,-0.5450856,-0.3943429,-0.28687626,0.068032146,-0.2793799,0.17298919,-0.36553562,-0.097853184,-0.2544747,-0.39872527,-0.14556861,-0.31479517,0.2559092,0.47166896,-0.31330687,0.47313118,0.5134543,-0.4678212,-0.12853557,0.26142156,0.43472284,-0.42842552,-0.1895876,0.538689,0.508651,-0.020272732,0.112327516,0.2704304,-0.046546757,0.32570732,-0.15148133,-0.19145513,0.18631572,-0.024152994,0.41603214,-0.3421499,0.0106860995,-0.2966229,-0.36713937,0.25841123,0.0843398,0.49082482,0.10800403,0.1874243,-0.26379472,-0.22531849,0.24924624,0.23119557,0.49940765,-0.051413506,0.20315129,-0.41888732,0.44097036,0.40453392,0.013338983,0.23434466,0.23942488,0.47894,-0.19898453,0.09253675,-0.032358468,-0.15213022,-0.3441009,-0.15600958,-0.08235118,0.12165731,-0.4481289,-0.4842423,-0.45797008,-0.4606034,0.08163166,-0.2981107,0.50207126,0.44195646,0.13850057,0.072246075,-0.34388685,0.030900061,0.35821778,0.47900867,0.5094063,0.23683065,0.18020362,-0.1369732,0.015235603,0.2786904,0.07954317,0.12543976});
|
|
auto e = NDArrayFactory::create<double>('c', {3});
|
|
auto f = NDArrayFactory::create<double>('c', {3});
|
|
auto g = NDArrayFactory::create<double>('c', {3});
|
|
auto h = NDArrayFactory::create<double>('c', {12});
|
|
|
|
auto z0 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z1 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z2 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z3 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z4 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z5 = NDArrayFactory::create<double>('c', {1, 3});
|
|
auto z6 = NDArrayFactory::create<double>('c', {1, 3});
|
|
|
|
nd4j::ops::lstmBlockCell op;
|
|
auto result = op.execute({&a, &b, &c, &d, &e, &f, &g, &h}, {&z0, &z1, &z2, &z3, &z4, &z5, &z6}, {1.0, -1.0}, {0}, {});
|
|
ASSERT_EQ(Status::OK(), result);
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_stack_1) {
|
|
auto x = NDArrayFactory::create<float>('c', {0});
|
|
auto e = NDArrayFactory::create<float>('c', {1, 0});
|
|
|
|
nd4j::ops::stack op;
|
|
auto result = op.execute({&x}, {}, {0});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(e, *z);
|
|
nd4j::ops::reduce_min sumOp;
|
|
auto res2 = sumOp.execute({&e}, {1.}, {1});
|
|
ASSERT_EQ(res2->status(), Status::OK());
|
|
auto out = res2->at(0);
|
|
|
|
ASSERT_EQ(out->e<float>(0), DataTypeUtils::infOrMax<float>());
|
|
delete res2;
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_stack_2) {
|
|
auto x = NDArrayFactory::empty<float>();
|
|
auto e = NDArrayFactory::create<float>('c', {0});
|
|
|
|
nd4j::ops::stack op;
|
|
auto result = op.execute({&x}, {}, {0});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_stack_3) {
|
|
auto x = NDArrayFactory::empty<float>();
|
|
auto e = NDArrayFactory::create<float>('c', {2, 0});
|
|
|
|
nd4j::ops::stack op;
|
|
auto result = op.execute({&x, &x}, {}, {0});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_stack_4) {
|
|
auto x = NDArrayFactory::create<float>('c', {0});
|
|
auto e = NDArrayFactory::create<float>('c', {2, 0});
|
|
|
|
nd4j::ops::stack op;
|
|
auto result = op.execute({&x, &x}, {}, {0});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_reduce_min_1) {
|
|
|
|
auto e = NDArrayFactory::create<float>('c', {1, 0});
|
|
nd4j::ops::reduce_min sumOp;
|
|
auto res2 = sumOp.execute({&e}, {1.}, {1});
|
|
ASSERT_EQ(res2->status(), Status::OK());
|
|
auto out = res2->at(0);
|
|
|
|
ASSERT_EQ(out->e<float>(0), DataTypeUtils::infOrMax<float>());
|
|
delete res2;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_reduce_max_1) {
|
|
|
|
auto e = NDArrayFactory::create<float>('c', {1, 0});
|
|
nd4j::ops::reduce_max sumOp;
|
|
auto res2 = sumOp.execute({&e}, {1.}, {1});
|
|
ASSERT_EQ(res2->status(), Status::OK());
|
|
auto out = res2->at(0);
|
|
|
|
ASSERT_EQ(out->e<float>(0), -DataTypeUtils::infOrMax<float>());
|
|
delete res2;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_reduce_sum_1) {
|
|
|
|
auto e = NDArrayFactory::create<float>('c', {1, 0});
|
|
nd4j::ops::reduce_sum sumOp;
|
|
auto res2 = sumOp.execute({&e}, {1.}, {1});
|
|
ASSERT_EQ(res2->status(), Status::OK());
|
|
auto out = res2->at(0);
|
|
ASSERT_EQ(out->e<float>(0), 0.f);
|
|
delete res2;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_reduce_mean_1) {
|
|
|
|
auto e = NDArrayFactory::create<float>('c', {1, 0});
|
|
nd4j::ops::reduce_mean sumOp;
|
|
auto res2 = sumOp.execute({&e}, {1.}, {1});
|
|
ASSERT_EQ(res2->status(), Status::OK());
|
|
auto out = res2->at(0);
|
|
// out->printShapeInfo("ReduceMean empty shape with keep dims");
|
|
// out->printIndexedBuffer("ReduceMean scalar");
|
|
ASSERT_TRUE(std::isnan(out->e<float>(0)));
|
|
delete res2;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_StridedSliceZeros_1) {
|
|
auto matrix = NDArrayFactory::create<double>('c', {1, 2, 0, 4});
|
|
auto b = NDArrayFactory::create<int>('c', {3}, {0, 0, 0});
|
|
auto e = NDArrayFactory::create<int>('c', {3}, {2,0,2});
|
|
auto s = NDArrayFactory::create<int>('c', {3}, {1,1,1});
|
|
|
|
auto exp = NDArrayFactory::create<double>('c', {1,0,0,4});
|
|
|
|
matrix.linspace(1);
|
|
|
|
nd4j::ops::strided_slice op;
|
|
auto result = op.execute({&matrix, &b, &e, &s}, {}, {0, 0, 0, 0, 0});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
ASSERT_TRUE(exp.isSameShape(z));
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, Test_StridedSliceZeros_2) {
|
|
auto matrix = NDArrayFactory::create<double>('c', {1, 2, 0, 4});
|
|
auto b = NDArrayFactory::create<int>('c', {3}, {0, 0, 0});
|
|
auto e = NDArrayFactory::create<int>('c', {3}, {2,0,2});
|
|
auto s = NDArrayFactory::create<int>('c', {3}, {1,1,1});
|
|
|
|
auto exp = NDArrayFactory::create<double>('c', {0,0,4});
|
|
|
|
matrix.linspace(1);
|
|
|
|
nd4j::ops::strided_slice op;
|
|
auto result = op.execute({&matrix, &b, &e, &s}, {}, {0, 0, 0, 0, 1});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
ASSERT_TRUE(exp.isSameShape(z));
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_argmax_1) {
|
|
auto x = NDArrayFactory::create<float>('c', {1, 0});
|
|
auto y = NDArrayFactory::create<int>(0);
|
|
auto e = NDArrayFactory::create<Nd4jLong>('c', {0});
|
|
|
|
nd4j::ops::argmax op;
|
|
//nd4j::ops::reduce_max op;
|
|
|
|
auto result = op.execute({&x, &y}, {}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
z->printShapeInfo("Z");
|
|
|
|
ASSERT_EQ(e, *z);
|
|
|
|
delete result;
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_argmax_2) {
|
|
auto x = NDArrayFactory::create<float>('c', {1, 0});
|
|
auto y = NDArrayFactory::create<int>(1);
|
|
|
|
nd4j::ops::argmax op;
|
|
try {
|
|
auto result = op.execute({&x, &y}, {&y}, {}, {}, {});
|
|
ASSERT_TRUE(false);
|
|
} catch (std::exception &e) {
|
|
//
|
|
}
|
|
}
|
|
|
|
TEST_F(DeclarableOpsTests14, test_empty_tanh_5) {
|
|
auto x = NDArrayFactory::create<float>('c', {32, 0});
|
|
|
|
nd4j::ops::tanh op;
|
|
auto result = op.execute({&x}, {}, {});
|
|
ASSERT_EQ(Status::OK(), result->status());
|
|
|
|
auto z = result->at(0);
|
|
|
|
ASSERT_TRUE(x.isSameShape(z));
|
|
ASSERT_EQ(x, *z);
|
|
|
|
delete result;
|
|
}
|