Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
faiss
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
钟尚武
faiss
Commits
fa91c139
Commit
fa91c139
authored
Apr 09, 2019
by
Matthijs Douze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
take into account torch offset when getting ptr
parent
5555ae7f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
test_pytorch_faiss.py
gpu/test/test_pytorch_faiss.py
+12
-5
No files found.
gpu/test/test_pytorch_faiss.py
View file @
fa91c139
...
...
@@ -11,16 +11,18 @@ import unittest
import
faiss
import
torch
def
swig_ptr_from_FloatTensor
(
x
):
assert
x
.
is_contiguous
()
assert
x
.
dtype
==
torch
.
float32
return
faiss
.
cast_integer_to_float_ptr
(
x
.
storage
()
.
data_ptr
())
return
faiss
.
cast_integer_to_float_ptr
(
x
.
storage
()
.
data_ptr
()
+
x
.
storage_offset
()
*
4
)
def
swig_ptr_from_LongTensor
(
x
):
assert
x
.
is_contiguous
()
assert
x
.
dtype
==
torch
.
int64
,
'dtype=
%
s'
%
x
.
dtype
return
faiss
.
cast_integer_to_long_ptr
(
x
.
storage
()
.
data_ptr
())
return
faiss
.
cast_integer_to_long_ptr
(
x
.
storage
()
.
data_ptr
()
+
x
.
storage_offset
()
*
8
)
def
search_index_pytorch
(
index
,
x
,
k
,
D
=
None
,
I
=
None
):
...
...
@@ -155,10 +157,15 @@ class PytorchFaissInterop(unittest.TestCase):
assert
np
.
all
(
I
==
gt_I
)
assert
np
.
all
(
np
.
abs
(
D
-
gt_D
)
.
max
()
<
1e-4
)
# test on subset
D
,
I
=
search_raw_array_pytorch
(
res
,
xb_t
,
xq_t
[
60
:
80
],
k
)
# back to CPU for verification
D
=
D
.
cpu
()
.
numpy
()
I
=
I
.
cpu
()
.
numpy
()
assert
np
.
all
(
I
==
gt_I
[
60
:
80
])
assert
np
.
all
(
np
.
abs
(
D
-
gt_D
[
60
:
80
])
.
max
()
<
1e-4
)
if
__name__
==
'__main__'
:
...
...
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