NVIDIA DeepStream SDK API Reference

6.4 Release
Tensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 
11 #ifndef CVCORE_TENSOR_H
12 #define CVCORE_TENSOR_H
13 
14 #include <initializer_list>
15 #include <stdexcept>
16 #include <string>
17 #include <type_traits>
18 
19 namespace cvcore {
20 
21 // there is no CUDA dependency at the data level, so we map half type to uint16_t for now
22 using half = std::uint16_t;
23 
29 {
30  LC,
31  CL,
32  HWC,
33  CHW,
34  DHWC,
35  NHWC = DHWC,
36  DCHW,
37  NCHW = DCHW,
38  CDHW,
39 };
40 
46 {
47  C1,
48  C2,
49  C3,
50  C4,
51  CX,
52 };
53 
59 {
60  U8,
61  U16,
62  S8,
63  S16,
64  F16,
65  F32,
66  F64,
67 };
68 
73 enum class TensorDimension
74 {
75  LENGTH,
76  HEIGHT,
77  WIDTH,
78  CHANNEL,
79  DEPTH,
80 };
81 
88 
95 
101 std::string GetChannelTypeAsString(ChannelType CT);
102 
108 std::string GetMemoryTypeAsString(bool isCPU);
109 
115 std::size_t GetChannelSize(ChannelType CT);
116 
121 {
122 public:
126  struct DimData
127  {
128  std::size_t size;
129  std::size_t stride;
130  };
131 
140  TensorBase(ChannelType type, const DimData *dimData, int dimCount, void *dataPtr, bool isCPU);
141 
149  TensorBase(ChannelType type, std::initializer_list<DimData> dimData, void *dataPtr, bool isCPU);
150 
158  TensorBase(ChannelType type, const DimData *dimData, int dimCount, bool isCPU);
159 
166  TensorBase(ChannelType type, std::initializer_list<DimData> dimData, bool isCPU);
167 
171  ~TensorBase();
172 
176  TensorBase(const TensorBase &) = delete;
177 
181  TensorBase &operator=(const TensorBase &) = delete;
182 
187 
192 
197  int getDimCount() const;
198 
204  std::size_t getSize(int dimIdx) const;
205 
211  std::size_t getStride(int dimIdx) const;
212 
217  ChannelType getType() const;
218 
223  void *getData() const;
224 
229  std::size_t getDataSize() const;
230 
235  bool isCPU() const;
236 
241  bool isOwning() const;
242 
243 protected:
244  TensorBase();
245 
246 private:
247  static constexpr int kMinDimCount = 2;
248  static constexpr int kMaxDimCount = 4;
249 
250  void *m_data;
251 
252  int m_dimCount;
253  DimData m_dimData[kMaxDimCount];
254 
255  ChannelType m_type;
256  bool m_isOwning;
257  bool m_isCPU;
258 };
259 
260 namespace detail {
261 
262 template<TensorLayout TL>
264 {
265  static_assert(TL == LC || TL == CL, "unsupported variant!");
266  static constexpr int kLength = TL == LC ? 0 : 1;
267  static constexpr int kChannel = TL == LC ? 1 : 0;
268 };
269 
270 template<TensorLayout TL>
272 {
273  static_assert(TL == HWC || TL == CHW, "unsupported variant!");
274  static constexpr int kWidth = TL == HWC ? 1 : 2;
275  static constexpr int kHeight = TL == HWC ? 0 : 1;
276  static constexpr int kChannel = TL == HWC ? 2 : 0;
277 };
278 
279 template<TensorLayout TL>
281 {
282  static_assert(TL == DHWC || TL == DCHW || TL == CDHW, "unsupported variant!");
283  static constexpr int kWidth = TL == DHWC ? 2 : (TL == DCHW ? 3 : 3);
284  static constexpr int kHeight = TL == DHWC ? 1 : (TL == DCHW ? 2 : 2);
285  static constexpr int kDepth = TL == DHWC ? 0 : (TL == DCHW ? 0 : 1);
286  static constexpr int kChannel = TL == DHWC ? 3 : (TL == DCHW ? 1 : 0);
287 };
288 
289 template<TensorLayout TL, typename = void>
291 {
292 };
293 
294 template<TensorLayout TL>
295 struct LayoutToIndex<TL, typename std::enable_if<TL == LC || TL == CL>::type> : public DimToIndex2D<TL>
296 {
297  static constexpr int kDimCount = 2;
298 };
299 
300 template<TensorLayout TL>
301 struct LayoutToIndex<TL, typename std::enable_if<TL == HWC || TL == CHW>::type> : public DimToIndex3D<TL>
302 {
303  static constexpr int kDimCount = 3;
304 };
305 
306 template<TensorLayout TL>
307 struct LayoutToIndex<TL, typename std::enable_if<TL == DHWC || TL == DCHW || TL == CDHW>::type>
308  : public DimToIndex4D<TL>
309 {
310  static constexpr int kDimCount = 4;
311 };
312 
313 template<ChannelType CT>
315 {
316 };
317 
318 template<>
320 {
321  using Type = std::uint8_t;
322 };
323 
324 template<>
326 {
327  using Type = std::uint16_t;
328 };
329 
330 template<>
332 {
333  using Type = std::int8_t;
334 };
335 
336 template<>
338 {
339  using Type = std::int16_t;
340 };
341 
342 template<>
344 {
345  using Type = float;
346 };
347 
348 template<>
350 {
352 };
353 
354 template<>
356 {
357  using Type = double;
358 };
359 
360 template<ChannelCount CC>
361 constexpr std::size_t ChannelToCount()
362 {
363  switch (CC)
364  {
365  case C1:
366  return 1;
367  case C2:
368  return 2;
369  case C3:
370  return 3;
371  case C4:
372  return 4;
373  }
374  return 0; // this is safe as this function will never be called for dynamic channel counts
375 }
376 
382 template<TensorLayout TL, ChannelType CT>
383 class Tensor2D : public TensorBase
384 {
385  using DataType = typename ChannelTypeToNative<CT>::Type;
386 
387 public:
391  Tensor2D() = default;
392 
398  Tensor2D(std::initializer_list<DimData> dimData, bool isCPU)
399  : TensorBase(CT, dimData, isCPU)
400  {
401  }
402 
409  Tensor2D(std::initializer_list<DimData> dimData, DataType *dataPtr, bool isCPU)
410  : TensorBase(CT, dimData, dataPtr, isCPU)
411  {
412  }
413 
418  std::size_t getLength() const
419  {
421  }
422 
427  std::size_t getChannelCount() const
428  {
430  }
431 
435  using TensorBase::getStride;
436 
442  std::size_t getStride(TensorDimension dim) const
443  {
444  switch (dim)
445  {
450  default:
451  throw std::out_of_range("cvcore::Tensor2D::getStride ==> Requested TensorDimension is out of bounds");
452  }
453  }
454 
459  DataType *getData()
460  {
461  return reinterpret_cast<DataType *>(TensorBase::getData());
462  }
463 
468  const DataType *getData() const
469  {
470  return reinterpret_cast<DataType *>(TensorBase::getData());
471  }
472 };
473 
479 template<TensorLayout TL, ChannelType CT>
480 class Tensor3D : public TensorBase
481 {
482  using DataType = typename ChannelTypeToNative<CT>::Type;
483 
484 public:
488  Tensor3D() = default;
489 
495  Tensor3D(std::initializer_list<DimData> dimData, bool isCPU)
496  : TensorBase(CT, dimData, isCPU)
497  {
498  }
499 
506  Tensor3D(std::initializer_list<DimData> dimData, DataType *dataPtr, bool isCPU)
507  : TensorBase(CT, dimData, dataPtr, isCPU)
508  {
509  }
510 
515  std::size_t getWidth() const
516  {
518  }
519 
524  std::size_t getHeight() const
525  {
527  }
528 
533  std::size_t getChannelCount() const
534  {
536  }
537 
541  using TensorBase::getStride;
542 
548  std::size_t getStride(TensorDimension dim) const
549  {
550  switch (dim)
551  {
558  default:
559  throw std::out_of_range("cvcore::Tensor3D::getStride ==> Requested TensorDimension is out of bounds");
560  }
561  }
562 
567  DataType *getData()
568  {
569  return reinterpret_cast<DataType *>(TensorBase::getData());
570  }
571 
576  const DataType *getData() const
577  {
578  return reinterpret_cast<DataType *>(TensorBase::getData());
579  }
580 };
581 
587 template<TensorLayout TL, ChannelType CT>
588 class Tensor4D : public TensorBase
589 {
590  using DataType = typename ChannelTypeToNative<CT>::Type;
591 
592 public:
596  Tensor4D() = default;
597 
603  Tensor4D(std::initializer_list<DimData> dimData, bool isCPU)
604  : TensorBase(CT, dimData, isCPU)
605  {
606  }
607 
614  Tensor4D(std::initializer_list<DimData> dimData, DataType *dataPtr, bool isCPU)
615  : TensorBase(CT, dimData, dataPtr, isCPU)
616  {
617  }
618 
623  std::size_t getWidth() const
624  {
626  }
627 
632  std::size_t getHeight() const
633  {
635  }
636 
641  std::size_t getDepth() const
642  {
644  }
645 
650  std::size_t getChannelCount() const
651  {
653  }
654 
658  using TensorBase::getStride;
659 
665  std::size_t getStride(TensorDimension dim) const
666  {
667  switch (dim)
668  {
677  default:
678  throw std::out_of_range("cvcore::Tensor4D::getStride ==> Requested TensorDimension is out of bounds");
679  }
680  }
681 
686  DataType *getData()
687  {
688  return reinterpret_cast<DataType *>(TensorBase::getData());
689  }
690 
695  const DataType *getData() const
696  {
697  return reinterpret_cast<DataType *>(TensorBase::getData());
698  }
699 };
700 
701 } // namespace detail
702 
703 template<TensorLayout TL, ChannelCount CC, ChannelType CT>
704 class Tensor;
705 
706 // 2D Tensors
707 
713 template<ChannelCount CC, ChannelType CT>
714 class Tensor<LC, CC, CT> : public detail::Tensor2D<LC, CT>
715 {
716 public:
718 
719  static constexpr ChannelCount kChannelCount = CC;
720 
721  Tensor() = default;
722 
723  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
724  Tensor(std::size_t length, bool isCPU = true)
725  : detail::Tensor2D<LC, CT>({{length, detail::ChannelToCount<CC>()}, {detail::ChannelToCount<CC>(), 1}}, isCPU)
726  {
727  }
728 
729  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
730  Tensor(std::size_t length, std::size_t channelCount, bool isCPU = true)
731  : detail::Tensor2D<LC, CT>({{length, channelCount}, {channelCount, 1}}, isCPU)
732  {
733  }
734 
735  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
736  Tensor(std::size_t length, DataType *dataPtr, bool isCPU = true)
737  : detail::Tensor2D<LC, CT>({{length, detail::ChannelToCount<CC>()}, {detail::ChannelToCount<CC>(), 1}}, dataPtr,
738  isCPU)
739  {
740  }
741 
742  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
743  Tensor(std::size_t length, std::size_t channelCount, DataType *dataPtr, bool isCPU = true)
744  : detail::Tensor2D<LC, CT>({{length, channelCount}, {channelCount, 1}}, dataPtr, isCPU)
745  {
746  }
747 };
748 
754 template<ChannelCount CC, ChannelType CT>
755 class Tensor<CL, CC, CT> : public detail::Tensor2D<CL, CT>
756 {
757 public:
759 
760  static constexpr ChannelCount kChannelCount = CC;
761 
762  Tensor() = default;
763 
764  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
765  Tensor(std::size_t length, bool isCPU = true)
766  : detail::Tensor2D<CL, CT>({{detail::ChannelToCount<CC>(), length}, {length, 1}}, isCPU)
767  {
768  }
769 
770  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
771  Tensor(std::size_t length, std::size_t channelCount, bool isCPU = true)
772  : detail::Tensor2D<CL, CT>({{channelCount, length}, {length, 1}}, isCPU)
773  {
774  }
775 
776  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
777  Tensor(std::size_t length, DataType *dataPtr, bool isCPU = true)
778  : detail::Tensor2D<CL, CT>({{detail::ChannelToCount<CC>(), length}, {length, 1}}, dataPtr, isCPU)
779  {
780  }
781 
782  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
783  Tensor(std::size_t length, std::size_t channelCount, DataType *dataPtr, bool isCPU = true)
784  : detail::Tensor2D<CL, CT>({{channelCount, length}, {length, 1}}, dataPtr, isCPU)
785  {
786  }
787 };
788 
789 // 3D Tensors
790 
796 template<ChannelCount CC, ChannelType CT>
797 class Tensor<HWC, CC, CT> : public detail::Tensor3D<HWC, CT>
798 {
799 public:
801 
802  static constexpr ChannelCount kChannelCount = CC;
803 
804  Tensor() = default;
805 
806  template<ChannelCount T = CC, typename B = bool,
807  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
808  Tensor(std::size_t width, std::size_t height, B isCPU = true)
809  : detail::Tensor3D<HWC, CT>({{height, width * detail::ChannelToCount<CC>()},
810  {width, detail::ChannelToCount<CC>()},
811  {detail::ChannelToCount<CC>(), 1}},
812  isCPU)
813  {
814  }
815 
816  template<ChannelCount T = CC, typename B = bool,
817  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
818  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, B isCPU = true)
819  : detail::Tensor3D<HWC, CT>({{height, width * channelCount}, {width, channelCount}, {channelCount, 1}}, isCPU)
820  {
821  }
822 
823  template<ChannelCount T = CC, typename B = bool,
824  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
825  Tensor(std::size_t width, std::size_t height, DataType *dataPtr, B isCPU = true)
826  : detail::Tensor3D<HWC, CT>({{height, width * detail::ChannelToCount<CC>()},
827  {width, detail::ChannelToCount<CC>()},
828  {detail::ChannelToCount<CC>(), 1}},
829  dataPtr, isCPU)
830  {
831  }
832 
833  template<ChannelCount T = CC, typename B = bool,
834  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
835  Tensor(std::size_t width, std::size_t height, std::size_t rowPitch, DataType *dataPtr, B isCPU = true)
836  : detail::Tensor3D<HWC, CT>({{height, rowPitch / GetChannelSize(CT)},
837  {width, detail::ChannelToCount<CC>()},
838  {detail::ChannelToCount<CC>(), 1}},
839  dataPtr, isCPU)
840  {
841  if (rowPitch % GetChannelSize(CT) != 0)
842  {
843  throw std::domain_error(
844  "cvcore::Tensor<HWC, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
845  }
846  }
847 
848  template<ChannelCount T = CC, typename B = bool,
849  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
850  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, DataType *dataPtr, B isCPU = true)
851  : detail::Tensor3D<HWC, CT>({{height, width * channelCount}, {width, channelCount}, {channelCount, 1}}, dataPtr,
852  isCPU)
853  {
854  }
855 
856  template<ChannelCount T = CC, typename B = bool,
857  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
858  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr,
859  B isCPU = true)
860  : detail::Tensor3D<HWC, CT>({{height, rowPitch / GetChannelSize(CT)}, {width, channelCount}, {channelCount, 1}},
861  dataPtr, isCPU)
862  {
863  if (rowPitch % GetChannelSize(CT) != 0)
864  {
865  throw std::domain_error(
866  "cvcore::Tensor<HWC, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
867  }
868  }
869 };
870 
876 template<ChannelCount CC, ChannelType CT>
877 class Tensor<CHW, CC, CT> : public detail::Tensor3D<CHW, CT>
878 {
879 public:
881 
882  static constexpr ChannelCount kChannelCount = CC;
883 
884  Tensor() = default;
885 
886  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
887  Tensor(std::size_t width, std::size_t height, bool isCPU = true)
888  : detail::Tensor3D<CHW, CT>({{detail::ChannelToCount<CC>(), width * height}, {height, width}, {width, 1}},
889  isCPU)
890  {
891  }
892 
893  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
894  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, bool isCPU = true)
895  : detail::Tensor3D<CHW, CT>({{channelCount, width * height}, {height, width}, {width, 1}}, isCPU)
896  {
897  }
898 
899  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
900  Tensor(std::size_t width, std::size_t height, DataType *dataPtr, bool isCPU = true)
901  : detail::Tensor3D<CHW, CT>({{detail::ChannelToCount<CC>(), width * height}, {height, width}, {width, 1}},
902  dataPtr, isCPU)
903  {
904  }
905 
906  template<ChannelCount T = CC, typename B = bool,
907  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
908  Tensor(std::size_t width, std::size_t height, std::size_t rowPitch, DataType *dataPtr, B isCPU = true)
909  : detail::Tensor3D<CHW, CT>({{detail::ChannelToCount<CC>(), height * rowPitch / GetChannelSize(CT)},
910  {height, rowPitch / GetChannelSize(CT)},
911  {width, 1}},
912  dataPtr, isCPU)
913  {
914  if (rowPitch % GetChannelSize(CT) != 0)
915  {
916  throw std::domain_error(
917  "cvcore::Tensor<CHW, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
918  }
919  }
920 
921  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
922  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, DataType *dataPtr, bool isCPU = true)
923  : detail::Tensor3D<CHW, CT>({{channelCount, width * height}, {height, width}, {width, 1}}, dataPtr, isCPU)
924  {
925  }
926 
927  template<ChannelCount T = CC, typename B = bool,
928  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
929  Tensor(std::size_t width, std::size_t height, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr,
930  B isCPU = true)
931  : detail::Tensor3D<CHW, CT>({{channelCount, height * rowPitch / GetChannelSize(CT)},
932  {height, rowPitch / GetChannelSize(CT)},
933  {width, 1}},
934  dataPtr, isCPU)
935  {
936  if (rowPitch % GetChannelSize(CT) != 0)
937  {
938  throw std::domain_error(
939  "cvcore::Tensor<CHW, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
940  }
941  }
942 };
943 
944 // 4D Tensors
945 
951 template<ChannelCount CC, ChannelType CT>
952 class Tensor<DHWC, CC, CT> : public detail::Tensor4D<DHWC, CT>
953 {
954 public:
956 
957  static constexpr ChannelCount kChannelCount = CC;
958 
959  Tensor() = default;
960 
961  template<ChannelCount T = CC, typename B = bool,
962  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
963  Tensor(std::size_t width, std::size_t height, std::size_t depth, B isCPU = true)
964  : detail::Tensor4D<DHWC, CT>({{depth, height * width * detail::ChannelToCount<CC>()},
965  {height, width * detail::ChannelToCount<CC>()},
966  {width, detail::ChannelToCount<CC>()},
967  {detail::ChannelToCount<CC>(), 1}},
968  isCPU)
969  {
970  }
971 
972  template<ChannelCount T = CC, typename B = bool,
973  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
974  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, B isCPU = true)
975  : detail::Tensor4D<DHWC, CT>({{depth, height * width * channelCount},
976  {height, width * channelCount},
977  {width, channelCount},
978  {channelCount, 1}},
979  isCPU)
980  {
981  }
982 
983  template<ChannelCount T = CC, typename B = bool,
984  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
985  Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, B isCPU = true)
986  : detail::Tensor4D<DHWC, CT>({{depth, height * width * detail::ChannelToCount<CC>()},
987  {height, width * detail::ChannelToCount<CC>()},
988  {width, detail::ChannelToCount<CC>()},
989  {detail::ChannelToCount<CC>(), 1}},
990  dataPtr, isCPU)
991  {
992  }
993 
994  template<ChannelCount T = CC, typename B = bool,
995  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
996  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t rowPitch, DataType *dataPtr,
997  B isCPU = true)
998  : detail::Tensor4D<DHWC, CT>({{depth, height * rowPitch / GetChannelSize(CT)},
999  {height, rowPitch / GetChannelSize(CT)},
1000  {width, detail::ChannelToCount<CC>()},
1001  {detail::ChannelToCount<CC>(), 1}},
1002  dataPtr, isCPU)
1003  {
1004  if (rowPitch % GetChannelSize(CT) != 0)
1005  {
1006  throw std::domain_error(
1007  "cvcore::Tensor<DHWC, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
1008  }
1009  }
1010 
1011  template<ChannelCount T = CC, typename B = bool,
1012  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
1013  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr,
1014  B isCPU = true)
1015  : detail::Tensor4D<DHWC, CT>({{depth, height * width * channelCount},
1016  {height, width * channelCount},
1017  {width, channelCount},
1018  {channelCount, 1}},
1019  dataPtr, isCPU)
1020  {
1021  }
1022 
1023  template<ChannelCount T = CC, typename B = bool,
1024  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
1025  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, std::size_t rowPitch,
1026  DataType *dataPtr, B isCPU = true)
1027  : detail::Tensor4D<DHWC, CT>({{depth, height * rowPitch / GetChannelSize(CT)},
1028  {height, rowPitch / GetChannelSize(CT)},
1029  {width, channelCount},
1030  {channelCount, 1}},
1031  dataPtr, isCPU)
1032  {
1033  if (rowPitch % GetChannelSize(CT) != 0)
1034  {
1035  throw std::domain_error(
1036  "cvcore::Tensor<DHWC, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
1037  }
1038  }
1039 };
1040 
1046 template<ChannelCount CC, ChannelType CT>
1047 class Tensor<DCHW, CC, CT> : public detail::Tensor4D<DCHW, CT>
1048 {
1049 public:
1051 
1052  static constexpr ChannelCount kChannelCount = CC;
1053 
1054  Tensor() = default;
1055 
1056  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
1057  Tensor(std::size_t width, std::size_t height, std::size_t depth, bool isCPU = true)
1058  : detail::Tensor4D<DCHW, CT>({{depth, detail::ChannelToCount<CC>() * width * height},
1059  {detail::ChannelToCount<CC>(), width * height},
1060  {height, width},
1061  {width, 1}},
1062  isCPU)
1063  {
1064  }
1065 
1066  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
1067  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, bool isCPU = true)
1068  : detail::Tensor4D<DCHW, CT>(
1069  {{depth, channelCount * width * height}, {channelCount, width * height}, {height, width}, {width, 1}},
1070  isCPU)
1071  {
1072  }
1073 
1074  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
1075  Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, bool isCPU = true)
1076  : detail::Tensor4D<DCHW, CT>({{depth, detail::ChannelToCount<CC>() * width * height},
1077  {detail::ChannelToCount<CC>(), width * height},
1078  {height, width},
1079  {width, 1}},
1080  dataPtr, isCPU)
1081  {
1082  }
1083 
1084  template<ChannelCount T = CC, typename B = bool,
1085  typename std::enable_if<T != CX && std::is_same<B, bool>::value>::type * = nullptr>
1086  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t rowPitch, DataType *dataPtr,
1087  B isCPU = true)
1088  : detail::Tensor4D<DCHW, CT>({{depth, detail::ChannelToCount<CC>() * height * rowPitch / GetChannelSize(CT)},
1089  {detail::ChannelToCount<CC>(), height * rowPitch / GetChannelSize(CT)},
1090  {height, rowPitch / GetChannelSize(CT)},
1091  {width, 1}},
1092  dataPtr, isCPU)
1093  {
1094  if (rowPitch % GetChannelSize(CT) != 0)
1095  {
1096  throw std::domain_error(
1097  "cvcore::Tensor<DCHW, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
1098  }
1099  }
1100 
1101  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
1102  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr,
1103  bool isCPU = true)
1104  : detail::Tensor4D<DCHW, CT>(
1105  {{depth, channelCount * width * height}, {channelCount, width * height}, {height, width}, {width, 1}},
1106  dataPtr, isCPU)
1107  {
1108  }
1109 
1110  template<ChannelCount T = CC, typename B = bool,
1111  typename std::enable_if<T == CX && std::is_same<B, bool>::value>::type * = nullptr>
1112  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, std::size_t rowPitch,
1113  DataType *dataPtr, B isCPU = true)
1114  : detail::Tensor4D<DCHW, CT>({{depth, channelCount * height * rowPitch / GetChannelSize(CT)},
1115  {channelCount, height * rowPitch / GetChannelSize(CT)},
1116  {height, rowPitch / GetChannelSize(CT)},
1117  {width, 1}},
1118  dataPtr, isCPU)
1119  {
1120  if (rowPitch % GetChannelSize(CT) != 0)
1121  {
1122  throw std::domain_error(
1123  "cvcore::Tensor<DCHW, CC, CT>::Tensor ==> Parameter rowPitch is not evenly divisible by channel size");
1124  }
1125  }
1126 };
1127 
1133 template<ChannelCount CC, ChannelType CT>
1134 class Tensor<CDHW, CC, CT> : public detail::Tensor4D<CDHW, CT>
1135 {
1136 public:
1138 
1139  static constexpr ChannelCount kChannelCount = CC;
1140 
1141  Tensor() = default;
1142 
1143  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
1144  Tensor(std::size_t width, std::size_t height, std::size_t depth, bool isCPU = true)
1145  : detail::Tensor4D<CDHW, CT>({{detail::ChannelToCount<CC>(), depth * width * height},
1146  {depth, width * height},
1147  {height, width},
1148  {width, 1}},
1149  isCPU)
1150  {
1151  }
1152 
1153  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
1154  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, bool isCPU = true)
1155  : detail::Tensor4D<CDHW, CT>(
1156  {{channelCount, depth * width * height}, {depth, width * height}, {height, width}, {width, 1}}, isCPU)
1157  {
1158  }
1159 
1160  template<ChannelCount T = CC, typename = typename std::enable_if<T != CX>::type>
1161  Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, bool isCPU = true)
1162  : detail::Tensor4D<CDHW, CT>({{detail::ChannelToCount<CC>(), depth * width * height},
1163  {depth, width * height},
1164  {height, width},
1165  {width, 1}},
1166  dataPtr, isCPU)
1167  {
1168  }
1169 
1170  template<ChannelCount T = CC, typename = typename std::enable_if<T == CX>::type>
1171  Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr,
1172  bool isCPU = true)
1173  : detail::Tensor4D<CDHW, CT>(
1174  {{channelCount, depth * width * height}, {depth, width * height}, {height, width}, {width, 1}}, dataPtr,
1175  isCPU)
1176  {
1177  }
1178 };
1179 
1180 } // namespace cvcore
1181 
1182 #endif // CVCORE_TENSOR_H
cvcore::detail::Tensor2D::getData
DataType * getData()
Get the raw data pointer to the 2D tensor.
Definition: Tensor.h:459
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:996
cvcore::TensorBase::getDataSize
std::size_t getDataSize() const
Get the total size of the Tensor in bytes.
cvcore::detail::Tensor3D::getStride
std::size_t getStride(TensorDimension dim) const
Get the stride of the 3D tensor.
Definition: Tensor.h:548
cvcore::detail::Tensor3D::getHeight
std::size_t getHeight() const
Get the height of the 3D tensor.
Definition: Tensor.h:524
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:835
cvcore::Tensor< HWC, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:800
cvcore::detail::DimToIndex4D::kHeight
static constexpr int kHeight
Definition: Tensor.h:284
cvcore::detail::Tensor2D::Tensor2D
Tensor2D()=default
Default Constructor.
cvcore::detail::Tensor4D::getStride
std::size_t getStride(TensorDimension dim) const
Get the stride of the 4D tensor.
Definition: Tensor.h:665
cvcore::detail::DimToIndex3D::kChannel
static constexpr int kChannel
Definition: Tensor.h:276
cvcore::Tensor< CL, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:758
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, B isCPU=true)
Definition: Tensor.h:808
cvcore::CHW
@ CHW
channel, height, width (channel planar).
Definition: Tensor.h:33
cvcore::S8
@ S8
int8_t.
Definition: Tensor.h:62
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:922
cvcore::detail::DimToIndex4D::kChannel
static constexpr int kChannel
Definition: Tensor.h:286
cvcore::Tensor< LC, CC, CT >::Tensor
Tensor(std::size_t length, std::size_t channelCount, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:743
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, bool isCPU=true)
Definition: Tensor.h:1057
cvcore::detail::Tensor4D::Tensor4D
Tensor4D()=default
Default Constructor.
cvcore::detail::ChannelTypeToNative< F64 >::Type
double Type
Definition: Tensor.h:357
cvcore::Tensor< LC, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:717
cvcore::GetMemoryTypeAsString
std::string GetMemoryTypeAsString(bool isCPU)
Function to get name of a Memory type used.
cvcore::TensorDimension::CHANNEL
@ CHANNEL
channel dimension.
cvcore
Definition: PnP.h:20
cvcore::detail::Tensor4D::getWidth
std::size_t getWidth() const
Get the width of the 4D tensor.
Definition: Tensor.h:623
cvcore::F64
@ F64
double.
Definition: Tensor.h:66
cvcore::detail::Tensor2D::getLength
std::size_t getLength() const
Get the length of the 2D tensor.
Definition: Tensor.h:418
cvcore::CL
@ CL
channel, length (channel planar).
Definition: Tensor.h:31
cvcore::TensorBase::DimData
Struct for storing dimension data.
Definition: Tensor.h:126
cvcore::detail::Tensor4D::getDepth
std::size_t getDepth() const
Get the depth of the 4D tensor.
Definition: Tensor.h:641
cvcore::detail::Tensor2D
Implementation of 2D tensors.
Definition: Tensor.h:383
cvcore::TensorDimension::LENGTH
@ LENGTH
length dimension.
cvcore::Tensor< CL, CC, CT >::Tensor
Tensor(std::size_t length, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:777
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:825
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, B isCPU=true)
Definition: Tensor.h:974
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, bool isCPU=true)
Definition: Tensor.h:887
cvcore::detail::Tensor4D::getHeight
std::size_t getHeight() const
Get the height of the 4D tensor.
Definition: Tensor.h:632
cvcore::detail::LayoutToIndex
Definition: Tensor.h:290
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:1075
cvcore::DCHW
@ DCHW
depth, channel, height, width (channel planar).
Definition: Tensor.h:36
cvcore::detail::ChannelTypeToNative< S16 >::Type
std::int16_t Type
Definition: Tensor.h:339
cvcore::detail::DimToIndex2D
Definition: Tensor.h:263
cvcore::GetChannelSize
std::size_t GetChannelSize(ChannelType CT)
Function to get element size (in bytes) of a ChannelType.
cvcore::GetChannelTypeAsString
std::string GetChannelTypeAsString(ChannelType CT)
Function to get name of a ChannelType value as string.
cvcore::LC
@ LC
length, channel (channel interleaved).
Definition: Tensor.h:30
cvcore::C1
@ C1
1 channels.
Definition: Tensor.h:47
cvcore::TensorBase::getData
void * getData() const
Get the raw data pointer to the Tensor.
cvcore::Tensor< CDHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, bool isCPU=true)
Definition: Tensor.h:1144
cvcore::Tensor< CDHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:1161
cvcore::Tensor< CL, CC, CT >::Tensor
Tensor(std::size_t length, std::size_t channelCount, bool isCPU=true)
Definition: Tensor.h:771
cvcore::detail::ChannelTypeToNative< U8 >::Type
std::uint8_t Type
Definition: Tensor.h:321
cvcore::detail::ChannelTypeToNative< S8 >::Type
std::int8_t Type
Definition: Tensor.h:333
cvcore::CX
@ CX
varying number of channels.
Definition: Tensor.h:51
cvcore::detail::Tensor4D::getData
const DataType * getData() const
Get the const raw data pointer to the 4D tensor.
Definition: Tensor.h:695
cvcore::TensorBase::~TensorBase
~TensorBase()
Destructor of Tensor.
cvcore::GetTensorLayoutAsString
std::string GetTensorLayoutAsString(TensorLayout TL)
Function to get name of a TensorLayout value as string.
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, bool isCPU=true)
Definition: Tensor.h:894
cvcore::TensorBase::getType
ChannelType getType() const
Get the ChannelType of the Tensor.
cvcore::TensorBase::DimData::stride
std::size_t stride
stride of each dimension.
Definition: Tensor.h:129
cvcore::TensorBase::TensorBase
TensorBase()
cvcore::TensorBase::DimData::size
std::size_t size
size of each dimension.
Definition: Tensor.h:128
cvcore::detail::DimToIndex2D::kLength
static constexpr int kLength
Definition: Tensor.h:266
cvcore::Tensor< CL, CC, CT >::Tensor
Tensor(std::size_t length, bool isCPU=true)
Definition: Tensor.h:765
cvcore::Tensor< CHW, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:880
cvcore::C3
@ C3
3 channels.
Definition: Tensor.h:49
cvcore::TensorBase::getStride
std::size_t getStride(int dimIdx) const
Get the stride of given dimension.
cvcore::Tensor
Definition: Tensor.h:704
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:908
cvcore::detail::Tensor2D::getStride
std::size_t getStride(TensorDimension dim) const
Get the stride of the 2D tensor.
Definition: Tensor.h:442
cvcore::detail::Tensor4D
Implementation of 4D tensors.
Definition: Tensor.h:588
cvcore::U8
@ U8
uint8_t.
Definition: Tensor.h:60
cvcore::detail::Tensor4D::getChannelCount
std::size_t getChannelCount() const
Get the channel count of the 4D tensor.
Definition: Tensor.h:650
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:1086
cvcore::TensorBase::isOwning
bool isOwning() const
Get the flag whether the Tensor owns the data.
cvcore::U16
@ U16
uint16_t.
Definition: Tensor.h:61
cvcore::detail::Tensor4D::Tensor4D
Tensor4D(std::initializer_list< DimData > dimData, DataType *dataPtr, bool isCPU)
Constructor of a non-owning 4D tensor.
Definition: Tensor.h:614
cvcore::C4
@ C4
4 channels.
Definition: Tensor.h:50
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, bool isCPU=true)
Definition: Tensor.h:1067
cvcore::detail::ChannelTypeToNative< F32 >::Type
float Type
Definition: Tensor.h:345
cvcore::detail::Tensor3D::Tensor3D
Tensor3D()=default
Default Constructor.
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, B isCPU=true)
Definition: Tensor.h:963
cvcore::Tensor< CL, CC, CT >::Tensor
Tensor(std::size_t length, std::size_t channelCount, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:783
cvcore::DHWC
@ DHWC
depth, height, width, channel (channel interleaved).
Definition: Tensor.h:34
cvcore::detail::Tensor3D::Tensor3D
Tensor3D(std::initializer_list< DimData > dimData, DataType *dataPtr, bool isCPU)
Constructor of a non-owning 3D tensor.
Definition: Tensor.h:506
cvcore::S16
@ S16
int16_t.
Definition: Tensor.h:63
cvcore::TensorBase::isCPU
bool isCPU() const
Get the flag whether the Tensor is allocated in CPU or GPU.
cvcore::Tensor< CDHW, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:1137
cvcore::detail::DimToIndex3D::kHeight
static constexpr int kHeight
Definition: Tensor.h:275
cvcore::TensorBase
Implementation of TensorBase class.
Definition: Tensor.h:120
cvcore::NCHW
@ NCHW
alias for DCHW.
Definition: Tensor.h:37
cvcore::detail::DimToIndex3D::kWidth
static constexpr int kWidth
Definition: Tensor.h:274
cvcore::CDHW
@ CDHW
channel, depth, height, width (channel planar).
Definition: Tensor.h:38
cvcore::NHWC
@ NHWC
alias for DHWC.
Definition: Tensor.h:35
cvcore::F32
@ F32
float.
Definition: Tensor.h:65
cvcore::detail::Tensor2D::Tensor2D
Tensor2D(std::initializer_list< DimData > dimData, DataType *dataPtr, bool isCPU)
Constructor of a non-owning 2D tensor.
Definition: Tensor.h:409
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:1102
cvcore::detail::Tensor4D::Tensor4D
Tensor4D(std::initializer_list< DimData > dimData, bool isCPU)
Constructor of a memory-owning 4D tensor.
Definition: Tensor.h:603
cvcore::F16
@ F16
cvcore::half.
Definition: Tensor.h:64
cvcore::TensorDimension::WIDTH
@ WIDTH
width dimension.
cvcore::detail::ChannelTypeToNative
Definition: Tensor.h:314
cvcore::detail::Tensor3D::Tensor3D
Tensor3D(std::initializer_list< DimData > dimData, bool isCPU)
Constructor of a memory-owning 3D tensor.
Definition: Tensor.h:495
cvcore::detail::Tensor3D::getData
DataType * getData()
Get the raw data pointer to the 3D tensor.
Definition: Tensor.h:567
cvcore::TensorDimension::HEIGHT
@ HEIGHT
height dimension.
cvcore::C2
@ C2
2 channels.
Definition: Tensor.h:48
cvcore::Tensor< DHWC, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:955
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:850
cvcore::detail::ChannelTypeToNative< U16 >::Type
std::uint16_t Type
Definition: Tensor.h:327
cvcore::detail::Tensor3D::getWidth
std::size_t getWidth() const
Get the width of the 3D tensor.
Definition: Tensor.h:515
cvcore::detail::Tensor3D
Implementation of 3D tensors.
Definition: Tensor.h:480
cvcore::Tensor< CDHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, bool isCPU=true)
Definition: Tensor.h:1154
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:858
cvcore::TensorDimension::DEPTH
@ DEPTH
depth dimension.
cvcore::detail::Tensor3D::getData
const DataType * getData() const
Get the const raw data pointer to the 3D tensor.
Definition: Tensor.h:576
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:929
cvcore::TensorDimension
TensorDimension
An enum.
Definition: Tensor.h:73
cvcore::detail::DimToIndex2D::kChannel
static constexpr int kChannel
Definition: Tensor.h:267
cvcore::Tensor< DCHW, CC, CT >::DataType
typename detail::ChannelTypeToNative< CT >::Type DataType
Definition: Tensor.h:1050
cvcore::Tensor< CDHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:1171
cvcore::detail::Tensor2D::Tensor2D
Tensor2D(std::initializer_list< DimData > dimData, bool isCPU)
Constructor of a memory-owning 2D tensor.
Definition: Tensor.h:398
cvcore::HWC
@ HWC
height, width, channel (channel interleaved).
Definition: Tensor.h:32
cvcore::TensorBase::getDimCount
int getDimCount() const
Get the dimension count of TensorBase.
cvcore::detail::ChannelTypeToNative< F16 >::Type
cvcore::half Type
Definition: Tensor.h:351
cvcore::detail::Tensor4D::getData
DataType * getData()
Get the raw data pointer to the 4D tensor.
Definition: Tensor.h:686
cvcore::detail::DimToIndex4D::kDepth
static constexpr int kDepth
Definition: Tensor.h:285
cvcore::TensorBase::getSize
std::size_t getSize(int dimIdx) const
Get the size of given dimension.
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:1025
cvcore::detail::Tensor2D::getChannelCount
std::size_t getChannelCount() const
Get the channel count of the 2D tensor.
Definition: Tensor.h:427
cvcore::ChannelType
ChannelType
An enum.
Definition: Tensor.h:58
cvcore::Tensor< LC, CC, CT >::Tensor
Tensor(std::size_t length, bool isCPU=true)
Definition: Tensor.h:724
cvcore::TensorLayout
TensorLayout
An enum.
Definition: Tensor.h:28
cvcore::TensorBase::operator=
TensorBase & operator=(const TensorBase &)=delete
TensorBase is non-copyable.
cvcore::detail::Tensor2D::getData
const DataType * getData() const
Get the const raw data pointer to the 2D tensor.
Definition: Tensor.h:468
cvcore::Tensor< DCHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, std::size_t rowPitch, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:1112
cvcore::Tensor< LC, CC, CT >::Tensor
Tensor(std::size_t length, std::size_t channelCount, bool isCPU=true)
Definition: Tensor.h:730
cvcore::detail::ChannelToCount
constexpr std::size_t ChannelToCount()
Definition: Tensor.h:361
cvcore::Tensor< CHW, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:900
cvcore::detail::DimToIndex4D
Definition: Tensor.h:280
cvcore::detail::DimToIndex4D::kWidth
static constexpr int kWidth
Definition: Tensor.h:283
cvcore::detail::DimToIndex3D
Definition: Tensor.h:271
cvcore::Tensor< LC, CC, CT >::Tensor
Tensor(std::size_t length, DataType *dataPtr, bool isCPU=true)
Definition: Tensor.h:736
cvcore::half
std::uint16_t half
Definition: Tensor.h:22
cvcore::detail::Tensor3D::getChannelCount
std::size_t getChannelCount() const
Get the channel count of the 3D tensor.
Definition: Tensor.h:533
cvcore::Tensor< HWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t channelCount, B isCPU=true)
Definition: Tensor.h:818
cvcore::ChannelCount
ChannelCount
An enum.
Definition: Tensor.h:45
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, std::size_t channelCount, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:1013
cvcore::Tensor< DHWC, CC, CT >::Tensor
Tensor(std::size_t width, std::size_t height, std::size_t depth, DataType *dataPtr, B isCPU=true)
Definition: Tensor.h:985
cvcore::GetChannelCountAsString
std::string GetChannelCountAsString(ChannelCount CC)
Function to get name of a ChannelCount value as string.