Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix LinearRegressionOutput with empty label
Browse files Browse the repository at this point in the history
  • Loading branch information
haohuw committed Jul 22, 2019
1 parent 9a1a102 commit 8447052
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cpp-package/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)

add_executable(test_regress_label test_regress_label.cpp ${CPP_PACKAGE_HAEDERS})
target_link_libraries(test_regress_label ${CPP_EXAMPLE_LIBS})
add_dependencies(test_regress_label ${CPPEX_DEPS})

add_executable(lenet lenet.cpp ${CPP_PACKAGE_HEADERS})
target_link_libraries(lenet ${CPP_EXAMPLE_LIBS})
add_dependencies(lenet ${CPPEX_DEPS})
Expand Down
33 changes: 33 additions & 0 deletions cpp-package/example/test_regress_label.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <vector>
#include <string>
#include "mxnet-cpp/MxNetCpp.h"

using namespace mxnet::cpp;


int main() {
std::cout << "Running regress label test" << std::endl;
Symbol data = Symbol::Variable("data");
Symbol label = Symbol::Variable("regress_label");
Symbol symbol = LinearRegressionOutput(data, label);
std::map<std::string, mxnet::cpp::OpReqType> opReqMap;
for (const auto& iter : symbol.ListArguments()) {
opReqMap[iter] = mxnet::cpp::OpReqType::kNullOp;
}
std::map<std::string, mxnet::cpp::NDArray> argMap({
{"data", NDArray(Shape{1, 3}, Context::cpu(), true)}
});

try {
symbol.SimpleBind(Context::cpu(),
argMap,
std::map<std::string, mxnet::cpp::NDArray>(),
opReqMap,
std::map<std::string, mxnet::cpp::NDArray>());
} catch (const std::exception& e) {
std::cout << "Error while binding in mxnet: " << MXGetLastError() << std::endl;
throw;
}
return 0;
}
3 changes: 3 additions & 0 deletions cpp-package/tests/ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ cp ../../build/cpp-package/example/test_score .
cp ../../build/cpp-package/example/test_ndarray_copy .
./test_ndarray_copy

cp ../../build/cpp-package/example/test_regress_label .
./test_regress_label

sh unittests/unit_test_mlp_csv.sh

cd inference
Expand Down
3 changes: 2 additions & 1 deletion src/operator/regression_output-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ inline bool RegressionOpShape(const nnvm::NodeAttrs& attrs,
const mxnet::TShape &dshape = in_attrs->at(0);
if (!shape_is_known(dshape)) return false;
auto &lshape = (*in_attrs)[1];
if (lshape.ndim() == 0) {
// if label is not defined, manually build the shape based on dshape
if (lshape.ndim() == -1) {
// special treatment for 1D output, to allow 1D label by default.
// Think about change convention later
if (dshape.ndim() == 2 && dshape[1] == 1) {
Expand Down

0 comments on commit 8447052

Please sign in to comment.