8000 ENH: Added libdivide for floor divide by ganesh-k13 · Pull Request #17727 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Added libdivide for floor divide #17727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
179038f
ENH: Added libdiv
ganesh-k13 Nov 7, 2020
e89175b
ENH: Fixed typos in header | use in2 over ip2
ganesh-k13 Nov 7, 2020
565759b
ENH: Added optimal divisor
ganesh-k13 Nov 8, 2020
d0c934c
ENH: Added libdivide header
ganesh-k13 Nov 8, 2020
b02399a
ENH: Made libdivide default
ganesh-k13 Nov 8, 2020
f0ddb7c
ENH: Handled divide by 0 case
ganesh-k13 Nov 8, 2020
72dcc04
ENH: Added libdivide zlib license
ganesh-k13 Nov 9, 2020
19835d2
ENH: Removed empty structure
ganesh-k13 Nov 10, 2020
3975a28
ENH: Auto generate libdivide structs
ganesh-k13 Nov 11, 2020
90e6cf5
ENH: Logic to optimize %
ganesh-k13 Nov 11, 2020
969aa03
ENH: Fix breaking case
ganesh-k13 Nov 11, 2020
44a3a31
ENH: Change comments
ganesh-k13 Nov 11, 2020
b3d70ef
ENH: Improved floor division (#17727)
ganesh-k13 Nov 11, 2020
931134b
ENH: Added asv benchmarks
ganesh-k13 Nov 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ doc/release/*.rst merge=union
numpy/linalg/lapack_lite/f2c.c linguist-vendored
numpy/linalg/lapack_lite/f2c.h linguist-vendored
tools/npy_tempita/* linguist-vendored
numpy/core/include/numpy/libdivide/* linguist-vendored

# Mark some files as generated
numpy/linalg/lapack_lite/f2c_*.c linguist-generated
Expand Down
5 changes: 5 additions & 0 deletions LICENSES_bundled.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ Name: dragon4
Files: numpy/core/src/multiarray/dragon4.c
License: MIT
For license text, see numpy/core/src/multiarray/dragon4.c

Name: libdivide
Files: numpy/core/include/numpy/libdivide/*
License: Zlib
For license text, see numpy/core/include/numpy/libdivide/LICENSE.txt
16 changes: 16 additions & 0 deletions benchmarks/benchmarks/bench_ufunc.py

Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ def time_less_than_scalar2(self, dtype):
(self.d < 1)


class CustomScalarFloorDivideInt(Benchmark):
params = ([np.int8, np.int16, np.int32, np.int64], [8, -8, 43, -43, 0])
param_names = ['dtype', 'divisors']
max_value = 10**7
min_value = -10**7

def setup(self, dtype, divisor):
iinfo = np.iinfo(dtype)
self.x = np.arange(
max(iinfo.min, self.min_value),
min(iinfo.max, self.max_value), dtype=dtype)

def time_floor_divide_int(self, dtpye, divisor):
self.x // divisor


class Scalar(Benchmark):
def setup(self):
self.x = np.asarray(1.0)
Expand Down
7 changes: 7 additions & 0 deletions doc/release/upcoming_changes/17727.performance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Improved performance in integer division of NumPy arrays
--------------------------------------------------------
Integer division of NumPy arrays now uses `libdivide <https://libdivide.com/>`
when the divisor is a constant. With the usage of libdivde and
other minor optimizations, there is a large speedup.
The ``//`` operator and ``np.floor_divide`` makes use
of the new changes.
21 changes: 21 additions & 0 deletions numpy/core/include/numpy/libdivide/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
zlib License
------------

Copyright (C) 2010 - 2019 ridiculous_fish, <libdivide@ridiculousfish.com>
Copyright (C) 2016 - 2019 Kim Walisch, <kim.walisch@gmail.com>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
437C
Loading
0