NumCpp  2.1.0
A C++ implementation of the Python Numpy library
Core/Shape.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/Core/Types.hpp"
32 #include "NumCpp/Utils/num2str.hpp"
33 
34 #include <iostream>
35 #include <string>
36 
37 namespace nc
38 {
39  //================================================================================
41  class Shape
42  {
43  public:
44  //====================================Attributes==============================
45  uint32 rows{ 0 };
46  uint32 cols{ 0 };
47 
48  //============================================================================
51  constexpr Shape() = default;
52 
53  //============================================================================
58  constexpr explicit Shape(uint32 inSquareSize) noexcept :
59  rows(inSquareSize),
60  cols(inSquareSize)
61  {}
62 
63  //============================================================================
69  constexpr Shape(uint32 inRows, uint32 inCols) noexcept :
70  rows(inRows),
71  cols(inCols)
72  {}
73 
74  //============================================================================
81  constexpr bool operator==(const Shape& inOtherShape) const noexcept
82  {
83  return rows == inOtherShape.rows && cols == inOtherShape.cols;
84  }
85 
86  //============================================================================
93  constexpr bool operator!=(const Shape& inOtherShape) const noexcept
94  {
95  return !(*this == inOtherShape);
96  }
97 
98  //============================================================================
103  constexpr uint32 size() const noexcept
104  {
105  return rows * cols;
106  }
107 
108  //============================================================================
114  constexpr bool isnull() const noexcept
115  {
116  return rows == 0 && cols == 0;
117  }
118 
119  //============================================================================
124  constexpr bool issquare() const noexcept
125  {
126  return rows == cols;
127  }
128 
129  //============================================================================
134  std::string str() const
135  {
136  std::string out = "[" + utils::num2str(rows) + ", " + utils::num2str(cols) + "]\n";
137  return out;
138  }
139 
140  //============================================================================
143  void print() const
144  {
145  std::cout << *this;
146  }
147 
148  //============================================================================
156  friend std::ostream& operator<<(std::ostream& inOStream, const Shape& inShape)
157  {
158  inOStream << inShape.str();
159  return inOStream;
160  }
161  };
162 } // namespace nc
nc::Shape::operator!=
constexpr bool operator!=(const Shape &inOtherShape) const noexcept
Definition: Core/Shape.hpp:93
nc::utils::num2str
std::string num2str(dtype inNumber)
Definition: num2str.hpp:47
nc::Shape::issquare
constexpr bool issquare() const noexcept
Definition: Core/Shape.hpp:124
nc::Shape::operator<<
friend std::ostream & operator<<(std::ostream &inOStream, const Shape &inShape)
Definition: Core/Shape.hpp:156
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
num2str.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:46
nc
Definition: Coordinate.hpp:45
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:45
nc::Shape::size
constexpr uint32 size() const noexcept
Definition: Core/Shape.hpp:103
nc::Shape::isnull
constexpr bool isnull() const noexcept
Definition: Core/Shape.hpp:114
nc::Shape::Shape
constexpr Shape(uint32 inRows, uint32 inCols) noexcept
Definition: Core/Shape.hpp:69
nc::Shape::operator==
constexpr bool operator==(const Shape &inOtherShape) const noexcept
Definition: Core/Shape.hpp:81
Types.hpp
nc::Shape::Shape
constexpr Shape(uint32 inSquareSize) noexcept
Definition: Core/Shape.hpp:58
nc::Shape::print
void print() const
Definition: Core/Shape.hpp:143
nc::Shape::Shape
constexpr Shape()=default
nc::Shape::str
std::string str() const
Definition: Core/Shape.hpp:134