Skip to content

Commit

Permalink
Shugeo unique fix (#6178)
Browse files Browse the repository at this point in the history
* Added test for unique op.

* Fixed unique with right index values.
  • Loading branch information
shugeo authored and raver119 committed Aug 18, 2018
1 parent 2fbc5b7 commit 3df8de9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
5 changes: 3 additions & 2 deletions libnd4j/include/ops/declarable/helpers/cpu/unique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ namespace helpers {
(*counts)(e) = countsMap[valuesVector[e]];
}

#pragma omp parallel for if(indices->lengthOf() > Environment::getInstance()->elementwiseThreshold()) schedule(static)
//#pragma omp parallel for if(indices->lengthOf() > Environment::getInstance()->elementwiseThreshold()) schedule(static)
for (int e = 0; e < indices->lengthOf(); e++) {
(*indices)(e) = indicesMap[(*input)(e)];
auto posI = std::find(valuesVector.begin(), valuesVector.end(), (*input)(e));
(*indices)(e) = std::distance(valuesVector.begin(), posI);//indicesMap[(*input)(e)];
}

return ND4J_STATUS_OK;
Expand Down
40 changes: 14 additions & 26 deletions libnd4j/tests_cpu/layers_tests/DeclarableOpsTests10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,19 @@ TEST_F(DeclarableOpsTests10, Test_Size_at_1) {

delete result;
}
/*
////////////////////////////////////////////////////////////////////////////////
TEST_F(DeclarableOpsTests10, ReverseMod_BP_Test_1) {
NDArray<double> inputX('c', {1, 6});
NDArray<double> inputY('c', {3, 4, 5, 1});
NDArray<double> axis(1.);
NDArray<double> gradO('c', {3, 4, 5, 6});
int exclusive, reverse;
inputX.assign(2.0);
inputY.assign(9.0);
////////////////////////////////////////

const OpArgsHolder<double> argsHolderFF({&inputX, &inputY}, {}, {});
const OpArgsHolder<double> argsHolderBP({&inputX, &inputY, &gradO}, {}, {});
nd4j::ops::reversemod<double> opFF;
nd4j::ops::reversemod_bp<double> opBP;
const bool isGradCorrect = GradCheck::checkGrad(opFF, opBP, argsHolderFF, argsHolderBP);
ASSERT_TRUE(isGradCorrect);
////////////////////////////////////////////////////////////////////////////////
TEST_F(DeclarableOpsTests10, Unique_SGO_Test_1) {
NDArray<double> input({3., 4., 3., 1., 3., 0., 2., 4., 2., 4.});
NDArray<double> expIdx({0., 1., 0., 2., 0., 3., 4., 1., 4., 1.});
NDArray<double> exp({3., 4., 1., 0., 2.});

nd4j::ops::unique<double> op;
auto res = op.execute({&input}, {}, {});
ASSERT_TRUE(res->status() == ND4J_STATUS_OK);
//res->at(0)->printIndexedBuffer("Unique values");
//res->at(1)->printIndexedBuffer("Unique idxs");
ASSERT_TRUE(exp.equalsTo(res->at(0)));
ASSERT_TRUE(expIdx.equalsTo(res->at(1)));
delete res;
}
*/
4 changes: 2 additions & 2 deletions libnd4j/tests_cpu/layers_tests/DeclarableOpsTests3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST_F(DeclarableOpsTests3, Test_Permute_2) {
TEST_F(DeclarableOpsTests3, Test_Unique_1) {
NDArray<float> x('c', {1, 5}, {1, 2, 1, 2, 3});
NDArray<float> expV('c', {3}, {1, 2, 3});
NDArray<float> expI('c', {5}, {0, 1, 0, 1, 4});
NDArray<float> expI('c', {5}, {0, 1, 0, 1, 2});
// NDArray<float> expI('c', {3}, {0, 1, 4});

nd4j::ops::unique<float> op;
Expand All @@ -129,7 +129,7 @@ TEST_F(DeclarableOpsTests3, Test_Unique_1) {
TEST_F(DeclarableOpsTests3, Test_Unique_2) {
NDArray<float> x('c', {1, 5}, {1, 2, 1, 2, 3});
NDArray<float> expV('c', {3}, {1, 2, 3});
NDArray<float> expI('c', {5}, {0, 1, 0, 1, 4});
NDArray<float> expI('c', {5}, {0, 1, 0, 1, 2});
NDArray<float> expC('c', {3}, {2, 2, 1});

nd4j::ops::unique_with_counts<float> op;
Expand Down

0 comments on commit 3df8de9

Please sign in to comment.