Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
5ecd904d
Commit
5ecd904d
authored
Jul 21, 2016
by
Davis King
Browse files
merged
parents
cf321559
fd6db821
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
339 additions
and
294 deletions
+339
-294
dlib/matlab/cmake_mex_wrapper
dlib/matlab/cmake_mex_wrapper
+1
-1
dlib/matlab/mex_wrapper.cpp
dlib/matlab/mex_wrapper.cpp
+215
-215
dlib/matlab/subprocess_stream.cpp
dlib/matlab/subprocess_stream.cpp
+13
-2
dlib/matrix/matrix.h
dlib/matrix/matrix.h
+8
-8
dlib/matrix/matrix_data_layout.h
dlib/matrix/matrix_data_layout.h
+102
-68
No files found.
dlib/matlab/cmake_mex_wrapper
View file @
5ecd904d
...
@@ -54,7 +54,7 @@ INCLUDE_DIRECTORIES("${dlib_matlab_binding_path}")
...
@@ -54,7 +54,7 @@ INCLUDE_DIRECTORIES("${dlib_matlab_binding_path}")
# Also add dlib to the include search path
# Also add dlib to the include search path
INCLUDE_DIRECTORIES(${dlib_matlab_binding_path}/../..)
INCLUDE_DIRECTORIES(${dlib_matlab_binding_path}/../..)
include(${dlib_matlab_binding_path}/../add_global_compiler_switch.cmake)
include(${dlib_matlab_binding_path}/../
cmake_utils/
add_global_compiler_switch.cmake)
add_global_define(MATLAB_MEX_FILE)
add_global_define(MATLAB_MEX_FILE)
# Determine the path to our CMakeLists.txt file. This is the file that
# Determine the path to our CMakeLists.txt file. This is the file that
...
...
dlib/matlab/mex_wrapper.cpp
View file @
5ecd904d
This diff is collapsed.
Click to expand it.
dlib/matlab/subprocess_stream.cpp
View file @
5ecd904d
...
@@ -434,9 +434,20 @@ namespace dlib
...
@@ -434,9 +434,20 @@ namespace dlib
stderr_pipe
.
close
();
stderr_pipe
.
close
();
char
*
argv
[]
=
{(
char
*
)
program_name
,
nullptr
};
char
*
argv
[]
=
{(
char
*
)
program_name
,
nullptr
};
char
*
cudadevs
=
getenv
(
"CUDA_VISIBLE_DEVICES"
);
if
(
cudadevs
)
{
std
::
string
extra
=
std
::
string
(
"CUDA_VISIBLE_DEVICES="
)
+
cudadevs
;
char
*
envp
[]
=
{(
char
*
)
extra
.
c_str
(),
nullptr
};
execve
(
argv
[
0
],
argv
,
envp
);
}
else
{
char
*
envp
[]
=
{
nullptr
};
char
*
envp
[]
=
{
nullptr
};
execve
(
argv
[
0
],
argv
,
envp
);
execve
(
argv
[
0
],
argv
,
envp
);
}
// If launching the child didn't work then bail immediately so the parent
// If launching the child didn't work then bail immediately so the parent
// process has no chance to get tweaked out (*cough* MATLAB *cough*).
// process has no chance to get tweaked out (*cough* MATLAB *cough*).
_Exit
(
1
);
_Exit
(
1
);
...
...
dlib/matrix/matrix.h
View file @
5ecd904d
...
@@ -1174,8 +1174,8 @@ namespace dlib
...
@@ -1174,8 +1174,8 @@ namespace dlib
{
{
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
// You can't move memory around when compiled in a matlab mex file and the
// You can't move memory around when compiled in a matlab mex file and the
// different locations have different
persistence
settings.
// different locations have different
ownership
settings.
if
(
data
.
_private_is_
persistent
()
==
item
.
data
.
_private_is_
persistent
())
if
(
data
.
_private_is_
owned_by_matlab
()
==
item
.
data
.
_private_is_
owned_by_matlab
())
{
{
swap
(
item
);
swap
(
item
);
}
}
...
@@ -1195,8 +1195,8 @@ namespace dlib
...
@@ -1195,8 +1195,8 @@ namespace dlib
{
{
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
// You can't move memory around when compiled in a matlab mex file and the
// You can't move memory around when compiled in a matlab mex file and the
// different locations have different
persistence
settings.
// different locations have different
ownership
settings.
if
(
data
.
_private_is_
persistent
()
==
rhs
.
data
.
_private_is_
persistent
())
if
(
data
.
_private_is_
owned_by_matlab
()
==
rhs
.
data
.
_private_is_
owned_by_matlab
())
{
{
swap
(
rhs
);
swap
(
rhs
);
}
}
...
@@ -1343,14 +1343,14 @@ namespace dlib
...
@@ -1343,14 +1343,14 @@ namespace dlib
return
data
.
_private_release_mxArray
();
return
data
.
_private_release_mxArray
();
}
}
void
_private_mark_
non_persistent
()
void
_private_mark_
owned_by_matlab
()
{
{
data
.
_private_mark_
non_persistent
();
data
.
_private_mark_
owned_by_matlab
();
}
}
bool
_private_is_
persistent
()
bool
_private_is_
owned_by_matlab
()
{
{
return
data
.
_private_is_
persistent
();
return
data
.
_private_is_
owned_by_matlab
();
}
}
#endif
#endif
...
...
dlib/matrix/matrix_data_layout.h
View file @
5ecd904d
...
@@ -187,8 +187,8 @@ namespace dlib
...
@@ -187,8 +187,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -257,8 +257,8 @@ namespace dlib
...
@@ -257,8 +257,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -339,8 +339,8 @@ namespace dlib
...
@@ -339,8 +339,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -424,8 +424,8 @@ namespace dlib
...
@@ -424,8 +424,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -511,8 +511,8 @@ namespace dlib
...
@@ -511,8 +511,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
T
*
data
;
T
*
data
;
...
@@ -634,8 +634,8 @@ namespace dlib
...
@@ -634,8 +634,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -704,8 +704,8 @@ namespace dlib
...
@@ -704,8 +704,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -786,8 +786,8 @@ namespace dlib
...
@@ -786,8 +786,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -871,8 +871,8 @@ namespace dlib
...
@@ -871,8 +871,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
private:
private:
...
@@ -938,8 +938,8 @@ namespace dlib
...
@@ -938,8 +938,8 @@ namespace dlib
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
non_persistent
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_mark_
owned_by_matlab
()
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
bool
_private_is_
persistent
()
const
{
return
tru
e
;
}
bool
_private_is_
owned_by_matlab
()
const
{
return
fals
e
;
}
#endif
#endif
long
nr
(
long
nr
(
...
@@ -981,9 +981,11 @@ namespace dlib
...
@@ -981,9 +981,11 @@ namespace dlib
const
static
long
NC
=
num_cols
;
const
static
long
NC
=
num_cols
;
layout
(
layout
(
)
:
data
(
0
),
nr_
(
0
),
nc_
(
0
),
make_persistent
(
tru
e
),
set_by_private_set_mxArray
(
false
),
mem
(
0
)
{
}
)
:
data
(
0
),
nr_
(
0
),
nc_
(
0
),
owned_by_matlab
(
fals
e
),
set_by_private_set_mxArray
(
false
),
mem
(
0
)
{
}
~
layout
()
~
layout
()
{
if
(
owned_by_matlab
)
{
{
if
(
!
set_by_private_set_mxArray
&&
mem
)
if
(
!
set_by_private_set_mxArray
&&
mem
)
{
{
...
@@ -992,6 +994,12 @@ namespace dlib
...
@@ -992,6 +994,12 @@ namespace dlib
data
=
0
;
data
=
0
;
}
}
}
}
else
if
(
data
)
{
delete
[]
data
;
data
=
0
;
}
}
double
&
operator
()
(
double
&
operator
()
(
long
r
,
long
r
,
...
@@ -1015,9 +1023,11 @@ namespace dlib
...
@@ -1015,9 +1023,11 @@ namespace dlib
mxArray
*
mem_
mxArray
*
mem_
)
)
{
{
DLIB_CASSERT
(
mem
==
0
&&
data
==
0
,
"You can't call this function on an already allocated matrix."
);
// We don't own the pointer, so make note of that so we won't try to free
// We don't own the pointer, so make note of that so we won't try to free
// it.
// it.
set_by_private_set_mxArray
=
true
;
set_by_private_set_mxArray
=
true
;
owned_by_matlab
=
true
;
mem
=
mem_
;
mem
=
mem_
;
data
=
mxGetPr
(
mem
);
data
=
mxGetPr
(
mem
);
nr_
=
mxGetM
(
mem
);
nr_
=
mxGetM
(
mem
);
...
@@ -1026,7 +1036,7 @@ namespace dlib
...
@@ -1026,7 +1036,7 @@ namespace dlib
mxArray
*
_private_release_mxArray
()
mxArray
*
_private_release_mxArray
()
{
{
DLIB_CASSERT
(
!
make_persistent
,
""
);
DLIB_CASSERT
(
owned_by_matlab
,
""
);
mxArray
*
temp
=
mem
;
mxArray
*
temp
=
mem
;
mem
=
0
;
mem
=
0
;
set_by_private_set_mxArray
=
false
;
set_by_private_set_mxArray
=
false
;
...
@@ -1036,21 +1046,21 @@ namespace dlib
...
@@ -1036,21 +1046,21 @@ namespace dlib
return
temp
;
return
temp
;
}
}
void
_private_mark_
non_persistent
()
void
_private_mark_
owned_by_matlab
()
{
{
DLIB_CASSERT
(
mem
==
0
,
"You can't convert a persistent matlab array to non-persistent
."
);
DLIB_CASSERT
(
mem
==
0
&&
data
==
0
,
"You can't say a matrix should be owned by matlab after it's been allocated
."
);
make_persistent
=
fals
e
;
owned_by_matlab
=
tru
e
;
}
}
bool
_private_is_
persistent
()
const
bool
_private_is_
owned_by_matlab
()
const
{
{
return
make_persistent
;
return
owned_by_matlab
;
}
}
void
swap
(
void
swap
(
layout
&
item
layout
&
item
)
)
{
{
std
::
swap
(
item
.
make_persistent
,
make_persistent
);
std
::
swap
(
item
.
owned_by_matlab
,
owned_by_matlab
);
std
::
swap
(
item
.
set_by_private_set_mxArray
,
set_by_private_set_mxArray
);
std
::
swap
(
item
.
set_by_private_set_mxArray
,
set_by_private_set_mxArray
);
std
::
swap
(
item
.
mem
,
mem
);
std
::
swap
(
item
.
mem
,
mem
);
std
::
swap
(
item
.
data
,
data
);
std
::
swap
(
item
.
data
,
data
);
...
@@ -1068,6 +1078,8 @@ namespace dlib
...
@@ -1068,6 +1078,8 @@ namespace dlib
long
nr
,
long
nr
,
long
nc
long
nc
)
)
{
if
(
owned_by_matlab
)
{
{
if
(
!
set_by_private_set_mxArray
&&
mem
)
if
(
!
set_by_private_set_mxArray
&&
mem
)
{
{
...
@@ -1080,9 +1092,14 @@ namespace dlib
...
@@ -1080,9 +1092,14 @@ namespace dlib
mem
=
mxCreateDoubleMatrix
(
nr
,
nc
,
mxREAL
);
mem
=
mxCreateDoubleMatrix
(
nr
,
nc
,
mxREAL
);
if
(
mem
==
0
)
if
(
mem
==
0
)
throw
std
::
bad_alloc
();
throw
std
::
bad_alloc
();
if
(
make_persistent
)
mexMakeArrayPersistent
(
mem
);
data
=
mxGetPr
(
mem
);
data
=
mxGetPr
(
mem
);
}
else
{
if
(
data
)
delete
[]
data
;
data
=
new
double
[
nr
*
nc
];
}
nr_
=
nr
;
nr_
=
nr
;
nc_
=
nc
;
nc_
=
nc
;
}
}
...
@@ -1091,7 +1108,7 @@ namespace dlib
...
@@ -1091,7 +1108,7 @@ namespace dlib
double
*
data
;
double
*
data
;
long
nr_
;
long
nr_
;
long
nc_
;
long
nc_
;
bool
make_persistent
;
bool
owned_by_matlab
;
bool
set_by_private_set_mxArray
;
bool
set_by_private_set_mxArray
;
mxArray
*
mem
;
mxArray
*
mem
;
};
};
...
@@ -1107,9 +1124,11 @@ namespace dlib
...
@@ -1107,9 +1124,11 @@ namespace dlib
const
static
long
NC
=
num_cols
;
const
static
long
NC
=
num_cols
;
layout
(
layout
(
)
:
data
(
0
),
nr_
(
0
),
nc_
(
0
),
make_persistent
(
tru
e
),
set_by_private_set_mxArray
(
false
),
mem
(
0
)
{
}
)
:
data
(
0
),
nr_
(
0
),
nc_
(
0
),
owned_by_matlab
(
fals
e
),
set_by_private_set_mxArray
(
false
),
mem
(
0
)
{
}
~
layout
()
~
layout
()
{
if
(
owned_by_matlab
)
{
{
if
(
!
set_by_private_set_mxArray
&&
mem
)
if
(
!
set_by_private_set_mxArray
&&
mem
)
{
{
...
@@ -1118,6 +1137,12 @@ namespace dlib
...
@@ -1118,6 +1137,12 @@ namespace dlib
data
=
0
;
data
=
0
;
}
}
}
}
else
if
(
data
)
{
delete
[]
data
;
data
=
0
;
}
}
float
&
operator
()
(
float
&
operator
()
(
long
r
,
long
r
,
...
@@ -1141,9 +1166,11 @@ namespace dlib
...
@@ -1141,9 +1166,11 @@ namespace dlib
mxArray
*
mem_
mxArray
*
mem_
)
)
{
{
DLIB_CASSERT
(
mem
==
0
&&
data
==
0
,
"You can't call this function on an already allocated matrix."
);
// We don't own the pointer, so make note of that so we won't try to free
// We don't own the pointer, so make note of that so we won't try to free
// it.
// it.
set_by_private_set_mxArray
=
true
;
set_by_private_set_mxArray
=
true
;
owned_by_matlab
=
true
;
mem
=
mem_
;
mem
=
mem_
;
data
=
(
float
*
)
mxGetData
(
mem
);
data
=
(
float
*
)
mxGetData
(
mem
);
nr_
=
mxGetM
(
mem
);
nr_
=
mxGetM
(
mem
);
...
@@ -1152,7 +1179,7 @@ namespace dlib
...
@@ -1152,7 +1179,7 @@ namespace dlib
mxArray
*
_private_release_mxArray
()
mxArray
*
_private_release_mxArray
()
{
{
DLIB_CASSERT
(
!
make_persistent
,
""
);
DLIB_CASSERT
(
owned_by_matlab
,
""
);
mxArray
*
temp
=
mem
;
mxArray
*
temp
=
mem
;
mem
=
0
;
mem
=
0
;
set_by_private_set_mxArray
=
false
;
set_by_private_set_mxArray
=
false
;
...
@@ -1162,21 +1189,21 @@ namespace dlib
...
@@ -1162,21 +1189,21 @@ namespace dlib
return
temp
;
return
temp
;
}
}
void
_private_mark_
non_persistent
()
void
_private_mark_
owned_by_matlab
()
{
{
DLIB_CASSERT
(
mem
==
0
,
"You can't convert a persistent matlab array to non-persistent
."
);
DLIB_CASSERT
(
mem
==
0
&&
data
==
0
,
"You can't say a matrix should be owned by matlab after it's been allocated
."
);
make_persistent
=
fals
e
;
owned_by_matlab
=
tru
e
;
}
}
bool
_private_is_
persistent
()
const
bool
_private_is_
owned_by_matlab
()
const
{
{
return
make_persistent
;
return
owned_by_matlab
;
}
}
void
swap
(
void
swap
(
layout
&
item
layout
&
item
)
)
{
{
std
::
swap
(
item
.
make_persistent
,
make_persistent
);
std
::
swap
(
item
.
owned_by_matlab
,
owned_by_matlab
);
std
::
swap
(
item
.
set_by_private_set_mxArray
,
set_by_private_set_mxArray
);
std
::
swap
(
item
.
set_by_private_set_mxArray
,
set_by_private_set_mxArray
);
std
::
swap
(
item
.
mem
,
mem
);
std
::
swap
(
item
.
mem
,
mem
);
std
::
swap
(
item
.
data
,
data
);
std
::
swap
(
item
.
data
,
data
);
...
@@ -1194,6 +1221,8 @@ namespace dlib
...
@@ -1194,6 +1221,8 @@ namespace dlib
long
nr
,
long
nr
,
long
nc
long
nc
)
)
{
if
(
owned_by_matlab
)
{
{
if
(
!
set_by_private_set_mxArray
&&
mem
)
if
(
!
set_by_private_set_mxArray
&&
mem
)
{
{
...
@@ -1206,9 +1235,14 @@ namespace dlib
...
@@ -1206,9 +1235,14 @@ namespace dlib
mem
=
mxCreateNumericMatrix
(
nr
,
nc
,
mxSINGLE_CLASS
,
mxREAL
);
mem
=
mxCreateNumericMatrix
(
nr
,
nc
,
mxSINGLE_CLASS
,
mxREAL
);
if
(
mem
==
0
)
if
(
mem
==
0
)
throw
std
::
bad_alloc
();
throw
std
::
bad_alloc
();
if
(
make_persistent
)
mexMakeArrayPersistent
(
mem
);
data
=
(
float
*
)
mxGetData
(
mem
);
data
=
(
float
*
)
mxGetData
(
mem
);
}
else
{
if
(
data
)
delete
[]
data
;
data
=
new
float
[
nr
*
nc
];
}
nr_
=
nr
;
nr_
=
nr
;
nc_
=
nc
;
nc_
=
nc
;
}
}
...
@@ -1217,7 +1251,7 @@ namespace dlib
...
@@ -1217,7 +1251,7 @@ namespace dlib
float
*
data
;
float
*
data
;
long
nr_
;
long
nr_
;
long
nc_
;
long
nc_
;
bool
make_persistent
;
bool
owned_by_matlab
;
bool
set_by_private_set_mxArray
;
bool
set_by_private_set_mxArray
;
mxArray
*
mem
;
mxArray
*
mem
;
};
};
...
...
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