Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
tensor_cpu.h
1 #pragma once
2 #include "linearhostmemory.h"
3 
4 template<typename, int> class ndarray_ref;
5 
6 namespace iu
7 {
11 template<typename PixelType>
12 class TensorCpu : public LinearHostMemory<PixelType, 1>
13 {
14 public:
16  typedef PixelType pixel_type;
17 
20  LinearHostMemory<PixelType, 1>(), samples_(0), channels_(0), height_(0), width_(0)
21  {
22  }
23 
25  virtual ~TensorCpu()
26  {
27  }
28 
35  TensorCpu(const unsigned int N, const unsigned int C, const unsigned int H, const unsigned int W) :
36  LinearHostMemory<PixelType, 1>(N * C * H * W), samples_(N), channels_(C), height_(H), width_(W)
37  {
38  }
39 
48  TensorCpu(PixelType* host_data, const unsigned int N, const unsigned int C, const unsigned int H,
49  const unsigned int W, bool ext_data_pointer = false) :
50  LinearHostMemory<PixelType, 1>(host_data, N * C * H * W, ext_data_pointer), samples_(N), channels_(C), height_(H), width_(
51  W)
52  {
54  }
55 
56 
58  PixelType getPixel(unsigned int n, unsigned int c, unsigned int x, unsigned int y)
59  {
60  return *this->data(n * (channels_ * height_ * width_) + c * (width_ * height_) + x * width_ + y);
61  }
62 
64  unsigned int samples() const
65  {
66  return samples_;
67  }
68 
70  unsigned int channels() const
71  {
72  return channels_;
73  }
74 
76  unsigned int height() const
77  {
78  return height_;
79  }
80 
82  unsigned int width() const
83  {
84  return width_;
85  }
86 
88  friend std::ostream& operator<<(std::ostream & out,
89  TensorCpu const& tensor)
90  {
91  out << "Tensor: height=" << tensor.height() << " width="
92  << tensor.width() << " samples=" << tensor.samples() << " channels="
93  << tensor.channels() << " onDevice=" << tensor.onDevice();
94  return out;
95  }
96 
99 
102 
103 private:
105  unsigned int samples_;
107  unsigned int channels_;
109  unsigned int height_;
111  unsigned int width_;
112 
113 private:
115  TensorCpu(const TensorCpu&);
117  TensorCpu& operator=(const TensorCpu&);
118 };
119 
120 } // namespace iu
121 
virtual ~TensorCpu()
Definition: tensor_cpu.h:25
unsigned int height() const
Definition: tensor_cpu.h:76
unsigned int samples() const
Definition: tensor_cpu.h:64
Linear host memory class.
Definition: linearhostmemory.h:33
PixelType getPixel(unsigned int n, unsigned int c, unsigned int x, unsigned int y)
Definition: tensor_cpu.h:58
unsigned int channels() const
Definition: tensor_cpu.h:70
Definition: image_cpu.h:7
TensorCpu(PixelType *host_data, const unsigned int N, const unsigned int C, const unsigned int H, const unsigned int W, bool ext_data_pointer=false)
Definition: tensor_cpu.h:48
ndarray_ref< PixelType, 4 > ref() const
unsigned int width() const
Definition: tensor_cpu.h:82
TensorCpu()
Definition: tensor_cpu.h:19
Host 4D tensor class.
Definition: tensor_cpu.h:12
friend std::ostream & operator<<(std::ostream &out, TensorCpu const &tensor)
Definition: tensor_cpu.h:88
PixelType pixel_type
Definition: tensor_cpu.h:16
PixelType * data(unsigned int offset=0)
Definition: linearhostmemory.h:137
virtual bool onDevice() const
Definition: linearhostmemory.h:194
TensorCpu(const unsigned int N, const unsigned int C, const unsigned int H, const unsigned int W)
Definition: tensor_cpu.h:35