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