Skip to content
Snippets Groups Projects

[Add] Resize Operator unit-tests

Closed Michal Szczepanski requested to merge mszczep/aidge_core:operator_resize into dev
All threads resolved!
Files
4
+ 122
0
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_CORE_OPERATOR_Resize_H_
#define AIDGE_CORE_OPERATOR_Resize_H_
#include <memory>
#include <vector>
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
enum class ResizeAttr { NoROI, NoScales, NoSizes };
class Resize_Op : public OperatorTensor,
public Registrable<Resize_Op, std::string, std::shared_ptr<OperatorImpl>(const Resize_Op&)>,
public StaticAttributes<ResizeAttr,
bool,
bool,
bool> {
public:
static const std::string Type;
Resize_Op() = delete;
using Attributes_ = StaticAttributes<ResizeAttr,
bool,
bool,
bool>;
template <ResizeAttr e>
using attr = typename Attributes_::template attr<e>;
Resize_Op(const bool noROI, const bool noScales, const bool noSizes)
: OperatorTensor(Type, 1, 3, 1),
// input tensor, onnx optional input [roi/scales/sizes] *constant, output
Attributes_(attr<ResizeAttr::NoROI>(noROI),
attr<ResizeAttr::NoScales>(noScales),
attr<ResizeAttr::NoSizes>(noSizes)) {}
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s),
* but not its input tensors (the new operator has no input associated).
* @param op Operator to copy.
*/
Resize_Op(const Resize_Op& op)
: OperatorTensor(op),
Attributes_(op)
{
// copy an operator
if (!op.backend().empty()) {
SET_IMPL_MACRO(Resize_Op, *this, op.backend());
}
else {
mImpl = nullptr;
}
}
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::Resize_Op
*/
std::shared_ptr<Operator> clone() const override {
return std::make_shared<Resize_Op>(*this);
}
bool dimsForwarded() const override final;
bool forwardDims(bool allowDataDependency = false) override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override final;
static const std::vector<std::string> getInputsName(){
// roi, scales, sizes, even if considered as const parameters/input
return {"data_input", "roi ", "scales", "sizes"};
}
static const std::vector<std::string> getOutputsName(){
return {"data_output"};
}
};
inline std::shared_ptr<Node> Resize(const std::size_t nbInputDims,
const bool noROI,
const bool noScales,
const bool noSizes,
const std::string &name = "") {
auto resize_node = std::make_shared<Node>(std::make_shared<Resize_Op>(noROI, noScales, noSizes), name);
// create empty producers of the same as the rank of input size [nbInputDims]
addProducer(resize_node, 1, std::array<DimSize_t, 1>({noROI ? 0 : nbInputDims}), "roi"); // already sets roi dims
addProducer(resize_node, 2, std::array<DimSize_t, 1>({noScales ? 0 : nbInputDims}), "scales"); // already sets scales dims
addProducer(resize_node, 3, std::array<DimSize_t, 1>({noSizes ? 0 : nbInputDims}), "sizes"); // already sets sizes dims
return resize_node;
}
} // namespace Aidge
namespace {
template <>
const char *const EnumStrings<Aidge::ResizeAttr>::data[] = {
"noROI",
"noScales",
"noSizes"
};
}
#endif /* AIDGE_CORE_OPERATOR_Resize_H_ */
Loading