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
Iterations
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
Eclipse Projects
aidge
aidge_core
Commits
10eba2d3
Commit
10eba2d3
authored
1 year ago
by
Maxence Naud
Browse files
Options
Downloads
Patches
Plain Diff
[Upd] Reshape.cpp and Gather.cpp computeOutputDims() function to check input emptyness
parent
66acc5cb
No related branches found
No related tags found
2 merge requests
!105
version 0.2.0
,
!74
Update vit operators
Pipeline
#38308
passed
1 year ago
Stage: static_analysis
Stage: build
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/operator/Gather.cpp
+17
-13
17 additions, 13 deletions
src/operator/Gather.cpp
src/operator/Reshape.cpp
+24
-22
24 additions, 22 deletions
src/operator/Reshape.cpp
with
41 additions
and
35 deletions
src/operator/Gather.cpp
+
17
−
13
View file @
10eba2d3
...
...
@@ -9,8 +9,8 @@
*
********************************************************************************/
#include
<cassert>
#include
<cstddef>
#include
<cstdint>
#include
<string>
#include
<vector>
...
...
@@ -26,18 +26,22 @@ void Aidge::Gather_Op::computeOutputDims() {
AIDGE_THROW_OR_ABORT
(
std
::
runtime_error
,
"Input was not connected"
);
}
std
::
vector
<
DimSize_t
>
outDims
=
getInput
(
0
)
->
dims
();
const
std
::
vector
<
DimSize_t
>
gatheredShape
=
this
->
template
getAttr
<
GatherAttr
::
GatheredShape
>();
// TODO: check indices and gatheredShape
if
(
!
getInput
(
0
)
->
empty
())
{
std
::
vector
<
DimSize_t
>
outDims
=
getInput
(
0
)
->
dims
();
const
std
::
vector
<
DimSize_t
>
gatheredShape
=
this
->
template
getAttr
<
GatherAttr
::
GatheredShape
>();
// TODO: check indices and gatheredShape
const
std
::
int64_t
axisIdx
=
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
>=
0
?
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
:
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
+
outDims
.
size
();
outDims
.
erase
(
outDims
.
begin
()
+
static_cast
<
std
::
size_t
>
(
axisIdx
));
if
(
!
gatheredShape
.
empty
())
{
outDims
.
insert
(
outDims
.
begin
()
+
static_cast
<
std
::
size_t
>
(
axisIdx
),
gatheredShape
.
begin
(),
gatheredShape
.
end
());
}
const
std
::
int64_t
axisIdx
=
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
>=
0
?
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
:
this
->
template
getAttr
<
GatherAttr
::
Axis
>()
+
outDims
.
size
();
outDims
.
erase
(
outDims
.
begin
()
+
static_cast
<
std
::
size_t
>
(
axisIdx
));
if
(
!
gatheredShape
.
empty
())
{
outDims
.
insert
(
outDims
.
cbegin
()
+
static_cast
<
std
::
size_t
>
(
axisIdx
),
gatheredShape
.
cbegin
(),
gatheredShape
.
cend
());
}
mOutputs
[
0
]
->
resize
(
outDims
);
mOutputs
[
0
]
->
resize
(
outDims
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/operator/Reshape.cpp
+
24
−
22
View file @
10eba2d3
...
...
@@ -27,30 +27,32 @@ void Aidge::Reshape_Op::computeOutputDims() {
AIDGE_THROW_OR_ABORT
(
std
::
runtime_error
,
"Input was not connected"
);
}
std
::
vector
<
DimSize_t
>
outDims
;
// variables to handle a negative dimension
bool
foundNegativeDimension
=
false
;
std
::
size_t
outSize
=
1
;
DimIdx_t
negativeIndex
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
this
->
template
getAttr
<
ReshapeAttr
::
Shape
>().
size
();
++
i
)
{
std
::
int64_t
dimSize
=
this
->
template
getAttr
<
ReshapeAttr
::
Shape
>()[
i
];
if
(
dimSize
<
0
)
{
if
(
foundNegativeDimension
)
{
AIDGE_THROW_OR_ABORT
(
std
::
runtime_error
,
"Found more than one negative dimension in Reshape Operator."
);
if
(
!
getInput
(
0
)
->
empty
())
{
std
::
vector
<
DimSize_t
>
outDims
;
// variables to handle a negative dimension
bool
foundNegativeDimension
=
false
;
std
::
size_t
outSize
=
1
;
DimIdx_t
negativeIndex
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
this
->
template
getAttr
<
ReshapeAttr
::
Shape
>().
size
();
++
i
)
{
std
::
int64_t
dimSize
=
this
->
template
getAttr
<
ReshapeAttr
::
Shape
>()[
i
];
if
(
dimSize
<
0
)
{
if
(
foundNegativeDimension
)
{
AIDGE_THROW_OR_ABORT
(
std
::
runtime_error
,
"Found more than one negative dimension in Reshape Operator."
);
}
foundNegativeDimension
=
true
;
dimSize
=
1
;
negativeIndex
=
static_cast
<
DimIdx_t
>
(
i
);
}
foundNegativeDimension
=
true
;
dimSize
=
1
;
negativeIndex
=
static_cast
<
DimIdx_t
>
(
i
);
outDims
.
push_back
(
static_cast
<
DimSize_t
>
(
dimSize
));
outSize
*=
static_cast
<
DimSize_t
>
(
dimSize
);
}
outDims
.
push_back
(
static_cast
<
DimSize_t
>
(
dimSize
));
outSize
*=
static_cast
<
DimSize_t
>
(
dimSize
);
}
if
(
foundNegativeDimension
)
{
outDims
[
negativeIndex
]
=
(
getInput
(
0
)
->
size
())
/
outSize
;
}
if
(
foundNegativeDimension
)
{
outDims
[
negativeIndex
]
=
(
getInput
(
0
)
->
size
())
/
outSize
;
}
mOutputs
[
0
]
->
resize
(
outDims
);
mOutputs
[
0
]
->
resize
(
outDims
);
}
}
\ No newline at end of file
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