Beatmup
Beatmup::NNets::Size Class Reference

Operation 3D input/output size. More...

#include <storage.h>

Public Types

enum class  Padding { SAME , VALID }
 Zero padding specification. More...
 

Public Member Functions

 Size ()
 
 Size (const Size &size, int depth)
 
 Size (int width, int height, int depth)
 
bool operator== (const Size &size) const
 
bool operator!= (const Size &size) const
 
int & operator[] (int di)
 
int operator[] (int di) const
 
int getWidth () const
 
int getHeight () const
 
int getDepth () const
 
int volume () const
 
bool zero () const
 
Size transform (Size kernel, Size stride, Padding padding, int depth=0) const
 Computes operation output size in function of operation kernel, padding, stride and depth, assuming that the current Size is the input size. More...
 
Size getOrigin (Size kernel, Size stride, Padding padding) const
 Computes operation origin in function of operation kernel, padding and stride, assuming that the current Size instance is the input size. More...
 
Size operator+ (const Size &size) const
 
Size operator- (const Size &size) const
 
Size operator* (const Size &size) const
 
Size operator/ (const Size &size) const
 
Size operator+ (int scalar) const
 
Size operator- (int scalar) const
 
Size operator* (int scalar) const
 
Size operator/ (int scalar) const
 

Static Public Attributes

static const Size EMPTY
 
static const Size ONES
 

Private Attributes

int dim [3]
 

Detailed Description

Operation 3D input/output size.

Dimensions are X (width), Y (height), Z (depth).

Definition at line 37 of file storage.h.

Member Enumeration Documentation

◆ Padding

Zero padding specification.

Enumerator
SAME 

operation output size matches its input size for unit strides

VALID 

no zero padding

Definition at line 45 of file storage.h.

45  {
46  SAME, //!< operation output size matches its input size for unit strides
47  VALID //!< no zero padding
48  };

Constructor & Destructor Documentation

◆ Size() [1/3]

Beatmup::NNets::Size::Size ( )
inline

Definition at line 53 of file storage.h.

53 { dim[0] = dim[1] = dim[2] = 0; }

◆ Size() [2/3]

Beatmup::NNets::Size::Size ( const Size size,
int  depth 
)
inline

Definition at line 54 of file storage.h.

54 : Size(size[0], size[1], depth) {}
jlong jobject size

◆ Size() [3/3]

Size::Size ( int  width,
int  height,
int  depth 
)

Definition at line 51 of file storage.cpp.

51  {
52  dim[0] = width;
53  dim[1] = height;
54  dim[2] = depth;
55 }
jlong jint width
jlong jint jint height

Member Function Documentation

◆ operator==()

bool Beatmup::NNets::Size::operator== ( const Size size) const
inline

Definition at line 57 of file storage.h.

57  {
58  return (dim[0] == size.dim[0]) && (dim[1] == size.dim[1]) && (dim[2] == size.dim[2]);
59  }

◆ operator!=()

bool Beatmup::NNets::Size::operator!= ( const Size size) const
inline

Definition at line 61 of file storage.h.

61  {
62  return (dim[0] != size.dim[0]) || (dim[1] != size.dim[1]) || (dim[2] != size.dim[2]);
63  }

◆ operator[]() [1/2]

int& Beatmup::NNets::Size::operator[] ( int  di)
inline

Definition at line 65 of file storage.h.

65  {
66  BEATMUP_ASSERT_DEBUG(0 <= di && di < 3);
67  return dim[di];
68  }
#define BEATMUP_ASSERT_DEBUG(C)
Definition: exception.h:163

◆ operator[]() [2/2]

int Beatmup::NNets::Size::operator[] ( int  di) const
inline

Definition at line 70 of file storage.h.

70  {
71  BEATMUP_ASSERT_DEBUG(0 <= di && di < 3);
72  return dim[di];
73  }

◆ getWidth()

int Beatmup::NNets::Size::getWidth ( ) const
inline

Definition at line 75 of file storage.h.

75 { return dim[0]; }

◆ getHeight()

int Beatmup::NNets::Size::getHeight ( ) const
inline

Definition at line 76 of file storage.h.

76 { return dim[1]; }

◆ getDepth()

int Beatmup::NNets::Size::getDepth ( ) const
inline

Definition at line 77 of file storage.h.

77 { return dim[2]; }

◆ volume()

int Beatmup::NNets::Size::volume ( ) const
inline

Definition at line 79 of file storage.h.

79  {
80  return dim[0] * dim[1] * dim[2];
81  }

◆ zero()

bool Beatmup::NNets::Size::zero ( ) const
inline

Definition at line 83 of file storage.h.

