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
421e5bcd
Commit
421e5bcd
authored
Jun 26, 2013
by
Davis King
Browse files
Added a dot() and slicing support to dlib.vector()
parent
20ed7ebe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
tools/python/src/vector.cpp
tools/python/src/vector.cpp
+32
-0
No files found.
tools/python/src/vector.cpp
View file @
421e5bcd
...
...
@@ -5,6 +5,7 @@
#include <boost/shared_ptr.hpp>
#include <dlib/matrix.h>
#include "serialize_pickle.h"
#include <boost/python/slice.hpp>
using
namespace
dlib
;
...
...
@@ -19,6 +20,11 @@ void cv_set_size(cv& m, long s)
m
=
0
;
}
double
dotprod
(
const
cv
&
a
,
const
cv
&
b
)
{
return
dot
(
a
,
b
);
}
string
cv__str__
(
const
cv
&
v
)
{
ostringstream
sout
;
...
...
@@ -100,6 +106,29 @@ double cv__getitem__(cv& m, long r)
}
cv
cv__getitem2__
(
cv
&
m
,
slice
r
)
{
slice
::
range
<
cv
::
iterator
>
bounds
;
bounds
=
r
.
get_indices
<>
(
m
.
begin
(),
m
.
end
());
long
num
=
(
bounds
.
stop
-
bounds
.
start
+
1
);
// round num up to the next multiple of bounds.step.
if
((
num
%
bounds
.
step
)
!=
0
)
num
+=
bounds
.
step
-
num
%
bounds
.
step
;
cv
temp
(
num
/
bounds
.
step
);
if
(
temp
.
size
()
==
0
)
return
temp
;
long
ii
=
0
;
while
(
bounds
.
start
!=
bounds
.
stop
)
{
temp
(
ii
++
)
=
*
bounds
.
start
;
std
::
advance
(
bounds
.
start
,
bounds
.
step
);
}
temp
(
ii
)
=
*
bounds
.
start
;
return
temp
;
}
tuple
cv_get_matrix_size
(
cv
&
m
)
{
return
make_tuple
(
m
.
nr
(),
m
.
nc
());
...
...
@@ -115,8 +144,11 @@ void bind_vector()
.
def
(
"__str__"
,
&
cv__str__
)
.
def
(
"__len__"
,
&
cv__len__
)
.
def
(
"__getitem__"
,
&
cv__getitem__
)
.
def
(
"__getitem__"
,
&
cv__getitem2__
)
.
def
(
"__setitem__"
,
&
cv__setitem__
)
.
add_property
(
"shape"
,
&
cv_get_matrix_size
)
.
def_pickle
(
serialize_pickle
<
cv
>
());
def
(
"dot"
,
dotprod
,
"Compute the dot product between two dense column vectors."
);
}
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