Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cyril Moineau
aidge_core
Commits
eb8bda50
Commit
eb8bda50
authored
1 year ago
by
Maxence Naud
Browse files
Options
Downloads
Patches
Plain Diff
[Fix] coord conversion functions in Tensor
parent
a2248696
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/aidge/data/Tensor.hpp
+13
-11
13 additions, 11 deletions
include/aidge/data/Tensor.hpp
with
13 additions
and
11 deletions
include/aidge/data/Tensor.hpp
+
13
−
11
View file @
eb8bda50
...
@@ -580,13 +580,14 @@ class Tensor : public Data,
...
@@ -580,13 +580,14 @@ class Tensor : public Data,
* @param flatIdx 1D index of the value considering a flatten tensor.
* @param flatIdx 1D index of the value considering a flatten tensor.
* @return std::vector<DimSize_t>
* @return std::vector<DimSize_t>
*/
*/
std
::
vector
<
std
::
size_t
>
getCoord
(
std
::
size_t
flatIdx
){
std
::
vector
<
std
::
size_t
>
getCoord
(
std
::
size_t
flatIdx
)
const
{
std
::
vector
<
std
::
size_t
>
coordIdx
=
{}
;
std
::
vector
<
std
::
size_t
>
coordIdx
=
std
::
vector
<
std
::
size_t
>
(
mDims
.
size
())
;
std
::
size_t
idx
=
flatIdx
;
std
::
size_t
idx
=
flatIdx
;
for
(
std
::
size_t
d
:
mDims
){
for
(
std
::
size_t
i
=
mDims
.
size
()
-
1
;
i
>
0
;
--
i
){
coordIdx
.
push_back
(
idx
%
d
);
coordIdx
[
i
]
=
(
idx
%
mDims
[
i
]
);
idx
/=
d
;
idx
/=
mDims
[
i
]
;
}
}
coordIdx
[
0
]
=
idx
%
mDims
[
0
];
return
coordIdx
;
return
coordIdx
;
}
}
...
@@ -596,16 +597,17 @@ class Tensor : public Data,
...
@@ -596,16 +597,17 @@ class Tensor : public Data,
* @param coordIdx Coordinate to an element in the tensor
* @param coordIdx Coordinate to an element in the tensor
* @return DimSize_t
* @return DimSize_t
*/
*/
std
::
size_t
getIdx
(
std
::
vector
<
std
::
size_t
>
coordIdx
){
std
::
size_t
getIdx
(
std
::
vector
<
std
::
size_t
>
coordIdx
)
const
{
// std::size_t flatIdx = 0;
// std::size_t stride = 1;
std
::
size_t
flatIdx
=
0
;
std
::
size_t
flatIdx
=
0
;
std
::
size_t
stride
=
1
;
assert
(
coordIdx
.
size
()
==
mDims
.
size
()
&&
"Coordinates does not match number of dimensions"
);
assert
(
coordIdx
.
size
()
==
mDims
.
size
()
&&
"Coordinates does not match number of dimensions"
);
for
(
std
::
size_t
i
=
0
;
i
<
mDims
.
size
();
++
i
){
std
::
size_t
i
=
0
;
for
(;
i
<
mDims
.
size
()
-
1
;
++
i
){
assert
(
coordIdx
[
i
]
<
mDims
[
i
]
&&
"Coordinates dimensions does not fit the dimensions of the tensor"
);
assert
(
coordIdx
[
i
]
<
mDims
[
i
]
&&
"Coordinates dimensions does not fit the dimensions of the tensor"
);
flatIdx
+=
(
coordIdx
[
i
]
*
stride
);
flatIdx
=
(
flatIdx
+
coordIdx
[
i
])
*
mDims
[
i
+
1
];
stride
*=
mDims
[
i
];
}
}
return
flatIdx
;
return
flatIdx
+
coordIdx
[
i
]
;
}
}
private
:
private
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment