diff options
author | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2016-05-07 23:57:04 +0300 |
---|---|---|
committer | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2016-05-07 23:57:04 +0300 |
commit | 29ef0fee9ef367de3f9c32436577aaf0e34dc7dd (patch) | |
tree | 9a644fa4c629408e33166d7725091ae40a57a9f1 /src | |
parent | 7fd950fbda443066f5c5ca24db2de35254de9164 (diff) |
deleted old tensor
Diffstat (limited to 'src')
-rw-r--r-- | src/tensor.h | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/src/tensor.h b/src/tensor.h deleted file mode 100644 index 932278a1..00000000 --- a/src/tensor.h +++ /dev/null @@ -1,117 +0,0 @@ -#pragma once - -#include <memory> -#include <functional> -#include <vector> -#include <cmath> - -namespace marian { - -class TensorImpl { - public: - typedef float value_type; - - TensorImpl(size_t size, value_type value) - : data_(size, value), tno_(tensorCounter++) - { - std::cerr << "Allocating tensor " << tno_ << std::endl; - } - - TensorImpl(const TensorImpl& t) - : data_(t.data_.begin(), t.data_.end()) - { - std::cerr << "Copying tensor " << tno_ << std::endl; - } - - ~TensorImpl() { - std::cerr << "Destroying tensor " << tno_ << std::endl; - } - - size_t size() const { - return data_.size(); - } - - value_type* data() { - return data_.data(); - } - - const value_type* data() const { - return data_.data(); - } - - size_t id() const { - return tno_; - } - - void set(value_type value) { - std::fill(data_.begin(), data_.end(), value); - } - - private: - std::vector<value_type> data_; - size_t tno_; - - static size_t tensorCounter; -}; - -size_t TensorImpl::tensorCounter = 0; - -class Tensor { - public: - typedef TensorImpl::value_type value_type; - - Tensor(size_t size, float value) - : pimpl_(new TensorImpl(size, value)) {} - - Tensor() {} - - ~Tensor() {} - - size_t size() const { - return pimpl_->size(); - } - - float* data() { - return pimpl_->data(); - } - - const float* data() const { - return pimpl_->data(); - } - - void set(float value) { - pimpl_->set(value); - } - - size_t id() const { - return pimpl_->id(); - } - - private: - std::shared_ptr<TensorImpl> pimpl_; -}; - -Tensor operator+(const Tensor a, const Tensor b) { - Tensor c(a.size(), 0); - for(size_t i = 0; i < a.size(); ++i) { - c.data()[i] = a.data()[i] + b.data()[i]; - } - return c; -} - -Tensor operator*(const Tensor a, const Tensor b) { - Tensor c(a.size(), 0); - for(size_t i = 0; i < a.size(); ++i) { - c.data()[i] = a.data()[i] * b.data()[i]; - } - return c; -} - -Tensor operator+=(Tensor a, const Tensor b) { - for(size_t i = 0; i < a.size(); ++i) { - a.data()[i] += b.data()[i]; - } - return a; -} - -}
\ No newline at end of file |