Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
ArmarX
RobotAPI
Commits
b8921a75
Commit
b8921a75
authored
2 years ago
by
Fabian Tërnava
Browse files
Options
Downloads
Patches
Plain Diff
Revert "more vector conversion methods"
This reverts commit
22e7d7df
.
parent
b302f62e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!332
Rename ARON numeric primitive typenames
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/RobotAPI/libraries/aron/converter/common/VectorConverter.h
+11
-74
11 additions, 74 deletions
...obotAPI/libraries/aron/converter/common/VectorConverter.h
with
11 additions
and
74 deletions
source/RobotAPI/libraries/aron/converter/common/VectorConverter.h
+
11
−
74
View file @
b8921a75
...
...
@@ -37,93 +37,37 @@ namespace armarx::aron::converter
{
class
AronVectorConverter
{
private:
template
<
typename
T
>
static
std
::
vector
<
T
>
convert_to_1d_vector
(
const
unsigned
char
*
data
,
const
int
elements
,
const
int
offset
,
const
int
size
)
{
ARMARX_CHECK_NOT_NULL
(
data
);
std
::
vector
<
T
>
v
(
elements
);
memcpy
(
v
.
data
(),
data
,
size
);
return
v
;
}
public:
AronVectorConverter
()
=
delete
;
template
<
typename
T
>
static
std
::
vector
<
std
::
vector
<
T
>>
ConvertTo2DVector
(
const
data
::
NDArray
&
nav
)
{
const
auto
&
dims
=
nav
.
getShape
();
if
(
dims
.
size
()
!=
3
)
{
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"The NDArray must have 3 dimensions."
,
nav
.
getPath
());
}
if
(
dims
.
at
(
dims
.
size
()
-
1
)
!=
sizeof
(
T
))
{
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"Last dimension of the array has to match the element size."
,
nav
.
getPath
());
}
const
int
one_row_size
=
dims
.
at
(
1
)
*
dims
.
at
(
2
);
std
::
vector
<
std
::
vector
<
T
>>
v
(
dims
.
at
(
0
));
for
(
int
i
=
0
;
i
<
dims
.
at
(
0
);
i
++
)
{
v
[
i
]
=
convert_to_1d_vector
<
T
>
(
nav
.
getData
(),
dims
.
at
(
1
),
i
*
one_row_size
,
one_row_size
);
}
return
v
;
}
template
<
typename
T
>
static
std
::
vector
<
std
::
vector
<
T
>>
ConvertTo2DVector
(
const
data
::
NDArrayPtr
&
nav
)
static
std
::
vector
<
T
>
ConvertToVector
(
const
data
::
NDArrayPtr
&
nav
)
{
ARMARX_CHECK_NOT_NULL
(
nav
);
return
ConvertTo2DVector
<
T
>
(
*
nav
);
}
template
<
typename
T
>
static
std
::
vector
<
T
>
ConvertTo1DVector
(
const
data
::
NDArray
&
nav
,
const
bool
allowFlatten
=
false
)
{
const
auto
&
dims
=
nav
.
getShape
();
const
auto
&
dims
=
nav
->
getShape
();
if
(
!
allowFlatten
&&
dims
.
size
()
!=
2
)
if
(
dims
.
size
()
!=
2
)
{
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"The NDArray must have
2
dimensions."
,
nav
.
getPath
());
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"The NDArray must have
two
dimensions."
,
nav
->
getPath
());
}
if
(
dims
.
at
(
dims
.
size
()
-
1
)
!=
sizeof
(
T
))
if
(
dims
.
at
(
1
)
!=
sizeof
(
T
))
{
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"
Last d
imension of the array has to match the element size."
,
nav
.
getPath
());
throw
error
::
AronException
(
__PRETTY_FUNCTION__
,
"
D
imension
1
of the array has to match the element size."
,
nav
->
getPath
());
}
const
int
one_row_size
=
std
::
accumulate
(
std
::
begin
(
dims
),
std
::
end
(
dims
),
1
,
std
::
multiplies
<>
());
std
::
vector
<
T
>
v
=
convert_to_1d_vector
<
T
>
(
nav
.
getData
(),
dims
.
at
(
0
),
0
,
one_row_size
);
return
v
;
}
const
int
size
=
std
::
accumulate
(
std
::
begin
(
dims
),
std
::
end
(
dims
),
1
,
std
::
multiplies
<>
());
template
<
typename
T
>
static
std
::
vector
<
T
>
ConvertTo1DVector
(
const
data
::
NDArrayPtr
&
nav
,
const
bool
allowFlatten
=
false
)
{
ARMARX_CHECK_NOT_NULL
(
nav
);
std
::
vector
<
T
>
v
(
dims
.
at
(
0
));
memcpy
(
v
.
data
(),
nav
->
getData
(),
size
);
return
ConvertTo1DVector
<
T
>
(
*
nav
,
allowFlatten
);
}
// alias
template
<
typename
T
>
static
std
::
vector
<
T
>
ConvertToVector
(
const
data
::
NDArrayPtr
&
nav
,
const
bool
allowFlatten
=
false
)
{
return
ConvertTo1DVector
<
T
>
(
nav
,
allowFlatten
);
return
v
;
}
// Attention: If a vector was flattened, the reconstruction is flattened as well!
template
<
typename
T
>
static
data
::
NDArrayPtr
ConvertFrom
1D
Vector
(
const
std
::
vector
<
T
>&
data
)
static
data
::
NDArrayPtr
ConvertFromVector
(
const
std
::
vector
<
T
>&
data
)
{
data
::
NDArrayPtr
ndArr
(
new
data
::
NDArray
);
...
...
@@ -133,13 +77,6 @@ namespace armarx::aron::converter
return
ndArr
;
}
// alias
template
<
typename
T
>
static
data
::
NDArrayPtr
ConvertFromVector
(
const
std
::
vector
<
T
>&
data
)
{
return
ConvertFrom1DVector
<
T
>
(
data
);
}
};
}
// namespace armarx::aron::converter
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