Skip to content
Snippets Groups Projects

[Add] Resize Operator unit-tests

Closed Michal Szczepanski requested to merge mszczep/aidge_core:operator_resize into dev
Files
3
+ 11
5
@@ -65,13 +65,18 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
std::vector<DimSize_t> outDims = getInput(0)->dims();
const std::vector<DimSize_t> inDims = getInput(0)->dims();
// declaration of smart pointer that retains shared owenership of an object, a dynamic type of tensor
std::shared_ptr<Tensor> fallback;
const auto& scales = getInput(2)->refCastFrom(fallback, NativeType<int64_t>::type, "cpu");
// const referance variable -> initializing with the results of refCastFrom function
// refCastFrom is called on the object returned by getInput(2)
// function cast input tensor to the type specified
const auto& scales = getInput(2)->refCastFrom(fallback, NativeType<float>::type, "cpu");
for (std::size_t dim=0; dim < getInput(2)->size(); ++dim) {
outDims[dim] = inDims[dim]*static_cast<int64_t*>(scales.getImpl()->hostPtr())[dim];
float scale = static_cast<float*>(scales.getImpl()->hostPtr())[dim];
outDims[dim] = static_cast<int64_t>(inDims[dim] * scale);
}
mOutputs[0]->resize(outDims);
return true;
}
@@ -89,8 +94,9 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
std::shared_ptr<Tensor> fallback;
const auto& sizes = getInput(3)->refCastFrom(fallback, NativeType<int64_t>::type, "cpu");
for (std::size_t dim=0; dim < getInput(3)->size(); ++dim) {
outDims[dim] = static_cast<int64_t*>(sizes.getImpl()->hostPtr())[dim];
// Replace the last two dimensions of outDims with the last two dimensions from sizes
for (std::size_t dim = sizes.size() - 2; dim < sizes.size(); ++dim) {
outDims[outDims.size() - 2 + (dim - (sizes.size() - 2))] = static_cast<int64_t*>(sizes.getImpl()->hostPtr())[dim];
}
mOutputs[0]->resize(outDims);
Loading