Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hydra-image-processor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
OpenSource
hydra-image-processor
Commits
5fa7d91c
Commit
5fa7d91c
authored
6 years ago
by
Mark Winter
Browse files
Options
Downloads
Patches
Plain Diff
Added string conversion routines for python arg converter
parent
3d57fabe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/c/WrapCmds/PyConverters.h
+62
-25
62 additions, 25 deletions
src/c/WrapCmds/PyConverters.h
with
62 additions
and
25 deletions
src/c/WrapCmds/PyConverters.h
+
62
−
25
View file @
5fa7d91c
...
...
@@ -68,6 +68,56 @@ namespace Script
};
};
// Helper struct to handle returning 0,1, or tuple of N outputs
template
<
std
::
size_t
N
>
struct
StoreHelper
{
private:
template
<
typename
...
ScrOuts
,
std
::
size_t
...
Is
>
static
void
store_out_impl
(
Script
::
ObjectType
*&
scriptTuple
,
const
std
::
tuple
<
ScrOuts
...
>&
outputs
,
mph
::
index_sequence
<
Is
...
>
)
{
(
void
)
std
::
initializer_list
<
int
>
{
(
PyTuple_SetItem
(
scriptTuple
,
Is
,
reinterpret_cast
<
Script
::
ObjectType
*>
(
std
::
get
<
Is
>
(
outputs
))),
void
(),
0
)...
};
}
public
:
template
<
typename
...
ScrOuts
>
static
Script
::
ObjectType
*
store_out
(
const
std
::
tuple
<
ScrOuts
...
>&
outputs
)
{
static_assert
(
sizeof
...
(
ScrOuts
)
==
N
,
"**** Output argument selector size mismatch ****"
);
Script
::
ObjectType
*
scriptOut
=
PyTuple_New
(
N
);
store_out_impl
(
scriptOut
,
outputs
,
mph
::
make_index_sequence
<
sizeof
...
(
ScrOuts
)
>
{});
return
scriptOut
;
}
};
template
<
>
struct
StoreHelper
<
1
>
{
template
<
typename
...
ScrOuts
>
static
Script
::
ObjectType
*
store_out
(
const
std
::
tuple
<
ScrOuts
...
>&
outputs
)
{
static_assert
(
sizeof
...
(
ScrOuts
)
==
1
,
"**** Output argument selector size mismatch ****"
);
return
reinterpret_cast
<
Script
::
ObjectType
*>
(
std
::
get
<
0
>
(
outputs
));
}
};
template
<
>
struct
StoreHelper
<
0
>
{
template
<
typename
...
ScrOuts
>
static
Script
::
ObjectType
*
store_out
(
const
std
::
tuple
<
ScrOuts
...
>&
outputs
)
{
static_assert
(
sizeof
...
(
ScrOuts
)
==
0
,
"**** Output argument selector size mismatch ****"
);
return
Py_None
;
}
};
template
<
typename
Derived
,
typename
...
Layout
>
struct
PyArgParser
:
public
ArgParser
<
Derived
,
Layout
...
>
...
...
@@ -118,18 +168,10 @@ namespace Script
static
void
store
(
ScriptPtrs
&
scriptPtrs
,
Script
::
ObjectType
*&
scriptOut
,
Script
::
ObjectType
*
scriptIn
)
{
using
OutInfo
=
typename
mph
::
tuple_info
<
typename
OutputSel
::
template
type
<
ScriptPtrs
>
>
;
auto
outPtrs
=
OutputSel
::
select
(
scriptPtrs
);
auto
outRefs
=
mph
::
tuple_deref
(
outPtrs
);
if
(
OutInfo
::
size
==
1
)
scriptOut
=
reinterpret_cast
<
Script
::
ObjectType
*>
(
std
::
get
<
0
>
(
outRefs
));
else
{
scriptOut
=
PyTuple_New
(
OutInfo
::
size
);
set_out_items
(
scriptOut
,
OutputSel
::
select
(
scriptPtrs
));
}
scriptOut
=
StoreHelper
<
OutputSel
::
seq
::
size
()
>::
store_out
(
outRefs
);
}
public
:
...
...
@@ -148,6 +190,17 @@ namespace Script
outPtr
=
Converter
::
fromNumeric
(
in
);
}
static
void
convert_impl
(
std
::
string
&
out
,
const
Script
::
ObjectType
*
inPtr
)
{
out
=
Converter
::
toString
(
const_cast
<
Script
::
ObjectType
*>
(
inPtr
));
}
template
<
typename
T
>
static
void
convert_impl
(
Script
::
ObjectType
*&
outPtr
,
const
std
::
string
&
in
)
{
outPtr
=
Converter
::
fromString
(
in
);
}
// Vector conversions
template
<
typename
T
>
static
void
convert_impl
(
Vec
<
T
>&
out
,
const
Script
::
ObjectType
*
inPtr
)
...
...
@@ -240,22 +293,6 @@ namespace Script
{
return
parse_script_impl
(
scriptIn
,
format
,
argpack
,
mph
::
make_index_sequence
<
sizeof
...
(
Args
)
>
());
}
template
<
typename
...
Args
,
std
::
size_t
...
Is
>
static
void
set_out_items_impl
(
PyObject
*&
scriptTuple
,
const
std
::
tuple
<
Args
...
>&
argpack
,
mph
::
index_sequence
<
Is
...
>
)
{
(
void
)
std
::
initializer_list
<
int
>
{
(
PyTuple_SetItem
(
scriptTuple
,
Is
,
reinterpret_cast
<
Script
::
ObjectType
*>
(
std
::
get
<
Is
>
(
argpack
))),
void
(),
0
)...
};
}
template
<
typename
...
Args
>
static
void
set_out_items
(
PyObject
*&
scriptTuple
,
const
std
::
tuple
<
Args
...
>&
argpack
)
{
set_out_items_impl
(
scriptTuple
,
argpack
,
mph
::
make_index_sequence
<
sizeof
...
(
Args
)
>
{});
}
};
};
\ 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