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
d41c2493
Commit
d41c2493
authored
6 years ago
by
Mark Winter
Browse files
Options
Downloads
Patches
Plain Diff
Implemented mex struct/array changes
parent
099e0d6d
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/Mex/MexTypes.h
+45
-8
45 additions, 8 deletions
src/c/Mex/MexTypes.h
with
45 additions
and
8 deletions
src/c/Mex/MexTypes.h
+
45
−
8
View file @
d41c2493
...
...
@@ -24,20 +24,21 @@ namespace Script
TYPE_MAPPING
(
double
,
mxDOUBLE_CLASS
)
END_TYPE_MAP
(
mxClassID
)
// Helper functions for array allocation
template
<
typename
T
>
ArrayType
*
createArray
(
const
DimInfo
&
info
)
template
<
typename
...
Args
>
inline
void
writeMsg
(
const
char
*
fmt
,
Args
&&
...
args
)
{
return
mxCreateNumericArray
(
info
.
dims
.
size
(),
info
.
dims
.
data
(),
ID_FROM_TYPE
(
T
),
mxREAL
);
mexPrintf
(
fmt
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
>
inline
ArrayType
*
createArray
<
bool
>
(
const
DimInfo
&
info
)
template
<
typename
...
Args
>
inline
void
errorMsg
(
const
char
*
fmt
,
Args
&&
...
args
)
{
return
mxCreateLogicalArray
(
info
.
dims
.
size
(),
info
.
dims
.
data
());
mexErrMsgTxt
(
formatMsg
(
fmt
,
std
::
forward
<
Args
>
(
args
)...).
c_str
());
}
namespace
ArrayInfo
namespace
Array
{
inline
bool
isColumnMajor
(
const
ArrayType
*
im
){
return
true
;}
inline
bool
isContiguous
(
const
ArrayType
*
im
){
return
true
;}
...
...
@@ -47,5 +48,41 @@ namespace Script
template
<
typename
T
>
T
*
getData
(
const
ArrayType
*
im
)
{
return
(
T
*
)
mxGetData
(
im
);
}
// Helper functions for array allocation
template
<
typename
T
>
ArrayType
*
create
(
const
DimInfo
&
info
)
{
return
mxCreateNumericArray
(
info
.
dims
.
size
(),
info
.
dims
.
data
(),
ID_FROM_TYPE
(
T
),
mxREAL
);
}
template
<
>
inline
ArrayType
*
create
<
bool
>
(
const
DimInfo
&
info
)
{
return
mxCreateLogicalArray
(
info
.
dims
.
size
(),
info
.
dims
.
data
());
}
};
// Minimal wrapper around script structure types
namespace
Struct
{
const
ObjectType
*
getVal
(
ObjectType
*
structPtr
,
std
::
size_t
idx
,
const
char
*
field
)
{
return
mxGetField
(
structPtr
,
idx
,
field
);
}
void
setVal
(
ObjectType
*
structPtr
,
std
::
size_t
idx
,
const
char
*
field
,
ObjectType
*
val
)
{
mxSetField
(
structPtr
,
idx
,
field
,
val
);
}
// Wrapper around script structure-array creation/access
ObjectType
*
create
(
std
::
size_t
size
,
const
std
::
vector
<
const
char
*>&
fields
)
{
const
char
**
fieldData
=
const_cast
<
const
char
**>
(
fields
.
data
());
return
mxCreateStructMatrix
(
size
,
1
,
(
int
)
fields
.
size
(),
fieldData
);
}
};
};
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