Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
eigenpy
Commits
65621933
Verified
Commit
65621933
authored
Dec 29, 2020
by
Justin Carpentier
Browse files
core: add new signature to allocate Eigen matrices
parent
7df6480e
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/eigenpy/eigen-allocator.hpp
View file @
65621933
...
...
@@ -19,50 +19,67 @@ namespace eigenpy
template
<
typename
MatType
,
bool
IsVectorAtCompileTime
=
MatType
::
IsVectorAtCompileTime
>
struct
init_matrix_or_array
{
static
MatType
*
run
(
int
rows
,
int
cols
,
void
*
storage
)
{
if
(
storage
)
return
new
(
storage
)
MatType
(
rows
,
cols
);
else
return
new
MatType
(
rows
,
cols
);
}
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
=
NULL
)
{
assert
(
PyArray_NDIM
(
pyArray
)
==
1
||
PyArray_NDIM
(
pyArray
)
==
2
);
int
rows
=
-
1
,
cols
=
-
1
;
if
(
PyArray_NDIM
(
pyArray
)
==
2
)
const
int
ndim
=
PyArray_NDIM
(
pyArray
);
if
(
ndim
==
2
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
}
else
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
else
if
(
ndim
==
1
)
{
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
cols
=
1
;
}
if
(
storage
)
return
new
(
storage
)
MatType
(
rows
,
cols
);
else
return
new
MatType
(
rows
,
cols
);
return
run
(
rows
,
cols
,
storage
);
}
};
template
<
typename
MatType
>
struct
init_matrix_or_array
<
MatType
,
true
>
{
static
MatType
*
run
(
int
rows
,
int
cols
,
void
*
storage
)
{
if
(
storage
)
return
new
(
storage
)
MatType
(
rows
,
cols
);
else
return
new
MatType
(
rows
,
cols
);
}
static
MatType
*
run
(
int
size
,
void
*
storage
)
{
if
(
storage
)
return
new
(
storage
)
MatType
(
size
);
else
return
new
MatType
(
size
);
}
static
MatType
*
run
(
PyArrayObject
*
pyArray
,
void
*
storage
=
NULL
)
{
if
(
PyArray_NDIM
(
pyArray
)
==
1
)
const
int
ndim
=
PyArray_NDIM
(
pyArray
);
if
(
ndim
==
1
)
{
const
int
rows_or_cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
if
(
storage
)
return
new
(
storage
)
MatType
(
rows_or_cols
);
else
return
new
MatType
(
rows_or_cols
);
const
int
size
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
return
run
(
size
,
storage
);
}
else
{
const
int
rows
=
(
int
)
PyArray_DIMS
(
pyArray
)[
0
];
const
int
cols
=
(
int
)
PyArray_DIMS
(
pyArray
)[
1
];
if
(
storage
)
return
new
(
storage
)
MatType
(
rows
,
cols
);
else
return
new
MatType
(
rows
,
cols
);
return
run
(
rows
,
cols
,
storage
);
}
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment