Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
673 commits
Select commit Hold shift + click to select a range
d5725a9
Merge branch 'adjusted_MLE' of https://github.com/snigdhagit/selectiv…
Nov 17, 2017
6d87c8f
commit test for non-orthogonal LASSO
Nov 17, 2017
32cabc3
added test for comparison of variances
Nov 17, 2017
6be3e95
commit changes
Nov 18, 2017
509c98b
new computation for observed Fisher info
Nov 19, 2017
3f110ab
checked non orthogonal lasso p 200
Nov 19, 2017
55f2a03
added test to compute univariate MLE based on E maps
Nov 20, 2017
36ef7b6
test BH with orthogonal design
Nov 21, 2017
caae0b0
added test for BH screening
Nov 21, 2017
e837b86
commit changes
Nov 21, 2017
e42ab38
added additional constraint in BH
Nov 21, 2017
9b0b3ca
commit comparsion with bootstrapped variance
Nov 24, 2017
4d208f8
changed map for sigma not equal to 1.
Nov 24, 2017
56a2051
added observed fisher info as a function of target
Nov 25, 2017
7fda4fb
return inv of hessian
Nov 25, 2017
ee18a0b
changed previous tests for MLE
Nov 25, 2017
07e283f
commit changes
Nov 25, 2017
c82c6cd
commit changes
Nov 26, 2017
ff48045
check sd from bootstrapped pivot
Nov 28, 2017
f14a036
tried estimating var based on a sample from selective distribution
Nov 30, 2017
4bd08a5
estimating sigma using glmnet
Dec 4, 2017
fa100e6
added arguments for relative risk computation
Dec 4, 2017
5c942d8
changes
Dec 4, 2017
aaa2c17
merging with snigdha recent work
jonathan-taylor Dec 5, 2017
9623d0a
print correct bias
jonathan-taylor Dec 5, 2017
ef66b4d
est sigma, lambda from CV.glmnet and option for independent estimator
Dec 5, 2017
a7c154c
found bug in offset term while setting implied mean
Dec 5, 2017
45b7fc2
added risk function
Dec 6, 2017
ccfb4fb
compute rel risks
Dec 6, 2017
639c90c
changed scale of glmnet
Dec 7, 2017
df1b830
cleaned risk
Dec 7, 2017
3b57a0c
added comparison of estimators appended with zeros
Dec 7, 2017
c69f5b1
commit additions of nonrand LASSO
Dec 7, 2017
a3803e1
added risk comparisons
Dec 8, 2017
377248a
added coverage
Dec 8, 2017
7ccf87b
commit all changes
Dec 8, 2017
d6dd7cb
commit changes
Dec 8, 2017
399d4bd
commit change
Dec 9, 2017
475269c
called sim.xy
Dec 10, 2017
9cf9386
commit merge
Dec 10, 2017
3165c90
getting coefs for all possible combinations of lambda and gamma
Dec 10, 2017
decb1e2
tuned version of relaxed lasso
Dec 10, 2017
0333f13
fix sigma and change coef in dgp
Dec 10, 2017
e931db6
return tuned relaxed lasso est
Dec 10, 2017
b40619b
commit all changes
Dec 10, 2017
3ed5da2
corrected glmnet
Dec 11, 2017
5136ee9
added both lambda min and 1se in glmnet
Dec 11, 2017
ac6b93e
comparisons for tuned estimator against sel MLE
Dec 11, 2017
be3f701
extract the tuned lambda in best subset and use it for rand LASSO
Dec 11, 2017
d1a8202
tried tuning randomized LASSO
Dec 11, 2017
70e1625
use external validation set to tune lambda
Dec 12, 2017
6268010
added tuned LASSO est
Dec 12, 2017
31c3361
added screening power
Dec 12, 2017
b3e2246
added coverages
Dec 12, 2017
b711f27
added false positives to screening attributes
Dec 12, 2017
7b81d39
added inferential power
Dec 12, 2017
b5bdf10
corrected power
Dec 13, 2017
4307d32
commit all changes
Dec 13, 2017
627a717
a small correction
Dec 13, 2017
37260e2
merging
jonathan-taylor Dec 14, 2017
7554f0a
centered y and added partial risks
Dec 15, 2017
5762b73
fixed scales in partial risk
Dec 15, 2017
f24b70a
tuning the selective MLE rather than lasso
jonathan-taylor Dec 16, 2017
7fdd58e
using full target
jonathan-taylor Dec 16, 2017
6a1668f
updated changes of target and tuning
Dec 17, 2017
39b7a4b
added debiased target
Dec 17, 2017
bdcad4a
commit changes so far
Dec 17, 2017
45c2a54
reverted back to fixing sigma as per snr in sim.xy
Dec 17, 2017
30464f7
normalized y's by sigma_est
Dec 17, 2017
b2b54ce
changed scale of relaxed lasso tuned
Dec 17, 2017
ab02c39
added target in selection map
Dec 18, 2017
ef6c9a6
bootstrap intervals very long for high dims
Dec 18, 2017
d0f853c
commit changes
Dec 18, 2017
641d1b6
installed best subset package-- enlist is changed
Dec 18, 2017
dc8ad99
commit before switch
Dec 19, 2017
778feaa
commit before switch
Dec 19, 2017
18dd458
run qq-norm diagnostic
Dec 20, 2017
29f257e
commit before switch
Dec 20, 2017
e30ad15
merge conflict
jonathan-taylor Dec 21, 2017
7fc650e
updates to R and C software
jonathan-taylor Dec 21, 2017
a263864
adding doc to selective MLE code
jonathan-taylor Dec 21, 2017
5fce4ce
coverage wo bootstrap
Dec 28, 2017
536063e
commit changes
Dec 28, 2017
4f6755a
selective coverage improving in high dimensions
Dec 29, 2017
bbe7e50
clean-up of code
Dec 29, 2017
cf1cdb1
removed bootstrapping for interval construction
Dec 29, 2017
256061d
more clean up and tests
Dec 29, 2017
d0bb945
commit before switch
Dec 29, 2017
df1ced0
fixing merge
jonathan-taylor Feb 7, 2018
8f79a6a
moving changes of MLE under randomized
jonathan-taylor Feb 7, 2018
8d91670
refector lasso so it can use affine gaussian sampler
jonathan-taylor Feb 8, 2018
e977ea4
renaming restricted_Mest to restricted_estimator, put in base module
jonathan-taylor Feb 8, 2018
594be73
incorrect mean specification for affine gaussian sampler
jonathan-taylor Feb 9, 2018
adf8b81
a few more steps for langevin
jonathan-taylor Feb 9, 2018
61bbe97
results llook close to R sampler -- not great still
jonathan-taylor Feb 13, 2018
48c0418
using full pvalues
jonathan-taylor Feb 13, 2018
3957bf3
using full targets
jonathan-taylor Feb 13, 2018
1a85195
WIP: writing highdim gaussian randomization version
jonathan-taylor Feb 14, 2018
9bde5b9
RF: finally working! using score instead of internal
jonathan-taylor Feb 15, 2018
ed3f62c
adding alternatives as a sequence
jonathan-taylor Feb 15, 2018
b02bbb3
Merge pull request #29 from jonathan-taylor/lasso_refactor
jonathan-taylor Feb 15, 2018
7ef5a45
BF: variable name
jonathan-taylor Feb 15, 2018
a72aaf4
Merge branch 'lasso_refactor'
jonathan-taylor Feb 15, 2018
23fadb2
BF: for full we can't use one-sided tests -- not what we observed
jonathan-taylor Feb 15, 2018
d24f444
comparing highdim to more general with decomposition
jonathan-taylor Feb 16, 2018
cf6bb6f
adding logdens_transform
jonathan-taylor Feb 17, 2018
ced3d9c
edits to take into account given conditional_cov and mean
jonathan-taylor Feb 22, 2018
cccf6bb
if nothing selected, don't sample and return empty summary
jonathan-taylor Feb 27, 2018
9b0822a
making sure solve_args are used
jonathan-taylor Feb 27, 2018
0fc9f09
Merge branch 'master' of github.com:jonathan-taylor/selective-inference
jonathan-taylor Feb 27, 2018
dd1e3be
added selective MLE method
jonathan-taylor Mar 1, 2018
e293886
moved selective mle to the affine_gaussian sampler
jonathan-taylor Mar 1, 2018
088e671
1D test of LASSO MLE
jonathan-taylor Mar 1, 2018
c56c94d
using python solver for now
jonathan-taylor Mar 1, 2018
4815d39
getting rid of ridge term
jonathan-taylor Mar 1, 2018
ed0d654
one dim problem
jonathan-taylor Mar 1, 2018
7c524e9
fixed an import
Mar 1, 2018
8b7deee
sign change in target_lin
Mar 2, 2018
a5eb9c6
match with selective UMVU computation
Mar 2, 2018
7d48a68
making a more rigorous test and comparison of old and new
jonathan-taylor Mar 6, 2018
278dc10
removing unused selective_MLE module -- for now everything in query
jonathan-taylor Mar 6, 2018
e2f1c9f
using C code for barrier solving
jonathan-taylor Mar 6, 2018
76b4eae
producing selective MLE intervals
jonathan-taylor Mar 6, 2018
94cac3e
allowed estimate of disperision
jonathan-taylor Mar 6, 2018
f78389c
commit changes in test
Mar 7, 2018
96db474
fix conflicts
Mar 7, 2018
1b4c1ae
starting to work on sqrtlasso
jonathan-taylor Mar 9, 2018
ece9a1d
BF: the skinny problem doesn't work with perturbation without modific…
jonathan-taylor Mar 9, 2018
ae30a14
NF: randomized sqrtLASSO implemented for highdim and general, only te…
jonathan-taylor Mar 9, 2018
a1ecae0
BF: fixing ridge scale of sqrtLASSO, cleaning up some ratios of sqrt …
jonathan-taylor Mar 9, 2018
41b5eb1
including line search for debiasing matrix, not tested yet
jonathan-taylor Mar 13, 2018
df99f81
WIP: trying to match with previous C function call
jonathan-taylor Mar 13, 2018
e0a819c
updates to C software
jonathan-taylor Mar 14, 2018
065ff20
NF: finished linesearch for debiasing matrix, tested with R comparison
jonathan-taylor Mar 14, 2018
82bb8cb
NF: debiased lasso targets, a little anticonservative
jonathan-taylor Mar 14, 2018
d47d1e1
BF: debiasing_matrix was returning none
jonathan-taylor Mar 15, 2018
a62bbc7
commit changes
Mar 17, 2018
b57204e
resolve conflict
Mar 17, 2018
8d4906f
clean tests
Mar 19, 2018
c85a736
adding new test
Mar 19, 2018
eacf8c8
updated test
Mar 20, 2018
7b4dedc
added a return of indep est to the func. selective_MLE
Mar 20, 2018
5f23a90
finished adding risks
Mar 20, 2018
04b51c5
tuned lasso and lasso in python not having same solns
Mar 22, 2018
4ea51eb
comparison of risks
Mar 22, 2018
01bb212
removed redundant print
Mar 22, 2018
cb03e75
commit changes in test
Mar 22, 2018
9f05925
reorganized test
Mar 27, 2018
c249aed
commit changes
Mar 27, 2018
1d26756
added inferential powers
Mar 27, 2018
3fc57f9
correction in power
Mar 27, 2018
60e25d0
adding Liu et al to library
jonathan-taylor Mar 27, 2018
dbc393d
WIP: fixing Liu
jonathan-taylor Mar 29, 2018
b6dbab5
BF: fixed Liu full lasso
jonathan-taylor Mar 29, 2018
504deb2
removing print statements
jonathan-taylor Mar 29, 2018
13182c4
WIP: debiased version of Liu (not tested fully)
jonathan-taylor Mar 29, 2018
c621eb9
BF: missing ref
jonathan-taylor Mar 29, 2018
44bd117
WIP: some cleanup in randomized
jonathan-taylor Mar 30, 2018
ebc41b9
moving Mest test
jonathan-taylor Mar 30, 2018
a4c9730
WIP: cleaning up randomized
jonathan-taylor Mar 30, 2018
da24793
old base file
jonathan-taylor Mar 30, 2018
8920d8d
other test
jonathan-taylor Mar 30, 2018
83b2644
merge conflict
jonathan-taylor Mar 30, 2018
1cf17f6
coverage for debiased target is short of target
Mar 31, 2018
705fa9d
coverage falling short of target for debiased
Apr 1, 2018
68b7ccd
double requirement
jonathan-taylor Apr 2, 2018
815f394
clarifying highdim docstring
jonathan-taylor Apr 3, 2018
dde4895
updating R software
jonathan-taylor Apr 3, 2018
b1236a6
added test for liu agreement
jonathan-taylor Apr 3, 2018
58d11a8
needed to reset the bound parameter for each row
jonathan-taylor Apr 5, 2018
ab31cb0
tests to ensure debiasing code working for more than one row
jonathan-taylor Apr 5, 2018
2fe9f29
adding dispersion estimate argument to summary -- what to do about lo…
jonathan-taylor Apr 5, 2018
a90538f
fixed version of debiased liu
jonathan-taylor Apr 5, 2018
fbad7e4
updated debiased LASSO
Apr 5, 2018
dbffe21
NF: modelX full lasso with known Q
jonathan-taylor Apr 6, 2018
fffb135
test to check full_modelX agrees with full
jonathan-taylor Apr 6, 2018
a8c92ed
BF: degrees of freedom
jonathan-taylor Apr 6, 2018
44485b3
allowed lasso_full to use a sparse estimate of inverse
jonathan-taylor Apr 6, 2018
b3ae655
separated high and low case instances
Apr 6, 2018
b676a92
removing report framework -- better to use the testing and comparison…
jonathan-taylor Apr 6, 2018
5cdf084
updated test for debised target
Apr 7, 2018
b2db3b7
debiased lasso inference based on selective MLE tested
Apr 7, 2018
6a54fcc
modelX to modelQ
jonathan-taylor Apr 7, 2018
e0000f5
update to R software
jonathan-taylor Apr 7, 2018
01f6e39
NF: for Gaussian allowing a modelled Q instead of X.T.dot(X)
jonathan-taylor Apr 7, 2018
88d2580
fixed imports
jonathan-taylor Apr 7, 2018
52e8b8b
restructured test and rectified scaling of target
Apr 8, 2018
be920b7
create plots + save results
Apr 10, 2018
d544fb4
tried to tune randomization scale
Apr 10, 2018
38fb609
tolerance arguments for selective mle
jonathan-taylor Apr 10, 2018
aac8dd0
scale of LASSO in python made to agree with glmnet
Apr 11, 2018
89561e1
corrected scales and reduced length of grid search for tuning randomi…
Apr 11, 2018
6f00013
corrected scales in selected target
Apr 11, 2018
680ee7c
randomized LASSO est seems comparable in risk to tuned estimators whe…
Apr 11, 2018
1e4bf65
added function fixedLassoInf from R
Apr 11, 2018
60900c4
corrected arguments that are passed to fixedLassoInf
Apr 11, 2018
7ad5340
calling R package for Lee inference, also for selected targets
Apr 11, 2018
88be596
add power post BH filter
Apr 11, 2018
b010ce1
added fdr and power post passing p-values through BH sieve
Apr 12, 2018
ccedbd8
removed some unnecessary prints
Apr 12, 2018
0adb83f
some more reorganization
Apr 12, 2018
6bf84e8
making notion of power consistent across tests
Apr 12, 2018
4e3d32a
organizing output
Apr 12, 2018
6495d0b
generate outputs
Apr 12, 2018
2b293cc
adding average selected size and discoveries
Apr 12, 2018
ffddcaa
run test for a grid of snr values
Apr 12, 2018
95ee767
add output files
Apr 13, 2018
d106ee4
added SLOPE to current working branch
Apr 13, 2018
21814f7
test for SLOPE
Apr 13, 2018
7ed837d
cleaned up test for SLOPE
Apr 13, 2018
8f4473c
check soln of randomized SLOPE
Apr 15, 2018
0cfecd5
detect clusters and rearange subgradient in decreasing order
Apr 15, 2018
cfb29ea
created a temporary class for SLOPE for now
Apr 16, 2018
d3ffb32
removed bug in fixing feasible point
Apr 16, 2018
5d420e4
removed a sign bug from score_linear
Apr 16, 2018
f144775
removed print statements, coverage is short of target
Apr 16, 2018
e48b25c
removed sign bug from opt_linear_term
Apr 16, 2018
ca75577
still coverage is short of target
Apr 16, 2018
6981890
add output files
Apr 17, 2018
1f26c09
commit results where tuning parameter is tuned using selective mle
Apr 17, 2018
d32de01
adding log posterior parametrized using sel_MLE in query
Apr 20, 2018
4b54c4a
added a missing term
Apr 20, 2018
1d430c8
changed name of func
Apr 20, 2018
04fa473
created class for ms that can be used for BH
Apr 23, 2018
3aff7af
regreg a requirement
jonathan-taylor Apr 23, 2018
74a7169
conflict in requirements
jonathan-taylor Apr 23, 2018
db5226e
Merge branch 'SLOPE' of github.com:jonathan-taylor/selective-inferenc…
jonathan-taylor Apr 23, 2018
a378707
merge conflucts
jonathan-taylor Apr 23, 2018
bc3c1d2
deleting output
jonathan-taylor Apr 23, 2018
273f376
removing ===
jonathan-taylor Apr 23, 2018
08f9a5f
moving some files around
jonathan-taylor Apr 23, 2018
ce8cbf3
highdim LASSO selective MLE should be reusable
jonathan-taylor Apr 23, 2018
6fdb30b
logistic debiased liu tests
jonathan-taylor Apr 24, 2018
76fd486
need to figure out what score is
Apr 26, 2018
780b86c
commit changes so far
Apr 27, 2018
7033ebc
BH needs debugging
Apr 27, 2018
5f45a52
affine version of barrier problem
jonathan-taylor Apr 27, 2018
9b2f212
updated of C software for barrier affine
jonathan-taylor Apr 27, 2018
40c0709
commit changes
Apr 28, 2018
14ca8d9
BH is not working yet
Apr 28, 2018
47c2c27
commit changes in branch before switch
Apr 28, 2018
90af11b
running slope with affine constraints, barrier code written in python
May 1, 2018
db64db1
coverage for SLOPE looks good
May 1, 2018
071d928
rearranged the terms returned by barrier_affine
May 2, 2018
38e152c
removed some unnecessary print checks
May 2, 2018
5e5c17c
push changes to SLOPE
May 2, 2018
67415c4
Merge pull request #33 from snigdhagit/test_SLOPE
jonathan-taylor May 2, 2018
df66abc
minor edit
jonathan-taylor May 2, 2018
66294b4
BF: wrong C file in selective_MLE_utils setup
jonathan-taylor May 2, 2018
895c008
moved general LASSO to sandbox, now highdim is just lasso
jonathan-taylor May 2, 2018
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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "travis-tools"]
path = travis-tools
url = https://github.com/matthew-brett/travis-tools.git
[submodule "R-software"]
path = R-software
url = https://github.com/selective-inference/R-software
[submodule "C-software"]
path = C-software
url = https://github.com/selective-inference/C-software
80 changes: 74 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: python
dist: trusty
python:
- 2.7
- 3.3
- 3.4
- 3.5
notifications:
email: false
addons:
Expand All @@ -13,29 +15,90 @@ env:
global:
# Maximal dependencies
- DEPENDS="cython numpy scipy matplotlib"
matrix:
include:
- python: 3.5
env:
- RUN_R_TESTS=1
- python: 2.7
env:
- RUN_R_TESTS=1
# Testing without matplotlib
- python: 2.7
env:
- DEPENDS="cython numpy scipy"
# Documentation doctests
- python: 2.7
env:
- DOC_DOC_TEST=1
# Setup.py install
- python: 2.7
env:
- INSTALL_TYPE=setup
- python: 2.7
env:
# Sdist install should collect all dependencies
- INSTALL_TYPE=sdist
- DEPENDS="cython numpy scipy"
- python: 2.7
env:
# Wheel install should collect all dependencies
- INSTALL_TYPE=wheel
- DEPENDS="cython numpy scipy"
- python: 2.7
env:
- INSTALL_TYPE=requirements
- DEPENDS=
before_install:
- source travis-tools/utils.sh
- travis_before_install
# Install regreg
- python -c "import numpy; print(numpy.version.version)"
- git clone https://github.com/jonathan-taylor/regreg.git
- cd regreg
- pip install -r requirements.txt
- pip install -e .
- cd ..
- sudo apt-get install software-properties-common
- sudo add-apt-repository -y ppa:marutter/c2d4u
- sudo add-apt-repository -y ppa:marutter/rrutter
- sudo apt-get update
- sudo apt-get install -y r-base r-base-dev r-cran-devtools r-cran-rcpp


