From bcba5e171c0af828468b77a1d929ca14f54bec8f Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Mon, 19 Sep 2016 17:39:40 +0100 Subject: [PATCH] debug --- src/node_operators_binary.h | 12 +++++++++++- src/node_operators_unary.h | 8 ++++++++ src/tensor.h | 17 ++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/node_operators_binary.h b/src/node_operators_binary.h index 38d9df4d..b80e6834 100644 --- a/src/node_operators_binary.h +++ b/src/node_operators_binary.h @@ -13,7 +13,17 @@ struct BinaryNodeOp : public Node { : Node(args...), a_(a), b_(b) {} void backward_numeric() { - backward(); + using namespace std; + cerr << "BinaryNodeOp::" << typeid(*this).name() << "::backward_numeric" << endl; + cerr << "BEFORE:" << endl; + cerr << "a_->grad()=" << a_->grad().Debug() << endl; + cerr << "b_->grad()=" << b_->grad().Debug() << endl; + cerr << "adj_=" << adj_.Debug() << endl; + backward(); + cerr << "AFTER:" << endl; + cerr << "a_->grad()=" << a_->grad().Debug() << endl; + cerr << "b_->grad()=" << b_->grad().Debug() << endl; + cerr << "adj_=" << adj_.Debug() << endl; } }; diff --git a/src/node_operators_unary.h b/src/node_operators_unary.h index f810fe21..b7959f8d 100644 --- a/src/node_operators_unary.h +++ b/src/node_operators_unary.h @@ -12,7 +12,15 @@ struct UnaryNodeOp : public Node { args...), a_(a) {} void backward_numeric() { + using namespace std; + cerr << "BinaryNodeOp::" << typeid(*this).name() << "::backward_numeric" << endl; + cerr << "BEFORE:" << endl; + cerr << "a_->grad()=" << a_->grad().Debug() << endl; + cerr << "adj_=" << adj_.Debug() << endl; backward(); + cerr << "AFTER:" << endl; + cerr << "a_->grad()=" << a_->grad().Debug() << endl; + cerr << "adj_=" << adj_.Debug() << endl; } }; diff --git a/src/tensor.h b/src/tensor.h index 3540bfdd..1ffcf0e1 100644 --- a/src/tensor.h +++ b/src/tensor.h @@ -405,17 +405,12 @@ class Tensor { */ std::string Debug() const { - return pimpl_->Debug(); - } - - /** - * @brief Print Tensor data on CPU (?) (const). - */ - void Print() const { - for (int i = 0; i < size(); ++i) { - std::cerr << (*this)[i] << " "; - } - std::cerr << std::endl; + if (!pimpl_) { + return "Not yet set"; + } + else { + return pimpl_->Debug(); + } } //void Load(const std::string &path);