NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
Core/Shape.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <iostream>
31#include <string>
32
33#include "NumCpp/Core/Types.hpp"
35
36namespace nc
37{
38 //================================================================================
40 class Shape
41 {
42 public:
43 //====================================Attributes==============================
46
47 //============================================================================
50 constexpr Shape() = default;
51
52 //============================================================================
57 constexpr explicit Shape(uint32 inSquareSize) noexcept :
58 rows(inSquareSize),
59 cols(inSquareSize)
60 {
61 }
62
63 //============================================================================
69 constexpr Shape(uint32 inRows, uint32 inCols) noexcept :
70 rows(inRows),
71 cols(inCols)
72 {
73 }
74
75 //============================================================================
82 bool operator==(const Shape& inOtherShape) const noexcept
83 {
84 return rows == inOtherShape.rows && cols == inOtherShape.cols;
85 }
86
87 //============================================================================
94 bool operator!=(const Shape& inOtherShape) const noexcept
95 {
96 return !(*this == inOtherShape);
97 }
98
99 //============================================================================
104 [[nodiscard]] uint32 size() const noexcept
105 {
106 return rows * cols;
107 }
108
109 //============================================================================
115 [[nodiscard]] bool isnull() const noexcept
116 {
117 return rows == 0 && cols == 0;
118 }
119
120 //============================================================================
125 [[nodiscard]] bool issquare() const noexcept
126 {
127 return rows == cols;
128 }
129
130 //============================================================================
135 [[nodiscard]] std::string str() const
136 {
137 std::string out = "[" + utils::num2str(rows) + ", " + utils::num2str(cols) + "]\n";
138 return out;
139 }
140
141 //============================================================================
144 void print() const
145 {
146 std::cout << *this;
147 }
148
149 //============================================================================
157 friend std::ostream& operator<<(std::ostream& inOStream, const Shape& inShape)
158 {
159 inOStream << inShape.str();
160 return inOStream;
161 }
162 };
163} // namespace nc
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
bool operator==(const Shape &inOtherShape) const noexcept
Definition: Core/Shape.hpp:82
friend std::ostream & operator<<(std::ostream &inOStream, const Shape &inShape)
Definition: Core/Shape.hpp:157
constexpr Shape()=default
bool isnull() const noexcept
Definition: Core/Shape.hpp:115
void print() const
Definition: Core/Shape.hpp:144
constexpr Shape(uint32 inRows, uint32 inCols) noexcept
Definition: Core/Shape.hpp:69
bool operator!=(const Shape &inOtherShape) const noexcept
Definition: Core/Shape.hpp:94
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:125
std::string str() const
Definition: Core/Shape.hpp:135
uint32 cols
Definition: Core/Shape.hpp:45
uint32 size() const noexcept
Definition: Core/Shape.hpp:104
std::string num2str(dtype inNumber)
Definition: num2str.hpp:44
Definition: Cartesian.hpp:40
std::uint32_t uint32
Definition: Types.hpp:40