class BCHW final : public FeatureLayout
{
private:
- BCHW(uint32_t batch, const FeatureShape &shape) : _batch{batch}, _shape{shape}
+ BCHW(const FeatureShape &shape) : _shape{shape}
{
// DO NOTHING
}
static const FeatureLayout::ID *uid(void);
const FeatureLayout::ID *id(void) const override { return uid(); }
- uint32_t batch(void) const override { return _batch; }
const FeatureShape &shape(void) const override { return _shape; }
ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override;
private:
- uint32_t _batch;
FeatureShape _shape;
public:
- static std::unique_ptr<BCHW> create(const FeatureShape &shape);
+ static std::unique_ptr<BCHW> create(const nncc::core::ADT::feature::Shape &shape);
};
/**
class BHWC : public coco::FeatureLayout
{
private:
- BHWC(uint32_t batch, const FeatureShape &shape) : _batch{batch}, _shape{shape}
+ BHWC(const FeatureShape &shape) : _shape{shape}
{
// DO NOTHING
}
static const FeatureLayout::ID *uid(void);
const FeatureLayout::ID *id(void) const override { return uid(); }
- uint32_t batch(void) const override { return _batch; }
const FeatureShape &shape(void) const override { return _shape; }
coco::ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override;
private:
- uint32_t _batch;
FeatureShape _shape;
public:
- static std::unique_ptr<BHWC> create(const FeatureShape &shape);
+ static std::unique_ptr<BHWC> create(const nncc::core::ADT::feature::Shape &shape);
};
/**
class BC : public coco::FeatureLayout
{
private:
- BC(uint32_t batch, const FeatureShape &shape) : _batch{batch}, _shape{shape}
+ BC(const FeatureShape &shape) : _shape{shape}
{
// DO NOTHING
}
static const FeatureLayout::ID *uid(void);
const FeatureLayout::ID *id(void) const override { return uid(); }
- uint32_t batch(void) const override { return _batch; }
const FeatureShape &shape(void) const override { return _shape; }
coco::ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override;
private:
- uint32_t _batch;
FeatureShape _shape;
public:
- static std::unique_ptr<BC> create(const FeatureShape &shape);
+ static std::unique_ptr<BC> create(const nncc::core::ADT::feature::Shape &shape);
};
/**
static const FeatureLayout::ID *uid(void);
const FeatureLayout::ID *id(void) const override { return uid(); }
- uint32_t batch(void) const override { return _batch; }
const FeatureShape &shape(void) const override { return _shape; }
ElemID &at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col);
uint32_t offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const;
private:
- uint32_t _batch;
FeatureShape _shape;
private:
std::vector<ElemID> _content;
public:
- static std::unique_ptr<Generic> create(const FeatureShape &shape);
+ static std::unique_ptr<Generic> create(const nncc::core::ADT::feature::Shape &shape);
};
} // namespace FeatureLayouts
namespace coco
{
-using FeatureShape = nncc::core::ADT::feature::Shape;
+/**
+ * @brief The shape of a feature map
+ *
+ * TODO Implement coco's own FeatureShape without "nncc::core::ADT::feature::Shape"
+ */
+class FeatureShape : public nncc::core::ADT::feature::Shape
+{
+public:
+ FeatureShape(uint32_t depth, uint32_t height, uint32_t width)
+ : Shape{depth, height, width}, _batch{1}
+ {
+ // DO NOTHING
+ }
+
+ FeatureShape(const nncc::core::ADT::feature::Shape &shape) : Shape{shape}, _batch{1}
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t batch(void) const { return _batch; }
+
+private:
+ uint32_t _batch;
+};
} // namespace coco
std::unique_ptr<BCHW> BCHW::create(const nncc::core::ADT::feature::Shape &shape)
{
// NOTE It is impossible to use make_unique here as the constructor is private
- return std::unique_ptr<BCHW>{new BCHW{1, shape}};
+ return std::unique_ptr<BCHW>{new BCHW{FeatureShape{shape}}};
}
} // namespace FeatureLayouts
std::unique_ptr<BHWC> BHWC::create(const nncc::core::ADT::feature::Shape &shape)
{
// NOTE It is impossible to use make_unique here as the constructor is private
- return std::unique_ptr<BHWC>{new BHWC{1, shape}};
+ return std::unique_ptr<BHWC>{new BHWC{FeatureShape{shape}}};
}
} // namespace FeatureLayouts
ElemID BC::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const
{
- assert(b < _batch);
+ assert(b < shape().batch());
uint32_t offset = 0;
std::unique_ptr<BC> BC::create(const nncc::core::ADT::feature::Shape &shape)
{
// NOTE It is impossible to use make_unique here as the constructor is private
- return std::unique_ptr<BC>{new BC{1, shape}};
+ return std::unique_ptr<BC>{new BC{FeatureShape{shape}}};
}
} // namespace FeatureLayouts
namespace FeatureLayouts
{
-Generic::Generic(const nncc::core::ADT::feature::Shape &shape) : _batch{1}, _shape{shape}
+Generic::Generic(const FeatureShape &shape) : _shape{shape}
{
- _content.resize(_batch * num_elements(_shape));
+ _content.resize(_shape.batch() * num_elements(_shape));
}
const FeatureLayout::ID *Generic::uid(void)
void Generic::reorder(const nncc::core::ADT::feature::Layout &l)
{
- assert(_batch == 1);
+ assert(shape().batch() == 1);
for (uint32_t ch = 0; ch < shape().depth(); ++ch)
{