Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
updates for latest cython
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed Jul 18, 2023
1 parent 49f49f1 commit 2acd317
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 55 deletions.
15 changes: 0 additions & 15 deletions ctpfrec/cy.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ from cython.parallel cimport prange
from scipy.special.cython_special cimport psi, gamma, loggamma
import time

## Note: As of the end of 2018, MSVC is still stuck with OpenMP 2.0 (released 2002), which does not support
## parallel for loops with unsigend iterators. If you are using a different compiler, this part can be safely removed
IF UNAME_SYSNAME == "Windows":
obj_ind_type = ctypes.c_longlong
ctypedef long long ind_type
ctypedef double long_double_type
obj_long_double_type = ctypes.c_double
LD_HUGE_VAL = HUGE_VAL
ELSE:
obj_ind_type = ctypes.c_size_t
ctypedef size_t ind_type
ctypedef long double long_double_type
obj_long_double_type = ctypes.c_longdouble
LD_HUGE_VAL = HUGE_VALL

### Main function
#################
def fit_ctpf(np.ndarray[real_t, ndim=2] Theta_shp, np.ndarray[real_t, ndim=2] Theta_rte,
Expand Down
8 changes: 1 addition & 7 deletions ctpfrec/cy_double.pyx → ctpfrec/cy_double.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ from scipy.linalg.cython_blas cimport ddot
from hpfrec import cython_loops_double as cython_loops
import ctypes

## TODO: use libc.math once Cython 0.30 is released
# from libc.math cimport log, exp
cdef extern from "<math.h>":
double log(double x) nogil
double exp(double x) nogil
const double HUGE_VAL
const long double HUGE_VALL
from libc.math cimport log, exp, HUGE_VAL, HUGE_VALL

c_real_t = ctypes.c_double
ctypedef double real_t
Expand Down
10 changes: 10 additions & 0 deletions ctpfrec/cy_double_nonwindows.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ctypes
from libc.math cimport HUGE_VALL

obj_ind_type = ctypes.c_size_t
ctypedef size_t ind_type
ctypedef long double long_double_type
obj_long_double_type = ctypes.c_longdouble
LD_HUGE_VAL = HUGE_VALL

include "cy_float.pxi"
10 changes: 10 additions & 0 deletions ctpfrec/cy_double_windows.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ctypes
from libc.math cimport HUGE_VAL

obj_ind_type = ctypes.c_longlong
ctypedef long long ind_type
ctypedef double long_double_type
obj_long_double_type = ctypes.c_double
LD_HUGE_VAL = HUGE_VAL

include "cy_double.pxi"
11 changes: 1 addition & 10 deletions ctpfrec/cy_float.pyx → ctpfrec/cy_float.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ from scipy.special.cython_special cimport psi, gamma
from hpfrec import cython_loops_float as cython_loops
import ctypes

## TODO: use libc.math once Cython 0.30 is released
# from libc.math cimport log, exp
cdef extern from "<math.h>":
double log(double x) nogil
float logf(float) nogil
double exp(double x) nogil
float expf(float) nogil
const float HUGE_VALF
const double HUGE_VAL
const long double HUGE_VALL
from libc.math cimport log, exp, logf, expf, HUGE_VALF, HUGE_VAL, HUGE_VALL

c_real_t = ctypes.c_float
ctypedef float real_t
Expand Down
10 changes: 10 additions & 0 deletions ctpfrec/cy_float_nonwindows.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ctypes
from libc.math cimport HUGE_VALL

obj_ind_type = ctypes.c_size_t
ctypedef size_t ind_type
ctypedef long double long_double_type
obj_long_double_type = ctypes.c_longdouble
LD_HUGE_VAL = HUGE_VALL

include "cy_double.pxi"
10 changes: 10 additions & 0 deletions ctpfrec/cy_float_windows.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ctypes
from libc.math cimport HUGE_VAL

obj_ind_type = ctypes.c_longlong
ctypedef long long ind_type
ctypedef double long_double_type
obj_long_double_type = ctypes.c_double
LD_HUGE_VAL = HUGE_VAL

include "cy_float.pxi"
10 changes: 5 additions & 5 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy
numpy>=1.25
scipy>=1.11.1
cython
hpfrec>=0.2.6
sphinx-rtd-theme
Sphinx
cython>=3.0.0
hpfrec>=0.2.9
sphinx-rtd-theme>=1.0.0
Sphinx>=4.2.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["cython", "setuptools", "wheel", "oldest-supported-numpy", "scipy"]
requires = ["cython>=3.0.0", "setuptools", "wheel", "numpy>=1.25", "scipy>=1.11.1"]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pandas
numpy>=1.18
numpy>=1.25
scipy>=1.11.1
cython
cython>=3.0.0
hpfrec>=0.2.3
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

30 changes: 17 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from Cython.Distutils import build_ext
import numpy
import sys, os, subprocess, warnings, re
import platform

IS_WINDOWS = platform.system() == "Windows"

found_omp = True
def set_omp_false():
Expand Down Expand Up @@ -205,36 +208,37 @@ def test_supports_compile_arg(self, comm, with_omp=False):
setup(
name = 'ctpfrec',
packages = ['ctpfrec'],
install_requires=[
'pandas>=0.24',
'numpy>=1.17',
'scipy',
'cython',
'hpfrec>=0.2.6'
],
version = '0.1.16',
version = '0.1.17',
description = 'Collaborative topic Poisson factorization for recommender systems',
author = 'David Cortes',
url = 'https://github.com/david-cortes/ctpfrec',
keywords = ['collaborative', 'topic', 'modeling', 'poisson', 'probabilistic', 'non-negative', 'factorization',
'variational inference', 'collaborative filtering', 'cold-start'],
classifiers = [],

cmdclass = {'build_ext': build_ext_subclass},
ext_modules = [
Extension(
"ctpfrec.cy_double",
sources=["ctpfrec/cy_double.pyx"],
sources=[
"ctpfrec/cy_double_nonwindows.pyx"
if not IS_WINDOWS
else
"ctpfrec/cy_double_windows.pyx"
],
include_dirs=[numpy.get_include()]
),
Extension(
"ctpfrec.cy_float",
sources=["ctpfrec/cy_float.pyx"],
sources=[
"ctpfrec/cy_float_nonwindows.pyx"
if not IS_WINDOWS
else
"ctpfrec/cy_float_windows.pyx"
],
include_dirs=[numpy.get_include()]
),
Extension(
"ctpfrec._check_openmp",
sources=["ctpfrec/return1.pyx"],
sources=["ctpfrec/return1.pyx" if found_omp else "ctpfrec/return0.pyx"],
include_dirs=[numpy.get_include()]
)
]
Expand Down

0 comments on commit 2acd317

Please sign in to comment.