Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
a68c27be
Commit
a68c27be
authored
May 28, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a hash() for matrices.
parent
f338f6b7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
3 deletions
+50
-3
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+17
-0
matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+24
-2
hash.cpp
dlib/test/hash.cpp
+9
-1
No files found.
dlib/matrix/matrix_utilities.h
View file @
a68c27be
...
...
@@ -16,6 +16,7 @@
#include "matrix_expressions.h"
#include "matrix_math_functions.h"
#include "matrix_op.h"
#include "../general_hash/murmur_hash3.h"
namespace
dlib
...
...
@@ -3966,6 +3967,22 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
m
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
uint32
hash
(
const
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
item
,
uint32
seed
=
0
)
{
DLIB_ASSERT_HAS_STANDARD_LAYOUT
(
T
);
if
(
item
.
size
()
==
0
)
return
0
;
else
return
murmur_hash3
(
&
item
(
0
,
0
),
sizeof
(
T
)
*
item
.
size
(),
seed
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
a68c27be
...
...
@@ -667,10 +667,11 @@ namespace dlib
long
NR
,
long
NC
,
typename
MM
,
typename
U
typename
U
,
typename
L
>
void
set_all_elements
(
matrix
<
T
,
NR
,
NC
,
MM
>&
m
,
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
m
,
U
value
);
/*!
...
...
@@ -690,6 +691,27 @@ namespace dlib
(This allows you to easily force a matrix_exp to fully evaluate)
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
uint32
hash
(
const
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
item
,
uint32
seed
=
0
);
/*!
ensures
- returns a 32bit hash of the data stored in item.
- Each value of seed results in a different hash function being used.
(e.g. hash(item,0) should generally not be equal to hash(item,1))
- uses the murmur_hash3() routine to compute the actual hash.
!*/
// ----------------------------------------------------------------------------------------
// if matrix_exp contains non-complex types (e.g. float, double)
...
...
dlib/test/hash.cpp
View file @
a68c27be
...
...
@@ -6,6 +6,7 @@
#include <cstdlib>
#include <ctime>
#include <dlib/hash.h>
#include <dlib/matrix.h>
#include "tester.h"
...
...
@@ -32,6 +33,9 @@ namespace
{
std
::
string
str1
=
"some random string"
;
std
::
wstring
str2
=
L"another String!"
;
matrix
<
unsigned
char
>
mat
(
2
,
2
);
mat
=
1
,
2
,
3
,
4
;
std
::
vector
<
unsigned
char
>
v
(
4
);
v
[
0
]
=
'c'
;
...
...
@@ -48,22 +52,26 @@ namespace
dlog
<<
LINFO
<<
"hash(str2): "
<<
hash
(
str2
);
dlog
<<
LINFO
<<
"hash(v): "
<<
hash
(
v
);
dlog
<<
LINFO
<<
"hash(m): "
<<
hash
(
m
);
dlog
<<
LINFO
<<
"hash(mat): "
<<
hash
(
mat
);
DLIB_TEST
(
hash
(
str1
)
==
1073638390
);
DLIB_TEST
(
hash
(
str2
)
==
2413364589
);
DLIB_TEST
(
hash
(
v
)
==
4054789286
);
DLIB_TEST
(
hash
(
m
)
==
2865512303
);
DLIB_TEST
(
hash
(
mat
)
==
1043635621
);
DLIB_TEST
(
murmur_hash3
(
&
str1
[
0
],
str1
.
size
(),
0
)
==
1073638390
);
dlog
<<
LINFO
<<
"hash(str1,1): "
<<
hash
(
str1
,
1
);
dlog
<<
LINFO
<<
"hash(str2,2): "
<<
hash
(
str2
,
2
);
dlog
<<
LINFO
<<
"hash(v,3): "
<<
hash
(
v
,
3
);
dlog
<<
LINFO
<<
"hash(m,3): "
<<
hash
(
m
,
4
);
dlog
<<
LINFO
<<
"hash(m,4): "
<<
hash
(
m
,
4
);
dlog
<<
LINFO
<<
"hash(mat,5): "
<<
hash
(
mat
,
5
);
DLIB_TEST
(
hash
(
str1
,
1
)
==
2977753747
);
DLIB_TEST
(
hash
(
str2
,
2
)
==
3656927287
);
DLIB_TEST
(
hash
(
v
,
3
)
==
2127112268
);
DLIB_TEST
(
hash
(
m
,
4
)
==
4200495810
);
DLIB_TEST
(
hash
(
mat
,
5
)
==
2380427865
);
DLIB_TEST
(
murmur_hash3
(
&
str1
[
0
],
str1
.
size
(),
1
)
==
2977753747
);
}
...
...
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