8000 MAINT: remove unused functions, rearrange headers (from CC=clang) by mattip · Pull Request #14534 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: remove unused functions, rearrange headers (from CC=clang) #14534

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 3 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
BUILD: remove unused functions, rearrange headers (from CC=clang)
  • Loading branch information
mattip committed Sep 20, 2019
commit f41d70459d4dfc0b252e9228ab581dd1944d5b5f
36 changes: 2 additions & 34 deletions numpy/core/src/npymath/npy_math_complex.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
* flag in an efficient way. The flag is IEEE specific. See
* https://github.com/freebsd/freebsd/blob/4c6378299/lib/msun/src/catrig.c#L42
*/
#if !defined(HAVE_CACOSF) || !defined(HAVE_CACOSL) || !defined(HAVE_CASINHF) || !defined(HAVE_CASINHL)
#define raise_inexact() do { \
volatile npy_float NPY_UNUSED(junk) = 1 + tiny; \
} while (0)


static const volatile npy_float tiny = 3.9443045e-31f;

#endif

/**begin repeat
* #type = npy_float, npy_double, npy_longdouble#
Expand All @@ -64,32 +65,13 @@ static const volatile npy_float tiny = 3.9443045e-31f;
* Constants
*=========================================================*/
static const @ctype@ c_1@c@ = {1.0@C@, 0.0};
static const @ctype@ c_half@c@ = {0.5@C@, 0.0};
static const @ctype@ c_i@c@ = {0.0, 1.0@C@};
static const @ctype@ c_ihalf@c@ = {0.0, 0.5@C@};

/*==========================================================
* Helper functions
*
* These are necessary because we do not count on using a
* C99 compiler.
*=========================================================*/
static NPY_INLINE
@ctype@
cadd@c@(@ctype@ a, @ctype@ b)
{
return npy_cpack@c@(npy_creal@c@(a) + npy_creal@c@(b),
npy_cimag@c@(a) + npy_cimag@c@(b));
}

static NPY_INLINE
@ctype@
csub@c@(@ctype@ a, @ctype@ b)
{
return npy_cpack@c@(npy_creal@c@(a) - npy_creal@c@(b),
npy_cimag@c@(a) - npy_cimag@c@(b));
}

static NPY_INLINE
@ctype@
cmul@c@(@ctype@ a, @ctype@ b)
Expand Down Expand Up @@ -132,20 +114,6 @@ cdiv@c@(@ctype@ a, @ctype@ b)
}
}

static NPY_INLINE
@ctype@
cneg@c@(@ctype@ a)
{
return npy_cpack@c@(-npy_creal@c@(a), -npy_cimag@c@(a));
}

static NPY_INLINE
@ctype@
cmuli@c@(@ctype@ a)
{
return npy_cpack@c@(-npy_cimag@c@(a), npy_creal@c@(a));
}

/*==========================================================
* Custom implementation of missing complex C99 functions
*=========================================================*/
Expand Down
47 changes: 38 additions & 9 deletions numpy/core/src/umath/scalarmath.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -1428,23 +1428,54 @@ static PyObject *
}
/**end repeat**/

/**begin repeat
*
* #name = byte, ubyte, short, ushort, int, uint,
* long, ulong, longlong, ulonglong,
* half, float, double, longdouble,
* cfloat, cdouble, clongdouble#
* #Name = Byte, UByte, Short, UShort, Int, UInt,
* Long, ULong, LongLong, ULongLong,
* Half, Float, Double, LongDouble,
* CFloat, CDouble, CLongDouble#
* #cmplx = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1#
* #to_ctype = , , , , , , , , , , npy_half_to_double, , , , , , #
* #which = float*17#
* #func = PyFloat_FromDouble*17#
*/
static NPY_INLINE PyObject *
@name@_@which@(PyObject *obj)
{
#if @cmplx@
if (emit_complexwarning() < 0) {
return NULL;
}
return @func@(@to_ctype@(PyArrayScalar_VAL(obj, @Name@).real));
#else
return @func@(@to_ctype@(PyArrayScalar_VAL(obj, @Name@)));
#endif
}
/**end repeat**/


#if !defined(NPY_PY3K)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This splits the @name@_@which@ templates into two parts: one for python2 using long (below) and one for both 2 and 3 using float (above).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to backport this, or shouldn't we just ignore python 2 for such a specific, rarely touched, code chunk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to backport. NEP 14 is not clear on this, but I think we have not been actively removing python2 code from th 8000 e master branch yet.

