output tensors in shape

This commit is contained in:
Hieu Hoang 2016-09-14 14:51:49 +02:00
parent 04a620db19
commit f05d17e7ae
2 changed files with 10 additions and 5 deletions

View File

@ -176,8 +176,13 @@ class TensorImpl {
std::vector<Float> values(totSize);
thrust::copy(data_.begin(), data_.end(), values.begin());
for (size_t i = 0; i < totSize; ++i) {
strm << values[i] << " ";
size_t ind = 0;
for (size_t i = 0; i < shape()[0]; ++i) {
for (size_t j = 0; j < shape()[1]; ++j) {
strm << values[ind] << " ";
++ind;
}
strm << std::endl;
}
return strm.str();
}

View File

@ -21,8 +21,8 @@ int main(int argc, char** argv) {
Expr w = param(shape={IMAGE_SIZE, LABEL_SIZE}, name="W0");
Expr b = param(shape={1, LABEL_SIZE}, name="b0");
Expr scores = dot(x, w) + b;
Expr lr = softmax(scores, axis=1, name="pred");
Expr z = dot(x, w) + b;
Expr lr = softmax(z, axis=1, name="pred");
Expr graph = -mean(sum(y * log(lr), axis=1), axis=0, name="cost");
//cerr << "lr=" << Debug(lr.val().shape()) << endl;
@ -46,7 +46,7 @@ int main(int argc, char** argv) {
graph.forward(500);
std::cerr << "scores: " << Debug(scores.val().shape()) << endl;
std::cerr << "z: " << Debug(z.val().shape()) << endl;
std::cerr << "lr: " << Debug(lr.val().shape()) << endl;
std::cerr << "Log-likelihood: " << Debug(graph.val().shape()) << endl ;