install:
# Install selection
- pip install -r requirements.txt
- pip install -e .
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
pip install -r requirements.txt -c constraints.txt;
else
pip install -r requirements.txt;
fi
- git submodule init
- git submodule update
- cd R-software
- git submodule init
- git submodule update
- Rscript -e "library(Rcpp); Rcpp::compileAttributes('selectiveInference')"
- sudo Rscript -e "install.packages(c('glmnet', 'intervals', 'adaptMCMC'), repos='http://cloud.r-project.org')"
- sudo R CMD INSTALL selectiveInference
- cd ..
- python -c "from statsmodels.api import PHReg"
- travis_install $INSTALL_TYPE

# command to run tests, e.g. python setup.py test
script:

- pip install nose
# No figure windows for mpl; quote to hide : from travis-ci yaml parsing
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
pip install -r doc-requirements.txt -c constraints.txt;
else
pip install -r doc-requirements.txt;
fi
# Change into an innocuous directory and find tests from installation
- mkdir for_testing
- cd for_testing
# No figure windows for mpl; quote to hide : from travis-ci yaml parsing
- 'echo "backend : agg" > matplotlibrc'

# Doctests only on platforms that have compatible fp output
- if [ `uname` == "Darwin" ] ||
[ "${TRAVIS_PYTHON_VERSION:0:1}" == "3" ]; then
Expand All @@ -45,6 +108,11 @@ script:
cp ../.coveragerc .;
COVER_ARGS="--with-coverage --cover-package selection";
fi
- env USE_SMALL_SAMPLES=1 SET_SEED=1 nosetests $DOCTEST_ARGS --verbose $COVER_ARGS selection
- |
if [ "$RUN_R_TESTS" ]; then
nosetests -v ../selection/algorithms/tests/test_compareR.py
else
env USE_SMALL_SAMPLES=1 USE_TEST_SEED=1 nosetests $DOCTEST_ARGS --verbose $COVER_ARGS selection
fi
after_success:
- if [ "${COVERAGE}" == "1" ]; then coveralls; fi
1 change: 1 addition & 0 deletions C-software
Submodule C-software added at 6947ac
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include AUTHOR LICENSE Makefile* MANIFEST.in setup* README.*
include Changelog TODO
recursive-include doc *
recursive-include tools *
# setup utilities
include setup_helpers.py
include cythexts.py
recursive-include fake_pyrex *
include versioneer.py
include selection/_version.py
1 change: 1 addition & 0 deletions R-software
Submodule R-software added at 9de1b7
1 change: 1 addition & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rpy2<2.9
60 changes: 39 additions & 21 deletions cythexts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from os.path import splitext, sep as filesep, join as pjoin, relpath
from hashlib import sha1
from subprocess import check_call