/**begin repeat
*
* #name = (byte, ubyte, short, ushort, int, uint,
* long, ulong, longlong, ulonglong,
* half, float, double, longdouble,
* cfloat, cdouble, clongdouble)*2#
* cfloat, cdouble, clongdouble)#
* #Name = (Byte, UByte, Short, UShort, Int, UInt,
* Long, ULong, LongLong, ULongLong,
* Half, Float, Double, LongDouble,
* CFloat, CDouble, CLongDouble)*2#
* #cmplx = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1)*2#
* #to_ctype = (, , , , , , , , , , npy_half_to_double, , , , , , )*2#
* #which = long*17, float*17#
* CFloat, CDouble, CLongDouble)#
* #cmplx = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1)#
* #to_ctype = (, , , , , , , , , , npy_half_to_double, , , , , , )#
* #which = long*17#
* #func = (PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,
* PyLong_FromDouble*3, npy_longdouble_to_PyLong,
* PyLong_FromDouble*2, npy_longdouble_to_PyLong,
* PyFloat_FromDouble*17#
* PyLong_FromDouble*2, npy_longdouble_to_PyLong#
*/
static NPY_INLINE PyObject *
@name@_@which@(PyObject *obj)
Expand All @@ -1460,8 +1491,6 @@ static NPY_INLINE PyObject *
}
/**end repeat**/

#if !defined(NPY_PY3K)

/**begin repeat
*
* #name = (byte, ubyte, short, ushort, int, uint,
Expand Down
5 changes: 2 additions & 3 deletions numpy/random/src/distributions/distributions.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef _RANDOMDGEN__DISTRIBUTIONS_H_
#define _RANDOMDGEN__DISTRIBUTIONS_H_

#pragma once
#include "Python.h"
#include "numpy/npy_common.h"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change and the others in the random/src files were needed to get rid of a warning. Googling it seems to suggest there is a circular include graph. This reordering solved it and seems harmless.

In file included from /usr/include/python3.6m/Python.h:77:
/usr/include/python3.6m/pytime.h:146:56: error: declaration of 'struct timespec' will not be visible outside of this function [-Werror,-Wvisibility]
PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep getting this warning anytime I compile C code that includes <numpy/random/*.h> with -std=c99. It is annoying and hides actual informative warnings. It will fill up the screen if included in multiple modules. Any ideas how I can get rid of these without disabling the visibility warning? @mattip

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a new issue and provide information so we can reproduce: what compiler and platform are you using? What version of NumPy? Some sample code and the actual warning you get would also help.

Copy link
Contributor
@zoj613 zoj613 Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will try and see if I can reproduce with an example. The warning is exactly the same as the one you mentioned above:

In file included from /usr/include/python3.6m/Python.h:77:
/usr/include/python3.6m/pytime.h:146:56: error: declaration of 'struct timespec' will not be visible outside of this function [-Werror,-Wvisibility]
PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);

It pops up anytime I compiled C code with numpy/npy_common.h and numpy/random/distributions.h. It is caused by the Python.h header included in those files. I can't silence it. Im on Manjaro linux 64bit, python 3.8/3.9.

#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>

#include "Python.h"
#include "numpy/npy_common.h"
#include "numpy/npy_math.h"
#include "numpy/random/bitgen.h"

Expand Down
2 changes: 1 addition & 1 deletion numpy/random/src/distributions/random_hypergeometric.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdint.h>
#include "distributions.h"
#include "logfactorial.h"
#include <stdint.h>

/*
* Generate a sample from the hypergeometric distribution.
Expand Down
2 changes: 1 addition & 1 deletion numpy/random/src/philox/philox.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _RANDOMDGEN__PHILOX_H_
#define _RANDOMDGEN__PHILOX_H_

#include <inttypes.h>
#include "numpy/npy_common.h"
#include <inttypes.h>

#define PHILOX_BUFFER_SIZE 4L

Expand Down
2 changes: 1 addition & 1 deletion numpy/random/src/sfc64/sfc64.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef _RANDOMDGEN__SFC64_H_
#define _RANDOMDGEN__SFC64_H_

#include "numpy/npy_common.h"
#include <inttypes.h>
#ifdef _WIN32
#include <stdlib.h>
#endif
#include "numpy/npy_common.h"

typedef struct s_sfc64_state {
uint64_t s[4];
Expand Down
0