diff --git a/marian/.project b/marian/.project
index 215485f6..e5b195c5 100644
--- a/marian/.project
+++ b/marian/.project
@@ -85,6 +85,11 @@
1
PARENT-1-PROJECT_LOC/src/marian.h
+
+ mnist.h
+ 1
+ PARENT-1-PROJECT_LOC/src/mnist.h
+
tensor.cu
1
diff --git a/src/tensor.cu b/src/tensor.cu
index 4711e62b..6048bb43 100644
--- a/src/tensor.cu
+++ b/src/tensor.cu
@@ -59,23 +59,34 @@ inline std::vector Tokenize( const std::string &input
void Tensor::Load(const std::string &path)
{
+ size_t totSize = std::accumulate(pimpl_->shape().begin(), pimpl_->shape().end(),
+ 1, std::multiplies());
+ cerr << "totSize=" << totSize << endl;
+ std::vector hostData(totSize);
+
fstream strm;
strm.open(path.c_str());
- size_t lineNum = 0;
string line;
+ size_t ind = 0;
while ( getline (strm, line) )
{
cerr << line << '\n';
vector toks = Tokenize(line);
for (size_t i = 0; i < toks.size(); ++i) {
- pimpl_->set(toks[i], lineNum, i);
+ hostData[ind] = toks[i];
}
- ++lineNum;
+ ++ind;
}
strm.close();
+ Load(hostData);
+}
+
+void Tensor::Load(const std::vector &values)
+{
+ pimpl_->set(values);
}
}
diff --git a/src/tensor.h b/src/tensor.h
index fea9398c..2cf4c267 100644
--- a/src/tensor.h
+++ b/src/tensor.h
@@ -152,10 +152,12 @@ class TensorImpl {
thrust::fill(data_.begin(), data_.end(), value);
}
- void set(value_type value, size_t x, size_t y) {
- assert(shape().size() == 2);
- size_t sizeRow = sizeof(Float) * shape()[1];
- data_[x + sizeRow * y] = value;
+ void set(const std::vector &values) {
+ size_t totSize = std::accumulate(shape().begin(), shape().end(),
+ 1, std::multiplies());
+ std::cerr << "totSize=" << totSize << " " << values.size() << std::endl;
+ assert(totSize == values.size());
+ thrust::copy(values.begin(), values.end(), data_.begin());
}
std::string Debug() const
@@ -247,6 +249,7 @@ class Tensor {
}
void Load(const std::string &path);
+ void Load(const std::vector &values);
};
diff --git a/src/test.cu b/src/test.cu
index 23971051..638a602c 100644
--- a/src/test.cu
+++ b/src/test.cu
@@ -12,7 +12,7 @@ int main(int argc, char** argv) {
using namespace marian;
using namespace keywords;
- /*
+
Expr x = input(shape={whatevs, 784}, name="X");
Expr y = input(shape={whatevs, 10}, name="Y");
@@ -27,6 +27,13 @@ int main(int argc, char** argv) {
Tensor tx({500, 784}, 1);
Tensor ty({500, 10}, 1);
+
+ int numImg, imgSize;
+ vector images = datasets::mnist::ReadImages("../examples/mnist/t10k-images-idx3-ubyte", numImg, imgSize);
+ vector labels = datasets::mnist::ReadLabels("../examples/mnist/t10k-labels-idx1-ubyte");
+ tx.Load(images);
+ //ty.Load(labels);
+
cerr << "tx=" << tx.Debug() << endl;
cerr << "ty=" << ty.Debug() << endl;
@@ -54,8 +61,10 @@ int main(int argc, char** argv) {
graph.backward();
//std::cerr << graph["pred"].val()[0] << std::endl;
- */
+
+ // XOR
+ /*
Expr x = input(shape={whatevs, 2}, name="X");
Expr y = input(shape={whatevs, 2}, name="Y");
@@ -76,6 +85,7 @@ int main(int argc, char** argv) {
tx.Load("../examples/xor/train.txt");
ty.Load("../examples/xor/label.txt");
+ */
#if 0
hook0(graph);