Skip to content
Snippets Groups Projects
Commit 690d5e51 authored by laurent soulier's avatar laurent soulier
Browse files

[DSGN] rolling back getCoord prototype to the one of the main branch (passing...

[DSGN] rolling back getCoord prototype to the one of the main branch (passing output by ref was an over-optimisation,, vector move semantic allows for a direct return by value)
parent 7fb46b1f
No related branches found
No related tags found
2 merge requests!41Support for any backend storage,!13Refactoring Tensor
Pipeline #35184 passed
......@@ -191,14 +191,13 @@ public:
};
/// @brief Get the logical coordinates of the data at given index
/// @param coordIdx coordinates of the desired data
/// @param flatIdx 1D index of the value considering a flatten tensor.
/// @note The index is expressed in number of elements
/// @return Logical coordinates of the data at given index
void getCoord(NbElts_t const flatIdx, std::vector<Coord_t> &coordIdx) const noexcept
/// @note return by value is efficient here as it relies on vector move semantic.
std::vector<Coord_t> getCoord(NbElts_t const flatIdx) const noexcept
{
assert(
(coordIdx.size() == mvDimensions.size())
&& "Coordinates dimensions does not fit the dimensions of the tensor");
std::vector<Coord_t> coordIdx(mvDimensions.size());
std::size_t In = flatIdx;
// trick for reverse loop without index underflow
// when i is 1, (i--)>0 is true but i contains 0 on ouput
......@@ -213,6 +212,8 @@ public:
// shift with respect to first data coordinates
coordIdx[i] = coordIdx[i] + mvFirstDataCoordinates[i];
}
return coordIdx;
};
/// @brief Get the linear index of the first Byte_t of the data at given
......
......@@ -518,8 +518,9 @@ public:
*
* @param flatIdx 1D index of the value considering a flatten tensor.
* @return std::vector<DimSize_t>
* @note return by value is efficient here as it relies on vector move semantic.
*/
void getCoord(NbElts_t const flatIdx, std::vector<Coord_t> &coordIdx) const noexcept;
std::vector<Coord_t> getCoord(NbElts_t const flatIdx) const noexcept;
/**
* @brief From the coordinate returns the 1D index of an element in the tensor.
......
......@@ -103,9 +103,7 @@ public:
// xxooo --> ok xxxoo --> out of bound
// xxooo xxxoo
// xxooo xxxoo
std::vector<Coord_t> beginningCoords(DIM);
mInputs[0]->getCoord(
this->template getAttr<SliceAttr::Beginning>(), beginningCoords);
const auto beginningCoords = mInputs[0]->getCoord(this->template getAttr<SliceAttr::Beginning>());
for (std::size_t i = 0; i < DIM; ++i)
{
if (beginningCoords[i] + this->template getAttr<SliceAttr::SliceDims>()[i]
......
......@@ -103,24 +103,7 @@ void init_Tensor(py::module& m)
.def("size", &Tensor::size)
.def("resize", (void (Tensor::*)(const std::vector<DimSize_t>&)) & Tensor::resize)
.def("has_impl", &Tensor::hasImpl)
.def(
"get_coord",
[](Tensor& b, NbElts_t flatIdx) -> std::vector<Coord_t> {
std::vector<Coord_t> Coords(b.dims().size());
/// @todo could be removed soon
assert(
(Coords.size() == b.dims().size())
&& "Python: coordinates dimensions does not fit the dimensions of "
"the tensor");
/// @todo could be removed soon
assert(
(Coords.size() == b.getImpl().getDimensions().size())
&& "Python: coordinates dimensions does not fit the dimensions of "
"the "
"tensorimpl");
b.getCoord(flatIdx, Coords);
return Coords;
})
.def("get_coord",&Tensor::getCoord)
.def("get_idx", &Tensor::getIdx)
.def_static("get_available_backends", &Tensor::getAvailableBackends)
.def("__str__", [](Tensor& b) { return b.toString(); })
......
......@@ -62,10 +62,9 @@ void Tensor::copyFromHost(Byte_t const *const srcPtr, std::size_t const Bytes)
mImpl->copyFromHost(srcPtr, Bytes);
}
void Tensor::getCoord(
NbElts_t const flatIdx, std::vector<Coord_t> &coordIdx) const noexcept
std::vector<Coord_t> Tensor::getCoord(NbElts_t const flatIdx) const noexcept
{
mImpl->getCoord(flatIdx, coordIdx);
return mImpl->getCoord(flatIdx);
}
NbElts_t Tensor::getIdx(std::vector<Coord_t> const &coordIdx) const noexcept
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment