Skip to content

Commit

Permalink
sys.big_endian to sys.byteorder (#3422)
Browse files Browse the repository at this point in the history
Summary:

Found vec_io failing when running some benchmarking.
There is no such field named big_endian in sys. So, reverting it to original field byteorder

Differential Revision: D56718607
  • Loading branch information
kuarora authored and facebook-github-bot committed May 10, 2024
1 parent e1e4ad0 commit 3b96c9d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions contrib/vecs_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def ivecs_read(fname):
a = np.fromfile(fname, dtype='int32')
if sys.big_endian:
if sys.byteorder == 'big':
a.byteswap(inplace=True)
d = a[0]
return a.reshape(-1, d + 1)[:, 1:].copy()
Expand All @@ -25,7 +25,7 @@ def fvecs_read(fname):


def ivecs_mmap(fname):
assert not sys.big_endian
assert sys.byteorder != 'big'
a = np.memmap(fname, dtype='int32', mode='r')
d = a[0]
return a.reshape(-1, d + 1)[:, 1:]
Expand All @@ -37,7 +37,7 @@ def fvecs_mmap(fname):

def bvecs_mmap(fname):
x = np.memmap(fname, dtype='uint8', mode='r')
if sys.big_endian:
if sys.byteorder == 'big':
da = x[:4][::-1].copy()
d = da.view('int32')[0]
else:
Expand All @@ -50,7 +50,7 @@ def ivecs_write(fname, m):
m1 = np.empty((n, d + 1), dtype='int32')
m1[:, 0] = d
m1[:, 1:] = m
if sys.big_endian:
if sys.byteorder == 'big':
m1.byteswap(inplace=True)
m1.tofile(fname)

Expand Down

0 comments on commit 3b96c9d

Please sign in to comment.