83  {
84  return dim[0] == 0 || dim[1] == 0 || dim[2] == 0;
85  }

◆ transform()

Size Size::transform ( Size  kernel,
Size  stride,
Padding  padding,
int  depth = 0 
) const

Computes operation output size in function of operation kernel, padding, stride and depth, assuming that the current Size is the input size.

Parameters
[in]kernelThe operation kernel size
[in]strideThe stride
[in]paddingThe padding
[in]depthThe output depth. If zero, the input depth is taken.
Returns
the output size.

Definition at line 58 of file storage.cpp.

58  {
59  Size result(dim[0], dim[1], depth == 0 ? this->dim[2] : depth);
60  if (padding == Padding::SAME) {
61  result.dim[0] = ceili(dim[0], stride[0]);
62  result.dim[1] = ceili(dim[1], stride[1]);
63  }
64  else {
65  result.dim[0] = ceili(dim[0] - kernel[0] + 1, stride[0]);
66  result.dim[1] = ceili(dim[1] - kernel[1] + 1, stride[1]);
67  }
68  return result;
69 }
Operation 3D input/output size.
Definition: storage.h:37
@ SAME
operation output size matches its input size for unit strides
#define ceili(x, y)
integer division x/y with ceiling
Definition: utils.hpp:21
Beatmup::IntPoint result

◆ getOrigin()

Size Size::getOrigin ( Size  kernel,
Size  stride,
Padding  padding 
) const

Computes operation origin in function of operation kernel, padding and stride, assuming that the current Size instance is the input size.

Parameters
[in]kernelThe operation kernel size
[in]strideThe stride
[in]paddingThe padding
Returns
the origin.

Definition at line 72 of file storage.cpp.

72  {
73  if (padding == Padding::SAME) {
74  return Size(
75  kernel[0] / 2 - (kernel[0] - ((dim[0] - 1) % stride[0]) - 1) / 2,
76  kernel[1] / 2 - (kernel[1] - ((dim[1] - 1) % stride[1]) - 1) / 2,
77  kernel[2] / 2 - (kernel[2] - ((dim[2] - 1) % stride[2]) - 1) / 2
78  );
79  }
80  else {
81  return Size(kernel[0] / 2, kernel[1] / 2, kernel[2] / 2);
82  }
83 }

◆ operator+() [1/2]

Size Beatmup::NNets::Size::operator+ ( const Size size) const
inline

Definition at line 108 of file storage.h.

108 { return Size(dim[0] + size[0], dim[1] + size[1], dim[2] + size[2]); }

◆ operator-() [1/2]

Size Beatmup::NNets::Size::operator- ( const Size size) const
inline

Definition at line 109 of file storage.h.

109 { return Size(dim[0] - size[0], dim[1] - size[1], dim[2] - size[2]); }

◆ operator*() [1/2]

Size Beatmup::NNets::Size::operator* ( const Size size) const
inline

Definition at line 110 of file storage.h.

110 { return Size(dim[0] * size[0], dim[1] * size[1], dim[2] * size[2]); }

◆ operator/() [1/2]

Size Beatmup::NNets::Size::operator/ ( const Size size) const
inline

Definition at line 111 of file storage.h.

111 { return Size(dim[0] / size[0], dim[1] / size[1], dim[2] / size[2]); }

◆ operator+() [2/2]

Size Beatmup::NNets::Size::operator+ ( int  scalar) const
inline

Definition at line 112 of file storage.h.

112 { return Size(dim[0] + scalar, dim[1] + scalar, dim[2] + scalar); }

◆ operator-() [2/2]

Size Beatmup::NNets::Size::operator- ( int  scalar) const
inline

Definition at line 113 of file storage.h.

113 { return Size(dim[0] - scalar, dim[1] - scalar, dim[2] - scalar); }

◆ operator*() [2/2]

Size Beatmup::NNets::Size::operator* ( int  scalar) const
inline

Definition at line 114 of file storage.h.

114 { return Size(dim[0] * scalar, dim[1] * scalar, dim[2] * scalar); }

◆ operator/() [2/2]

Size Beatmup::NNets::Size::operator/ ( int  scalar) const
inline

Definition at line 115 of file storage.h.

115 { return Size(dim[0] / scalar, dim[1] / scalar, dim[2] / scalar); }

Member Data Documentation

◆ dim

int Beatmup::NNets::Size::dim[3]
private

Definition at line 39 of file storage.h.

◆ EMPTY

const Size Size::EMPTY
static

Definition at line 50 of file storage.h.

◆ ONES

const Size Size::ONES
static

Definition at line 51 of file storage.h.


The documentation for this class was generated from the following files: