Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eigenpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
eigenpy
Commits
a805df9a
Verified
Commit
a805df9a
authored
5 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
core: rename helper
parent
c636bfcd
No related branches found
Branches containing commit
Tags
v2.0.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/eigen-allocator.hpp
+64
-59
64 additions, 59 deletions
include/eigenpy/eigen-allocator.hpp
with
64 additions
and
59 deletions
include/eigenpy/eigen-allocator.hpp
+
64
−
59
View file @
a805df9a
...
...
@@ -11,80 +11,85 @@
namespace
eigenpy
{
template
<
typename
MatType
,
bool
IsVectorAtCompileTime
=
MatType
::
IsVectorAtCompileTime
>
struct
initEigenObject
namespace
details
{
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
)
template
<
typename
MatType
,
bool
IsVectorAtCompileTime
=
MatType
::
IsVectorAtCompileTime
>
struct
init_matrix_or_array
{
assert
(
PyArray_NDIM
(
pyArray
)
==
1
||
PyArray_NDIM
(
pyArray
)
==
2
);
int
rows
=
-
1
,
cols
=
-
1
;
if
(
PyArray_NDIM
(
pyArray
)
==
2
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
}
else
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
1
;
assert
(
PyArray_NDIM
(
pyArray
)
==
1
||
PyArray_NDIM
(
pyArray
)
==
2
);
int
rows
=
-
1
,
cols
=
-
1
;
if
(
PyArray_NDIM
(
pyArray
)
==
2
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
}
else
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
1
;
}
return
new
(
storage
)
MatType
(
rows
,
cols
);
}
return
new
(
storage
)
MatType
(
rows
,
cols
);
}
};
};
template
<
typename
MatType
>
struct
initEigenObject
<
MatType
,
true
>
{
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
)
template
<
typename
MatType
>
struct
init_matrix_or_array
<
MatType
,
true
>
{
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
)
{
const
int
rows_or_cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
return
new
(
storage
)
MatType
(
rows_or_cols
);
}
else
{
const
int
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
const
int
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
return
new
(
storage
)
MatType
(
rows
,
cols
);
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
{
const
int
rows_or_cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
return
new
(
storage
)
MatType
(
rows_or_cols
);
}
else
{
const
int
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
const
int
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
return
new
(
storage
)
MatType
(
rows
,
cols
);
}
}
}
};
};
template
<
typename
Scalar
,
typename
NewScalar
,
bool
cast_is_valid
=
FromTypeToType
<
Scalar
,
NewScalar
>
::
value
>
struct
CastMatToMat
{
template
<
typename
MatrixIn
,
typename
MatrixOut
>
static
void
run
(
const
Eigen
::
MatrixBase
<
MatrixIn
>
&
input
,
const
Eigen
::
MatrixBase
<
MatrixOut
>
&
dest
)
template
<
typename
Scalar
,
typename
NewScalar
,
bool
cast_is_valid
=
FromTypeToType
<
Scalar
,
NewScalar
>
::
value
>
struct
cast_matrix_or_array
{
MatrixOut
&
dest_
=
const_cast
<
MatrixOut
&>
(
dest
.
derived
());
if
(
dest
.
rows
()
==
input
.
rows
())
dest_
=
input
.
template
cast
<
NewScalar
>();
else
dest_
=
input
.
transpose
().
template
cast
<
NewScalar
>();
}
};
template
<
typename
MatrixIn
,
typename
MatrixOut
>
static
void
run
(
const
Eigen
::
MatrixBase
<
MatrixIn
>
&
input
,
const
Eigen
::
MatrixBase
<
MatrixOut
>
&
dest
)
{
MatrixOut
&
dest_
=
const_cast
<
MatrixOut
&>
(
dest
.
derived
());
if
(
dest
.
rows
()
==
input
.
rows
())
dest_
=
input
.
template
cast
<
NewScalar
>();
else
dest_
=
input
.
transpose
().
template
cast
<
NewScalar
>();
}
};
template
<
typename
Scalar
,
typename
NewScalar
>
struct
CastMatToMat
<
Scalar
,
NewScalar
,
false
>
{
template
<
typename
MatrixIn
,
typename
MatrixOut
>
static
void
run
(
const
Eigen
::
MatrixBase
<
MatrixIn
>
&
/*input*/
,
const
Eigen
::
MatrixBase
<
MatrixOut
>
&
/*dest*/
)
template
<
typename
Scalar
,
typename
NewScalar
>
struct
cast_matrix_or_array
<
Scalar
,
NewScalar
,
false
>
{
// do nothing
assert
(
"Must never happened"
);
}
};
template
<
typename
MatrixIn
,
typename
MatrixOut
>
static
void
run
(
const
Eigen
::
MatrixBase
<
MatrixIn
>
&
/*input*/
,
const
Eigen
::
MatrixBase
<
MatrixOut
>
&
/*dest*/
)
{
// do nothing
assert
(
"Must never happened"
);
}
};
}
// namespace details
#define EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType,Scalar,NewScalar,pyArray,mat) \
CastMatToMat
<Scalar,NewScalar>::run(MapNumpy<MatType,Scalar>::map(pyArray),mat)
details::cast_matrix_or_array
<Scalar,NewScalar>::run(MapNumpy<MatType,Scalar>::map(pyArray),mat)
#define EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType,Scalar,NewScalar,mat,pyArray) \
CastMatToMat
<Scalar,NewScalar>::run(mat,MapNumpy<MatType,NewScalar>::map(pyArray))
details::cast_matrix_or_array
<Scalar,NewScalar>::run(mat,MapNumpy<MatType,NewScalar>::map(pyArray))
template
<
typename
MatType
>
struct
EigenObjectAllocator
...
...
@@ -94,7 +99,7 @@ namespace eigenpy
static
void
allocate
(
PyArrayObject
*
pyArray
,
void
*
storage
)
{
Type
*
mat_ptr
=
initEigenObject
<
Type
>::
run
(
pyArray
,
storage
);
Type
*
mat_ptr
=
details
::
init_matrix_or_array
<
Type
>::
run
(
pyArray
,
storage
);
Type
&
mat
=
*
mat_ptr
;
const
int
pyArray_Type
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
...
...
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