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
fa5c666b
Commit
fa5c666b
authored
Aug 08, 2017
by
Davis King
Browse files
Added an overload of mat() that takes a row stride value.
parent
594df9a6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
4 deletions
+77
-4
dlib/matrix/matrix_blas_bindings.h
dlib/matrix/matrix_blas_bindings.h
+2
-2
dlib/matrix/matrix_mat.h
dlib/matrix/matrix_mat.h
+31
-2
dlib/matrix/matrix_mat_abstract.h
dlib/matrix/matrix_mat_abstract.h
+29
-0
dlib/test/matrix.cpp
dlib/test/matrix.cpp
+15
-0
No files found.
dlib/matrix/matrix_blas_bindings.h
View file @
fa5c666b
...
@@ -424,7 +424,7 @@ namespace dlib
...
@@ -424,7 +424,7 @@ namespace dlib
template
<
typename
T
>
template
<
typename
T
>
int
get_ld
(
const
matrix_op
<
op_pointer_to_col_vect
<
T
>
>&
m
)
{
return
m
.
nc
();
}
int
get_ld
(
const
matrix_op
<
op_pointer_to_col_vect
<
T
>
>&
m
)
{
return
m
.
nc
();
}
template
<
typename
T
>
template
<
typename
T
>
int
get_ld
(
const
matrix_op
<
op_pointer_to_mat
<
T
>
>&
m
)
{
return
m
.
nc
()
;
}
int
get_ld
(
const
matrix_op
<
op_pointer_to_mat
<
T
>
>&
m
)
{
return
m
.
op
.
stride
;
}
// --------
// --------
...
@@ -443,7 +443,7 @@ namespace dlib
...
@@ -443,7 +443,7 @@ namespace dlib
template
<
typename
T
>
template
<
typename
T
>
int
get_inc
(
const
matrix_op
<
op_pointer_to_col_vect
<
T
>
>&
)
{
return
1
;
}
int
get_inc
(
const
matrix_op
<
op_pointer_to_col_vect
<
T
>
>&
)
{
return
1
;
}
template
<
typename
T
>
template
<
typename
T
>
int
get_inc
(
const
matrix_op
<
op_pointer_to_mat
<
T
>
>&
)
{
return
1
;
}
int
get_inc
(
const
matrix_op
<
op_pointer_to_mat
<
T
>
>&
m
)
{
return
m
.
op
.
stride
==
m
.
op
.
cols
?
1
:
0
;
}
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
int
get_inc
(
const
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
)
{
return
1
;
}
int
get_inc
(
const
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
)
{
return
1
;
}
...
...
dlib/matrix/matrix_mat.h
View file @
fa5c666b
...
@@ -319,11 +319,19 @@ namespace dlib
...
@@ -319,11 +319,19 @@ namespace dlib
const
T
*
ptr_
,
const
T
*
ptr_
,
const
long
nr_
,
const
long
nr_
,
const
long
nc_
const
long
nc_
)
:
ptr
(
ptr_
),
rows
(
nr_
),
cols
(
nc_
){}
)
:
ptr
(
ptr_
),
rows
(
nr_
),
cols
(
nc_
),
stride
(
nc_
){}
op_pointer_to_mat
(
const
T
*
ptr_
,
const
long
nr_
,
const
long
nc_
,
const
long
stride_
)
:
ptr
(
ptr_
),
rows
(
nr_
),
cols
(
nc_
),
stride
(
stride_
){}
const
T
*
ptr
;
const
T
*
ptr
;
const
long
rows
;
const
long
rows
;
const
long
cols
;
const
long
cols
;
const
long
stride
;
const
static
long
cost
=
1
;
const
static
long
cost
=
1
;
const
static
long
NR
=
0
;
const
static
long
NR
=
0
;
...
@@ -333,7 +341,7 @@ namespace dlib
...
@@ -333,7 +341,7 @@ namespace dlib
typedef
default_memory_manager
mem_manager_type
;
typedef
default_memory_manager
mem_manager_type
;
typedef
row_major_layout
layout_type
;
typedef
row_major_layout
layout_type
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
ptr
[
r
*
cols
+
c
];
}
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
ptr
[
r
*
stride
+
c
];
}
long
nr
()
const
{
return
rows
;
}
long
nr
()
const
{
return
rows
;
}
long
nc
()
const
{
return
cols
;
}
long
nc
()
const
{
return
cols
;
}
...
@@ -419,6 +427,27 @@ namespace dlib
...
@@ -419,6 +427,27 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
ptr
,
nr
,
nc
));
return
matrix_op
<
op
>
(
op
(
ptr
,
nr
,
nc
));
}
}
template
<
typename
T
>
const
matrix_op
<
op_pointer_to_mat
<
T
>
>
mat
(
const
T
*
ptr
,
long
nr
,
long
nc
,
long
stride
)
{
DLIB_ASSERT
(
nr
>=
0
&&
nc
>=
0
&&
stride
>
0
,
"
\t
const matrix_exp mat(ptr, nr, nc, stride)"
<<
"
\n\t
nr and nc must be >= 0 while stride > 0"
<<
"
\n\t
nr: "
<<
nr
<<
"
\n\t
nc: "
<<
nc
<<
"
\n\t
stride: "
<<
stride
);
typedef
op_pointer_to_mat
<
T
>
op
;
return
matrix_op
<
op
>
(
op
(
ptr
,
nr
,
nc
,
stride
));
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/matrix/matrix_mat_abstract.h
View file @
fa5c666b
...
@@ -153,6 +153,35 @@ namespace dlib
...
@@ -153,6 +153,35 @@ namespace dlib
the pointer and thus will not delete or free it.
the pointer and thus will not delete or free it.
!*/
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
const
matrix_exp
mat
(
const
T
*
ptr
,
long
nr
,
long
nc
,
long
stride
);
/*!
requires
- nr >= 0
- nc >= 0
- stride > 0
- ptr == a pointer to at least (nr-1)*stride+nc T objects (or the NULL pointer if nr*nc==0)
ensures
- returns a matrix M such that:
- M.nr() == nr
- m.nc() == nc
- for all valid r and c:
M(r,c) == ptr[r*stride + c]
(i.e. the pointer is interpreted as a matrix laid out in memory
in row major order, with a row stride of the given stride amount.)
- Note that the returned matrix doesn't take "ownership" of
the pointer and thus will not delete or free it.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
dlib/test/matrix.cpp
View file @
fa5c666b
...
@@ -1350,6 +1350,21 @@ namespace
...
@@ -1350,6 +1350,21 @@ namespace
DLIB_TEST
(
mm
(
3
)
==
4
);
DLIB_TEST
(
mm
(
3
)
==
4
);
}
}
{
const
long
n
=
5
;
matrix
<
double
>
m1
,
m2
,
m3
,
truth
;
m1
=
randm
(
n
,
n
);
m2
=
randm
(
n
,
n
);
rectangle
rect1
(
1
,
1
,
3
,
3
);
rectangle
rect2
(
2
,
1
,
4
,
3
);
truth
=
subm
(
m1
,
rect1
)
*
subm
(
m2
,
rect2
);
m3
=
mat
(
&
m1
(
0
,
0
)
+
6
,
3
,
3
,
m1
.
nc
())
*
mat
(
&
m2
(
0
,
0
)
+
7
,
3
,
3
,
m2
.
nc
());
DLIB_TEST
(
max
(
abs
(
truth
-
m3
))
<
1e-13
);
}
{
{
const
long
n
=
5
;
const
long
n
=
5
;
matrix
<
double
>
m1
,
m2
,
m3
,
truth
;
matrix
<
double
>
m1
,
m2
,
m3
,
truth
;
...
...
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