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
7f6768d0
Commit
7f6768d0
authored
3 months ago
by
Wissam Boussella
Browse files
Options
Downloads
Patches
Plain Diff
Refactor setDataFormat method to improve data type handling and transformation logic
parent
167021e1
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
+35
-10
35 additions, 10 deletions
include/aidge/data/Tensor.hpp
with
35 additions
and
10 deletions
include/aidge/data/Tensor.hpp
+
35
−
10
View file @
7f6768d0
...
...
@@ -452,19 +452,44 @@ public:
}
/**
* @brief Set the DataFormat of the Tensor and transpose data, only
* if the Tensor has already been initialized and copyTrans is true.
* In this case, a transposition occurs only if both previous format and
* new format are different from DataFormat::Default.
* @param df New DataFormat
* @param copyTrans If true (default), when both previous format and new
* format are different from DataFormat::Default, previous
* data is copy-transposed.
* @brief Set the DataType of the Tensor and converts data
* if the Tensor has already been initialized and copyCast is true.
* @param dt DataType
* @param copyCast If true (default), previous data is copy-casted. Otherwise
* previous data is lost.
*/
void
setDataFormat
(
const
DataFormat
df
,
bool
copyTrans
=
true
)
{
if
(
mImpl
&&
copyTrans
&&
(
dataFormat
()
!=
df
)
&&
df
!=
DataFormat
::
Default
&&
dataFormat
()
!=
DataFormat
::
Default
)
{
copyTranspose
(
*
this
,
getDataFormatTranspose
(
dataFormat
(),
df
));
if
(
!
copyTrans
||
df
==
dataFormat
())
{
mDataFormat
=
df
;
return
;
}
// Skip transformation if both formats are Default or NNCH
if
((
df
==
DataFormat
::
Default
&&
dataFormat
()
==
DataFormat
::
Default
)
||
df
==
DataFormat
::
NCHW
&&
dataFormat
()
==
DataFormat
::
NCHW
)
{
mDataFormat
=
df
;
return
;
}
const
auto
transpose
=
getDataFormatTranspose
(
dataFormat
(),
df
);
if
(
mImpl
)
{
copyTranspose
(
*
this
,
transpose
);
}
else
{
std
::
vector
<
DimSize_t
>
newDims
;
newDims
.
reserve
(
nbDims
());
for
(
std
::
size_t
i
=
0
;
i
<
nbDims
();
++
i
)
{
newDims
.
push_back
(
dims
()[
transpose
[
i
]]);
}
mDims
=
std
::
move
(
newDims
);
std
::
vector
<
std
::
size_t
>
newStrides
(
nbDims
(),
1
);
for
(
size_t
i
=
0
;
i
<
nbDims
();
++
i
)
{
for
(
size_t
j
=
i
+
1
;
j
<
nbDims
();
++
j
)
{
newStrides
[
i
]
*=
newDims
[
j
];
}
}
mStrides
=
std
::
move
(
newStrides
);
}
mDataFormat
=
df
;
}
...
...
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