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
2d9f6d80
Commit
2d9f6d80
authored
1 year ago
by
Olivier BICHLER
Browse files
Options
Downloads
Patches
Plain Diff
getIdx() accepts less dimensions
parent
80f23f80
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
+11
-13
11 additions, 13 deletions
include/aidge/data/Tensor.hpp
with
11 additions
and
13 deletions
include/aidge/data/Tensor.hpp
+
11
−
13
View file @
2d9f6d80
...
...
@@ -338,9 +338,7 @@ class Tensor : public Data,
*/
template
<
std
::
array
<
DimSize_t
,
1
>
::
size_type
DIM
>
// deducing std::array size_type and declaring DIM accordingly
void
resize
(
const
std
::
array
<
DimSize_t
,
DIM
>
&
dims
)
{
static_assert
(
DIM
<=
MaxDim
,
"Too many tensor dimensions required by resize, not supported"
);
mDims
.
assign
(
dims
.
begin
(),
dims
.
end
());
computeSize
();
resize
(
std
::
vector
<
DimSize_t
>
(
dims
.
begin
(),
dims
.
end
()));
}
/**
...
...
@@ -504,9 +502,9 @@ class Tensor : public Data,
}
/**
* @brief From the the 1D index, return the coordinate of an element in the tensor.
* @brief From the the 1D
contiguous
index, return the coordinate of an element in the tensor.
*
* @param flatIdx 1D index of the value considering a flatten tensor.
* @param flatIdx 1D
contiguous
index of the value considering a flatten
, contiguous,
tensor.
* @return std::vector<DimSize_t>
*/
std
::
vector
<
std
::
size_t
>
getCoord
(
std
::
size_t
flatIdx
)
const
{
...
...
@@ -521,19 +519,19 @@ class Tensor : public Data,
}
/**
* @brief From the coordinate returns the 1D index of an element in the tensor.
* @brief From the coordinate returns the 1D contiguous index of an element in the tensor.
* If the number of coordinates is inferior to the number of dimensions,
* the remaining coordinates are assumed to be 0.
*
* @param coordIdx Coordinate to an element in the tensor
* @return DimSize_t
* @return DimSize_t
Contiguous index
*/
std
::
size_t
getIdx
(
std
::
vector
<
std
::
size_t
>
coordIdx
)
const
{
// std::size_t flatIdx = 0;
// std::size_t stride = 1;
std
::
size_t
getIdx
(
const
std
::
vector
<
std
::
size_t
>&
coordIdx
)
const
{
AIDGE_ASSERT
(
coordIdx
.
size
()
<=
mDims
.
size
(),
"Coordinates does not match number of dimensions"
);
std
::
size_t
flatIdx
=
0
;
assert
(
coordIdx
.
size
()
==
mDims
.
size
()
&&
"Coordinates does not match number of dimensions"
);
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"
);
for
(;
i
<
coordIdx
.
size
()
-
1
;
++
i
){
AIDGE_ASSERT
(
coordIdx
[
i
]
<
mDims
[
i
]
,
"Coordinates dimensions does not fit the dimensions of the tensor"
);
flatIdx
=
(
flatIdx
+
coordIdx
[
i
])
*
mDims
[
i
+
1
];
}
return
flatIdx
+
coordIdx
[
i
];
...
...
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