mirror of
https://github.com/marian-nmt/marian.git
synced 2024-09-11 06:15:56 +03:00
set value in tensor
This commit is contained in:
parent
a8a664ca36
commit
8dcdf8f28a
@ -59,23 +59,29 @@ inline std::vector<T> 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<int>());
|
||||
cerr << "totSize=" << totSize << endl;
|
||||
std::vector<float> 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<Float> toks = Tokenize<Float>(line);
|
||||
for (size_t i = 0; i < toks.size(); ++i) {
|
||||
pimpl_->set(toks[i], lineNum, i);
|
||||
hostData[ind] = toks[i];
|
||||
}
|
||||
|
||||
++lineNum;
|
||||
++ind;
|
||||
}
|
||||
strm.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -152,10 +152,8 @@ 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<Float> &values) {
|
||||
thrust::copy(values.begin(), values.end(), data_.begin());
|
||||
}
|
||||
|
||||
std::string Debug() const
|
||||
|
Loading…
Reference in New Issue
Block a user