from distutils.command.build_ext import build_ext
from distutils.command.sdist import sdist
Expand Down Expand Up @@ -95,6 +94,8 @@ def cyproc_exts(exts, cython_min_version,
Can be ``build_ext`` input (if we have good c files) or cython
``build_ext`` if we have a good cython, or a class raising an informative
error on ``run()``
need_cython : bool
True if we need Cython to build extensions, False otherwise.
"""
if stamped_pyx_ok(exts, hash_stamps_fname):
# Replace pyx with c files, use standard builder
Expand All @@ -107,29 +108,33 @@ def cyproc_exts(exts, cython_min_version,
else:
sources.append(source)
mod.sources = sources
return build_ext
return build_ext, False
# We need cython
try:
from Cython.Compiler.Version import version as cyversion
except ImportError:
cython_ok = False
else:
cython_ok = LooseVersion(cyversion) >= cython_min_version
if cython_ok:
return derror_maker(build_ext,
'Need cython>={0} to build extensions '
'but cannot import "Cython"'.format(
cython_min_version)), True
if LooseVersion(cyversion) >= cython_min_version:
from Cython.Distutils import build_ext as extbuilder
return extbuilder
return extbuilder, True
return derror_maker(build_ext,
'Need cython>=%s to build extensions'
% cython_min_version)
'Need cython>={0} to build extensions'
'but found cython version {1}'.format(
cython_min_version, cyversion)), True


def build_stamp(pyxes):
def build_stamp(pyxes, include_dirs=()):
""" Cythonize files in `pyxes`, return pyx, C filenames, hashes

Parameters
----------
pyxes : sequence
sequence of filenames of files on which to run Cython
include_dirs : sequence
Any extra include directories in which to find Cython files.

Returns
-------
Expand All @@ -139,11 +144,17 @@ def build_stamp(pyxes):
hash>; "c_filename", <c filemane>; "c_hash", <c file SHA1 hash>.
"""
pyx_defs = {}
from Cython.Compiler.Main import compile
from Cython.Compiler.CmdLine import parse_command_line
includes = sum([['--include-dir', d] for d in include_dirs], [])
for source in pyxes:
base, ext = splitext(source)
pyx_hash = sha1(open(source, 'rt').read()).hexdigest()
c_filename = base + '.c'
check_call('cython ' + source, shell=True)
options, sources = parse_command_line(includes + [source])
result = compile(sources, options)
if result.num_errors > 0:
raise RuntimeError('Cython failed to compile ' + source)
c_hash = sha1(open(c_filename, 'rt').read()).hexdigest()
pyx_defs[source] = dict(pyx_hash=pyx_hash,
c_filename=c_filename,
Expand Down Expand Up @@ -173,22 +184,19 @@ def write_stamps(pyx_defs, stamp_fname='pyx-stamps'):
pyx_info['c_hash']))


def find_pyx(root_dir=None):
def find_pyx(root_dir):
""" Recursively find files with extension '.pyx' starting at `root_dir`

Parameters
----------
root_dir : None or str, optional
Directory from which to search for pyx files. If None, use current
working directory.
root_dir : str
Directory from which to search for pyx files.

Returns
-------
pyxes : list
list of filenames relative to `root_dir`
"""
if root_dir is None:
root_dir = os.getcwd()
pyxes = []
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
Expand All @@ -199,7 +207,8 @@ def find_pyx(root_dir=None):
return pyxes


def get_pyx_sdist(sdist_like=sdist, hash_stamps_fname='pyx-stamps'):
def get_pyx_sdist(sdist_like=sdist, hash_stamps_fname='pyx-stamps',
include_dirs=()):
""" Add pyx->c conversion, hash recording to sdist command `sdist_like`

Parameters
Expand All @@ -210,6 +219,8 @@ def get_pyx_sdist(sdist_like=sdist, hash_stamps_fname='pyx-stamps'):
hash_stamps_fname : str, optional
filename to which to write hashes of pyx / py and c files. Default is
``pyx-stamps``
include_dirs : sequence
Any extra include directories in which to find Cython files.

Returns
-------
Expand Down Expand Up @@ -240,7 +251,7 @@ def make_distribution(self):
base, ext = splitext(source)
if ext in ('.pyx', '.py'):
pyxes.append(source)
self.pyx_defs = build_stamp(pyxes)
self.pyx_defs = build_stamp(pyxes, include_dirs)
for pyx_fname, pyx_info in self.pyx_defs.items():
self.filelist.append(pyx_info['c_filename'])
sdist_like.make_distribution(self)
Expand All @@ -254,7 +265,8 @@ def make_release_tree(self, base_dir, files):
return PyxSDist


def build_stamp_source(root_dir=None, stamp_fname='pyx-stamps'):
def build_stamp_source(root_dir=None, stamp_fname='pyx-stamps',
include_dirs=None):
""" Build cython c files, make stamp file in source tree `root_dir`

Parameters
Expand All @@ -264,7 +276,13 @@ def build_stamp_source(root_dir=None, stamp_fname='pyx-stamps'):
working directory.
stamp_fname : str, optional
Filename for stamp file we will write
include_dirs : None or sequence
Any extra Cython include directories
"""
if root_dir is None:
root_dir = os.getcwd()
if include_dirs is None:
include_dirs = [pjoin(root_dir, 'src')]
pyxes = find_pyx(root_dir)
pyx_defs = build_stamp(pyxes)
pyx_defs = build_stamp(pyxes, include_dirs=include_dirs)
write_stamps(pyx_defs, stamp_fname)
4 changes: 4 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Requirements for developing regreg
# Check these dependencies against regreg/info.py
-r requirements.txt
nose
9 changes: 9 additions & 0 deletions doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Requirements for building docs
# Check these dependencies against doc/conf.py
-r dev-requirements.txt
sphinx>=1.4
numpydoc
matplotlib
texext
nb2plots
rpy2
Loading