diff --git a/.gitignore b/.gitignore index 2e04d26c866a6..ace2c21bfd0ed 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ pip-log.txt scikit_learn.egg-info/ .coverage coverage +*.py,cover tags covtype.data.gz 20news-18828/ diff --git a/appveyor.yml b/appveyor.yml index 7d91bf06eecf1..c5a3263ddd0bc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,9 @@ environment: # /E:ON and /V:ON options are not enabled in the batch script intepreter # See: http://stackoverflow.com/a/13751649/163740 CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\continuous_integration\\appveyor\\run_with_env.cmd" + WHEELHOUSE_UPLOADER_USERNAME: sklearn-appveyor + WHEELHOUSE_UPLOADER_SECRET: + secure: BQm8KfEj6v2Y+dQxb2syQvTFxDnHXvaNktkLcYSq7jfbTOO6eH9n09tfQzFUVcWZ matrix: - PYTHON: "C:\\Python27_32" @@ -25,11 +28,6 @@ environment: PYTHON_VERSION: "3.4.1" PYTHON_ARCH: "64" -branches: - only: - - master - - 0.15.X - install: # Install Python (from the official .msi of http://python.org) and pip when # not already installed. @@ -54,15 +52,22 @@ build: false test_script: # Change to a non-source folder to make sure we run the tests on the # installed library. - - "cd C:\\" + - "mkdir empty_folder" + - "cd empty_folder" # Skip joblib tests that require multiprocessing as they are prone to random # slow down - "python -c \"import nose; nose.main()\" -s sklearn" + # Move back to the project folder + - "cd .." + artifacts: # Archive the generated wheel package in the ci.appveyor.com build report. - path: dist\* -#on_success: -# - TODO: upload the content of dist/*.whl to a public wheelhouse +on_success: + # Upload the generated wheel package to Rackspace + # On Windows, Apache Libcloud cannot find a standard CA cert bundle so we + # disable the ssl checks. + - "python -m wheelhouse_uploader upload --no-ssl-check --local-folder=dist sklearn-windows-wheels" diff --git a/benchmarks/bench_covertype.py b/benchmarks/bench_covertype.py index db78dc7e0b58c..dd25a1a5c2ab3 100644 --- a/benchmarks/bench_covertype.py +++ b/benchmarks/bench_covertype.py @@ -42,17 +42,13 @@ """ from __future__ import division, print_function -print(__doc__) - # Author: Peter Prettenhofer +# Arnaud Joly # License: BSD 3 clause -import logging import os -import sys from time import time -from optparse import OptionParser - +import argparse import numpy as np from sklearn.datasets import fetch_covtype, get_data_home @@ -62,73 +58,35 @@ from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier from sklearn.ensemble import GradientBoostingClassifier -from sklearn import metrics +from sklearn.metrics import zero_one_loss from sklearn.externals.joblib import Memory - -logging.basicConfig(level=logging.INFO, - format='%(asctime)s %(levelname)s %(message)s') -logger = logging.getLogger(__name__) - -op = OptionParser() -op.add_option("--classifiers", - dest="classifiers", default='liblinear,GaussianNB,SGD,CART', - help="comma-separated list of classifiers to benchmark. " - "default: %default. available: " - "liblinear, GaussianNB, SGD, CART, ExtraTrees,\n" - "RandomForest, GBRT") - -op.add_option("--n-jobs", - dest="n_jobs", default=1, type=int, - help="Number of concurrently running workers for models that" - " support parallelism.") - -# Each number generator use the same seed to avoid coupling issue between -# estimators. -op.add_option("--random-seed", - dest="random_seed", default=13, type=int, - help="Common seed used by random number generator.") - -op.print_help() - -(opts, args) = op.parse_args() -if len(args) > 0: - op.error("this script takes no arguments.") - sys.exit(1) +from sklearn.utils import check_array # Memoize the data extraction and memory map the resulting # train / test splits in readonly mode -joblib_cache_folder = os.path.join(get_data_home(), 'covertype_benchmark_data') -m = Memory(joblib_cache_folder, mmap_mode='r') +memory = Memory(os.path.join(get_data_home(), 'covertype_benchmark_data'), + mmap_mode='r') -# Load the data, then cache and memmap the train/test split -@m.cache -def load_data(dtype=np.float32, order='C'): +@memory.cache +def load_data(dtype=np.float32, order='C', random_state=13): + """Load the data, then cache and memmap the train/test split""" ###################################################################### ## Load dataset print("Loading dataset...") data = fetch_covtype(download_if_missing=True, shuffle=True, - random_state=opts.random_seed) - X, y = data['data'], data['target'] - X = np.asarray(X, dtype=dtype) - - if order.lower() == 'f': - X = np.asfortranarray(X) + random_state=random_state) + X = check_array(data['data'], dtype=dtype, order=order) + y = (data['target'] != 1).astype(np.int) - # class 1 vs. all others. - y[np.where(y != 1)] = -1 - - ###################################################################### ## Create train-test split (as [Joachims, 2006]) - logger.info("Creating train-test split...") + print("Creating train-test split...") n_train = 522911 - X_train = X[:n_train] y_train = y[:n_train] X_test = X[n_train:] y_test = y[n_train:] - ###################################################################### ## Standardize first 10 features (the numerical ones) mean = X_train.mean(axis=0) std = X_train.std(axis=0) @@ -139,130 +97,92 @@ def load_data(dtype=np.float32, order='C'): return X_train, X_test, y_train, y_test -X_train, X_test, y_train, y_test = load_data() - -###################################################################### -## Print dataset statistics -print("") -print("Dataset statistics:") -print("===================") -print("%s %d" % ("number of features:".ljust(25), - X_train.shape[1])) -print("%s %d" % ("number of classes:".ljust(25), - np.unique(y_train).shape[0])) -print("%s %s" % ("data type:".ljust(25), X_train.dtype)) -print("%s %d (pos=%d, neg=%d, size=%dMB)" - % ("number of train samples:".ljust(25), - X_train.shape[0], np.sum(y_train == 1), - np.sum(y_train == -1), int(X_train.nbytes / 1e6))) -print("%s %d (pos=%d, neg=%d, size=%dMB)" - % ("number of test samples:".ljust(25), - X_test.shape[0], np.sum(y_test == 1), - np.sum(y_test == -1), int(X_test.nbytes / 1e6))) - - -classifiers = dict() - - -###################################################################### -## Benchmark classifiers -def benchmark(clf): - t0 = time() - clf.fit(X_train, y_train) - train_time = time() - t0 - t0 = time() - pred = clf.predict(X_test) - test_time = time() - t0 - err = metrics.zero_one_loss(y_test, pred, normalize=True) - return err, train_time, test_time - -###################################################################### -## Train Liblinear model -liblinear_parameters = { - 'loss': 'l2', - 'penalty': 'l2', - 'C': 1000, - 'dual': False, - 'tol': 1e-3, - "random_state": opts.random_seed, +ESTIMATORS = { + 'GBRT': GradientBoostingClassifier(n_estimators=250), + 'ExtraTrees': ExtraTreesClassifier(n_estimators=20), + 'RandomForest': RandomForestClassifier(n_estimators=20), + 'CART': DecisionTreeClassifier(min_samples_split=5), + 'SGD': SGDClassifier(alpha=0.001, n_iter=2), + 'GaussianNB': GaussianNB(), + 'liblinear': LinearSVC(loss="l2", penalty="l2", C=1000, dual=False, + tol=1e-3) } -classifiers['liblinear'] = LinearSVC(**liblinear_parameters) - -###################################################################### -## Train GaussianNB model -classifiers['GaussianNB'] = GaussianNB() - -###################################################################### -## Train SGD model -sgd_parameters = { - 'alpha': 0.001, - 'n_iter': 2, - 'n_jobs': opts.n_jobs, - "random_state": opts.random_seed, -} -classifiers['SGD'] = SGDClassifier(**sgd_parameters) - -###################################################################### -## Train CART model -classifiers['CART'] = DecisionTreeClassifier(min_samples_split=5, - max_depth=None, - random_state=opts.random_seed) - -###################################################################### -## Train RandomForest model -rf_parameters = { - "n_estimators": 20, - "n_jobs": opts.n_jobs, - "random_state": opts.random_seed, -} -classifiers['RandomForest'] = RandomForestClassifier(**rf_parameters) - -###################################################################### -## Train Extra-Trees model -classifiers['ExtraTrees'] = ExtraTreesClassifier(n_estimators=20, - n_jobs=opts.n_jobs, - random_state=opts.random_seed) - -###################################################################### -## Train GBRT model -classifiers['GBRT'] = GradientBoostingClassifier(n_estimators=250, - random_state=opts.random_seed) - - -selected_classifiers = opts.classifiers.split(',') -for name in selected_classifiers: - if name not in classifiers: - op.error('classifier %r unknown' % name) - sys.exit(1) - -print() -print("Training Classifiers") -print("====================") -print() -err, train_time, test_time = {}, {}, {} -for name in sorted(selected_classifiers): - print("Training %s ..." % name) - err[name], train_time[name], test_time[name] = benchmark(classifiers[name]) - -###################################################################### -## Print classification performance -print() -print("Classification performance:") -print("===========================") -print() - - -def print_row(clf_type, train_time, test_time, err): - print("%s %s %s %s" % (clf_type.ljust(12), - ("%.4fs" % train_time).center(10), - ("%.4fs" % test_time).center(10), - ("%.4f" % err).center(10))) - -print("%s %s %s %s" % ("Classifier ", "train-time", "test-time", - "error-rate")) -print("-" * 44) - -for name in sorted(selected_classifiers, key=lambda name: err[name]): - print_row(name, train_time[name], test_time[name], err[name]) -print() -print() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--classifiers', nargs="+", + choices=ESTIMATORS, type=str, + default=['liblinear', 'GaussianNB', 'SGD', 'CART'], + help="list of classifiers to benchmark.") + parser.add_argument('--n-jobs', nargs="?", default=1, type=int, + help="Number of concurrently running workers for " + "models that support parallelism.") + parser.add_argument('--order', nargs="?", default="C", type=str, + choices=["F", "C"], + help="Allow to choose between fortran and C ordered " + "data") + parser.add_argument('--random-seed', nargs="?", default=13, type=int, + help="Common seed used by random number generator.") + args = vars(parser.parse_args()) + + print(__doc__) + + X_train, X_test, y_train, y_test = load_data( + order=args["order"], random_state=args["random_seed"]) + + print("") + print("Dataset statistics:") + print("===================") + print("%s %d" % ("number of features:".ljust(25), X_train.shape[1])) + print("%s %d" % ("number of classes:".ljust(25), np.unique(y_train).size)) + print("%s %s" % ("data type:".ljust(25), X_train.dtype)) + print("%s %d (pos=%d, neg=%d, size=%dMB)" + % ("number of train samples:".ljust(25), + X_train.shape[0], np.sum(y_train == 1), + np.sum(y_train == 0), int(X_train.nbytes / 1e6))) + print("%s %d (pos=%d, neg=%d, size=%dMB)" + % ("number of test samples:".ljust(25), + X_test.shape[0], np.sum(y_test == 1), + np.sum(y_test == 0), int(X_test.nbytes / 1e6))) + + print() + print("Training Classifiers") + print("====================") + error, train_time, test_time = {}, {}, {} + for name in sorted(args["classifiers"]): + print("Training %s ... " % name, end="") + estimator = ESTIMATORS[name] + estimator_params = estimator.get_params() + + if "random_state" in estimator_params: + estimator.set_params(random_state=args["random_seed"]) + + if "n_jobs" in estimator_params: + estimator.set_params(n_jobs=args["n_jobs"]) + + time_start = time() + estimator.fit(X_train, y_train) + train_time[name] = time() - time_start + + time_start = time() + y_pred = estimator.predict(X_test) + test_time[name] = time() - time_start + + error[name] = zero_one_loss(y_test, y_pred) + + print("done") + + print() + print("Classification performance:") + print("===========================") + print("%s %s %s %s" + % ("Classifier ", "train-time", "test-time", "error-rate")) + print("-" * 44) + for name in sorted(args["classifiers"], key=error.get): + print("%s %s %s %s" % (name.ljust(12), + ("%.4fs" % train_time[name]).center(10), + ("%.4fs" % test_time[name]).center(10), + ("%.4f" % error[name]).center(10))) + + print() diff --git a/benchmarks/bench_multilabel_metrics.py b/benchmarks/bench_multilabel_metrics.py index 3cf5cb0a7f663..4a4cdd7f33902 100755 --- a/benchmarks/bench_multilabel_metrics.py +++ b/benchmarks/bench_multilabel_metrics.py @@ -12,11 +12,13 @@ import sys import matplotlib.pyplot as plt +import scipy.sparse as sp import numpy as np from sklearn.datasets import make_multilabel_classification from sklearn.metrics import (f1_score, accuracy_score, hamming_loss, jaccard_similarity_score) +from sklearn.utils.testing import ignore_warnings METRICS = { @@ -30,9 +32,12 @@ FORMATS = { 'sequences': lambda y: [list(np.flatnonzero(s)) for s in y], 'dense': lambda y: y, + 'csr': lambda y: sp.csr_matrix(y), + 'csc': lambda y: sp.csc_matrix(y), } +@ignore_warnings def benchmark(metrics=tuple(v for k, v in sorted(METRICS.items())), formats=tuple(v for k, v in sorted(FORMATS.items())), samples=1000, classes=4, density=.2, @@ -109,7 +114,7 @@ def _tabulate(results, metrics, formats): def _plot(results, metrics, formats, title, x_ticks, x_label, - format_markers=('x', '|', 'o'), + format_markers=('x', '|', 'o', '+'), metric_colors=('c', 'm', 'y', 'k', 'g', 'r', 'b')): """ Plot the results by metric, format and some other variable given by diff --git a/continuous_integration/appveyor/requirements.txt b/continuous_integration/appveyor/requirements.txt index f8cd41f64529b..d86a2b15601d3 100644 --- a/continuous_integration/appveyor/requirements.txt +++ b/continuous_integration/appveyor/requirements.txt @@ -4,7 +4,12 @@ # This is a temporary solution. As soon as numpy and scipy provide official # wheel for windows we ca delete this --find-links line. --find-links http://28daf2247a33ed269873-7b1aad3fab3cc330e1fd9d109892382a.r6.cf2.rackcdn.com/index.html -numpy -scipy + +# fix the versions of numpy to force the use of numpy and scipy to use the whl +# of the rackspace folder instead of trying to install from more recent +# source tarball published on PyPI +numpy==1.8.1 +scipy==0.14.0 nose wheel +wheelhouse_uploader diff --git a/continuous_integration/install.sh b/continuous_integration/install.sh index c9b0b56392f99..aaf448dd543af 100644 --- a/continuous_integration/install.sh +++ b/continuous_integration/install.sh @@ -4,8 +4,15 @@ # The behavior of the script is controlled by environment variabled defined # in the .travis.yml in the top level folder of the project. +# License: 3-clause BSD + set -e +# Fix the compilers to workaround avoid having the Python 3.4 build +# lookup for g++44 unexpectedly. +export CC=gcc +export CXX=g++ + sudo apt-get update -qq if [[ "$INSTALL_ATLAS" == "true" ]]; then sudo apt-get install -qq libatlas3gf-base libatlas-dev @@ -18,10 +25,10 @@ if [[ "$DISTRIB" == "conda" ]]; then # Use the miniconda installer for faster download / install of conda # itself - wget http://repo.continuum.io/miniconda/Miniconda-2.2.2-Linux-x86_64.sh \ + wget http://repo.continuum.io/miniconda/Miniconda-3.6.0-Linux-x86_64.sh \ -O miniconda.sh chmod +x miniconda.sh && ./miniconda.sh -b - export PATH=/home/travis/anaconda/bin:$PATH + export PATH=/home/travis/miniconda/bin:$PATH conda update --yes conda # Configure the conda environment and put it in the path using the diff --git a/continuous_integration/test_script.sh b/continuous_integration/test_script.sh index 8e22e75a99fe1..ddb1d82b363fe 100644 --- a/continuous_integration/test_script.sh +++ b/continuous_integration/test_script.sh @@ -4,6 +4,8 @@ # The behavior of the script is controlled by environment variabled defined # in the .travis.yml in the top level folder of the project. +# License: 3-clause BSD + set -e python --version diff --git a/doc/datasets/index.rst b/doc/datasets/index.rst index 7bff294e52048..2e36c85b659da 100644 --- a/doc/datasets/index.rst +++ b/doc/datasets/index.rst @@ -108,33 +108,113 @@ Sample generators In addition, scikit-learn includes various random sample generators that can be used to build artificial datasets of controlled size and complexity. +Generators for classification and clustering +-------------------------------------------- + +These generators produce a matrix of features and corresponding discrete +targets. + +Single label +~~~~~~~~~~~~ + +Both :func:`make_blobs` and :func:`make_classification` create multiclass +datasets by allocating each class one or more normally-distributed clusters of +points. :func:`make_blobs` provides greater control regarding the centers and +standard deviations of each cluster, and is used to demonstrate clustering. +:func:`make_classification` specialises in introducing noise by way of: +correlated, redundant and uninformative features; multiple Gaussian clusters +per class; and linear transformations of the feature space. + +:func:`make_gaussian_quantiles` divides a single Gaussian cluster into +near-equal-size classes separated by concentric hyperspheres. +:func:`make_hastie_10_2` generates a similar binary, 10-dimensional problem. + .. image:: ../auto_examples/datasets/images/plot_random_dataset_001.png :target: ../auto_examples/datasets/plot_random_dataset.html :scale: 50 :align: center +:func:`make_circles` and :func:`make_moons` generate 2d binary classification +datasets that are challenging to certain algorithms (e.g. centroid-based +clustering or linear classification), including optional Gaussian noise. +They are useful for visualisation. produces Gaussian +data with a spherical decision boundary for binary classification. + +Multilabel +~~~~~~~~~~ + +:func:`make_multilabel_classification` generates random samples with multiple +labels, reflecting a bag of words drawn from a mixture of topics. The number of +topics for each document is drawn from a Poisson distribution, and the topics +themselves are drawn from a fixed random distribution. Similarly, the number of +words is drawn from Poisson, with words drawn from a multinomial, where each +topic defines a probability distribution over words. Simplifications with +respect to true bag-of-words mixtures include: + +* Per-topic word distributions are independently drawn, where in reality all + would be affected by a sparse base distribution, and would be correlated. +* For a document generated from multiple topics, all topics are weighted + equally in generating its bag of words. +* Documents without labels words at random, rather than from a base + distribution. + +.. image:: ../auto_examples/datasets/images/plot_random_multilabel_dataset_001.png + :target: ../auto_examples/datasets/plot_random_multilabel_dataset.html + :scale: 50 + :align: center + +Biclustering +~~~~~~~~~~~~ + +.. autosummary:: + + :toctree: ../modules/generated/ + :template: function.rst + + make_biclusters + make_checkerboard + + +Generators for regression +------------------------- + +:func:`make_regression` produces regression targets as an optionally-sparse +random linear combination of random features, with noise. Its informative +features may be uncorrelated, or low rank (few features account for most of the +variance). + +Other regression generators generate functions deterministically from +randomized features. :func:`make_sparse_uncorrelated` produces a target as a +linear combination of four features with fixed coefficients. +Others encode explicitly non-linear relations: +:func:`make_friedman1` is related by polynomial and sine transforms; +:func:`make_friedman2` includes feature multiplication and reciprocation; and +:func:`make_friedman3` is similar with an arctan transformation on the target. + +Generators for manifold learning +-------------------------------- + +.. autosummary:: + + :toctree: ../modules/generated/ + :template: function.rst + + make_s_curve + make_swiss_roll + +Generators for decomposition +---------------------------- + .. autosummary:: :toctree: ../modules/generated/ :template: function.rst - make_classification - make_multilabel_classification - make_regression - make_blobs - make_friedman1 - make_friedman2 - make_friedman3 - make_hastie_10_2 make_low_rank_matrix make_sparse_coded_signal - make_sparse_uncorrelated make_spd_matrix - make_swiss_roll - make_s_curve make_sparse_spd_matrix - make_biclusters - make_checkerboard + .. _libsvm_loader: diff --git a/doc/developers/utilities.rst b/doc/developers/utilities.rst index a661a539ba028..9f24e24fc65cf 100644 --- a/doc/developers/utilities.rst +++ b/doc/developers/utilities.rst @@ -140,8 +140,8 @@ Efficient Routines for Sparse Matrices The ``sklearn.utils.sparsefuncs`` cython module hosts compiled extensions to efficiently process ``scipy.sparse`` data. -- :func:`sparsefuncs.mean_variance_axis0`: compute the means and - variances along axis 0 of a CSR matrix. +- :func:`sparsefuncs.mean_variance_axis`: compute the means and + variances along a specified axis of a CSR matrix. Used for normalizing the tolerance stopping criterion in :class:`sklearn.cluster.k_means_.KMeans`. diff --git a/doc/faq.rst b/doc/faq.rst index 8a1fae625528d..d78ee4e6e738c 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -47,7 +47,7 @@ Not in the forseeable future. scikit-learn tries to provide a unified API for the basic tasks in machine learning, with pipelines and meta-algorithms like grid search to tie everything together. The required concepts, APIs, algorithms and -expertise required for stuctured learning are different from what +expertise required for structured learning are different from what scikit-learn has to offer. If we started doing arbitrary structured learning, we'd need to redesign the whole package and the project would likely collapse under its own weight. diff --git a/doc/install.rst b/doc/install.rst index 6c5775e35ca45..a97b97dc5bda6 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -80,13 +80,19 @@ Installing build dependencies Installing from source requires you to have installed the scikit-learn runtime dependencies, Python development headers and a working C/C++ compiler. -Under Debian-based operating systems, which include Ubuntu, -you can install all these requirements by issuing:: +Under Debian-based operating systems, which include Ubuntu, if you have +Python 2 you can install all these requirements by issuing:: sudo apt-get install build-essential python-dev python-setuptools \ python-numpy python-scipy \ libatlas-dev libatlas3gf-base +If you have Python 3:: + + sudo apt-get install build-essential python3-dev python3-setuptools \ + python3-numpy python3-scipy \ + libatlas-dev libatlas3gf-base + On recent Debian and Ubuntu (e.g. Ubuntu 13.04 or later) make sure that ATLAS is used to provide the implementation of the BLAS and LAPACK linear algebra routines:: @@ -290,7 +296,7 @@ PATH environment variable. 32-bit Python -~~~~~~~~~~~~~ +------------- For 32-bit Python it is possible use the standalone installers for `Microsoft Visual C++ Express 2008 `_ @@ -306,7 +312,7 @@ folder:: 64-bit Python -~~~~~~~~~~~~~ +------------- For the 64-bit architecture, you either need the full Visual Studio or the free Windows SDKs that can be downloaded from the links below. @@ -348,7 +354,7 @@ Python. Building binary packages and installers -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--------------------------------------- The ``.whl`` package and ``.exe`` installers can be built with:: @@ -359,7 +365,7 @@ The resulting packages are generated in the ``dist/`` folder. Using an alternative compiler -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +----------------------------- It is possible to use `MinGW `_ (a port of GCC to Windows OS) as an alternative to MSVC for 32-bit Python. Not that extensions built with diff --git a/doc/modules/clustering.rst b/doc/modules/clustering.rst index 94701ed2a788a..d8f07927bb6a8 100644 --- a/doc/modules/clustering.rst +++ b/doc/modules/clustering.rst @@ -180,7 +180,7 @@ value. This is not the case in this implementation: iteration stops when centroids move less than the tolerance. Given enough time, K-means will always converge, however this may be to a local -minimum. This is highly dependent on the the initialization of the centroids. +minimum. This is highly dependent on the initialization of the centroids. As a result, the computation is often done several times, with different initializations of the centroids. One method to help address this issue is the k-means++ initialization scheme, which has been implemented in scikit-learn diff --git a/doc/modules/cross_validation.rst b/doc/modules/cross_validation.rst index 129ff19d3a38e..329d831b99b6d 100644 --- a/doc/modules/cross_validation.rst +++ b/doc/modules/cross_validation.rst @@ -264,8 +264,8 @@ fold cross validation should be preferred to LOO. `_, Intl. Jnt. Conf. AI * R. Bharat Rao, G. Fung, R. Rosales, `On the Dangers of Cross-Validation. An Experimental Evaluation `_, SIAM 2008 - * G. James, D. Witten, T. Hastie, R Tibshirani, `An Introduction to Statitical Learning - `_, Springer 2013 + * G. James, D. Witten, T. Hastie, R Tibshirani, `An Introduction to + Statistical Learning `_, Springer 2013 Leave-P-Out - LPO diff --git a/doc/modules/kernel_approximation.rst b/doc/modules/kernel_approximation.rst index 727a10f474da1..f19890ebbda73 100644 --- a/doc/modules/kernel_approximation.rst +++ b/doc/modules/kernel_approximation.rst @@ -19,7 +19,7 @@ can be better suited for online learning and can significantly reduce the cost of learning with very large datasets. Standard kernelized SVMs do not scale well to large datasets, but using an approximate kernel map it is possible to use much more efficient linear SVMs. -In particularly the combination of kernel map approximations with +In particular, the combination of kernel map approximations with :class:`SGDClassifier` can make non-linear learning on large datasets possible. Since there has not been much empirical work using approximate embeddings, it diff --git a/doc/modules/linear_model.rst b/doc/modules/linear_model.rst index 55a8c5b8e13df..599019c4c7696 100644 --- a/doc/modules/linear_model.rst +++ b/doc/modules/linear_model.rst @@ -184,8 +184,8 @@ for another implementation:: >>> clf = linear_model.Lasso(alpha = 0.1) >>> clf.fit([[0, 0], [1, 1]], [0, 1]) Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000, - normalize=False, positive=False, precompute='auto', tol=0.0001, - warm_start=False) + normalize=False, positive=False, precompute='auto', random_state=None, + selection='cyclic', tol=0.0001, warm_start=False) >>> clf.predict([[1, 1]]) array([ 0.8]) @@ -671,14 +671,29 @@ The lbfgs and newton-cg solvers only support L2 penalization and are found to converge faster for some high dimensional data. L1 penalization yields sparse predicting weights. -For L1 penalization :func:`sklearn.svm.l1_min_c` allows to calculate -the lower bound for C in order to get a non "null" (all feature weights to -zero) model. +Several estimators are available for logistic regression. -The implementation of Logistic Regression relies on the excellent -`LIBLINEAR library `_, -which is shipped with scikit-learn. +:class:`LogisticRegression` has an option of using three solvers, +"liblinear", "lbfgs" and "newton-cg". +The solver "liblinear" uses a coordinate descent (CD) algorithm based on +Liblinear. For L1 penalization :func:`sklearn.svm.l1_min_c` allows to +calculate the lower bound for C in order to get a non "null" (all feature weights to +zero) model. This relies on the excellent +`LIBLINEAR library `_, +which is shipped with scikit-learn. However, the CD algorithm implemented in +liblinear cannot learn a true multinomial (multiclass) model; +instead, the optimization problem is decomposed in a "one-vs-rest" fashion +so separate binary classifiers are trained for all classes. +This happens under the hood, so :class:`LogisticRegression` instances +using this solver behave as multiclass classifiers. + +Setting `multi_class` to "multinomial" with the "lbfgs" solver +in :class:`LogisticRegression` learns a true multinomial logistic +regression model, which means that its probability estimates should +be better calibrated than the default "one-vs-rest" setting. +L-BFGS cannot optimize L1-penalized models, though, +so the "multinomial" setting does not learn sparse models. .. topic:: Examples: @@ -686,6 +701,21 @@ which is shipped with scikit-learn. * :ref:`example_linear_model_plot_logistic_path.py` +.. _liblinear_differences: + +.. topic:: Differences from liblinear: + + There might be a difference in the scores obtained between + :class:`LogisticRegression` with ``solver=liblinear`` + or :class:`LinearSVC` and the external liblinear library directly, + when ``fit_intercept=False`` and the fit ``coef_`` (or) the data to + be predicted are zeroes. This is because for the sample(s) with + ``decision_function`` zero, :class:`LogisticRegression` and :class:`LinearSVC` + predict the negative class, while liblinear predicts the positive class. + Note that a model with ``fit_intercept=False`` and having many samples with + ``decision_function`` zero, is likely to be a underfit, bad model and you are + advised to set ``fit_intercept=True`` and increase the intercept_scaling. + .. note:: **Feature selection with sparse logistic regression** A logistic regression with L1 penalty yields sparse models, and can @@ -695,8 +725,10 @@ which is shipped with scikit-learn. :class:`LogisticRegressionCV` implements Logistic Regression with builtin cross-validation to find out the optimal C parameter. In general the "newton-cg" and "lbfgs" solvers are found to be faster -due to warm-starting. For the multiclass case, One-vs-All is used -and an optimal C is obtained for each class. +due to warm-starting. For the multiclass case, if `multi_class` +option is set to "ovr", an optimal C is obtained for each class and if +the `multi_class` option is set to "multinomial", an optimal C is +obtained that minimizes the cross-entropy loss. Stochastic Gradient Descent - SGD diff --git a/doc/modules/manifold.rst b/doc/modules/manifold.rst index 20c4328baede6..5cf546906a72b 100644 --- a/doc/modules/manifold.rst +++ b/doc/modules/manifold.rst @@ -411,8 +411,8 @@ There exists two types of MDS algorithm: metric and non metric. In the scikit-learn, the class :class:`MDS` implements both. In Metric MDS, the input similarity matrix arises from a metric (and thus respects the triangular inequality), the distances between output two points are then set to be as -close as possible to the similarity or dissimilarity data. In the non metric -vision, the algorithms will try to preserve the order of the distances, and +close as possible to the similarity or dissimilarity data. In the non-metric +version, the algorithms will try to preserve the order of the distances, and hence seek for a monotonic relationship between the distances in the embedded space and the similarities/dissimilarities. diff --git a/doc/modules/model_evaluation.rst b/doc/modules/model_evaluation.rst index f4d4d7c6bb51e..f7bd64b815272 100644 --- a/doc/modules/model_evaluation.rst +++ b/doc/modules/model_evaluation.rst @@ -20,8 +20,10 @@ model: This is discussed on section :ref:`scoring_parameter`. * **Metric functions**: The :mod:`metrics` module implements functions - assessing prediction errors for specific purposes. This is discussed in - the section :ref:`prediction_error_metrics`. + assessing prediction error for specific purposes. These metrics are detailed + in sections on :ref:`classification_metrics`, + :ref:`multilabel_ranking_metrics`, :ref:`regression_metrics` and + :ref:`clustering_metrics`. Finally, :ref:`dummy_estimators` are useful to get a baseline value of those metrics for random predictions. @@ -42,7 +44,7 @@ Model selection and evaluation using tools, such as controls what metric they apply to estimators evaluated. Common cases: predefined values --------------------------------- +------------------------------- For the most common usecases, you can simply provide a string as the ``scoring`` parameter. Possible values are: @@ -91,22 +93,31 @@ predicted values. These are detailed below, in the next sections. .. _scoring: -Defining your scoring strategy from score functions +Defining your scoring strategy from metric functions ----------------------------------------------------- -The scoring parameter can be a callable that takes model predictions and -ground truth. +The module :mod:`sklearn.metric` also exposes a set of simple functions +measuring a prediction error given ground truth and prediction: -However, if you want to use a scoring function that takes additional parameters, such as -:func:`fbeta_score`, you need to generate an appropriate scoring object. The -simplest way to generate a callable object for scoring is by using -:func:`make_scorer`. -That function converts score functions (discussed below in :ref:`prediction_error_metrics`) into callables that can be -used for model evaluation. +- functions ending with ``_score`` return a value to + maximize (the higher the better). -One typical use case is to wrap an existing scoring function from the library -with non default value for its parameters such as the ``beta`` parameter for the -:func:`fbeta_score` function:: +- functions ending with ``_error`` or ``_loss`` return a + value to minimize (the lower the better). + +Metrics available for various machine learning tasks are detailed in sections +below. + +Many metrics are not given names to be used as ``scoring`` values, +sometimes because they require additional parameters, such as +:func:`fbeta_score`. In such cases, you need to generate an appropriate +scoring object. The simplest way to generate a callable object for scoring +is by using :func:`make_scorer`. That function converts metrics +into callables that can be used for model evaluation. + +One typical use case is to wrap an existing metric function from the library +with non default value for its parameters, such as the ``beta`` parameter for +the :func:`fbeta_score` function:: >>> from sklearn.metrics import fbeta_score, make_scorer >>> ftwo_scorer = make_scorer(fbeta_score, beta=2) @@ -138,6 +149,8 @@ from a simple python function:: * any additional parameters, such as ``beta`` in an :func:`f1_score`. +.. _diy_scoring: + Implementing your own scoring object ------------------------------------ You can generate even more flexible model scores by constructing your own @@ -154,24 +167,10 @@ the following two rules: ``estimator``'s predictions on ``X`` which reference to ``y``. Again, higher numbers are better. -.. _prediction_error_metrics: - -Function for prediction-error metrics -====================================== - -The module :mod:`sklearn.metric` also exposes a set of simple functions -measuring a prediction error given ground truth and prediction: - -- functions ending with ``_score`` return a value to - maximize (the higher the better). - -- functions ending with ``_error`` or ``_loss`` return a - value to minimize (the lower the better). - .. _classification_metrics: Classification metrics ------------------------ +======================= .. currentmodule:: sklearn.metrics @@ -228,7 +227,7 @@ And some work with binary and multilabel indicator format: In the following sub-sections, we will describe each of those functions. Accuracy score -.............. +-------------- The :func:`accuracy_score` function computes the `accuracy `_, the fraction @@ -261,7 +260,7 @@ where :math:`1(x)` is the `indicator function In the multilabel case with binary label indicators: :: - >>> accuracy_score(np.array([[0.0, 1.0], [1.0, 1.0]]), np.ones((2, 2))) + >>> accuracy_score(np.array([[0, 1], [1, 1]]), np.ones((2, 2))) 0.5 .. topic:: Example: @@ -271,7 +270,7 @@ In the multilabel case with binary label indicators: :: the dataset. Confusion matrix -................ +---------------- The :func:`confusion_matrix` function computes the `confusion matrix `_ to evaluate @@ -313,7 +312,7 @@ from the :ref:`example_model_selection_plot_confusion_matrix.py` example): Classification report -...................... +---------------------- The :func:`classification_report` function builds a text report showing the main classification metrics. Here a small example with custom ``target_names`` @@ -348,7 +347,7 @@ and inferred labels:: grid search with a nested cross-validation. Hamming loss -............. +------------- The :func:`hamming_loss` computes the average Hamming loss or `Hamming distance `_ between two sets @@ -374,7 +373,7 @@ where :math:`1(x)` is the `indicator function In the multilabel case with binary label indicators: :: - >>> hamming_loss(np.array([[0.0, 1.0], [1.0, 1.0]]), np.zeros((2, 2))) + >>> hamming_loss(np.array([[0, 1], [1, 1]]), np.zeros((2, 2))) 0.75 .. note:: @@ -395,7 +394,7 @@ In the multilabel case with binary label indicators: :: Jaccard similarity coefficient score -..................................... +------------------------------------- The :func:`jaccard_similarity_score` function computes the average (default) or sum of `Jaccard similarity coefficients @@ -426,13 +425,13 @@ score is equal to the classification accuracy. In the multilabel case with binary label indicators: :: - >>> jaccard_similarity_score(np.array([[0.0, 1.0], [1.0, 1.0]]), np.ones((2, 2))) + >>> jaccard_similarity_score(np.array([[0, 1], [1, 1]]), np.ones((2, 2))) 0.75 .. _precision_recall_f_measure_metrics: Precision, recall and F-measures -................................. +--------------------------------- The `precision `_ is intuitively the ability of the classifier not to label as @@ -639,7 +638,7 @@ Then the metrics are defined as: Hinge loss -........... +----------- The :func:`hinge_loss` function computes the average `hinge loss function `_. The hinge @@ -663,8 +662,8 @@ with a svm classifier:: >>> est = svm.LinearSVC(random_state=0) >>> est.fit(X, y) LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True, - intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2', - random_state=0, tol=0.0001, verbose=0) + intercept_scaling=1, loss='l2', max_iter=1000, multi_class='ovr', + penalty='l2', random_state=0, tol=0.0001, verbose=0) >>> pred_decision = est.decision_function([[-2], [3], [0.5]]) >>> pred_decision # doctest: +ELLIPSIS array([-2.18..., 2.36..., 0.09...]) @@ -673,7 +672,8 @@ with a svm classifier:: Log loss -........ +-------- + The log loss, also called logistic regression loss or cross-entropy loss, is a loss function defined on probability estimates. It is commonly used in (multinomial) logistic regression and neural networks, @@ -725,7 +725,7 @@ The log loss is non-negative. Matthews correlation coefficient -................................. +--------------------------------- The :func:`matthews_corrcoef` function computes the Matthew's correlation coefficient (MCC) for binary classes (quoting the `Wikipedia article on the @@ -761,7 +761,7 @@ function: .. _roc_metrics: Receiver operating characteristic (ROC) -....................................... +--------------------------------------- The function :func:`roc_curve` computes the `receiver operating characteristic curve, or ROC curve (quoting @@ -857,7 +857,7 @@ if predicted outputs have been binarized. .. _zero_one_loss: Zero one loss -.............. +-------------- The :func:`zero_one_loss` function computes the sum or the average of the 0-1 classification loss (:math:`L_{0-1}`) over :math:`n_{\text{samples}}`. By @@ -889,7 +889,7 @@ where :math:`1(x)` is the `indicator function In the multilabel case with binary label indicators: :: - >>> zero_one_loss(np.array([[0.0, 1.0], [1.0, 1.0]]), np.ones((2, 2))) + >>> zero_one_loss(np.array([[0, 1], [1, 1]]), np.ones((2, 2))) 0.5 @@ -903,7 +903,7 @@ In the multilabel case with binary label indicators: :: .. _multilabel_ranking_metrics: Multilabel ranking metrics --------------------------- +========================== .. currentmodule:: sklearn.metrics @@ -912,7 +912,8 @@ associated with it. The goal is to give high scores and better rank to the ground truth labels. Label ranking average precision -............................... +------------------------------- + The :func:`label_ranking_average_precision_score` function implements the label ranking average precision (LRAP). This metric is linked to the :func:`average_precision_score` function, but is based on the notion of @@ -955,7 +956,7 @@ Here a small example of usage of this function:: .. _regression_metrics: Regression metrics -------------------- +=================== .. currentmodule:: sklearn.metrics @@ -966,7 +967,7 @@ to handle the multioutput case: :func:`mean_absolute_error`, Explained variance score -......................... +------------------------- The :func:`explained_variance_score` computes the `explained variance regression score `_. @@ -991,7 +992,7 @@ function:: 0.957... Mean absolute error -................... +------------------- The :func:`mean_absolute_error` function computes the `mean absolute error `_, which is a risk @@ -1021,7 +1022,7 @@ Here a small example of usage of the :func:`mean_absolute_error` function:: Mean squared error -................... +------------------- The :func:`mean_squared_error` function computes the `mean square error `_, which is a risk @@ -1056,7 +1057,7 @@ function:: evaluate gradient boosting regression. R² score, the coefficient of determination -........................................... +------------------------------------------- The :func:`r2_score` function computes R², the `coefficient of determination `_. @@ -1092,31 +1093,17 @@ Here a small example of usage of the :func:`r2_score` function:: for an example of R² score usage to evaluate Lasso and Elastic Net on sparse signals. +.. _clustering_metrics: + Clustering metrics ====================== -The :mod:`sklearn.metrics` implements several losses, scores and utility -function for more information see the :ref:`clustering_evaluation` -section. - - -Biclustering metrics -==================== - -The :mod:`sklearn.metrics` module implements bicluster scoring -metrics. For more information see the :ref:`biclustering_evaluation` -section. - - .. currentmodule:: sklearn.metrics -.. _clustering_metrics: - -Clustering metrics -------------------- - The :mod:`sklearn.metrics` implements several losses, scores and utility -functions. For more information see the :ref:`clustering_evaluation` section. +functions. For more information see the :ref:`clustering_evaluation` +section for instance clustering, and :ref:`biclustering_evaluation` for +biclustering. .. _dummy_estimators: diff --git a/doc/modules/multiclass.rst b/doc/modules/multiclass.rst index 720f573ff4e07..a960bb1a418b4 100644 --- a/doc/modules/multiclass.rst +++ b/doc/modules/multiclass.rst @@ -62,7 +62,9 @@ if you're using one of these unless you want custom multiclass behavior: - Inherently multiclass: :ref:`Naive Bayes `, :class:`sklearn.lda.LDA`, :ref:`Decision Trees `, :ref:`Random Forests `, - :ref:`Nearest Neighbors `. + :ref:`Nearest Neighbors `, + setting "multi_class=multinomial" in + :class:`sklearn.linear_model.LogisticRegression`. - One-Vs-One: :class:`sklearn.svm.SVC`. - One-Vs-All: all linear models except :class:`sklearn.svm.SVC`. diff --git a/doc/modules/preprocessing.rst b/doc/modules/preprocessing.rst index 4d3b04ade3c7b..04aadf5a0531a 100644 --- a/doc/modules/preprocessing.rst +++ b/doc/modules/preprocessing.rst @@ -469,7 +469,7 @@ in the matrix. This format is thus suitable when there are many more missing values than observed values. :class:`Imputer` can be used in a Pipeline as a way to build a composite -estimator that supports imputation. See :ref:`example_imputation.py` +estimator that supports imputation. See :ref:`example_missing_values.py`. .. _data_reduction: diff --git a/doc/modules/scaling_strategies.rst b/doc/modules/scaling_strategies.rst index e4c5e9953ca75..087512a02dfde 100644 --- a/doc/modules/scaling_strategies.rst +++ b/doc/modules/scaling_strategies.rst @@ -1,8 +1,8 @@ .. _scaling_strategies: -================== -Scaling Strategies -================== +================================================= +Strategies to scale computationally: bigger data +================================================= For some applications the amount of examples, features (or both) and/or the speed at which they need to be processed are challenging for traditional diff --git a/doc/modules/svm.rst b/doc/modules/svm.rst index dc8d3bbaf757a..ddd015611dd51 100644 --- a/doc/modules/svm.rst +++ b/doc/modules/svm.rst @@ -129,8 +129,8 @@ two classes, only one model is trained:: >>> lin_clf = svm.LinearSVC() >>> lin_clf.fit(X, Y) # doctest: +NORMALIZE_WHITESPACE LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True, - intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2', - random_state=None, tol=0.0001, verbose=0) + intercept_scaling=1, loss='l2', max_iter=1000, multi_class='ovr', + penalty='l2', random_state=None, tol=0.0001, verbose=0) >>> dec = lin_clf.decision_function([[1]]) >>> dec.shape[1] 4 diff --git a/doc/sphinxext/gen_rst.py b/doc/sphinxext/gen_rst.py index 9a8d2535a2b26..0dff63a667e4e 100644 --- a/doc/sphinxext/gen_rst.py +++ b/doc/sphinxext/gen_rst.py @@ -870,7 +870,7 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery): my_stdout = my_stdout.replace( my_globals['__doc__'], '') - my_stdout = my_stdout.strip() + my_stdout = my_stdout.strip().expandtabs() if my_stdout: stdout = '**Script output**::\n\n %s\n\n' % ( '\n '.join(my_stdout.split('\n'))) @@ -1028,7 +1028,7 @@ def embed_code_links(app, exception): # ensure greediness names = sorted(str_repl, key=len, reverse=True) - expr = re.compile(r'(?)' + # don't follow '.' or '>' '|'.join(re.escape(name) for name in names)) diff --git a/doc/sphinxext/numpy_ext/docscrape_sphinx.py b/doc/sphinxext/numpy_ext/docscrape_sphinx.py index b8c263ea0a1d1..ca28300eab8a4 100644 --- a/doc/sphinxext/numpy_ext/docscrape_sphinx.py +++ b/doc/sphinxext/numpy_ext/docscrape_sphinx.py @@ -188,14 +188,14 @@ def __str__(self, indent=0, func_role="obj"): out += self._str_index() + [''] out += self._str_summary() out += self._str_extended_summary() - for param_list in ('Parameters', 'Returns', 'Raises'): + for param_list in ('Parameters', 'Returns', 'Raises', 'Attributes'): out += self._str_param_list(param_list) out += self._str_warnings() out += self._str_see_also(func_role) out += self._str_section('Notes') out += self._str_references() out += self._str_examples() - for param_list in ('Attributes', 'Methods'): + for param_list in ('Methods',): out += self._str_member_list(param_list) out = self._str_indent(out, indent) return '\n'.join(out) diff --git a/doc/testimonials/images/machinalis.png b/doc/testimonials/images/machinalis.png new file mode 100644 index 0000000000000..efb4d10e9cfac Binary files /dev/null and b/doc/testimonials/images/machinalis.png differ diff --git a/doc/testimonials/testimonials.rst b/doc/testimonials/testimonials.rst index 2cc93dabe2a82..cdb0f1aafdcb0 100644 --- a/doc/testimonials/testimonials.rst +++ b/doc/testimonials/testimonials.rst @@ -569,3 +569,41 @@ Guillaume Lebourgeois & Samuel Charron - Data Scientists at Data Publica + +`Machinalis `_ +----------------------------------------- + +.. raw:: html + + + +Scikit-learn is the cornerstone of all the machine learning projects carried at +Machinalis. It has a consistent API, a wide selection of algorithms and lots +of auxiliary tools to deal with the boilerplate. +We have used it in production environments on a variety of projects +including click-through rate prediction, `information extraction `_, +and even counting sheep! + +In fact, we use it so much that we've started to freeze our common use cases +into Python packages, some of them open-sourced, like +`FeatureForge `_ . +Scikit-learn in one word: Awesome. + +.. raw:: html + + + +Rafael Carrascosa, Lead developer + +.. raw:: html + + + + diff --git a/doc/themes/scikit-learn/static/nature.css_t b/doc/themes/scikit-learn/static/nature.css_t index 3635483de70d4..41214f3cb64e5 100644 --- a/doc/themes/scikit-learn/static/nature.css_t +++ b/doc/themes/scikit-learn/static/nature.css_t @@ -1022,7 +1022,7 @@ p.citing { background-color: #fff; } -dl.class dt, dl.function dt { +dl.class > dt, dl.function > dt, dl.method > dt { padding: 10px; background-color: #f8f8f8; color: #222; diff --git a/doc/tutorial/statistical_inference/model_selection.rst b/doc/tutorial/statistical_inference/model_selection.rst index 76ca0bbfebc4d..e4fa5fedd3454 100644 --- a/doc/tutorial/statistical_inference/model_selection.rst +++ b/doc/tutorial/statistical_inference/model_selection.rst @@ -99,7 +99,7 @@ of the computer. - Split it K folds, train on K-1 and then test on left-out - - It preserves the class ratios / label distribution within each fold. + - It preserves the class ratios / label distribution within each fold. - Leave one observation out @@ -155,7 +155,7 @@ estimator during the construction and exposes an estimator API:: 0.94228356336260977 -By default, the :class:`GridSearchCV` uses a 3-fold cross-validation. However, +By default, the :class:`GridSearchCV` uses a 3-fold cross-validation. However, if it detects that a classifier is passed, rather than a regressor, it uses a stratified 3-fold. @@ -196,7 +196,8 @@ automatically by cross-validation:: >>> lasso.fit(X_diabetes, y_diabetes) LassoCV(alphas=None, copy_X=True, cv=None, eps=0.001, fit_intercept=True, max_iter=1000, n_alphas=100, n_jobs=1, normalize=False, positive=False, - precompute='auto', tol=0.0001, verbose=False) + precompute='auto', random_state=None, selection='cyclic', tol=0.0001, + verbose=False) >>> # The estimator chose automatically its lambda: >>> lasso.alpha_ # doctest: +ELLIPSIS 0.01229... @@ -213,7 +214,7 @@ appended to their name. **Bonus**: How much can you trust the selection of alpha? .. literalinclude:: ../../auto_examples/exercises/plot_cv_diabetes.py - :lines: 11-22 + :lines: 17-24 **Solution:** :ref:`example_exercises_plot_cv_diabetes.py` diff --git a/doc/tutorial/statistical_inference/putting_together.rst b/doc/tutorial/statistical_inference/putting_together.rst index eec42d0e7f3c6..7ca7abfc5a47c 100644 --- a/doc/tutorial/statistical_inference/putting_together.rst +++ b/doc/tutorial/statistical_inference/putting_together.rst @@ -17,7 +17,7 @@ can predict variables. We can also create combined estimators: :align: right .. literalinclude:: ../../auto_examples/plot_digits_pipe.py - :lines: 24-67 + :lines: 26-66 diff --git a/doc/tutorial/statistical_inference/supervised_learning.rst b/doc/tutorial/statistical_inference/supervised_learning.rst index 3475542f718ef..1c2ff603e4b87 100644 --- a/doc/tutorial/statistical_inference/supervised_learning.rst +++ b/doc/tutorial/statistical_inference/supervised_learning.rst @@ -93,9 +93,9 @@ Scikit-learn documentation for more information about this type of classifier.) >>> # Create and fit a nearest-neighbor classifier >>> from sklearn.neighbors import KNeighborsClassifier >>> knn = KNeighborsClassifier() - >>> knn.fit(iris_X_train, iris_y_train) + >>> knn.fit(iris_X_train, iris_y_train) # doctest: +NORMALIZE_WHITESPACE KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski', - n_neighbors=5, p=2, weights='uniform') + metric_params=None, n_neighbors=5, p=2, weights='uniform') >>> knn.predict(iris_X_test) array([1, 2, 1, 0, 0, 0, 2, 1, 2, 0]) >>> iris_y_test @@ -253,7 +253,7 @@ We can choose ``alpha`` to minimize left out error, this time using the diabetes dataset rather than our synthetic data:: >>> alphas = np.logspace(-4, -1, 6) - >>> from __future__ import print_function + >>> from __future__ import print_function >>> print([regr.set_params(alpha=alpha ... ).fit(diabetes_X_train, diabetes_y_train, ... ).score(diabetes_X_test, diabetes_y_test) for alpha in alphas]) # doctest: +ELLIPSIS @@ -328,7 +328,7 @@ application of Occam's razor: *prefer simpler models*. >>> regr.fit(diabetes_X_train, diabetes_y_train) Lasso(alpha=0.025118864315095794, copy_X=True, fit_intercept=True, max_iter=1000, normalize=False, positive=False, precompute='auto', - tol=0.0001, warm_start=False) + random_state=None, selection='cyclic', tol=0.0001, warm_start=False) >>> print(regr.coef_) [ 0. -212.43764548 517.19478111 313.77959962 -160.8303982 -0. -187.19554705 69.38229038 508.66011217 71.84239008] @@ -371,7 +371,8 @@ function or **logistic** function: >>> logistic.fit(iris_X_train, iris_y_train) LogisticRegression(C=100000.0, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, max_iter=100, - penalty='l2', random_state=None, solver='liblinear', tol=0.0001) + multi_class='ovr', penalty='l2', random_state=None, + solver='liblinear', tol=0.0001, verbose=0) This is known as :class:`LogisticRegression`. @@ -400,10 +401,10 @@ This is known as :class:`LogisticRegression`. model. Leave out the last 10% and test prediction performance on these observations. - .. literalinclude:: ../../auto_examples/exercises/plot_digits_classification_exercise.py - :lines: 12-17 + .. literalinclude:: ../../auto_examples/exercises/digits_classification_exercise.py + :lines: 15-19 - Solution: :download:`../../auto_examples/exercises/plot_digits_classification_exercise.py` + Solution: :download:`../../auto_examples/exercises/digits_classification_exercise.py` Support vector machines (SVMs) @@ -567,6 +568,6 @@ creating a decision energy by positioning *kernels* on observations: intuitions. .. literalinclude:: ../../auto_examples/exercises/plot_iris_exercise.py - :lines: 15-22 + :lines: 18-23 Solution: :download:`../../auto_examples/exercises/plot_iris_exercise.py` diff --git a/doc/tutorial/statistical_inference/unsupervised_learning.rst b/doc/tutorial/statistical_inference/unsupervised_learning.rst index d62c7e50d61bb..1b66f2d2780ae 100644 --- a/doc/tutorial/statistical_inference/unsupervised_learning.rst +++ b/doc/tutorial/statistical_inference/unsupervised_learning.rst @@ -183,7 +183,7 @@ clustering an image: :align: right .. literalinclude:: ../../auto_examples/cluster/plot_lena_ward_segmentation.py - :lines: 21-44 + :lines: 21-45 .. >>> from sklearn.feature_extraction.image import grid_to_graph diff --git a/doc/whats_new.rst b/doc/whats_new.rst index b899171d588db..ccf1721b8413a 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -12,7 +12,6 @@ Changelog New features ............ - - Incremental fit for :class:`GaussianNB `. - Add ``sample_weight`` support to :class:`dummy.DummyClassifier`. By @@ -25,16 +24,40 @@ New features `Manoj Kumar`_, `Fabian Pedregosa`_, `Gael Varoquaux`_ and `Alexandre Gramfort`_. + - Added ``warm_start`` constructor parameter to make it possible for any + trained forest model to grow additional trees incrementally. By + `Laurent Direr`_. + + Enhancements ............ - - Add support for sample weights in scorer objects. Metrics with sample - weight support will automatically benefit from it. + weight support will automatically benefit from it. By `Noel Dawe`_ and + `Vlad Niculae`_. - Added ``newton-cg`` and `lbfgs` solver support in :class:`linear_model.LogisticRegression`. By `Manoj Kumar`_. + - Add ``selection="random"`` parameter to implement stochastic coordinate + descent for :class:`linear_model.Lasso`, :class:`linear_model.ElasticNet` + and related. By `Manoj Kumar`_. + + - Add ``sample_weight`` parameter to `metrics.jaccard_similarity_score` and + `metrics.log_loss`. By `Jatin Shah`_. + + - Support sparse multilabel indicator representation in + :class:`preprocessing.LabelBinarizer` and + :class:`multiclass.OneVsRestClassifier` (by `Hamzeh Alsalhi`_ with thanks + to `Rohit Sivaprasad`_), as well as evaluation metrics (by + `Joel Nothman`_). + + - Add ``multi_class="multinomial"`` option in + :class:`linear_model.LogisticRegression` to implement a Logistic + Regression solver that minimizes the cross-entropy or multinomial loss + instead of the default One-vs-Rest setting. By `Lars Buitinck`_ and + `Manoj Kumar`_. + Documentation improvements .......................... @@ -43,6 +66,17 @@ Documentation improvements Bug fixes ......... + - The :class:`decomposition.PCA` now undoes whitening in its + ``inverse_transform``. Also, its ``components_`` now always have unit + length. By Michael Eickenberg. + + - Fix incomplete download of the dataset when + :func:`datasets.download_20newsgroups` is called. By `Manoj Kumar`_. + + - Various fixes to the Gaussian processes subpackage by Vincent Dubourg + and Jan Hendrik Metzen. + + API changes summary ------------------- @@ -57,6 +91,92 @@ API changes summary :func:`multiclass.fit_ecoc` and :func:`multiclass.predict_ecoc` are deprecated. Use the underlying estimators instead. + - Nearest neighbors estimators used to take arbitrary keyword arguments + and pass these to their distance metric. This will no longer be supported + in scikit-learn 0.18; use the ``metric_params`` argument instead. + + +.. _changes_0_15_2: + +0.15.2 +====== + +Bug fixes +--------- + + - Fixed handling of the ``p`` parameter of the Minkowski distance that was + previously ignored in nearest neighbors models. By `Nikolay Mayorov`_. + + - Fixed duplicated alphas in :class:`linear_model.LassoLars` with early + stopping on 32 bit Python. By `Olivier Grisel`_ and `Fabian Pedregosa`_. + + - Fixed the build under Windows when scikit-learn is built with MSVC while + NumPy is built with MinGW. By `Olivier Grisel`_ and Federico Vaggi. + + - Fixed an array index overflow bug in the coordinate descent solver. By + `Gael Varoquaux`_. + + - Better handling of numpy 1.9 deprecation warnings. By `Gael Varoquaux`_. + + - Removed unnecessary data copy in :class:`cluster.KMeans`. + By `Gael Varoquaux`_. + + - Explicitly close open files to avoid ``ResourceWarnings`` under Python 3. + By Calvin Giles. + + - The ``transform`` of :class:`lda.LDA` now projects the input on the most + discriminant directions. By Martin Billinger. + + - Fixed potential overflow in ``_tree.safe_realloc`` by `Lars Buitinck`_. + + - Performance optimization in :class:`istonic.IsotonicRegression`. + By Robert Bradshaw. + + - ``nose`` is non-longer a runtime dependency to import ``sklearn``, only for + running the tests. By `Joel Nothman`_. + + - Many documentation and website fixes by `Joel Nothman`_, `Lars Buitinck`_ + and others. + +.. _changes_0_15_1: + +0.15.1 +====== + +Bug fixes +--------- + + - Made :func:`cross_validation.cross_val_score` use + :class:`cross_validation.KFold` instead of + :class:`cross_validation.StratifiedKFold` on multi-output classification + problems. By `Nikolay Mayorov`_. + + - Support unseen labels :class:`preprocessing.LabelBinarizer` to restore + the default behavior of 0.14.1 for backward compatibility. By + `Hamzeh Alsalhi`_. + + - Fixed the :class:`cluster.KMeans` stopping criterion that prevented early + convergence detection. By Edward Raff and `Gael Varoquaux`_. + + - Fixed the behavior of :class:`multiclass.OneVsOneClassifier`. + in case of ties at the per-class vote level by computing the correct + per-class sum of prediction scores. By `Andreas Müller`_. + + - Made :func:`cross_validation.cross_val_score` and + :class:`grid_search.GridSearchCV` accept Python lists as input data. + This is especially useful for cross-validation and model selection of + text processing pipelines. By `Andreas Müller`_. + + - Fixed data input checks of most estimators to accept input data that + implements the NumPy ``__array__`` protocol. This is the case for + for ``pandas.Series`` and ``pandas.DataFrame`` in recent versions of + pandas. By `Gael Varoquaux`_. + + - Fixed a regression for :class:`linear_model.SGDClassifier` with + ``class_weight="auto"`` on data with non-contiguous labels. By + `Olivier Grisel`_. + + .. _changes_0_15: 0.15 @@ -2826,3 +2946,9 @@ David Huard, Dave Morrill, Ed Schofield, Travis Oliphant, Pearu Peterson. .. _Hamzeh Alsalhi: https://github.com/hamsal .. _Ronald Phlypo: https://github.com/rphlypo + +.. _Laurent Direr: https://github.com/ldirer + +.. _Nikolay Mayorov: https://github.com/nmayorov + +.. _Jatin Shah: http://jatinshah.org/ diff --git a/examples/applications/plot_out_of_core_classification.py b/examples/applications/plot_out_of_core_classification.py index 840b5a2e4f64f..61e899053a6a3 100644 --- a/examples/applications/plot_out_of_core_classification.py +++ b/examples/applications/plot_out_of_core_classification.py @@ -64,22 +64,18 @@ def _not_in_sphinx(): class ReutersParser(html_parser.HTMLParser): """Utility class to parse a SGML file and yield documents one at a time.""" - def __init__(self, verbose=0, encoding='latin-1'): - html_parser.HTMLParser.__init__(self, verbose) + def __init__(self, encoding='latin-1'): + html_parser.HTMLParser.__init__(self) self._reset() self.encoding = encoding - if not six.PY2: - # In Python 3 need to be defined explicitly - def handle_starttag(tag, attrs): - method = 'start_' + tag - getattr(self, method, lambda x: None)(attrs) - self.handle_starttag = handle_starttag - - def handle_endtag(tag): - method = 'end_' + tag - getattr(self, method, lambda: None)() - self.handle_endtag = handle_endtag + def handle_starttag(self, tag, attrs): + method = 'start_' + tag + getattr(self, method, lambda x: None)(attrs) + + def handle_endtag(self, tag): + method = 'end_' + tag + getattr(self, method, lambda: None)() def _reset(self): self.in_title = 0 diff --git a/examples/classification/plot_classification_probability.py b/examples/classification/plot_classification_probability.py index e63bc1d376099..1b768535e4391 100644 --- a/examples/classification/plot_classification_probability.py +++ b/examples/classification/plot_classification_probability.py @@ -4,8 +4,9 @@ =============================== Plot the classification probability for different classifiers. We use a 3 -class dataset, and we classify it with a Support Vector classifier, as -well as L1 and L2 penalized logistic regression. +class dataset, and we classify it with a Support Vector classifier, L1 +and L2 penalized logistic regression with either a One-Vs-Rest or multinomial +setting. The logistic regression is not a multiclass classifier out of the box. As a result it can identify only the first class. @@ -33,15 +34,23 @@ class dataset, and we classify it with a Support Vector classifier, as # Create different classifiers. The logistic regression cannot do # multiclass out of the box. classifiers = {'L1 logistic': LogisticRegression(C=C, penalty='l1'), - 'L2 logistic': LogisticRegression(C=C, penalty='l2'), + 'L2 logistic (OvR)': LogisticRegression(C=C, penalty='l2'), 'Linear SVC': SVC(kernel='linear', C=C, probability=True, - random_state=0)} + random_state=0), + 'L2 logistic (Multinomial)': LogisticRegression( + C=C, solver='lbfgs', multi_class='multinomial' + )} n_classifiers = len(classifiers) plt.figure(figsize=(3 * 2, n_classifiers * 2)) plt.subplots_adjust(bottom=.2, top=.95) +xx = np.linspace(3, 9, 100) +yy = np.linspace(1, 5, 100).T +xx, yy = np.meshgrid(xx, yy) +Xfull = np.c_[xx.ravel(), yy.ravel()] + for index, (name, classifier) in enumerate(classifiers.items()): classifier.fit(X, y) @@ -50,10 +59,6 @@ class dataset, and we classify it with a Support Vector classifier, as print("classif_rate for %s : %f " % (name, classif_rate)) # View probabilities= - xx = np.linspace(3, 9, 100) - yy = np.linspace(1, 5, 100).T - xx, yy = np.meshgrid(xx, yy) - Xfull = np.c_[xx.ravel(), yy.ravel()] probas = classifier.predict_proba(Xfull) n_classes = np.unique(y_pred).size for k in range(n_classes): diff --git a/examples/cluster/plot_kmeans_digits.py b/examples/cluster/plot_kmeans_digits.py index e56634d7ee202..cdd5073937efd 100644 --- a/examples/cluster/plot_kmeans_digits.py +++ b/examples/cluster/plot_kmeans_digits.py @@ -3,7 +3,7 @@ A demo of K-Means clustering on the handwritten digits data =========================================================== -In this example with compare the various initialization strategies for +In this example we compare the various initialization strategies for K-means in terms of runtime and quality of the results. As the ground truth is known here, we also apply different cluster diff --git a/examples/datasets/plot_random_dataset.py b/examples/datasets/plot_random_dataset.py index be5108754c145..d1802ce8f8e0e 100644 --- a/examples/datasets/plot_random_dataset.py +++ b/examples/datasets/plot_random_dataset.py @@ -4,46 +4,58 @@ ============================================== Plot several randomly generated 2D classification datasets. -This example illustrates the `datasets.make_classification` -function. +This example illustrates the :func:`datasets.make_classification` +:func:`datasets.make_blobs` and :func:`datasets.make_gaussian_quantiles` +functions. -Three binary and two multi-class classification datasets -are generated, with different numbers of informative -features and clusters per class. -""" +For ``make_classification``, three binary and two multi-class classification +datasets are generated, with different numbers of informative features and +clusters per class. """ print(__doc__) import matplotlib.pyplot as plt from sklearn.datasets import make_classification +from sklearn.datasets import make_blobs +from sklearn.datasets import make_gaussian_quantiles -plt.figure(figsize=(8, 6)) +plt.figure(figsize=(8, 8)) plt.subplots_adjust(bottom=.05, top=.9, left=.05, right=.95) -plt.subplot(221) -plt.title("One informative feature, one cluster", fontsize='small') +plt.subplot(321) +plt.title("One informative feature, one cluster per class", fontsize='small') X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=1, n_clusters_per_class=1) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) -plt.subplot(222) -plt.title("Two informative features, one cluster", fontsize='small') +plt.subplot(322) +plt.title("Two informative features, one cluster per class", fontsize='small') X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) -plt.subplot(223) -plt.title("Two informative features, two clusters", fontsize='small') +plt.subplot(323) +plt.title("Two informative features, two clusters per class", fontsize='small') X2, Y2 = make_classification(n_features=2, n_redundant=0, n_informative=2) plt.scatter(X2[:, 0], X2[:, 1], marker='o', c=Y2) -plt.subplot(224) +plt.subplot(324) plt.title("Multi-class, two informative features, one cluster", fontsize='small') X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1, n_classes=3) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) +plt.subplot(325) +plt.title("Three blobs", fontsize='small') +X1, Y1 = make_blobs(n_features=2, centers=3) +plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) + +plt.subplot(326) +plt.title("Gaussian divided into three quantiles", fontsize='small') +X1, Y1 = make_gaussian_quantiles(n_features=2, n_classes=3) +plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) + plt.show() diff --git a/examples/datasets/plot_random_multilabel_dataset.py b/examples/datasets/plot_random_multilabel_dataset.py new file mode 100644 index 0000000000000..4efcd19ed02ef --- /dev/null +++ b/examples/datasets/plot_random_multilabel_dataset.py @@ -0,0 +1,96 @@ +""" +============================================== +Plot randomly generated multilabel dataset +============================================== + +This illustrates the `datasets.make_multilabel_classification` dataset +generator. Each sample consists of counts of two features (up to 50 in +total), which are differently distributed in each of two classes. + +Points are labeled as follows, where Y means the class is present: + + ===== ===== ===== ====== + 1 2 3 Color + ===== ===== ===== ====== + Y N N Red + N Y N Blue + N N Y Yellow + Y Y N Purple + Y N Y Orange + Y Y N Green + Y Y Y Brown + ===== ===== ===== ====== + +A star marks the expected sample for each class; its size reflects the +probability of selecting that class label. + +The left and right examples highlight the ``n_labels`` parameter: +more of the samples in the right plot have 2 or 3 labels. + +Note that this two-dimensional example is very degenerate: +generally the number of features would be much greater than the +"document length", while here we have much larger documents than vocabulary. +Similarly, with ``n_classes > n_features``, it is much less likely that a +feature distinguishes a particular cluss. +""" + +from __future__ import print_function +import numpy as np +import matplotlib.pyplot as plt + +from sklearn.datasets import make_multilabel_classification as make_ml_clf + +print(__doc__) + +COLORS = np.array(['!', + '#FF3333', # red + '#0198E1', # blue + '#BF5FFF', # purple + '#FCD116', # yellow + '#FF7216', # orange + '#4DBD33', # green + '#87421F' # brown + ]) + +# Use same random seed for multiple calls to make_multilabel_classification to +# ensure same distributions +RANDOM_SEED = np.random.randint(2 ** 10) + + +def plot_2d(ax, n_labels=1, n_classes=3, length=50): + X, Y, p_c, p_w_c = make_ml_clf(n_samples=150, n_features=2, + n_classes=n_classes, n_labels=n_labels, + length=length, allow_unlabeled=False, + return_indicator=True, + return_distributions=True, + random_state=RANDOM_SEED) + + ax.scatter(X[:, 0], X[:, 1], color=COLORS.take((Y * [1, 2, 4] + ).sum(axis=1)), + marker='.') + ax.scatter(p_w_c[0] * length, p_w_c[1] * length, + marker='*', linewidth=.5, edgecolor='black', + s=20 + 1500 * p_c ** 2, + color=COLORS.take([1, 2, 4])) + ax.set_xlabel('Feature 0 count') + return p_c, p_w_c + + +_, (ax1, ax2) = plt.subplots(1, 2, sharex='row', sharey='row', figsize=(8, 4)) +plt.subplots_adjust(bottom=.15) + +p_c, p_w_c = plot_2d(ax1, n_labels=1) +ax1.set_title('n_labels=1, length=50') +ax1.set_ylabel('Feature 1 count') + +plot_2d(ax2, n_labels=3) +ax2.set_title('n_labels=3, length=50') +ax2.set_xlim(left=0, auto=True) +ax2.set_ylim(bottom=0, auto=True) + +plt.show() + +print('The data was generated from (random_state=%d):' % RANDOM_SEED) +print('Class', 'P(C)', 'P(w0|C)', 'P(w1|C)', sep='\t') +for k, p, p_w in zip(['red', 'blue', 'yellow'], p_c, p_w_c.T): + print('%s\t%0.2f\t%0.2f\t%0.2f' % (k, p, p_w[0], p_w[1])) diff --git a/examples/exercises/plot_digits_classification_exercise.py b/examples/exercises/digits_classification_exercise.py similarity index 100% rename from examples/exercises/plot_digits_classification_exercise.py rename to examples/exercises/digits_classification_exercise.py diff --git a/examples/exercises/plot_cv_diabetes.py b/examples/exercises/plot_cv_diabetes.py index 5e07a4f2dc996..4d1b984443ca5 100644 --- a/examples/exercises/plot_cv_diabetes.py +++ b/examples/exercises/plot_cv_diabetes.py @@ -9,20 +9,18 @@ :ref:`model_selection_tut` section of the :ref:`stat_learn_tut_index`. """ from __future__ import print_function +print(__doc__) import numpy as np import matplotlib.pyplot as plt from sklearn import cross_validation, datasets, linear_model -print(__doc__) - diabetes = datasets.load_diabetes() X = diabetes.data[:150] y = diabetes.target[:150] lasso = linear_model.Lasso() - alphas = np.logspace(-4, -.5, 30) scores = list() diff --git a/examples/feature_selection/plot_rfe_digits.py b/examples/feature_selection/plot_rfe_digits.py index 4716bdc82cf7d..bcbf28c7d78ca 100644 --- a/examples/feature_selection/plot_rfe_digits.py +++ b/examples/feature_selection/plot_rfe_digits.py @@ -16,6 +16,7 @@ from sklearn.svm import SVC from sklearn.datasets import load_digits from sklearn.feature_selection import RFE +import matplotlib.pyplot as plt # Load the digits dataset digits = load_digits() @@ -29,7 +30,6 @@ ranking = rfe.ranking_.reshape(digits.images[0].shape) # Plot pixel ranking -import matplotlib.pyplot as plt plt.matshow(ranking) plt.colorbar() plt.title("Ranking of pixels with RFE") diff --git a/examples/gaussian_process/gp_diabetes_dataset.py b/examples/gaussian_process/gp_diabetes_dataset.py index 830cca6b26709..e851623a1122c 100644 --- a/examples/gaussian_process/gp_diabetes_dataset.py +++ b/examples/gaussian_process/gp_diabetes_dataset.py @@ -40,7 +40,7 @@ gp.fit(X, y) # Deactivate maximum likelihood estimation for the cross-validation loop -gp.theta0 = gp.theta # Given correlation parameter = MLE +gp.theta0 = gp.theta_ # Given correlation parameter = MLE gp.thetaL, gp.thetaU = None, None # None bounds deactivate MLE # Perform a cross-validation estimate of the coefficient of determination using diff --git a/examples/imputation.py b/examples/missing_values.py similarity index 98% rename from examples/imputation.py rename to examples/missing_values.py index aa04521de2950..4ccdd41289466 100644 --- a/examples/imputation.py +++ b/examples/missing_values.py @@ -48,7 +48,7 @@ # Estimate the score without the lines containing missing values X_filtered = X_full[~missing_samples, :] -y_filtered = y_full[~missing_samples, :] +y_filtered = y_full[~missing_samples] estimator = RandomForestRegressor(random_state=0, n_estimators=100) score = cross_val_score(estimator, X_filtered, y_filtered).mean() print("Score without the samples containing missing values = %.2f" % score) diff --git a/examples/model_selection/plot_confusion_matrix.py b/examples/model_selection/plot_confusion_matrix.py index 144020a320577..771d058e2a4a5 100644 --- a/examples/model_selection/plot_confusion_matrix.py +++ b/examples/model_selection/plot_confusion_matrix.py @@ -10,16 +10,29 @@ off-diagonal elements are those that are mislabeled by the classifier. The higher the diagonal values of the confusion matrix the better, indicating many correct predictions. + +The figures show the confusion matrix with and without +normalization by class support size (number of elements +in each class). This kind of normalization can be +interesting in case of class imbalance to have a more +visual interpretation of which class is being misclassified. + +Here the results are not as good as they could be as our +choice for the regularization parameter C was not the best. +In real life applications this parameter is usually chosen +using :ref:`grid_search`. + """ print(__doc__) +import numpy as np +import matplotlib.pyplot as plt + from sklearn import svm, datasets from sklearn.cross_validation import train_test_split from sklearn.metrics import confusion_matrix -import matplotlib.pyplot as plt - # import some data to play with iris = datasets.load_iris() X = iris.data @@ -28,19 +41,38 @@ # Split the data into a training set and a test set X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) -# Run classifier -classifier = svm.SVC(kernel='linear') +# Run classifier, using a model that is too regularized (C too low) to see +# the impact on the results +classifier = svm.SVC(kernel='linear', C=0.01) y_pred = classifier.fit(X_train, y_train).predict(X_test) + +def plot_confusion_matrix(cm, title='Confusion matrix', cmap=plt.cm.Blues): + plt.imshow(cm, interpolation='nearest', cmap=cmap) + plt.title(title) + plt.colorbar() + tick_marks = np.arange(len(iris.target_names)) + plt.xticks(tick_marks, iris.target_names, rotation=45) + plt.yticks(tick_marks, iris.target_names) + plt.tight_layout() + plt.ylabel('True label') + plt.xlabel('Predicted label') + + # Compute confusion matrix cm = confusion_matrix(y_test, y_pred) - +np.set_printoptions(precision=2) +print('Confusion matrix, without normalization') print(cm) +plt.figure() +plot_confusion_matrix(cm) + +# Normalize the confusion matrix by row (i.e by the number of samples +# in each class) +cm_normalized = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] +print('Normalized confusion matrix') +print(cm_normalized) +plt.figure() +plot_confusion_matrix(cm_normalized, title='Normalized confusion matrix') -# Show confusion matrix in a separate window -plt.matshow(cm) -plt.title('Confusion matrix') -plt.colorbar() -plt.ylabel('True label') -plt.xlabel('Predicted label') plt.show() diff --git a/examples/plot_kernel_approximation.py b/examples/plot_kernel_approximation.py index 4aca910f227e5..cbf78be4dfbc0 100644 --- a/examples/plot_kernel_approximation.py +++ b/examples/plot_kernel_approximation.py @@ -17,7 +17,7 @@ subsets of the training set (for :class:`Nystroem`) for the approximate mapping are shown. -Please not that the dataset here is not large enough to show the benefits +Please note that the dataset here is not large enough to show the benefits of kernel approximation, as the exact SVM is still reasonably fast. Sampling more dimensions clearly leads to better classification results, but diff --git a/examples/tree/plot_tree_regression.py b/examples/tree/plot_tree_regression.py index 63ff810ec7d2c..c0f0cc5b0f513 100644 --- a/examples/tree/plot_tree_regression.py +++ b/examples/tree/plot_tree_regression.py @@ -15,7 +15,10 @@ """ print(__doc__) +# Import the necessary modules and libraries import numpy as np +from sklearn.tree import DecisionTreeRegressor +import matplotlib.pyplot as plt # Create a random dataset rng = np.random.RandomState(1) @@ -24,8 +27,6 @@ y[::5] += 3 * (0.5 - rng.rand(16)) # Fit regression model -from sklearn.tree import DecisionTreeRegressor - clf_1 = DecisionTreeRegressor(max_depth=2) clf_2 = DecisionTreeRegressor(max_depth=5) clf_1.fit(X, y) @@ -37,8 +38,6 @@ y_2 = clf_2.predict(X_test) # Plot the results -import matplotlib.pyplot as plt - plt.figure() plt.scatter(X, y, c="k", label="data") plt.plot(X_test, y_1, c="g", label="max_depth=2", linewidth=2) diff --git a/setup.py b/setup.py index ce56c590f1921..22528c47b7073 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ # # Copyright (C) 2007-2009 Cournapeau David # 2010 Fabian Pedregosa +# License: 3-clause BSD descr = """A set of python modules for machine learning and data mining""" @@ -22,7 +23,8 @@ DISTNAME = 'scikit-learn' DESCRIPTION = 'A set of python modules for machine learning and data mining' -LONG_DESCRIPTION = open('README.rst').read() +with open('README.rst') as f: + LONG_DESCRIPTION = f.read() MAINTAINER = 'Andreas Mueller' MAINTAINER_EMAIL = 'amueller@ais.uni-bonn.de' URL = 'http://scikit-learn.org' diff --git a/sklearn/__init__.py b/sklearn/__init__.py index e58b3cd6c90bc..cce879f66abe1 100644 --- a/sklearn/__init__.py +++ b/sklearn/__init__.py @@ -36,14 +36,19 @@ else: from . import __check_build from .base import clone + __check_build # avoid flakes unused variable error - __all__ = ['cross_validation', 'cluster', 'covariance', - 'datasets', 'decomposition', 'feature_extraction', - 'feature_selection', 'semi_supervised', - 'gaussian_process', 'grid_search', 'hmm', 'lda', 'linear_model', - 'metrics', 'mixture', 'naive_bayes', 'neighbors', 'pipeline', - 'preprocessing', 'qda', 'svm', 'clone', - 'cross_decomposition', 'isotonic'] + __all__ = ['cluster', 'covariance', 'cross_decomposition', + 'cross_validation', 'datasets', 'decomposition', 'dummy', + 'ensemble', 'externals', 'feature_extraction', + 'feature_selection', 'gaussian_process', 'grid_search', 'hmm', + 'isotonic', 'kernel_approximation', 'lda', 'learning_curve', + 'linear_model', 'manifold', 'metrics', 'mixture', 'multiclass', + 'naive_bayes', 'neighbors', 'neural_network', 'pipeline', + 'preprocessing', 'qda', 'random_projection', 'semi_supervised', + 'svm', 'tree', + # Non-modules: + 'clone'] def setup_module(module): diff --git a/sklearn/base.py b/sklearn/base.py index 5c7ba0d92eaf9..e3cf483a8a3d0 100644 --- a/sklearn/base.py +++ b/sklearn/base.py @@ -374,8 +374,9 @@ def get_indices(self, i): Indices of columns in the dataset that belong to the bicluster. """ - from .cluster.bicluster.utils import get_indices - return get_indices(self.rows_[i], self.columns_[i]) + rows = self.rows_[i] + columns = self.columns_[i] + return np.nonzero(rows)[0], np.nonzero(columns)[0] def get_shape(self, i): """Shape of the i'th bicluster. @@ -385,8 +386,8 @@ def get_shape(self, i): shape : (int, int) Number of rows and columns (resp.) in the bicluster. """ - from .cluster.bicluster.utils import get_shape - return get_shape(self.rows_[i], self.columns_[i]) + indices = self.get_indices(i) + return tuple(len(i) for i in indices) def get_submatrix(self, i, data): """Returns the submatrix corresponding to bicluster `i`. @@ -395,8 +396,10 @@ def get_submatrix(self, i, data): ``columns_`` attributes exist. """ - from .cluster.bicluster.utils import get_submatrix - return get_submatrix(self.rows_[i], self.columns_[i], data) + from .utils.validation import check_array + data = check_array(data, accept_sparse='csr') + row_ind, col_ind = self.get_indices(i) + return data[row_ind[:, np.newaxis], col_ind] ############################################################################### diff --git a/sklearn/cluster/affinity_propagation_.py b/sklearn/cluster/affinity_propagation_.py index 201b3006cb229..400a24eb60b2f 100644 --- a/sklearn/cluster/affinity_propagation_.py +++ b/sklearn/cluster/affinity_propagation_.py @@ -220,19 +220,19 @@ class AffinityPropagation(BaseEstimator, ClusterMixin): Attributes ---------- - `cluster_centers_indices_` : array, shape (n_clusters,) + cluster_centers_indices_ : array, shape (n_clusters,) Indices of cluster centers - `cluster_centers_` : array, shape (n_clusters, n_features) + cluster_centers_ : array, shape (n_clusters, n_features) Cluster centers (if affinity != ``precomputed``). - `labels_` : array, shape (n_samples,) + labels_ : array, shape (n_samples,) Labels of each point - `affinity_matrix_` : array, shape (n_samples, n_samples) + affinity_matrix_ : array, shape (n_samples, n_samples) Stores the affinity matrix used in ``fit``. - `n_iter_` : int + n_iter_ : int Number of iterations taken to converge. Notes diff --git a/sklearn/cluster/bicluster/spectral.py b/sklearn/cluster/bicluster.py similarity index 94% rename from sklearn/cluster/bicluster/spectral.py rename to sklearn/cluster/bicluster.py index 0b023ceacce0a..7a32764a6cd1e 100644 --- a/sklearn/cluster/bicluster/spectral.py +++ b/sklearn/cluster/bicluster.py @@ -1,4 +1,4 @@ -"""Implements spectral biclustering algorithms. +"""Spectral biclustering algorithms. Authors : Kemal Eren License: BSD 3 clause @@ -11,22 +11,19 @@ from scipy.sparse import dia_matrix from scipy.sparse import issparse -from sklearn.base import BaseEstimator, BiclusterMixin -from sklearn.externals import six -from sklearn.utils.arpack import svds -from sklearn.utils.arpack import eigsh -from sklearn.cluster import KMeans -from sklearn.cluster import MiniBatchKMeans +from . import KMeans, MiniBatchKMeans +from ..base import BaseEstimator, BiclusterMixin +from ..externals import six +from ..utils.arpack import eigsh, svds -from sklearn.utils.extmath import randomized_svd -from sklearn.utils.extmath import safe_sparse_dot -from sklearn.utils.extmath import make_nonnegative -from sklearn.utils.extmath import norm +from ..utils.extmath import (make_nonnegative, norm, randomized_svd, + safe_sparse_dot) -from sklearn.utils.validation import assert_all_finite -from sklearn.utils.validation import check_array +from ..utils.validation import assert_all_finite, check_array -from .utils import check_array_ndim + +__all__ = ['SpectralCoclustering', + 'SpectralBiclustering'] def _scale_normalize(X): @@ -121,7 +118,6 @@ def fit(self, X): """ X = check_array(X, accept_sparse='csr', dtype=np.float64) - check_array_ndim(X) self._check_parameters() self._fit(X) @@ -236,17 +232,17 @@ class SpectralCoclustering(BaseSpectral): Attributes ---------- - `rows_` : array-like, shape (n_row_clusters, n_rows) + rows_ : array-like, shape (n_row_clusters, n_rows) Results of the clustering. `rows[i, r]` is True if cluster `i` contains row `r`. Available only after calling ``fit``. - `columns_` : array-like, shape (n_column_clusters, n_columns) + columns_ : array-like, shape (n_column_clusters, n_columns) Results of the clustering, like `rows`. - `row_labels_` : array-like, shape (n_rows,) + row_labels_ : array-like, shape (n_rows,) The bicluster label of each row. - `column_labels_` : array-like, shape (n_cols,) + column_labels_ : array-like, shape (n_cols,) The bicluster label of each column. References @@ -364,17 +360,17 @@ class SpectralBiclustering(BaseSpectral): Attributes ---------- - `rows_` : array-like, shape (n_row_clusters, n_rows) + rows_ : array-like, shape (n_row_clusters, n_rows) Results of the clustering. `rows[i, r]` is True if cluster `i` contains row `r`. Available only after calling ``fit``. - `columns_` : array-like, shape (n_column_clusters, n_columns) + columns_ : array-like, shape (n_column_clusters, n_columns) Results of the clustering, like `rows`. - `row_labels_` : array-like, shape (n_rows,) + row_labels_ : array-like, shape (n_rows,) Row partition labels. - `column_labels_` : array-like, shape (n_cols,) + column_labels_ : array-like, shape (n_cols,) Column partition labels. References diff --git a/sklearn/cluster/bicluster/__init__.py b/sklearn/cluster/bicluster/__init__.py deleted file mode 100644 index e8289eefc1e91..0000000000000 --- a/sklearn/cluster/bicluster/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .spectral import SpectralCoclustering, SpectralBiclustering - -__all__ = ['SpectralCoclustering', - 'SpectralBiclustering'] diff --git a/sklearn/cluster/bicluster/tests/__init__.py b/sklearn/cluster/bicluster/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/sklearn/cluster/bicluster/tests/test_utils.py b/sklearn/cluster/bicluster/tests/test_utils.py deleted file mode 100644 index 67a5406f63122..0000000000000 --- a/sklearn/cluster/bicluster/tests/test_utils.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Tests for bicluster utilities.""" - -import numpy as np - -from scipy.sparse import csr_matrix, issparse - -from sklearn.utils.testing import assert_equal -from sklearn.utils.testing import assert_array_equal -from sklearn.utils.testing import assert_true - -from sklearn.cluster.bicluster.utils import get_indicators -from sklearn.cluster.bicluster.utils import get_shape -from sklearn.cluster.bicluster.utils import get_submatrix - - -def test_get_indicators(): - rows = [2, 4, 5] - columns = [0, 1, 3] - shape = (6, 4) - row_ind, col_ind = get_indicators(rows, columns, shape) - assert_array_equal(row_ind, [False, False, True, False, True, True]) - assert_array_equal(col_ind, [True, True, False, True]) - - -def test_get_shape(): - rows = [True, True, False, False] - cols = [True, False, True, True] - assert_equal(get_shape(rows, cols), (2, 3)) - - -def test_get_submatrix(): - data = np.arange(20).reshape(5, 4) - rows = [True, True, False, False, True] - cols = [False, False, True, True] - for X in (data, csr_matrix(data)): - submatrix = get_submatrix(rows, cols, X) - if issparse(submatrix): - submatrix = submatrix.toarray() - assert_array_equal(submatrix, [[2, 3], - [6, 7], - [18, 19]]) - submatrix[:] = -1 - if issparse(X): - X = X.toarray() - assert_true(np.all(X != -1)) diff --git a/sklearn/cluster/bicluster/utils.py b/sklearn/cluster/bicluster/utils.py deleted file mode 100644 index 8a89676752687..0000000000000 --- a/sklearn/cluster/bicluster/utils.py +++ /dev/null @@ -1,40 +0,0 @@ -import numpy as np - - -def check_array_ndim(X): - if X.ndim != 2: - raise ValueError("Argument `X` has the wrong dimensionality." - " It must have exactly two dimensions, but" - " {} != 2".format(X.ndim)) - - -def get_indices(rows, columns): - """Convert indicator vectors to lists of indices for bicluster `i`.""" - row_idx = np.nonzero(rows)[0] - col_idx = np.nonzero(columns)[0] - return row_idx, col_idx - - -def get_indicators(rows, columns, shape): - """Convert indices to indicator vectors""" - row_ind = np.zeros(shape[0], dtype=np.bool) - col_ind = np.zeros(shape[1], dtype=np.bool) - row_ind[rows] = True - col_ind[columns] = True - return row_ind, col_ind - - -def get_shape(rows, columns): - """Returns shape of bicluster from indicator vectors""" - indices = get_indices(rows, columns) - return tuple(len(i) for i in indices) - - -def get_submatrix(rows, columns, data): - """Returns the submatrix corresponding to bicluster `i`. - - Works with sparse matrices. - - """ - rows, cols = get_indices(rows, columns) - return data[rows[:, np.newaxis], cols] diff --git a/sklearn/cluster/dbscan_.py b/sklearn/cluster/dbscan_.py index 493ed86fded49..eebdbfa46f4b7 100644 --- a/sklearn/cluster/dbscan_.py +++ b/sklearn/cluster/dbscan_.py @@ -201,13 +201,13 @@ class DBSCAN(BaseEstimator, ClusterMixin): Attributes ---------- - `core_sample_indices_` : array, shape = [n_core_samples] + core_sample_indices_ : array, shape = [n_core_samples] Indices of core samples. - `components_` : array, shape = [n_core_samples, n_features] + components_ : array, shape = [n_core_samples, n_features] Copy of each core sample found by training. - `labels_` : array, shape = [n_samples] + labels_ : array, shape = [n_samples] Cluster labels for each point in the dataset given to fit(). Noisy samples are given the label -1. diff --git a/sklearn/cluster/hierarchical.py b/sklearn/cluster/hierarchical.py index b643b2c5666e2..911be26ff5f05 100644 --- a/sklearn/cluster/hierarchical.py +++ b/sklearn/cluster/hierarchical.py @@ -567,16 +567,16 @@ class AgglomerativeClustering(BaseEstimator, ClusterMixin): Attributes ---------- - `labels_` : array [n_samples] + labels_ : array [n_samples] cluster labels for each point - `n_leaves_` : int + n_leaves_ : int Number of leaves in the hierarchical tree. - `n_components_` : int + n_components_ : int The estimated number of connected components in the graph. - `children_` : array-like, shape = [n_nodes, 2] + children_ : array-like, shape = [n_nodes, 2] The children of each non-leaf node. Values less than `n_samples` refer to leaves of the tree. A greater value `i` indicates a node with children `children_[i - n_samples]`. @@ -727,16 +727,16 @@ class Ward(AgglomerativeClustering): Attributes ---------- - `labels_` : array [n_features] + labels_ : array [n_features] cluster labels for each feature - `n_leaves_` : int + n_leaves_ : int Number of leaves in the hierarchical tree. - `n_components_` : int + n_components_ : int The estimated number of connected components in the graph. - `children_` : array-like, shape = [n_nodes, 2] + children_ : array-like, shape = [n_nodes, 2] The children of each non-leaf node. Values less than `n_samples` refer to leaves of the tree. A greater value `i` indicates a node with children `children_[i - n_samples]`. @@ -797,18 +797,18 @@ class WardAgglomeration(AgglomerationTransform, Ward): Attributes ---------- - `children_` : array-like, shape = [n_nodes, 2] + children_ : array-like, shape = [n_nodes, 2] The children of each non-leaf node. Values less than `n_samples` refer to leaves of the tree. A greater value `i` indicates a node with children `children_[i - n_samples]`. - `labels_` : array [n_features] + labels_ : array [n_features] cluster labels for each feature - `n_leaves_` : int + n_leaves_ : int Number of leaves in the hierarchical tree. - `n_components_` : int + n_components_ : int The estimated number of connected components in the graph. """ diff --git a/sklearn/cluster/k_means_.py b/sklearn/cluster/k_means_.py index 6bf739cdc664c..f32bd16abb363 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -18,9 +18,9 @@ from ..base import BaseEstimator, ClusterMixin, TransformerMixin from ..metrics.pairwise import euclidean_distances -from ..utils.extmath import row_norms +from ..utils.extmath import row_norms, squared_norm from ..utils.sparsefuncs_fast import assign_rows_csr -from ..utils.sparsefuncs import mean_variance_axis0 +from ..utils.sparsefuncs import mean_variance_axis from ..utils.fixes import astype from ..utils import check_array from ..utils import check_random_state @@ -141,13 +141,13 @@ def _k_init(X, n_clusters, x_squared_norms, random_state, n_local_trials=None): def _tolerance(X, tol): """Return a tolerance which is independent of the dataset""" if sp.issparse(X): - variances = mean_variance_axis0(X)[1] + variances = mean_variance_axis(X, axis=0)[1] else: variances = np.var(X, axis=0) return np.mean(variances) * tol -def k_means(X, n_clusters, init='k-means++', precompute_distances=True, +def k_means(X, n_clusters, init='k-means++', precompute_distances='auto', n_init=10, max_iter=300, verbose=False, tol=1e-4, random_state=None, copy_x=True, n_jobs=1, return_n_iter=False): @@ -186,6 +186,17 @@ def k_means(X, n_clusters, init='k-means++', precompute_distances=True, If a callable is passed, it should take arguments X, k and and a random state and return an initialization. + precompute_distances : {'auto', True, False} + Precompute distances (faster but takes more memory). + + 'auto' : do not precompute distances if n_samples * n_clusters > 12 + million. This corresponds to about 100MB overhead per job using + double precision. + + True : always precompute distances + + False : never precompute distances + tol : float, optional The relative increment in the results before declaring convergence. @@ -240,12 +251,25 @@ def k_means(X, n_clusters, init='k-means++', precompute_distances=True, X = as_float_array(X, copy=copy_x) tol = _tolerance(X, tol) + # If the distances are precomputed every job will create a matrix of shape + # (n_clusters, n_samples). To stop KMeans from eating up memory we only + # activate this if the created matrix is guaranteed to be under 100MB. 12 + # million entries consume a little under 100MB if they are of type double. + if precompute_distances == 'auto': + n_samples = X.shape[0] + precompute_distances = (n_clusters * n_samples) < 12e6 + elif isinstance(precompute_distances, bool): + pass + else: + raise ValueError("precompute_distances should be 'auto' or True/False" + ", but a value of %r was passed" % + precompute_distances) + # subtract of mean of x for more accurate distance computations if not sp.issparse(X) or hasattr(init, '__array__'): X_mean = X.mean(axis=0) if not sp.issparse(X): - if copy_x: - X = X.copy() + # The copy was already done above X -= X_mean if hasattr(init, '__array__'): @@ -349,6 +373,9 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300, x_squared_norms: array Precomputed x_squared_norms. + precompute_distances : boolean, default: True + Precompute distances (faster but takes more memory). + random_state: integer or numpy.RandomState, optional The generator used to initialize the centers. If an integer is given, it fixes the seed. Defaults to the global numpy random @@ -407,7 +434,7 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300, best_centers = centers.copy() best_inertia = inertia - if np.sum((centers_old - centers) ** 2) <= tol: + if squared_norm(centers_old - centers) <= tol: if verbose: print("Converged at iteration %d" % i) break @@ -625,9 +652,17 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. - precompute_distances : boolean, default: True + precompute_distances : {'auto', True, False} Precompute distances (faster but takes more memory). + 'auto' : do not precompute distances if n_samples * n_clusters > 12 + million. This corresponds to about 100MB overhead per job using + double precision. + + True : always precompute distances + + False : never precompute distances + tol : float, default: 1e-4 Relative tolerance with regards to inertia to declare convergence @@ -648,13 +683,13 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): Attributes ---------- - `cluster_centers_` : array, [n_clusters, n_features] + cluster_centers_ : array, [n_clusters, n_features] Coordinates of cluster centers - `labels_` : + labels_ : Labels of each point - `inertia_` : float + inertia_ : float Sum of distances of samples to their closest cluster center. Notes @@ -684,7 +719,7 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): """ def __init__(self, n_clusters=8, init='k-means++', n_init=10, max_iter=300, - tol=1e-4, precompute_distances=True, + tol=1e-4, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1): if hasattr(init, '__array__'): @@ -718,7 +753,7 @@ def _check_test_data(self, X): raise ValueError("Incorrect number of features. " "Got %d features, expected %d" % ( n_features, expected_n_features)) - if not X.dtype.kind is 'f': + if X.dtype.kind is not 'f': warnings.warn("Got data type %s, converted to float " "to avoid overflows" % X.dtype, RuntimeWarning, stacklevel=2) @@ -911,7 +946,7 @@ def _mini_batch_step(X, x_squared_norms, centers, counts, random_state=random_state) if verbose: print("[MiniBatchKMeans] Reassigning %i cluster centers." - % n_reassigns) + % n_reassigns) if sp.issparse(X) and not sp.issparse(centers): assign_rows_csr(X, @@ -1109,13 +1144,13 @@ class MiniBatchKMeans(KMeans): Attributes ---------- - `cluster_centers_` : array, [n_clusters, n_features] + cluster_centers_ : array, [n_clusters, n_features] Coordinates of cluster centers - `labels_` : + labels_ : Labels of each point (if compute_labels is set to True). - `inertia_` : float + inertia_ : float The value of the inertia criterion associated with the chosen partition (if compute_labels is set to True). The inertia is defined as the sum of square distances of samples to their nearest diff --git a/sklearn/cluster/mean_shift_.py b/sklearn/cluster/mean_shift_.py index d97a2da02ce91..3f550daddfe01 100644 --- a/sklearn/cluster/mean_shift_.py +++ b/sklearn/cluster/mean_shift_.py @@ -262,10 +262,10 @@ class MeanShift(BaseEstimator, ClusterMixin): Attributes ---------- - `cluster_centers_` : array, [n_clusters, n_features] + cluster_centers_ : array, [n_clusters, n_features] Coordinates of cluster centers. - `labels_` : + labels_ : Labels of each point. Notes diff --git a/sklearn/cluster/spectral.py b/sklearn/cluster/spectral.py index f2b63ce992b41..daf6003a5686d 100644 --- a/sklearn/cluster/spectral.py +++ b/sklearn/cluster/spectral.py @@ -349,11 +349,11 @@ class SpectralClustering(BaseEstimator, ClusterMixin): Attributes ---------- - `affinity_matrix_` : array-like, shape (n_samples, n_samples) + affinity_matrix_ : array-like, shape (n_samples, n_samples) Affinity matrix used for clustering. Available only if after calling ``fit``. - `labels_` : + labels_ : Labels of each point Notes diff --git a/sklearn/cluster/bicluster/tests/test_spectral.py b/sklearn/cluster/tests/test_bicluster.py similarity index 83% rename from sklearn/cluster/bicluster/tests/test_spectral.py rename to sklearn/cluster/tests/test_bicluster.py index ddee24d48e5c3..31513bfdfc641 100644 --- a/sklearn/cluster/bicluster/tests/test_spectral.py +++ b/sklearn/cluster/tests/test_bicluster.py @@ -10,19 +10,59 @@ from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_raises +from sklearn.utils.testing import assert_true from sklearn.utils.testing import SkipTest +from sklearn.base import BaseEstimator, BiclusterMixin + from sklearn.cluster.bicluster import SpectralCoclustering from sklearn.cluster.bicluster import SpectralBiclustering -from sklearn.cluster.bicluster.spectral import _scale_normalize -from sklearn.cluster.bicluster.spectral import _bistochastic_normalize -from sklearn.cluster.bicluster.spectral import _log_normalize +from sklearn.cluster.bicluster import _scale_normalize +from sklearn.cluster.bicluster import _bistochastic_normalize +from sklearn.cluster.bicluster import _log_normalize from sklearn.metrics import consensus_score from sklearn.datasets import make_biclusters, make_checkerboard +class MockBiclustering(BaseEstimator, BiclusterMixin): + # Mock object for testing get_submatrix. + def __init__(self): + pass + + def get_indices(self, i): + # Overridden to reproduce old get_submatrix test. + return (np.where([True, True, False, False, True])[0], + np.where([False, False, True, True])[0]) + + +def test_get_submatrix(): + data = np.arange(20).reshape(5, 4) + model = MockBiclustering() + + for X in (data, csr_matrix(data), data.tolist()): + submatrix = model.get_submatrix(0, X) + if issparse(submatrix): + submatrix = submatrix.toarray() + assert_array_equal(submatrix, [[2, 3], + [6, 7], + [18, 19]]) + submatrix[:] = -1 + if issparse(X): + X = X.toarray() + assert_true(np.all(X != -1)) + + +def _test_shape_indices(model): + """Test get_shape and get_indices on fitted model.""" + for i in range(model.n_clusters): + m, n = model.get_shape(i) + i_ind, j_ind = model.get_indices(i) + assert_equal(len(i_ind), m) + assert_equal(len(j_ind), n) + + def test_spectral_coclustering(): """Test Dhillon's Spectral CoClustering on a simple problem.""" param_grid = {'svd_method': ['randomized', 'arpack'], @@ -49,6 +89,8 @@ def test_spectral_coclustering(): assert_equal(consensus_score(model.biclusters_, (rows, cols)), 1) + _test_shape_indices(model) + def test_spectral_biclustering(): """Test Kluger methods on a checkerboard dataset.""" @@ -88,6 +130,8 @@ def test_spectral_biclustering(): assert_equal(consensus_score(model.biclusters_, (rows, cols)), 1) + _test_shape_indices(model) + def _do_scale_test(scaled): """Check that rows sum to one constant, and columns to another.""" diff --git a/sklearn/cluster/tests/test_hierarchical.py b/sklearn/cluster/tests/test_hierarchical.py index 7ea65cddb2047..9568bcd99d090 100644 --- a/sklearn/cluster/tests/test_hierarchical.py +++ b/sklearn/cluster/tests/test_hierarchical.py @@ -209,6 +209,9 @@ def test_ward_agglomeration(): assert_warns(DeprecationWarning, WardAgglomeration) with warnings.catch_warnings(record=True) as warning_list: warnings.simplefilter("always", DeprecationWarning) + if hasattr(np, 'VisibleDeprecationWarning'): + # Let's not catch the numpy internal DeprecationWarnings + warnings.simplefilter('ignore', np.VisibleDeprecationWarning) ward = WardAgglomeration(n_clusters=5, connectivity=connectivity) ward.fit(X) assert_equal(len(warning_list), 1) diff --git a/sklearn/cluster/tests/test_k_means.py b/sklearn/cluster/tests/test_k_means.py index 66b3a42f00ee0..47262aecd0be1 100644 --- a/sklearn/cluster/tests/test_k_means.py +++ b/sklearn/cluster/tests/test_k_means.py @@ -211,6 +211,13 @@ def test_k_means_plus_plus_init_2_jobs(): _check_fitted_model(km) +def test_k_means_precompute_distances_flag(): + # check that a warning is raised if the precompute_distances flag is not + # supported + km = KMeans(precompute_distances="wrong") + assert_raises(ValueError, km.fit, X) + + def test_k_means_plus_plus_init_sparse(): km = KMeans(init="k-means++", n_clusters=n_clusters, random_state=42) km.fit(X_csr) diff --git a/sklearn/covariance/empirical_covariance_.py b/sklearn/covariance/empirical_covariance_.py index 3832187f59af3..9dc730b72e0ac 100644 --- a/sklearn/covariance/empirical_covariance_.py +++ b/sklearn/covariance/empirical_covariance_.py @@ -97,10 +97,10 @@ class EmpiricalCovariance(BaseEstimator): Attributes ---------- - `covariance_` : 2D ndarray, shape (n_features, n_features) + covariance_ : 2D ndarray, shape (n_features, n_features) Estimated covariance matrix - `precision_` : 2D ndarray, shape (n_features, n_features) + precision_ : 2D ndarray, shape (n_features, n_features) Estimated pseudo-inverse matrix. (stored only if store_precision is True) @@ -136,7 +136,7 @@ def get_precision(self): Returns ------- - `precision_` : array-like, + precision_ : array-like, The precision matrix associated to the current covariance object. """ diff --git a/sklearn/covariance/graph_lasso_.py b/sklearn/covariance/graph_lasso_.py index f64cb6a12216e..3a546ae1cddcf 100644 --- a/sklearn/covariance/graph_lasso_.py +++ b/sklearn/covariance/graph_lasso_.py @@ -18,6 +18,7 @@ from ..utils import ConvergenceWarning from ..utils.extmath import pinvh +from ..utils.validation import check_random_state from ..linear_model import lars_path from ..linear_model import cd_fast from ..cross_validation import _check_cv as check_cv, cross_val_score @@ -201,7 +202,7 @@ def graph_lasso(emp_cov, alpha, cov_init=None, mode='cd', tol=1e-4, / (precision_[idx, idx] + 1000 * eps)) coefs, _, _, _ = cd_fast.enet_coordinate_descent_gram( coefs, alpha, 0, sub_covariance, row, row, - max_iter, tol) + max_iter, tol, check_random_state(None), False) else: # Use LARS _, _, coefs = lars_path( @@ -284,13 +285,13 @@ class GraphLasso(EmpiricalCovariance): Attributes ---------- - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated covariance matrix - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. - `n_iter_` : int + n_iter_ : int Number of iterations run. See Also @@ -358,13 +359,13 @@ def graph_lasso_path(X, alphas, cov_init=None, X_test=None, mode='cd', Returns ------- - `covariances_` : List of 2D ndarray, shape (n_features, n_features) + covariances_ : List of 2D ndarray, shape (n_features, n_features) The estimated covariance matrices. - `precisions_` : List of 2D ndarray, shape (n_features, n_features) + precisions_ : List of 2D ndarray, shape (n_features, n_features) The estimated (sparse) precision matrices. - `scores_` : List of float + scores_ : List of float The generalisation error (log-likelihood) on the test data. Returned only if test data is passed. """ @@ -452,22 +453,22 @@ class GraphLassoCV(GraphLasso): Attributes ---------- - `covariance_` : numpy.ndarray, shape (n_features, n_features) + covariance_ : numpy.ndarray, shape (n_features, n_features) Estimated covariance matrix. - `precision_` : numpy.ndarray, shape (n_features, n_features) + precision_ : numpy.ndarray, shape (n_features, n_features) Estimated precision matrix (inverse covariance). - `alpha_`: float + alpha_ : float Penalization parameter selected. - `cv_alphas_`: list of float + cv_alphas_ : list of float All penalization parameters explored. `grid_scores`: 2D numpy.ndarray (n_alphas, n_folds) Log-likelihood score on left-out data across folds. - `n_iter_` : int + n_iter_ : int Number of iterations run for the optimal alpha. See Also diff --git a/sklearn/covariance/outlier_detection.py b/sklearn/covariance/outlier_detection.py index 143cd0db5b0fe..f4e2749004d59 100644 --- a/sklearn/covariance/outlier_detection.py +++ b/sklearn/covariance/outlier_detection.py @@ -111,17 +111,17 @@ class EllipticEnvelope(ClassifierMixin, OutlierDetectionMixin, MinCovDet): The amount of contamination of the data set, i.e. the proportion of \ outliers in the data set. - `location_` : array-like, shape (n_features,) + location_ : array-like, shape (n_features,) Estimated robust location - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated robust covariance matrix - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True) - `support_` : array-like, shape (n_samples,) + support_ : array-like, shape (n_samples,) A mask of the observations that have been used to compute the robust estimates of location and shape. diff --git a/sklearn/covariance/robust_covariance.py b/sklearn/covariance/robust_covariance.py index 8b832f72550c2..08de1804b1912 100644 --- a/sklearn/covariance/robust_covariance.py +++ b/sklearn/covariance/robust_covariance.py @@ -217,7 +217,7 @@ def select_candidates(X, n_support, n_trials, select=1, n_iter=30, See Also --------- - `c_step` function + c_step Returns ------- @@ -523,32 +523,32 @@ class MinCovDet(EmpiricalCovariance): Attributes ---------- - `raw_location_` : array-like, shape (n_features,) + raw_location_ : array-like, shape (n_features,) The raw robust estimated location before correction and re-weighting. - `raw_covariance_` : array-like, shape (n_features, n_features) + raw_covariance_ : array-like, shape (n_features, n_features) The raw robust estimated covariance before correction and re-weighting. - `raw_support_` : array-like, shape (n_samples,) + raw_support_ : array-like, shape (n_samples,) A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and re-weighting. - `location_` : array-like, shape (n_features,) + location_ : array-like, shape (n_features,) Estimated robust location - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated robust covariance matrix - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True) - `support_` : array-like, shape (n_samples,) + support_ : array-like, shape (n_samples,) A mask of the observations that have been used to compute the robust estimates of location and shape. - `dist_` : array-like, shape (n_samples,) + dist_ : array-like, shape (n_samples,) Mahalanobis distances of the training set (on which `fit` is called) observations. diff --git a/sklearn/covariance/shrunk_covariance_.py b/sklearn/covariance/shrunk_covariance_.py index b7c32880c199b..28d0ccfa8ed61 100644 --- a/sklearn/covariance/shrunk_covariance_.py +++ b/sklearn/covariance/shrunk_covariance_.py @@ -75,10 +75,10 @@ class ShrunkCovariance(EmpiricalCovariance): Attributes ---------- - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated covariance matrix - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True) @@ -331,14 +331,14 @@ class LedoitWolf(EmpiricalCovariance): Attributes ---------- - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated covariance matrix - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True) - `shrinkage_` : float, 0 <= shrinkage <= 1 + shrinkage_ : float, 0 <= shrinkage <= 1 Coefficient in the convex combination used for the computation of the shrunk estimate. @@ -491,14 +491,14 @@ class OAS(EmpiricalCovariance): Attributes ---------- - `covariance_` : array-like, shape (n_features, n_features) + covariance_ : array-like, shape (n_features, n_features) Estimated covariance matrix. - `precision_` : array-like, shape (n_features, n_features) + precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True) - `shrinkage_` : float, 0 <= shrinkage <= 1 + shrinkage_ : float, 0 <= shrinkage <= 1 coefficient in the convex combination used for the computation of the shrunk estimate. diff --git a/sklearn/cross_decomposition/cca_.py b/sklearn/cross_decomposition/cca_.py index d0ba4ec2ea9d3..35f1be7259278 100644 --- a/sklearn/cross_decomposition/cca_.py +++ b/sklearn/cross_decomposition/cca_.py @@ -29,31 +29,31 @@ class CCA(_PLS): Attributes ---------- - `x_weights_` : array, [p, n_components] + x_weights_ : array, [p, n_components] X block weights vectors. - `y_weights_` : array, [q, n_components] + y_weights_ : array, [q, n_components] Y block weights vectors. - `x_loadings_` : array, [p, n_components] + x_loadings_ : array, [p, n_components] X block loadings vectors. - `y_loadings_` : array, [q, n_components] + y_loadings_ : array, [q, n_components] Y block loadings vectors. - `x_scores_` : array, [n_samples, n_components] + x_scores_ : array, [n_samples, n_components] X scores. - `y_scores_` : array, [n_samples, n_components] + y_scores_ : array, [n_samples, n_components] Y scores. - `x_rotations_` : array, [p, n_components] + x_rotations_ : array, [p, n_components] X block to latents rotations. - `y_rotations_` : array, [q, n_components] + y_rotations_ : array, [q, n_components] Y block to latents rotations. - `n_iter_` : array-like + n_iter_ : array-like Number of iterations of the NIPALS inner loop for each component. diff --git a/sklearn/cross_decomposition/pls_.py b/sklearn/cross_decomposition/pls_.py index 4f655053725d1..b46874671c36b 100644 --- a/sklearn/cross_decomposition/pls_.py +++ b/sklearn/cross_decomposition/pls_.py @@ -154,34 +154,34 @@ class _PLS(six.with_metaclass(ABCMeta), BaseEstimator, TransformerMixin, Attributes ---------- - `x_weights_` : array, [p, n_components] + x_weights_ : array, [p, n_components] X block weights vectors. - `y_weights_` : array, [q, n_components] + y_weights_ : array, [q, n_components] Y block weights vectors. - `x_loadings_` : array, [p, n_components] + x_loadings_ : array, [p, n_components] X block loadings vectors. - `y_loadings_` : array, [q, n_components] + y_loadings_ : array, [q, n_components] Y block loadings vectors. - `x_scores_` : array, [n_samples, n_components] + x_scores_ : array, [n_samples, n_components] X scores. - `y_scores_` : array, [n_samples, n_components] + y_scores_ : array, [n_samples, n_components] Y scores. - `x_rotations_` : array, [p, n_components] + x_rotations_ : array, [p, n_components] X block to latents rotations. - `y_rotations_` : array, [q, n_components] + y_rotations_ : array, [q, n_components] Y block to latents rotations. coefs: array, [p, q] The coefficients of the linear model: Y = X coefs + Err - `n_iter_` : array-like + n_iter_ : array-like Number of iterations of the NIPALS inner loop for each component. Not useful if the algorithm given is "svd". @@ -475,34 +475,34 @@ class PLSRegression(_PLS): Attributes ---------- - `x_weights_` : array, [p, n_components] + x_weights_ : array, [p, n_components] X block weights vectors. - `y_weights_` : array, [q, n_components] + y_weights_ : array, [q, n_components] Y block weights vectors. - `x_loadings_` : array, [p, n_components] + x_loadings_ : array, [p, n_components] X block loadings vectors. - `y_loadings_` : array, [q, n_components] + y_loadings_ : array, [q, n_components] Y block loadings vectors. - `x_scores_` : array, [n_samples, n_components] + x_scores_ : array, [n_samples, n_components] X scores. - `y_scores_` : array, [n_samples, n_components] + y_scores_ : array, [n_samples, n_components] Y scores. - `x_rotations_` : array, [p, n_components] + x_rotations_ : array, [p, n_components] X block to latents rotations. - `y_rotations_` : array, [q, n_components] + y_rotations_ : array, [q, n_components] Y block to latents rotations. coefs: array, [p, q] The coefficients of the linear model: Y = X coefs + Err - `n_iter_` : array-like + n_iter_ : array-like Number of iterations of the NIPALS inner loop for each component. @@ -599,31 +599,31 @@ class PLSCanonical(_PLS): Attributes ---------- - `x_weights_` : array, shape = [p, n_components] + x_weights_ : array, shape = [p, n_components] X block weights vectors. - `y_weights_` : array, shape = [q, n_components] + y_weights_ : array, shape = [q, n_components] Y block weights vectors. - `x_loadings_` : array, shape = [p, n_components] + x_loadings_ : array, shape = [p, n_components] X block loadings vectors. - `y_loadings_` : array, shape = [q, n_components] + y_loadings_ : array, shape = [q, n_components] Y block loadings vectors. - `x_scores_` : array, shape = [n_samples, n_components] + x_scores_ : array, shape = [n_samples, n_components] X scores. - `y_scores_` : array, shape = [n_samples, n_components] + y_scores_ : array, shape = [n_samples, n_components] Y scores. - `x_rotations_` : array, shape = [p, n_components] + x_rotations_ : array, shape = [p, n_components] X block to latents rotations. - `y_rotations_` : array, shape = [q, n_components] + y_rotations_ : array, shape = [q, n_components] Y block to latents rotations. - `n_iter_` : array-like + n_iter_ : array-like Number of iterations of the NIPALS inner loop for each component. Not useful if the algorithm provided is "svd". @@ -711,16 +711,16 @@ class PLSSVD(BaseEstimator, TransformerMixin): Attributes ---------- - `x_weights_` : array, [p, n_components] + x_weights_ : array, [p, n_components] X block weights vectors. - `y_weights_` : array, [q, n_components] + y_weights_ : array, [q, n_components] Y block weights vectors. - `x_scores_` : array, [n_samples, n_components] + x_scores_ : array, [n_samples, n_components] X scores. - `y_scores_` : array, [n_samples, n_components] + y_scores_ : array, [n_samples, n_components] Y scores. See also diff --git a/sklearn/cross_validation.py b/sklearn/cross_validation.py index fd649935dc381..ebcf4f934f043 100644 --- a/sklearn/cross_validation.py +++ b/sklearn/cross_validation.py @@ -24,6 +24,7 @@ from .base import is_classifier, clone from .utils import indexable, check_random_state, safe_indexing from .utils.validation import _num_samples, check_array +from .utils.multiclass import type_of_target from .externals.joblib import Parallel, delayed, logger from .externals.six import with_metaclass from .externals.six.moves import zip @@ -1096,10 +1097,11 @@ def cross_val_score(estimator, X, y=None, scoring=None, cv=None, n_jobs=1, a scorer callable object / function with signature ``scorer(estimator, X, y)``. - cv : cross-validation generator, optional, default: None - A cross-validation generator. If None, a 3-fold cross - validation is used or 3-fold stratified cross-validation - when y is supplied and estimator is a classifier. + cv : cross-validation generator or int, optional, default: None + A cross-validation generator to use. If int, determines + the number of folds in StratifiedKFold if y is binary + or multiclass and estimator is a classifier, or the number + of folds in KFold otherwise. If None, it is equivalent to cv=3. n_jobs : integer, optional The number of CPUs to use to do the computation. -1 means @@ -1360,7 +1362,10 @@ def _check_cv(cv, X=None, y=None, classifier=False, warn_mask=False): else: needs_indices = None if classifier: - cv = StratifiedKFold(y, cv, indices=needs_indices) + if type_of_target(y) in ['binary', 'multiclass']: + cv = StratifiedKFold(y, cv, indices=needs_indices) + else: + cv = KFold(_num_samples(y), cv, indices=needs_indices) else: if not is_sparse: n_samples = len(X) diff --git a/sklearn/datasets/base.py b/sklearn/datasets/base.py index 844129092a446..358a872d94730 100644 --- a/sklearn/datasets/base.py +++ b/sklearn/datasets/base.py @@ -183,7 +183,10 @@ def load_files(container_path, description=None, categories=None, target = target[indices] if load_content: - data = [open(filename, 'rb').read() for filename in filenames] + data = [] + for filename in filenames: + with open(filename, 'rb') as f: + data.append(f.read()) if encoding is not None: data = [d.decode(encoding, decode_error) for d in data] return Bunch(data=data, @@ -301,7 +304,8 @@ def load_digits(n_class=10): module_path = dirname(__file__) data = np.loadtxt(join(module_path, 'data', 'digits.csv.gz'), delimiter=',') - descr = open(join(module_path, 'descr', 'digits.rst')).read() + with open(join(module_path, 'descr', 'digits.rst')) as f: + descr = f.read() target = data[:, -1] flat_data = data[:, :-1] images = flat_data.view() @@ -402,26 +406,31 @@ def load_boston(): (506, 13) """ module_path = dirname(__file__) - data_file = csv.reader(open(join(module_path, 'data', - 'boston_house_prices.csv'))) - fdescr = open(join(module_path, 'descr', 'boston_house_prices.rst')) - temp = next(data_file) - n_samples = int(temp[0]) - n_features = int(temp[1]) - data = np.empty((n_samples, n_features)) - target = np.empty((n_samples,)) - temp = next(data_file) # names of features - feature_names = np.array(temp) - - for i, d in enumerate(data_file): - data[i] = np.asarray(d[:-1], dtype=np.float) - target[i] = np.asarray(d[-1], dtype=np.float) + + fdescr_name = join(module_path, 'descr', 'boston_house_prices.rst') + with open(fdescr_name) as f: + descr_text = f.read() + + data_file_name = join(module_path, 'data', 'boston_house_prices.csv') + with open(data_file_name) as f: + data_file = csv.reader(f) + temp = next(data_file) + n_samples = int(temp[0]) + n_features = int(temp[1]) + data = np.empty((n_samples, n_features)) + target = np.empty((n_samples,)) + temp = next(data_file) # names of features + feature_names = np.array(temp) + + for i, d in enumerate(data_file): + data[i] = np.asarray(d[:-1], dtype=np.float) + target[i] = np.asarray(d[-1], dtype=np.float) return Bunch(data=data, target=target, # last column is target value feature_names=feature_names[:-1], - DESCR=fdescr.read()) + DESCR=descr_text) def load_sample_images(): diff --git a/sklearn/datasets/mlcomp.py b/sklearn/datasets/mlcomp.py index b824fe80da756..315faa34f77ff 100644 --- a/sklearn/datasets/mlcomp.py +++ b/sklearn/datasets/mlcomp.py @@ -28,7 +28,7 @@ def load_mlcomp(name_or_id, set_="raw", mlcomp_root=None, **kwargs): name_or_id : the integer id or the string name metadata of the MLComp dataset to load - `set_` : select the portion to load: 'train', 'test' or 'raw' + set_ : select the portion to load: 'train', 'test' or 'raw' mlcomp_root : the filesystem path to the root folder where MLComp datasets are stored, if mlcomp_root is None, the MLCOMP_DATASETS_HOME diff --git a/sklearn/datasets/samples_generator.py b/sklearn/datasets/samples_generator.py index f2de7c7d81719..30e02792cc1f0 100644 --- a/sklearn/datasets/samples_generator.py +++ b/sklearn/datasets/samples_generator.py @@ -76,7 +76,7 @@ def make_classification(n_samples=100, n_features=20, n_informative=2, The number of redundant features. These features are generated as random linear combinations of the informative features. - n_repeated : int, optional (default=2) + n_repeated : int, optional (default=0) The number of duplicated features, drawn randomly from the informative and the redundant features. @@ -138,6 +138,11 @@ def make_classification(n_samples=100, n_features=20, n_informative=2, ---------- .. [1] I. Guyon, "Design of experiments for the NIPS 2003 variable selection benchmark", 2003. + + See also + -------- + make_blobs: simplified variant + make_multilabel_classification: unrelated generator for multilabel tasks """ generator = check_random_state(random_state) @@ -244,6 +249,7 @@ def make_classification(n_samples=100, n_features=20, n_informative=2, def make_multilabel_classification(n_samples=100, n_features=20, n_classes=5, n_labels=2, length=50, allow_unlabeled=True, sparse=False, return_indicator=False, + return_distributions=False, random_state=None): """Generate a random multilabel classification problem. @@ -269,11 +275,15 @@ def make_multilabel_classification(n_samples=100, n_features=20, n_classes=5, The number of classes of the classification problem. n_labels : int, optional (default=2) - The average number of labels per instance. Number of labels follows - a Poisson distribution that never takes the value 0. + The average number of labels per instance. More precisely, the number + of labels per sample is drawn from a Poisson distribution with + ``n_labels`` as its expected value, but samples are bounded (using + rejection sampling) by ``n_classes``, and must be nonzero if + ``allow_unlabeled`` is False. length : int, optional (default=50) - Sum of the features (number of words if documents). + The sum of the features (number of words if documents) is drawn from + a Poisson distribution with this expected value. allow_unlabeled : bool, optional (default=True) If ``True``, some instances might not belong to any class. @@ -285,6 +295,11 @@ def make_multilabel_classification(n_samples=100, n_features=20, n_classes=5, If ``True``, return ``Y`` in the binary indicator format, else return a tuple of lists of labels. + return_distributions : bool, optional (default=False) + If ``True``, return the prior class probability and conditional + probabilities of features given classes, from which the data was + drawn. + random_state : int, RandomState instance or None, optional (default=None) If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; @@ -299,6 +314,14 @@ def make_multilabel_classification(n_samples=100, n_features=20, n_classes=5, Y : tuple of lists or array of shape [n_samples, n_classes] The label sets. + p_c : array, shape [n_classes] + The probability of each class being drawn. Only returned if + ``return_distributions=True``. + + p_w_c : array, shape [n_features, n_classes] + The probability of each feature being drawn given each class. + Only returned if ``return_distributions=True``. + """ generator = check_random_state(random_state) p_c = generator.rand(n_classes) @@ -367,6 +390,8 @@ def sample_example(): '0.17.', DeprecationWarning) + if return_distributions: + return X, Y, p_c, p_w_c return X, Y @@ -402,6 +427,10 @@ def make_hastie_10_2(n_samples=12000, random_state=None): ---------- .. [1] T. Hastie, R. Tibshirani and J. Friedman, "Elements of Statistical Learning Ed. 2", Springer, 2009. + + See also + -------- + make_gaussian_quantiles: a generalization of this dataset approach """ rs = check_random_state(random_state) @@ -420,7 +449,7 @@ def make_regression(n_samples=100, n_features=100, n_informative=10, """Generate a random regression problem. The input set can either be well conditioned (by default) or have a low - rank-fat tail singular profile. See the `make_low_rank_matrix` for + rank-fat tail singular profile. See :func:`make_low_rank_matrix` for more details. The output is generated by applying a (potentially biased) random linear @@ -688,6 +717,10 @@ def make_blobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0, (10, 2) >>> y array([0, 0, 1, 0, 2, 2, 2, 1, 1, 0]) + + See also + -------- + make_classification: a more intricate variant """ generator = check_random_state(random_state) @@ -1106,6 +1139,10 @@ def make_spd_matrix(n_dim, random_state=None): ------- X : array of shape [n_dim, n_dim] The random symmetric, positive-definite matrix. + + See also + -------- + make_sparse_spd_matrix """ generator = check_random_state(random_state) @@ -1144,6 +1181,10 @@ def make_sparse_spd_matrix(dim=1, alpha=0.95, norm_diag=False, The sparsity is actually imposed on the cholesky factor of the matrix. Thus alpha does not translate directly into the filling fraction of the matrix itself. + + See also + -------- + make_spd_matrix """ random_state = check_random_state(random_state) @@ -1407,6 +1448,9 @@ def make_biclusters(shape, n_clusters, noise=0.0, minval=10, of the seventh ACM SIGKDD international conference on Knowledge discovery and data mining (pp. 269-274). ACM. + See also + -------- + make_checkerboard """ generator = check_random_state(random_state) n_rows, n_cols = shape @@ -1494,6 +1538,9 @@ def make_checkerboard(shape, n_clusters, noise=0.0, minval=10, Spectral biclustering of microarray data: coclustering genes and conditions. Genome research, 13(4), 703-716. + See also + -------- + make_biclusters """ generator = check_random_state(random_state) diff --git a/sklearn/datasets/tests/test_samples_generator.py b/sklearn/datasets/tests/test_samples_generator.py index 900196190aa5a..b6c5dac64e55c 100644 --- a/sklearn/datasets/tests/test_samples_generator.py +++ b/sklearn/datasets/tests/test_samples_generator.py @@ -154,6 +154,19 @@ def test_make_multilabel_classification_return_indicator(): assert_equal(Y.shape, (25, 3), "Y shape mismatch") assert_true(np.all(np.sum(Y, axis=0) > min_length)) + # Also test return_distributions + X2, Y2, p_c, p_w_c = make_multilabel_classification( + n_samples=25, n_features=20, n_classes=3, random_state=0, + return_indicator=True, allow_unlabeled=allow_unlabeled, + return_distributions=True) + + assert_array_equal(X, X2) + assert_array_equal(Y, Y2) + assert_equal(p_c.shape, (3,)) + assert_almost_equal(p_c.sum(), 1) + assert_equal(p_w_c.shape, (20, 3)) + assert_almost_equal(p_w_c.sum(axis=0), [1] * 3) + def test_make_hastie_10_2(): X, y = make_hastie_10_2(n_samples=100, random_state=0) diff --git a/sklearn/datasets/tests/test_svmlight_format.py b/sklearn/datasets/tests/test_svmlight_format.py index 7e71d261d206a..d1ee8c09dbe26 100644 --- a/sklearn/datasets/tests/test_svmlight_format.py +++ b/sklearn/datasets/tests/test_svmlight_format.py @@ -113,17 +113,19 @@ def test_load_compressed(): with NamedTemporaryFile(prefix="sklearn-test", suffix=".gz") as tmp: tmp.close() # necessary under windows - shutil.copyfileobj(open(datafile, "rb"), gzip.open(tmp.name, "wb")) + with open(datafile, "rb") as f: + shutil.copyfileobj(f, gzip.open(tmp.name, "wb")) Xgz, ygz = load_svmlight_file(tmp.name) - assert_array_equal(X.toarray(), Xgz.toarray()) - assert_array_equal(y, ygz) + assert_array_equal(X.toarray(), Xgz.toarray()) + assert_array_equal(y, ygz) with NamedTemporaryFile(prefix="sklearn-test", suffix=".bz2") as tmp: tmp.close() # necessary under windows - shutil.copyfileobj(open(datafile, "rb"), BZ2File(tmp.name, "wb")) + with open(datafile, "rb") as f: + shutil.copyfileobj(f, BZ2File(tmp.name, "wb")) Xbz, ybz = load_svmlight_file(tmp.name) - assert_array_equal(X.toarray(), Xbz.toarray()) - assert_array_equal(y, ybz) + assert_array_equal(X.toarray(), Xbz.toarray()) + assert_array_equal(y, ybz) @raises(ValueError) diff --git a/sklearn/datasets/twenty_newsgroups.py b/sklearn/datasets/twenty_newsgroups.py index a2f9099015975..c325aa9c5204a 100644 --- a/sklearn/datasets/twenty_newsgroups.py +++ b/sklearn/datasets/twenty_newsgroups.py @@ -80,10 +80,15 @@ def download_20newsgroups(target_dir, cache_path): if not os.path.exists(target_dir): os.makedirs(target_dir) - if not os.path.exists(archive_path): - logger.warn("Downloading dataset from %s (14 MB)", URL) - opener = urlopen(URL) - open(archive_path, 'wb').write(opener.read()) + if os.path.exists(archive_path): + # Download is not complete as the .tar.gz file is removed after + # download. + logger.warn("Download was incomplete, downloading again.") + os.remove(archive_path) + + logger.warn("Downloading dataset from %s (14 MB)", URL) + opener = urlopen(URL) + open(archive_path, 'wb').write(opener.read()) logger.info("Decompressing %s", archive_path) tarfile.open(archive_path, "r:gz").extractall(path=target_dir) @@ -196,7 +201,8 @@ def fetch_20newsgroups(data_home=None, subset='train', categories=None, cache = None if os.path.exists(cache_path): try: - compressed_content = open(cache_path, 'rb').read() + with open(cache_path, 'rb') as f: + compressed_content = f.read() uncompressed_content = codecs.decode( compressed_content, 'zlib_codec') cache = pickle.loads(uncompressed_content) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index d526838163fe3..55a6b55e39b7d 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -822,7 +822,7 @@ class SparseCoder(BaseEstimator, SparseCodingMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] The unchanged dictionary atoms See also @@ -933,13 +933,13 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] dictionary atoms extracted from the data - `error_` : array + error_ : array vector of errors at each iteration - `n_iter_` : int + n_iter_ : int Number of iterations run. Notes @@ -1092,10 +1092,10 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] components extracted from the data - `inner_stats_` : tuple of (A, B) ndarrays + inner_stats_ : tuple of (A, B) ndarrays Internal sufficient statistics that are kept by the algorithm. Keeping them is useful in online settings, to avoid loosing the history of the evolution, but they shouldn't have any use for the @@ -1103,7 +1103,7 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin): A (n_components, n_components) is the dictionary covariance matrix. B (n_features, n_components) is the data approximation matrix - `n_iter_` : int + n_iter_ : int Number of iterations run. Notes diff --git a/sklearn/decomposition/factor_analysis.py b/sklearn/decomposition/factor_analysis.py index 324e67ec92bce..10ea29aaafa78 100644 --- a/sklearn/decomposition/factor_analysis.py +++ b/sklearn/decomposition/factor_analysis.py @@ -94,16 +94,16 @@ class FactorAnalysis(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Components with maximum variance. - `loglike_` : list, [n_iterations] + loglike_ : list, [n_iterations] The log likelihood at each iteration. - `noise_variance_` : array, shape=(n_features,) + noise_variance_ : array, shape=(n_features,) The estimated noise variance for each feature. - `n_iter_` : int + n_iter_ : int Number of iterations run. References diff --git a/sklearn/decomposition/fastica_.py b/sklearn/decomposition/fastica_.py index a69d16d4332b4..489ccbf5af78d 100644 --- a/sklearn/decomposition/fastica_.py +++ b/sklearn/decomposition/fastica_.py @@ -411,13 +411,13 @@ def my_g(x): Attributes ---------- - `components_` : 2D array, shape (n_components, n_features) + components_ : 2D array, shape (n_components, n_features) The unmixing matrix. - `mixing_` : array, shape (n_features, n_components) + mixing_ : array, shape (n_features, n_components) The mixing matrix. - `n_iter_`: int + n_iter_ : int If the algorithm is "deflation", n_iter is the maximum number of iterations run across all components. Else they are just the number of iterations taken to converge. diff --git a/sklearn/decomposition/kernel_pca.py b/sklearn/decomposition/kernel_pca.py index 37330246883f1..7a2c5e2cf403e 100644 --- a/sklearn/decomposition/kernel_pca.py +++ b/sklearn/decomposition/kernel_pca.py @@ -74,13 +74,16 @@ class KernelPCA(BaseEstimator, TransformerMixin): Attributes ---------- - `lambdas_`, `alphas_`: - Eigenvalues and eigenvectors of the centered kernel matrix + lambdas_ : + Eigenvalues of the centered kernel matrix - `dual_coef_`: + alphas_ : + Eigenvectors of the centered kernel matrix + + dual_coef_ : Inverse transform matrix - `X_transformed_fit_`: + X_transformed_fit_ : Projection of the fitted data on the kernel principal components References diff --git a/sklearn/decomposition/nmf.py b/sklearn/decomposition/nmf.py index 81d492a6a829f..9d5337dfe2574 100644 --- a/sklearn/decomposition/nmf.py +++ b/sklearn/decomposition/nmf.py @@ -306,15 +306,15 @@ class ProjectedGradientNMF(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Non-negative components of the data. - `reconstruction_err_` : number + reconstruction_err_ : number Frobenius norm of the matrix difference between the training data and the reconstructed data from the fit produced by the model. ``|| X - WH ||_2`` - ``n_iter_`` : int + n_iter_ : int Number of iterations run. Examples diff --git a/sklearn/decomposition/pca.py b/sklearn/decomposition/pca.py index f3422d8073736..839b2dc876802 100644 --- a/sklearn/decomposition/pca.py +++ b/sklearn/decomposition/pca.py @@ -5,6 +5,7 @@ # Olivier Grisel # Mathieu Blondel # Denis A. Engemann +# Michael Eickenberg # # License: BSD 3 clause @@ -138,23 +139,23 @@ class PCA(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Components with maximum variance. - `explained_variance_ratio_` : array, [n_components] + explained_variance_ratio_ : array, [n_components] Percentage of variance explained by each of the selected components. \ k is not set then all components are stored and the sum of explained \ variances is equal to 1.0 - `mean_` : array, [n_features] + mean_ : array, [n_features] Per-feature empirical mean, estimated from the training set. - `n_components_` : int + n_components_ : int The estimated number of components. Relevant when n_components is set to 'mle' or a number between 0 and 1 to select using explained variance. - `noise_variance_` : float + noise_variance_ : float The estimated noise covariance following the Probabilistic PCA model from Tipping and Bishop 1999. See "Pattern Recognition and Machine Learning" by C. Bishop, 12.2.1 p. 574 or @@ -271,10 +272,7 @@ def _fit(self, X): explained_variance_ratio_ = (explained_variance_ / explained_variance_.sum()) - if self.whiten: - components_ = V / (S[:, np.newaxis] / sqrt(n_samples)) - else: - components_ = V + components_ = V n_components = self.n_components if n_components is None: @@ -356,8 +354,6 @@ def get_precision(self): # Get precision using matrix inversion lemma components_ = self.components_ exp_var = self.explained_variance_ - if self.whiten: - components_ = components_ * np.sqrt(exp_var[:, np.newaxis]) exp_var_diff = np.maximum(exp_var - self.noise_variance_, 0.) precision = np.dot(components_, components_.T) / self.noise_variance_ precision.flat[::len(precision) + 1] += 1. / exp_var_diff @@ -388,6 +384,8 @@ def transform(self, X): if self.mean_ is not None: X = X - self.mean_ X_transformed = fast_dot(X, self.components_.T) + if self.whiten: + X_transformed /= np.sqrt(self.explained_variance_) return X_transformed def inverse_transform(self, X): @@ -403,13 +401,15 @@ def inverse_transform(self, X): Returns ------- X_original array-like, shape (n_samples, n_features) - - Notes - ----- - If whitening is enabled, inverse_transform does not compute the - exact inverse operation as transform. """ - return fast_dot(X, self.components_) + self.mean_ + if self.whiten: + return fast_dot( + X, + np.sqrt(self.explained_variance_[:, np.newaxis]) * + self.components_) + self.mean_ + else: + return fast_dot(X, self.components_) + self.mean_ + def score_samples(self, X): """Return the log-likelihood of each sample @@ -495,15 +495,15 @@ class RandomizedPCA(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Components with maximum variance. - `explained_variance_ratio_` : array, [n_components] + explained_variance_ratio_ : array, [n_components] Percentage of variance explained by each of the selected components. \ k is not set then all components are stored and the sum of explained \ variances is equal to 1.0 - `mean_` : array, [n_features] + mean_ : array, [n_features] Per-feature empirical mean, estimated from the training set. Examples diff --git a/sklearn/decomposition/sparse_pca.py b/sklearn/decomposition/sparse_pca.py index a5aff9b710b02..52925eccd8ccc 100644 --- a/sklearn/decomposition/sparse_pca.py +++ b/sklearn/decomposition/sparse_pca.py @@ -60,13 +60,13 @@ class SparsePCA(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Sparse components extracted from the data. - `error_` : array + error_ : array Vector of errors at each iteration. - `n_iter_` : int + n_iter_ : int Number of iterations run. See also @@ -212,13 +212,13 @@ class MiniBatchSparsePCA(SparsePCA): Attributes ---------- - `components_` : array, [n_components, n_features] + components_ : array, [n_components, n_features] Sparse components extracted from the data. - `error_` : array + error_ : array Vector of errors at each iteration. - `n_iter_` : int + n_iter_ : int Number of iterations run. See also diff --git a/sklearn/decomposition/tests/test_pca.py b/sklearn/decomposition/tests/test_pca.py index b710ecb717f6c..b31ca4d680404 100644 --- a/sklearn/decomposition/tests/test_pca.py +++ b/sklearn/decomposition/tests/test_pca.py @@ -151,8 +151,7 @@ def test_pca_inverse(): pca.fit(X) Y = pca.transform(X) Y_inverse = pca.inverse_transform(Y) - relative_max_delta = (np.abs(X - Y_inverse) / np.abs(X).mean()).max() - assert_almost_equal(relative_max_delta, 0.11, decimal=2) + assert_almost_equal(X, Y_inverse, decimal=3) def test_pca_validation(): diff --git a/sklearn/decomposition/truncated_svd.py b/sklearn/decomposition/truncated_svd.py index 2b5f3a50baf76..3b2033204e505 100644 --- a/sklearn/decomposition/truncated_svd.py +++ b/sklearn/decomposition/truncated_svd.py @@ -17,7 +17,7 @@ from ..base import BaseEstimator, TransformerMixin from ..utils import check_array, as_float_array, check_random_state from ..utils.extmath import randomized_svd, safe_sparse_dot, svd_flip -from ..utils.sparsefuncs import mean_variance_axis0 +from ..utils.sparsefuncs import mean_variance_axis __all__ = ["TruncatedSVD"] @@ -64,12 +64,12 @@ class TruncatedSVD(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, shape (n_components, n_features) + components_ : array, shape (n_components, n_features) - `explained_variance_ratio_` : array, [n_components] + explained_variance_ratio_ : array, [n_components] Percentage of variance explained by each of the selected components. - `explained_variance_` : array, [n_components] + explained_variance_ : array, [n_components] The variance of the training samples transformed by a projection to each component. @@ -175,7 +175,7 @@ def fit_transform(self, X, y=None): X_transformed = np.dot(U, np.diag(Sigma)) self.explained_variance_ = exp_var = np.var(X_transformed, axis=0) if sp.issparse(X): - _, full_var = mean_variance_axis0(X) + _, full_var = mean_variance_axis(X, axis=0) full_var = full_var.sum() else: full_var = np.var(X, axis=0).sum() diff --git a/sklearn/dummy.py b/sklearn/dummy.py index a55ca3b332499..6436514510116 100644 --- a/sklearn/dummy.py +++ b/sklearn/dummy.py @@ -1,16 +1,20 @@ # Author: Mathieu Blondel # Arnaud Joly -# Maheshakya Wijewardena +# Maheshakya Wijewardena # License: BSD 3 clause from __future__ import division +import warnings import numpy as np +import scipy.sparse as sp from .base import BaseEstimator, ClassifierMixin, RegressorMixin from .externals.six.moves import xrange from .utils import check_random_state from .utils.validation import check_array from sklearn.utils import deprecated +from sklearn.utils.random import random_choice_csc +from sklearn.utils.multiclass import class_distribution class DummyClassifier(BaseEstimator, ClassifierMixin): @@ -43,21 +47,25 @@ class DummyClassifier(BaseEstimator, ClassifierMixin): Attributes ---------- - `classes_` : array or list of array of shape = [n_classes] + classes_ : array or list of array of shape = [n_classes] Class labels for each output. - `n_classes_` : array or list of array of shape = [n_classes] + n_classes_ : array or list of array of shape = [n_classes] Number of label for each output. - `class_prior_` : array or list of array of shape = [n_classes] + class_prior_ : array or list of array of shape = [n_classes] Probability of each class for each output. - `n_outputs_` : int, + n_outputs_ : int, Number of outputs. - `outputs_2d_` : bool, + outputs_2d_ : bool, True if the output at fit is 2d, else false. + `sparse_output_` : bool, + True if the array returned from predict is to be in sparse CSC format. + Is automatically set to True if the input y is passed in sparse format. + """ def __init__(self, strategy="stratified", random_state=None, @@ -90,16 +98,24 @@ def fit(self, X, y, sample_weight=None): "constant"): raise ValueError("Unknown strategy type.") - y = np.atleast_1d(y) - self.output_2d_ = y.ndim == 2 + if self.strategy == "uniform" and sp.issparse(y): + y = y.toarray() + warnings.warn('A local copy of the target data has been converted ' + 'to a numpy array. Predicting on sparse target data ' + 'with the uniform strategy would not save memory ' + 'and would be slower.', + UserWarning) + + self.sparse_output_ = sp.issparse(y) + if not self.sparse_output_: + y = np.atleast_1d(y) + + self.output_2d_ = y.ndim == 2 if y.ndim == 1: y = np.reshape(y, (-1, 1)) self.n_outputs_ = y.shape[1] - self.classes_ = [] - self.n_classes_ = [] - self.class_prior_ = [] if self.strategy == "constant": if self.constant is None: @@ -111,16 +127,14 @@ def fit(self, X, y, sample_weight=None): raise ValueError("Constant target value should have " "shape (%d, 1)." % self.n_outputs_) - for k in xrange(self.n_outputs_): - classes, y_k = np.unique(y[:, k], return_inverse=True) - self.classes_.append(classes) - self.n_classes_.append(classes.shape[0]) - class_prior = np.bincount(y_k, weights=sample_weight) - self.class_prior_.append(class_prior / class_prior.sum()) - - # Checking in case of constant strategy if the constant provided - # by the user is in y. - if self.strategy == "constant": + (self.classes_, + self.n_classes_, + self.class_prior_) = class_distribution(y, sample_weight) + + if self.strategy == "constant": + for k in range(self.n_outputs_): + # Checking in case of constant strategy if the constant + # provided by the user is in y. if constant[k] not in self.classes_[k]: raise ValueError("The constant target value must be " "present in training data") @@ -172,26 +186,42 @@ def predict(self, X): if self.n_outputs_ == 1: proba = [proba] - y = [] - for k in xrange(self.n_outputs_): + if self.sparse_output_: + class_prob = None if self.strategy == "most_frequent": - ret = np.ones(n_samples, dtype=int) * class_prior_[k].argmax() + classes_ = [np.array([cp.argmax()]) for cp in class_prior_] elif self.strategy == "stratified": - ret = proba[k].argmax(axis=1) + class_prob = class_prior_ elif self.strategy == "uniform": - ret = rs.randint(n_classes_[k], size=n_samples) + raise ValueError("Sparse target prediction is not " + "supported with the uniform strategy") elif self.strategy == "constant": - ret = np.ones(n_samples, dtype=int) * ( - np.where(classes_[k] == constant[k])) + classes_ = [np.array([c]) for c in constant] - y.append(classes_[k][ret]) + y = random_choice_csc(n_samples, classes_, class_prob, + self.random_state) + else: + if self.strategy == "most_frequent": + y = np.tile([classes_[k][class_prior_[k].argmax()] for + k in range(self.n_outputs_)], [n_samples, 1]) - y = np.vstack(y).T - if self.n_outputs_ == 1 and not self.output_2d_: - y = np.ravel(y) + elif self.strategy == "stratified": + y = np.vstack(classes_[k][proba[k].argmax(axis=1)] for + k in range(self.n_outputs_)).T + + elif self.strategy == "uniform": + ret = [classes_[k][rs.randint(n_classes_[k], size=n_samples)] + for k in range(self.n_outputs_)] + y = np.vstack(ret).T + + elif self.strategy == "constant": + y = np.tile(self.constant, (n_samples, 1)) + + if self.n_outputs_ == 1 and not self.output_2d_: + y = np.ravel(y) return y @@ -306,14 +336,14 @@ class DummyRegressor(BaseEstimator, RegressorMixin): Attributes ---------- - `constant_` : float or array of shape [n_outputs] + constant_ : float or array of shape [n_outputs] Mean or median of the training targets or constant value given the by the user. - `n_outputs_` : int, + n_outputs_ : int, Number of outputs. - `outputs_2d_` : bool, + outputs_2d_ : bool, True if the output at fit is 2d, else false. """ diff --git a/sklearn/ensemble/bagging.py b/sklearn/ensemble/bagging.py index 24b252913f2ff..3bded083991fb 100644 --- a/sklearn/ensemble/bagging.py +++ b/sklearn/ensemble/bagging.py @@ -277,7 +277,8 @@ def fit(self, X, y, sample_weight=None): self.estimators_ = None # Parallel loop - n_jobs, n_estimators, starts = _partition_estimators(self) + n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators, + self.n_jobs) seeds = random_state.randint(MAX_INT, size=self.n_estimators) all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose)( @@ -377,29 +378,29 @@ class BaggingClassifier(BaseBagging, ClassifierMixin): Attributes ---------- - `base_estimator_`: list of estimators + base_estimator_ : list of estimators The base estimator from which the ensemble is grown. - `estimators_`: list of estimators + estimators_ : list of estimators The collection of fitted base estimators. - `estimators_samples_`: list of arrays + estimators_samples_ : list of arrays The subset of drawn samples (i.e., the in-bag samples) for each base estimator. - `estimators_features_`: list of arrays + estimators_features_ : list of arrays The subset of drawn features for each base estimator. - `classes_`: array of shape = [n_classes] + classes_ : array of shape = [n_classes] The classes labels. - `n_classes_`: int or list + n_classes_ : int or list The number of classes. - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_decision_function_` : array of shape = [n_samples, n_classes] + oob_decision_function_ : array of shape = [n_samples, n_classes] Decision function computed with out-of-bag estimate on the training set. If n_estimators is small it might be possible that a data point was never left out during the bootstrap. In this case, @@ -549,7 +550,8 @@ def predict_proba(self, X): "".format(self.n_features_, X.shape[1])) # Parallel loop - n_jobs, n_estimators, starts = _partition_estimators(self) + n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators, + self.n_jobs) all_proba = Parallel(n_jobs=n_jobs, verbose=self.verbose)( delayed(_parallel_predict_proba)( @@ -594,7 +596,8 @@ def predict_log_proba(self, X): "".format(self.n_features_, X.shape[1])) # Parallel loop - n_jobs, n_estimators, starts = _partition_estimators(self) + n_jobs, n_estimators, starts = _partition_estimators( + self.n_estimators, self.n_jobs) all_log_proba = Parallel(n_jobs=n_jobs, verbose=self.verbose)( delayed(_parallel_predict_log_proba)( @@ -649,7 +652,8 @@ def decision_function(self, X): "".format(self.n_features_, X.shape[1])) # Parallel loop - n_jobs, n_estimators, starts = _partition_estimators(self) + n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators, + self.n_jobs) all_decisions = Parallel(n_jobs=n_jobs, verbose=self.verbose)( delayed(_parallel_decision_function)( @@ -728,20 +732,20 @@ class BaggingRegressor(BaseBagging, RegressorMixin): Attributes ---------- - `estimators_`: list of estimators + estimators_ : list of estimators The collection of fitted sub-estimators. - `estimators_samples_`: list of arrays + estimators_samples_ : list of arrays The subset of drawn samples (i.e., the in-bag samples) for each base estimator. - `estimators_features_`: list of arrays + estimators_features_ : list of arrays The subset of drawn features for each base estimator. - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_decision_function_` : array of shape = [n_samples, n_classes] + oob_decision_function_ : array of shape = [n_samples, n_classes] Decision function computed with out-of-bag estimate on the training set. If n_estimators is small it might be possible that a data point was never left out during the bootstrap. In this case, @@ -808,7 +812,8 @@ def predict(self, X): X = check_array(X, accept_sparse=['csr', 'csc', 'coo']) # Parallel loop - n_jobs, n_estimators, starts = _partition_estimators(self) + n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators, + self.n_jobs) all_y_hat = Parallel(n_jobs=n_jobs, verbose=self.verbose)( delayed(_parallel_predict_regression)( diff --git a/sklearn/ensemble/base.py b/sklearn/ensemble/base.py index 2031853b8ca91..f13a1fd16cbc6 100644 --- a/sklearn/ensemble/base.py +++ b/sklearn/ensemble/base.py @@ -33,10 +33,10 @@ class BaseEnsemble(BaseEstimator, MetaEstimatorMixin): Attributes ---------- - `base_estimator_`: list of estimators + base_estimator_ : list of estimators The base estimator from which the ensemble is grown. - `estimators_`: list of estimators + estimators_ : list of estimators The collection of fitted base estimators. """ @@ -95,19 +95,19 @@ def __iter__(self): return iter(self.estimators_) -def _partition_estimators(ensemble): +def _partition_estimators(n_estimators, n_jobs): """Private function used to partition estimators between jobs.""" # Compute the number of jobs - if ensemble.n_jobs == -1: - n_jobs = min(cpu_count(), ensemble.n_estimators) + if n_jobs == -1: + n_jobs = min(cpu_count(), n_estimators) else: - n_jobs = min(ensemble.n_jobs, ensemble.n_estimators) + n_jobs = min(n_jobs, n_estimators) # Partition estimators between jobs - n_estimators = (ensemble.n_estimators // n_jobs) * np.ones(n_jobs, - dtype=np.int) - n_estimators[:ensemble.n_estimators % n_jobs] += 1 - starts = np.cumsum(n_estimators) + n_estimators_per_job = (n_estimators // n_jobs) * np.ones(n_jobs, + dtype=np.int) + n_estimators_per_job[:n_estimators % n_jobs] += 1 + starts = np.cumsum(n_estimators_per_job) - return n_jobs, n_estimators.tolist(), [0] + starts.tolist() + return n_jobs, n_estimators_per_job.tolist(), [0] + starts.tolist() diff --git a/sklearn/ensemble/forest.py b/sklearn/ensemble/forest.py index afa97dd5a4207..16dd17d39892d 100644 --- a/sklearn/ensemble/forest.py +++ b/sklearn/ensemble/forest.py @@ -38,7 +38,7 @@ class calls the ``fit`` method of each sub-estimator on random samples from __future__ import division -import itertools +from itertools import chain import numpy as np from warnings import warn from abc import ABCMeta, abstractmethod @@ -66,83 +66,41 @@ class calls the ``fit`` method of each sub-estimator on random samples MAX_INT = np.iinfo(np.int32).max -def _parallel_build_trees(trees, forest, X, y, sample_weight, verbose): - """Private function used to build a batch of trees within a job.""" - for i, tree in enumerate(trees): - if verbose > 1: - print("building tree %d of %d" % (i + 1, len(trees))) - - if forest.bootstrap: - n_samples = X.shape[0] - if sample_weight is None: - curr_sample_weight = np.ones((n_samples,), dtype=np.float64) - else: - curr_sample_weight = sample_weight.copy() - - random_state = check_random_state(tree.random_state) - indices = random_state.randint(0, n_samples, n_samples) - sample_counts = np.bincount(indices, minlength=n_samples) - curr_sample_weight *= sample_counts - - tree.fit(X, y, - sample_weight=curr_sample_weight, - check_input=False) - - tree.indices_ = sample_counts > 0. +def _parallel_build_trees(tree, forest, X, y, sample_weight, tree_idx, n_trees, + verbose=0): + """Private function used to fit a single tree in parallel.""" + if verbose > 1: + print("building tree %d of %d" % (tree_idx + 1, n_trees)) + if forest.bootstrap: + n_samples = X.shape[0] + if sample_weight is None: + curr_sample_weight = np.ones((n_samples,), dtype=np.float64) else: - tree.fit(X, y, - sample_weight=sample_weight, - check_input=False) - - return trees - - -def _parallel_predict_proba(trees, X, n_classes, n_outputs): - """Private function used to compute a batch of predictions within a job.""" - n_samples = X.shape[0] + curr_sample_weight = sample_weight.copy() - if n_outputs == 1: - proba = np.zeros((n_samples, n_classes)) + random_state = check_random_state(tree.random_state) + indices = random_state.randint(0, n_samples, n_samples) + sample_counts = np.bincount(indices, minlength=n_samples) + curr_sample_weight *= sample_counts - for tree in trees: - proba_tree = tree.predict_proba(X) + tree.fit(X, y, + sample_weight=curr_sample_weight, + check_input=False) - if n_classes == tree.n_classes_: - proba += proba_tree - - else: - proba[:, tree.classes_] += \ - proba_tree[:, range(len(tree.classes_))] + tree.indices_ = sample_counts > 0. else: - proba = [] - - for k in xrange(n_outputs): - proba.append(np.zeros((n_samples, n_classes[k]))) - - for tree in trees: - proba_tree = tree.predict_proba(X) - - for k in xrange(n_outputs): - if n_classes[k] == tree.n_classes_[k]: - proba[k] += proba_tree[k] - - else: - proba[k][:, tree.classes_] += \ - proba_tree[k][:, range(len(tree.classes_))] - - return proba + tree.fit(X, y, + sample_weight=sample_weight, + check_input=False) + return tree -def _parallel_predict_regression(trees, X): - """Private function used to compute a batch of predictions within a job.""" - return sum(tree.predict(X) for tree in trees) - -def _parallel_apply(tree, X): - """Private helper function for parallizing calls to apply in a forest.""" - return tree.tree_.apply(X) +def _parallel_helper(obj, methodname, *args, **kwargs): + """Private helper to workaround Python 2 pickle limitations""" + return getattr(obj, methodname)(*args, **kwargs) class BaseForest(six.with_metaclass(ABCMeta, BaseEnsemble, @@ -162,7 +120,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(BaseForest, self).__init__( base_estimator=base_estimator, n_estimators=n_estimators, @@ -173,6 +132,7 @@ def __init__(self, self.n_jobs = n_jobs self.random_state = random_state self.verbose = verbose + self.warm_start = warm_start def apply(self, X): """Apply trees in the forest to X, return leaf indices. @@ -191,7 +151,8 @@ def apply(self, X): X = check_array(X, dtype=DTYPE) results = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, backend="threading")( - delayed(_parallel_apply)(tree, X) for tree in self.estimators_) + delayed(_parallel_helper)(tree.tree_, 'apply', X) + for tree in self.estimators_) return np.array(results).T def fit(self, X, y, sample_weight=None): @@ -218,8 +179,6 @@ def fit(self, X, y, sample_weight=None): self : object Returns self. """ - random_state = check_random_state(self.random_state) - # Convert data # ensure_2d=False because there are actually unit test checking we fail # for 1d. FIXME make this consistent in the future. @@ -254,34 +213,47 @@ def fit(self, X, y, sample_weight=None): raise ValueError("Out of bag estimation only available" " if bootstrap=True") - # Assign chunk of trees to jobs - n_jobs, n_trees, starts = _partition_estimators(self) - trees = [] + random_state = check_random_state(self.random_state) + + if not self.warm_start: + # Free allocated memory, if any + self.estimators_ = [] - for i in range(self.n_estimators): - tree = self._make_estimator(append=False) - tree.set_params(random_state=random_state.randint(MAX_INT)) - trees.append(tree) + n_more_estimators = self.n_estimators - len(self.estimators_) - # Free allocated memory, if any - self.estimators_ = None + if n_more_estimators < 0: + raise ValueError('n_estimators=%d must be larger or equal to ' + 'len(estimators_)=%d when warm_start==True' + % (self.n_estimators, len(self.estimators_))) - # Parallel loop: we use the threading backend as the Cython code for - # fitting the trees is internally releasing the Python GIL making - # threading always more efficient than multiprocessing in that case. - all_trees = Parallel(n_jobs=n_jobs, verbose=self.verbose, + elif n_more_estimators == 0: + warn("Warm-start fitting without increasing n_estimators does not " + "fit new trees.") + else: + if self.warm_start and len(self.estimators_) > 0: + # We draw from the random state to get the random state we + # would have got if we hadn't used a warm_start. + random_state.randint(MAX_INT, size=len(self.estimators_)) + + trees = [] + for i in range(n_more_estimators): + tree = self._make_estimator(append=False) + tree.set_params(random_state=random_state.randint(MAX_INT)) + trees.append(tree) + + # Parallel loop: we use the threading backend as the Cython code + # for fitting the trees is internally releasing the Python GIL + # making threading always more efficient than multiprocessing in + # that case. + trees = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, backend="threading")( - delayed(_parallel_build_trees)( - trees[starts[i]:starts[i + 1]], - self, - X, - y, - sample_weight, - verbose=self.verbose) - for i in range(n_jobs)) + delayed(_parallel_build_trees)( + t, self, X, y, sample_weight, i, len(trees), + verbose=self.verbose) + for i, t in enumerate(trees)) - # Reduce - self.estimators_ = list(itertools.chain(*all_trees)) + # Collect newly grown trees + self.estimators_.extend(trees) if self.oob_score: self._set_oob_score(X, y) @@ -314,8 +286,10 @@ def feature_importances_(self): raise ValueError("Estimator not fitted, " "call `fit` before `feature_importances_`.") - return sum(tree.feature_importances_ - for tree in self.estimators_) / self.n_estimators + all_importances = Parallel(n_jobs=self.n_jobs)( + delayed(getattr)(tree, 'feature_importances_') + for tree in self.estimators_) + return sum(all_importances) / self.n_estimators class ForestClassifier(six.with_metaclass(ABCMeta, BaseForest, @@ -335,7 +309,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(ForestClassifier, self).__init__( base_estimator, @@ -345,7 +320,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) def _set_oob_score(self, X, y): n_classes_ = self.n_classes_ @@ -460,17 +436,14 @@ def predict_proba(self, X): X = check_array(X, dtype=DTYPE) # Assign chunk of trees to jobs - n_jobs, n_trees, starts = _partition_estimators(self) + n_jobs, n_trees, starts = _partition_estimators(self.n_estimators, + self.n_jobs) # Parallel loop all_proba = Parallel(n_jobs=n_jobs, verbose=self.verbose, backend="threading")( - delayed(_parallel_predict_proba)( - self.estimators_[starts[i]:starts[i + 1]], - X, - self.n_classes_, - self.n_outputs_) - for i in range(n_jobs)) + delayed(_parallel_helper)(e, 'predict_proba', X) + for e in self.estimators_) # Reduce proba = all_proba[0] @@ -538,7 +511,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(ForestRegressor, self).__init__( base_estimator, n_estimators=n_estimators, @@ -547,7 +521,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) def predict(self, X): """Predict regression target for X. @@ -570,14 +545,14 @@ def predict(self, X): X = check_array(X, dtype=DTYPE) # Assign chunk of trees to jobs - n_jobs, n_trees, starts = _partition_estimators(self) + n_jobs, n_trees, starts = _partition_estimators(self.n_estimators, + self.n_jobs) # Parallel loop all_y_hat = Parallel(n_jobs=n_jobs, verbose=self.verbose, backend="threading")( - delayed(_parallel_predict_regression)( - self.estimators_[starts[i]:starts[i + 1]], X) - for i in range(n_jobs)) + delayed(_parallel_helper)(e, 'predict', X) + for e in self.estimators_) # Reduce y_hat = sum(all_y_hat) / len(self.estimators_) @@ -706,26 +681,31 @@ class RandomForestClassifier(ForestClassifier): verbose : int, optional (default=0) Controls the verbosity of the tree building process. + warm_start : bool, optional (default=False) + When set to ``True``, reuse the solution of the previous call to fit + and add more estimators to the ensemble, otherwise, just fit a whole + new forest. + Attributes ---------- - `estimators_`: list of DecisionTreeClassifier + estimators_ : list of DecisionTreeClassifier The collection of fitted sub-estimators. - `classes_`: array of shape = [n_classes] or a list of such arrays + classes_ : array of shape = [n_classes] or a list of such arrays The classes labels (single output problem), or a list of arrays of class labels (multi-output problem). - `n_classes_`: int or list + n_classes_ : int or list The number of classes (single output problem), or a list containing the number of classes for each output (multi-output problem). - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_decision_function_` : array of shape = [n_samples, n_classes] + oob_decision_function_ : array of shape = [n_samples, n_classes] Decision function computed with out-of-bag estimate on the training set. If n_estimators is small it might be possible that a data point was never left out during the bootstrap. In this case, @@ -753,7 +733,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(RandomForestClassifier, self).__init__( base_estimator=DecisionTreeClassifier(), n_estimators=n_estimators, @@ -765,7 +746,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) self.criterion = criterion self.max_depth = max_depth @@ -859,18 +841,23 @@ class RandomForestRegressor(ForestRegressor): verbose : int, optional (default=0) Controls the verbosity of the tree building process. + warm_start : bool, optional (default=False) + When set to ``True``, reuse the solution of the previous call to fit + and add more estimators to the ensemble, otherwise, just fit a whole + new forest. + Attributes ---------- - `estimators_`: list of DecisionTreeRegressor + estimators_ : list of DecisionTreeRegressor The collection of fitted sub-estimators. - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_prediction_` : array of shape = [n_samples] + oob_prediction_ : array of shape = [n_samples] Prediction computed with out-of-bag estimate on the training set. References @@ -895,7 +882,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(RandomForestRegressor, self).__init__( base_estimator=DecisionTreeRegressor(), n_estimators=n_estimators, @@ -907,7 +895,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) self.criterion = criterion self.max_depth = max_depth @@ -1002,26 +991,31 @@ class ExtraTreesClassifier(ForestClassifier): verbose : int, optional (default=0) Controls the verbosity of the tree building process. + warm_start : bool, optional (default=False) + When set to ``True``, reuse the solution of the previous call to fit + and add more estimators to the ensemble, otherwise, just fit a whole + new forest. + Attributes ---------- - `estimators_`: list of DecisionTreeClassifier + estimators_ : list of DecisionTreeClassifier The collection of fitted sub-estimators. - `classes_`: array of shape = [n_classes] or a list of such arrays + classes_ : array of shape = [n_classes] or a list of such arrays The classes labels (single output problem), or a list of arrays of class labels (multi-output problem). - `n_classes_`: int or list + n_classes_ : int or list The number of classes (single output problem), or a list containing the number of classes for each output (multi-output problem). - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_decision_function_` : array of shape = [n_samples, n_classes] + oob_decision_function_ : array of shape = [n_samples, n_classes] Decision function computed with out-of-bag estimate on the training set. If n_estimators is small it might be possible that a data point was never left out during the bootstrap. In this case, @@ -1052,7 +1046,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(ExtraTreesClassifier, self).__init__( base_estimator=ExtraTreeClassifier(), n_estimators=n_estimators, @@ -1063,7 +1058,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) self.criterion = criterion self.max_depth = max_depth @@ -1159,18 +1155,23 @@ class ExtraTreesRegressor(ForestRegressor): verbose : int, optional (default=0) Controls the verbosity of the tree building process. + warm_start : bool, optional (default=False) + When set to ``True``, reuse the solution of the previous call to fit + and add more estimators to the ensemble, otherwise, just fit a whole + new forest. + Attributes ---------- - `estimators_`: list of DecisionTreeRegressor + estimators_ : list of DecisionTreeRegressor The collection of fitted sub-estimators. - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_score_` : float + oob_score_ : float Score of the training dataset obtained using an out-of-bag estimate. - `oob_prediction_` : array of shape = [n_samples] + oob_prediction_ : array of shape = [n_samples] Prediction computed with out-of-bag estimate on the training set. References @@ -1197,7 +1198,8 @@ def __init__(self, oob_score=False, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(ExtraTreesRegressor, self).__init__( base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, @@ -1209,7 +1211,8 @@ def __init__(self, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) self.criterion = criterion self.max_depth = max_depth @@ -1281,9 +1284,14 @@ class RandomTreesEmbedding(BaseForest): verbose : int, optional (default=0) Controls the verbosity of the tree building process. + warm_start : bool, optional (default=False) + When set to ``True``, reuse the solution of the previous call to fit + and add more estimators to the ensemble, otherwise, just fit a whole + new forest. + Attributes ---------- - `estimators_`: list of DecisionTreeClassifier + estimators_ : list of DecisionTreeClassifier The collection of fitted sub-estimators. References @@ -1306,7 +1314,8 @@ def __init__(self, sparse_output=True, n_jobs=1, random_state=None, - verbose=0): + verbose=0, + warm_start=False): super(RandomTreesEmbedding, self).__init__( base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, @@ -1318,7 +1327,8 @@ def __init__(self, oob_score=False, n_jobs=n_jobs, random_state=random_state, - verbose=verbose) + verbose=verbose, + warm_start=warm_start) self.criterion = 'mse' self.max_depth = max_depth diff --git a/sklearn/ensemble/gradient_boosting.py b/sklearn/ensemble/gradient_boosting.py index cefaec06d6993..c030edf99b94f 100644 --- a/sklearn/ensemble/gradient_boosting.py +++ b/sklearn/ensemble/gradient_boosting.py @@ -389,7 +389,7 @@ def _update_terminal_region(self, tree, terminal_regions, leaf, X, y, y = y.take(terminal_region, axis=0) numerator = residual.sum() - denominator = np.sum((y - residual) * (1 - y + residual)) + denominator = np.dot(y - residual, 1 - y + residual) if denominator == 0.0: tree.value[leaf, 0, 0] = 0.0 @@ -822,6 +822,7 @@ def _fit_stages(self, X, y, y_pred, random_state, begin_at_stage=0, verbose_reporter.init(self, begin_at_stage) # perform boosting iterations + i = begin_at_stage for i in range(begin_at_stage, self.n_estimators): # subsampling @@ -1050,34 +1051,34 @@ class GradientBoostingClassifier(BaseGradientBoosting, ClassifierMixin): Attributes ---------- - `feature_importances_` : array, shape = [n_features] + feature_importances_ : array, shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_improvement_` : array, shape = [n_estimators] + oob_improvement_ : array, shape = [n_estimators] The improvement in loss (= deviance) on the out-of-bag samples relative to the previous iteration. ``oob_improvement_[0]`` is the improvement in loss of the first stage over the ``init`` estimator. - `oob_score_` : array, shape = [n_estimators] + oob_score_ : array, shape = [n_estimators] Score of the training dataset obtained using an out-of-bag estimate. The i-th score ``oob_score_[i]`` is the deviance (= loss) of the model at iteration ``i`` on the out-of-bag sample. Deprecated: use `oob_improvement_` instead. - `train_score_` : array, shape = [n_estimators] + train_score_ : array, shape = [n_estimators] The i-th score ``train_score_[i]`` is the deviance (= loss) of the model at iteration ``i`` on the in-bag sample. If ``subsample == 1`` this is the deviance on the training data. - `loss_` : LossFunction + loss_ : LossFunction The concrete ``LossFunction`` object. `init` : BaseEstimator The estimator that provides the initial predictions. Set via the ``init`` argument or ``loss.init_estimator``. - `estimators_`: list of DecisionTreeRegressor + estimators_ : list of DecisionTreeRegressor The collection of fitted sub-estimators. See also @@ -1322,34 +1323,34 @@ class GradientBoostingRegressor(BaseGradientBoosting, RegressorMixin): Attributes ---------- - `feature_importances_` : array, shape = [n_features] + feature_importances_ : array, shape = [n_features] The feature importances (the higher, the more important the feature). - `oob_improvement_` : array, shape = [n_estimators] + oob_improvement_ : array, shape = [n_estimators] The improvement in loss (= deviance) on the out-of-bag samples relative to the previous iteration. ``oob_improvement_[0]`` is the improvement in loss of the first stage over the ``init`` estimator. - `oob_score_` : array, shape = [n_estimators] + oob_score_ : array, shape = [n_estimators] Score of the training dataset obtained using an out-of-bag estimate. The i-th score ``oob_score_[i]`` is the deviance (= loss) of the model at iteration ``i`` on the out-of-bag sample. Deprecated: use `oob_improvement_` instead. - `train_score_` : array, shape = [n_estimators] + train_score_ : array, shape = [n_estimators] The i-th score ``train_score_[i]`` is the deviance (= loss) of the model at iteration ``i`` on the in-bag sample. If ``subsample == 1`` this is the deviance on the training data. - `loss_` : LossFunction + loss_ : LossFunction The concrete ``LossFunction`` object. `init` : BaseEstimator The estimator that provides the initial predictions. Set via the ``init`` argument or ``loss.init_estimator``. - `estimators_`: list of DecisionTreeRegressor + estimators_ : list of DecisionTreeRegressor The collection of fitted sub-estimators. See also diff --git a/sklearn/ensemble/tests/test_forest.py b/sklearn/ensemble/tests/test_forest.py index f0462d7dd9257..c7c3b37d4e51a 100644 --- a/sklearn/ensemble/tests/test_forest.py +++ b/sklearn/ensemble/tests/test_forest.py @@ -22,6 +22,7 @@ from sklearn.utils.testing import assert_greater_equal from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import ignore_warnings from sklearn import datasets from sklearn.decomposition import TruncatedSVD @@ -184,30 +185,30 @@ def check_importance(name, X, y): """Check variable importances.""" ForestClassifier = FOREST_CLASSIFIERS[name] + for n_jobs in [1, 2]: + clf = ForestClassifier(n_estimators=10, n_jobs=n_jobs) + clf.fit(X, y) + importances = clf.feature_importances_ + n_important = np.sum(importances > 0.1) + assert_equal(importances.shape[0], 10) + assert_equal(n_important, 3) - clf = ForestClassifier(n_estimators=10) - clf.fit(X, y) - importances = clf.feature_importances_ - n_important = np.sum(importances > 0.1) - assert_equal(importances.shape[0], 10) - assert_equal(n_important, 3) - - X_new = clf.transform(X, threshold="mean") - assert_less(0 < X_new.shape[1], X.shape[1]) + X_new = clf.transform(X, threshold="mean") + assert_less(0 < X_new.shape[1], X.shape[1]) - # Check with sample weights - sample_weight = np.ones(y.shape) - sample_weight[y == 1] *= 100 + # Check with sample weights + sample_weight = np.ones(y.shape) + sample_weight[y == 1] *= 100 - clf = ForestClassifier(n_estimators=50, random_state=0) - clf.fit(X, y, sample_weight=sample_weight) - importances = clf.feature_importances_ - assert_true(np.all(importances >= 0.0)) + clf = ForestClassifier(n_estimators=50, n_jobs=n_jobs, random_state=0) + clf.fit(X, y, sample_weight=sample_weight) + importances = clf.feature_importances_ + assert_true(np.all(importances >= 0.0)) - clf = ForestClassifier(n_estimators=50, random_state=0) - clf.fit(X, y, sample_weight=3 * sample_weight) - importances_bis = clf.feature_importances_ - assert_almost_equal(importances, importances_bis) + clf = ForestClassifier(n_estimators=50, n_jobs=n_jobs, random_state=0) + clf.fit(X, y, sample_weight=3 * sample_weight) + importances_bis = clf.feature_importances_ + assert_almost_equal(importances, importances_bis) def test_importances(): @@ -670,6 +671,141 @@ def test_1d_input(): yield check_1d_input, name, X, X_2d, y +def check_warm_start(name, random_state=42): + """Test if fitting incrementally with warm start gives a forest of the + right size and the same results as a normal fit.""" + X, y = datasets.make_hastie_10_2(n_samples=20, random_state=1) + ForestEstimator = FOREST_ESTIMATORS[name] + clf_ws = None + for n_estimators in [5, 10]: + if clf_ws is None: + clf_ws = ForestEstimator(n_estimators=n_estimators, + random_state=random_state, + warm_start=True) + else: + clf_ws.set_params(n_estimators=n_estimators) + clf_ws.fit(X, y) + assert_equal(len(clf_ws), n_estimators) + + clf_no_ws = ForestEstimator(n_estimators=10, random_state=random_state, + warm_start=False) + clf_no_ws.fit(X, y) + + assert_equal(set([tree.random_state for tree in clf_ws]), + set([tree.random_state for tree in clf_no_ws])) + + assert_array_equal(clf_ws.apply(X), clf_no_ws.apply(X), + err_msg="Failed with {0}".format(name)) + + +def test_warm_start(): + for name in FOREST_ESTIMATORS: + yield check_warm_start, name + + +def check_warm_start_clear(name): + """Test if fit clears state and grows a new forest when warm_start==False. + """ + X, y = datasets.make_hastie_10_2(n_samples=20, random_state=1) + ForestEstimator = FOREST_ESTIMATORS[name] + clf = ForestEstimator(n_estimators=5, max_depth=1, warm_start=False, + random_state=1) + clf.fit(X, y) + + clf_2 = ForestEstimator(n_estimators=5, max_depth=1, warm_start=True, + random_state=2) + clf_2.fit(X, y) # inits state + clf_2.set_params(warm_start=False, random_state=1) + clf_2.fit(X, y) # clears old state and equals clf + + assert_array_almost_equal(clf_2.apply(X), clf.apply(X)) + + +def test_warm_start_clear(): + for name in FOREST_ESTIMATORS: + yield check_warm_start_clear, name + + +def check_warm_start_smaller_n_estimators(name): + """Test if warm start second fit with smaller n_estimators raises error.""" + X, y = datasets.make_hastie_10_2(n_samples=20, random_state=1) + ForestEstimator = FOREST_ESTIMATORS[name] + clf = ForestEstimator(n_estimators=5, max_depth=1, warm_start=True) + clf.fit(X, y) + clf.set_params(n_estimators=4) + assert_raises(ValueError, clf.fit, X, y) + + +def test_warm_start_smaller_n_estimators(): + for name in FOREST_ESTIMATORS: + yield check_warm_start_smaller_n_estimators, name + + +def check_warm_start_equal_n_estimators(name): + """Test if warm start with equal n_estimators does nothing and returns the + same forest and raises a warning.""" + X, y = datasets.make_hastie_10_2(n_samples=20, random_state=1) + ForestEstimator = FOREST_ESTIMATORS[name] + clf = ForestEstimator(n_estimators=5, max_depth=3, warm_start=True, + random_state=1) + clf.fit(X, y) + + clf_2 = ForestEstimator(n_estimators=5, max_depth=3, warm_start=True, + random_state=1) + clf_2.fit(X, y) + # Now clf_2 equals clf. + + clf_2.set_params(random_state=2) + assert_warns(UserWarning, clf_2.fit, X, y) + # If we had fit the trees again we would have got a different forest as we + # changed the random state. + assert_array_equal(clf.apply(X), clf_2.apply(X)) + + +def test_warm_start_equal_n_estimators(): + for name in FOREST_ESTIMATORS: + yield check_warm_start_equal_n_estimators, name + + +def check_warm_start_oob(name): + """Test that the warm start computes oob score when asked.""" + X, y = datasets.make_hastie_10_2(n_samples=20, random_state=1) + ForestEstimator = FOREST_ESTIMATORS[name] + # Use 15 estimators to avoid 'some inputs do not have OOB scores' warning. + clf = ForestEstimator(n_estimators=15, max_depth=3, warm_start=False, + random_state=1, bootstrap=True, oob_score=True) + clf.fit(X, y) + + clf_2 = ForestEstimator(n_estimators=5, max_depth=3, warm_start=False, + random_state=1, bootstrap=True, oob_score=False) + clf_2.fit(X, y) + + clf_2.set_params(warm_start=True, oob_score=True, n_estimators=15) + clf_2.fit(X, y) + + assert_true(hasattr(clf_2, 'oob_score_')) + assert_equal(clf.oob_score_, clf_2.oob_score_) + + # Test that oob_score is computed even if we don't need to train + # additional trees. + clf_3 = ForestEstimator(n_estimators=15, max_depth=3, warm_start=True, + random_state=1, bootstrap=True, oob_score=False) + clf_3.fit(X, y) + assert_true(not(hasattr(clf_3, 'oob_score_'))) + + clf_3.set_params(oob_score=True) + ignore_warnings(clf_3.fit)(X, y) + + assert_equal(clf.oob_score_, clf_3.oob_score_) + + +def test_warm_start_oob(): + for name in FOREST_CLASSIFIERS: + yield check_warm_start_oob, name + for name in FOREST_REGRESSORS: + yield check_warm_start_oob, name + + if __name__ == "__main__": import nose nose.runmodule() diff --git a/sklearn/ensemble/tests/test_gradient_boosting.py b/sklearn/ensemble/tests/test_gradient_boosting.py index a6d24b5fbe4e0..0600181044c83 100644 --- a/sklearn/ensemble/tests/test_gradient_boosting.py +++ b/sklearn/ensemble/tests/test_gradient_boosting.py @@ -675,7 +675,7 @@ def test_warm_start_n_estimators(): def test_warm_start_max_depth(): - """Test if possible to fit trees of differet depth in ensemble. """ + """Test if possible to fit trees of different depth in ensemble. """ X, y = datasets.make_hastie_10_2(n_samples=100, random_state=1) for Cls in [GradientBoostingRegressor, GradientBoostingClassifier]: est = Cls(n_estimators=100, max_depth=1, warm_start=True) @@ -916,6 +916,18 @@ def test_max_leaf_nodes_max_depth(): assert_equal(tree.max_depth, 1) +def test_warm_start_wo_nestimators_change(): + """Test if warm_start does nothing if n_estimators is not changed. + + Regression test for #3513. + """ + clf = GradientBoostingClassifier(n_estimators=10, warm_start=True) + clf.fit([[0, 1], [2, 3]], [0, 1]) + assert clf.estimators_.shape[0] == 10 + clf.fit([[0, 1], [2, 3]], [0, 1]) + assert clf.estimators_.shape[0] == 10 + + if __name__ == "__main__": import nose nose.runmodule() diff --git a/sklearn/ensemble/weight_boosting.py b/sklearn/ensemble/weight_boosting.py old mode 100755 new mode 100644 index 376ce70a86a64..aba931cf6d5c8 --- a/sklearn/ensemble/weight_boosting.py +++ b/sklearn/ensemble/weight_boosting.py @@ -312,23 +312,23 @@ class AdaBoostClassifier(BaseWeightBoosting, ClassifierMixin): Attributes ---------- - `estimators_` : list of classifiers + estimators_ : list of classifiers The collection of fitted sub-estimators. - `classes_` : array of shape = [n_classes] + classes_ : array of shape = [n_classes] The classes labels. - `n_classes_` : int + n_classes_ : int The number of classes. - `estimator_weights_` : array of floats + estimator_weights_ : array of floats Weights for each estimator in the boosted ensemble. - `estimator_errors_` : array of floats + estimator_errors_ : array of floats Classification error for each estimator in the boosted ensemble. - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances if supported by the ``base_estimator``. See also @@ -854,16 +854,16 @@ class AdaBoostRegressor(BaseWeightBoosting, RegressorMixin): Attributes ---------- - `estimators_` : list of classifiers + estimators_ : list of classifiers The collection of fitted sub-estimators. - `estimator_weights_` : array of floats + estimator_weights_ : array of floats Weights for each estimator in the boosted ensemble. - `estimator_errors_` : array of floats + estimator_errors_ : array of floats Regression error for each estimator in the boosted ensemble. - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances if supported by the ``base_estimator``. See also diff --git a/sklearn/externals/joblib/__init__.py b/sklearn/externals/joblib/__init__.py index 39c7fdf2e2452..6b2f73e46e121 100644 --- a/sklearn/externals/joblib/__init__.py +++ b/sklearn/externals/joblib/__init__.py @@ -100,7 +100,7 @@ """ -__version__ = '0.8.2' +__version__ = '0.8.3' from .memory import Memory, MemorizedResult diff --git a/sklearn/externals/joblib/numpy_pickle.py b/sklearn/externals/joblib/numpy_pickle.py index 4ff777d0d8eec..cd4e29bdbf39f 100644 --- a/sklearn/externals/joblib/numpy_pickle.py +++ b/sklearn/externals/joblib/numpy_pickle.py @@ -107,7 +107,8 @@ def read(self, unpickler): "Reconstruct the array" filename = os.path.join(unpickler._dirname, self.filename) # Load the array from the disk - if unpickler.np.__version__ >= '1.3': + np_ver = [int(x) for x in unpickler.np.__version__.split('.', 2)[:2]] + if np_ver >= [1, 3]: array = unpickler.np.load(filename, mmap_mode=unpickler.mmap_mode) else: diff --git a/sklearn/externals/joblib/parallel.py b/sklearn/externals/joblib/parallel.py index e7a5b0b945bb2..c04e46fd55761 100644 --- a/sklearn/externals/joblib/parallel.py +++ b/sklearn/externals/joblib/parallel.py @@ -103,12 +103,21 @@ def __call__(self, *args, **kwargs): ############################################################################### -def delayed(function): - """ Decorator used to capture the arguments of a function. +def delayed(function, check_pickle=True): + """Decorator used to capture the arguments of a function. + + Pass `check_pickle=False` when: + + - performing a possibly repeated check is too costly and has been done + already once outside of the call to delayed. + + - when used in conjunction `Parallel(backend='threading')`. + """ # Try to pickle the input function, to catch the problems early when - # using with multiprocessing - pickle.dumps(function) + # using with multiprocessing: + if check_pickle: + pickle.dumps(function) def delayed_function(*args, **kwargs): return function, args, kwargs @@ -519,7 +528,7 @@ def retrieve(self): # Capture exception to add information on the local # stack in addition to the distant stack this_report = format_outer_frames(context=10, - stack_start=1) + stack_start=1) report = """Multiprocessing exception: %s --------------------------------------------------------------------------- diff --git a/sklearn/externals/joblib/pool.py b/sklearn/externals/joblib/pool.py index 486ca69eaf364..9a450e41b3108 100644 --- a/sklearn/externals/joblib/pool.py +++ b/sklearn/externals/joblib/pool.py @@ -200,7 +200,9 @@ def __call__(self, a): # a is already backed by a memmap file, let's reuse it directly return _reduce_memmap_backed(a, m) - if self._max_nbytes is not None and a.nbytes > self._max_nbytes: + if (not a.dtype.hasobject + and self._max_nbytes is not None + and a.nbytes > self._max_nbytes): # check that the folder exists (lazily create the pool temp folder # if required) try: diff --git a/sklearn/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index ee2922be19abd..2884d301f2233 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -52,10 +52,10 @@ class DictVectorizer(BaseEstimator, TransformerMixin): Attributes ---------- - `vocabulary_` : dict + vocabulary_ : dict A dictionary mapping feature names to feature indices. - `feature_names_` : list + feature_names_ : list A list of length n_features containing the feature names (e.g., "f=ham" and "f=spam"). diff --git a/sklearn/feature_extraction/tests/test_text.py b/sklearn/feature_extraction/tests/test_text.py index c20c849689f02..0b3aa8f5ea7fb 100644 --- a/sklearn/feature_extraction/tests/test_text.py +++ b/sklearn/feature_extraction/tests/test_text.py @@ -18,6 +18,7 @@ from sklearn.pipeline import Pipeline from sklearn.svm import LinearSVC +from sklearn.base import clone import numpy as np from nose import SkipTest @@ -283,7 +284,8 @@ def test_countvectorizer_stop_words(): def test_countvectorizer_empty_vocabulary(): try: - CountVectorizer(vocabulary=[]) + vect = CountVectorizer(vocabulary=[]) + vect.fit(["foo"]) assert False, "we shouldn't get here" except ValueError as e: assert_in("empty vocabulary", str(e).lower()) @@ -440,10 +442,10 @@ def test_vectorizer(): # (equivalent to term count vectorizer + tfidf transformer) train_data = iter(ALL_FOOD_DOCS[:-1]) tv = TfidfVectorizer(norm='l1') - assert_false(tv.fixed_vocabulary) tv.max_df = v1.max_df tfidf2 = tv.fit_transform(train_data).toarray() + assert_false(tv.fixed_vocabulary_) assert_array_almost_equal(tfidf, tfidf2) # test the direct tfidf vectorizer with new data @@ -767,7 +769,7 @@ def test_vectorizer_pipeline_grid_selection(): best_vectorizer = grid_search.best_estimator_.named_steps['vect'] assert_equal(best_vectorizer.ngram_range, (1, 1)) assert_equal(best_vectorizer.norm, 'l2') - assert_false(best_vectorizer.fixed_vocabulary) + assert_false(best_vectorizer.fixed_vocabulary_) def test_vectorizer_pipeline_cross_validation(): @@ -777,7 +779,6 @@ def test_vectorizer_pipeline_cross_validation(): # label junk food as -1, the others as +1 target = [-1] * len(JUNK_FOOD_DOCS) + [1] * len(NOTJUNK_FOOD_DOCS) - pipeline = Pipeline([('vect', TfidfVectorizer()), ('svc', LinearSVC())]) @@ -824,11 +825,10 @@ def test_tfidf_vectorizer_with_fixed_vocabulary(): # non regression smoke test for inheritance issues vocabulary = ['pizza', 'celeri'] vect = TfidfVectorizer(vocabulary=vocabulary) - assert_true(vect.fixed_vocabulary) X_1 = vect.fit_transform(ALL_FOOD_DOCS) X_2 = vect.transform(ALL_FOOD_DOCS) assert_array_almost_equal(X_1.toarray(), X_2.toarray()) - assert_true(vect.fixed_vocabulary) + assert_true(vect.fixed_vocabulary_) def test_pickling_vectorizer(): @@ -870,7 +870,8 @@ def test_pickling_transformer(): def test_non_unique_vocab(): vocab = ['a', 'b', 'c', 'a', 'a'] - assert_raises(ValueError, CountVectorizer, vocabulary=vocab) + vect = CountVectorizer(vocabulary=vocab) + assert_raises(ValueError, vect.fit, []) def test_hashingvectorizer_nan_in_docs(): @@ -901,3 +902,11 @@ def test_tfidfvectorizer_export_idf(): vect = TfidfVectorizer(use_idf=True) vect.fit(JUNK_FOOD_DOCS) assert_array_almost_equal(vect.idf_, vect._tfidf.idf_) + + +def test_vectorizer_vocab_clone(): + vect_vocab = TfidfVectorizer(vocabulary=["the"]) + vect_vocab_clone = clone(vect_vocab) + vect_vocab.fit(ALL_FOOD_DOCS) + vect_vocab_clone.fit(ALL_FOOD_DOCS) + assert_equal(vect_vocab_clone.vocabulary_, vect_vocab.vocabulary_) diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index 1d3d18e6e8aa4..4f26470590d55 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -28,7 +28,8 @@ from ..preprocessing import normalize from .hashing import FeatureHasher from .stop_words import ENGLISH_STOP_WORDS -from sklearn.externals import six +from ..utils import deprecated +from ..externals import six __all__ = ['CountVectorizer', 'ENGLISH_STOP_WORDS', @@ -236,6 +237,38 @@ def build_analyzer(self): raise ValueError('%s is not a valid tokenization scheme/analyzer' % self.analyzer) + def _check_vocabulary(self): + vocabulary = self.vocabulary + if vocabulary is not None: + if not isinstance(vocabulary, Mapping): + vocab = {} + for i, t in enumerate(vocabulary): + if vocab.setdefault(t, i) != i: + msg = "Duplicate term in vocabulary: %r" % t + raise ValueError(msg) + vocabulary = vocab + else: + indices = set(six.itervalues(vocabulary)) + if len(indices) != len(vocabulary): + raise ValueError("Vocabulary contains repeated indices.") + for i in xrange(len(vocabulary)): + if i not in indices: + msg = ("Vocabulary of size %d doesn't contain index " + "%d." % (len(vocabulary), i)) + raise ValueError(msg) + if not vocabulary: + raise ValueError("empty vocabulary passed to fit") + self.fixed_vocabulary_ = True + self.vocabulary_ = dict(vocabulary) + else: + self.fixed_vocabulary_ = False + + @property + @deprecated("The `fixed_vocabulary` attribute is deprecated and will be " + "removed in 0.18. Please use `fixed_vocabulary_` instead.") + def fixed_vocabulary(self): + return self.fixed_vocabulary_ + class HashingVectorizer(BaseEstimator, VectorizerMixin): """Convert a collection of text documents to a matrix of token occurrences @@ -327,9 +360,7 @@ class HashingVectorizer(BaseEstimator, VectorizerMixin): will be used. stop_words: string {'english'}, list, or None (default) - If a string, it is passed to _check_stop_list and the appropriate stop - list is returned. 'english' is currently the only supported string - value. + If 'english', a built-in stop word list for English is used. If a list, that list is assumed to contain stop words, all of which will be removed from the resulting tokens. @@ -514,9 +545,7 @@ class CountVectorizer(BaseEstimator, VectorizerMixin): will be used. stop_words : string {'english'}, list, or None (default) - If a string, it is passed to _check_stop_list and the appropriate stop - list is returned. 'english' is currently the only supported string - value. + If 'english', a built-in stop word list for English is used. If a list, that list is assumed to contain stop words, all of which will be removed from the resulting tokens. @@ -573,10 +602,10 @@ class CountVectorizer(BaseEstimator, VectorizerMixin): Attributes ---------- - `vocabulary_` : dict + vocabulary_ : dict A mapping of terms to feature indices. - `stop_words_` : set + stop_words_ : set Terms that were ignored because they occurred in either too many (`max_df`) or in too few (`min_df`) documents. @@ -616,29 +645,7 @@ def __init__(self, input='content', encoding='utf-8', "max_features=%r, neither a positive integer nor None" % max_features) self.ngram_range = ngram_range - if vocabulary is not None: - if not isinstance(vocabulary, Mapping): - vocab = {} - for i, t in enumerate(vocabulary): - if vocab.setdefault(t, i) != i: - msg = "Duplicate term in vocabulary: %r" % t - raise ValueError(msg) - vocabulary = vocab - else: - indices = set(six.itervalues(vocabulary)) - if len(indices) != len(vocabulary): - raise ValueError("Vocabulary contains repeated indices.") - for i in xrange(len(vocabulary)): - if i not in indices: - msg = ("Vocabulary of size %d doesn't contain index " - "%d." % (len(vocabulary), i)) - raise ValueError(msg) - if not vocabulary: - raise ValueError("empty vocabulary passed to fit") - self.fixed_vocabulary = True - self.vocabulary_ = dict(vocabulary) - else: - self.fixed_vocabulary = False + self.vocabulary = vocabulary self.binary = binary self.dtype = dtype @@ -773,16 +780,18 @@ def fit_transform(self, raw_documents, y=None): # We intentionally don't call the transform method to make # fit_transform overridable without unwanted side effects in # TfidfVectorizer. + self._check_vocabulary() max_df = self.max_df min_df = self.min_df max_features = self.max_features - vocabulary, X = self._count_vocab(raw_documents, self.fixed_vocabulary) + vocabulary, X = self._count_vocab(raw_documents, + self.fixed_vocabulary_) if self.binary: X.data.fill(1) - if not self.fixed_vocabulary: + if not self.fixed_vocabulary_: X = self._sort_features(X, vocabulary) n_doc = X.shape[0] @@ -820,6 +829,9 @@ def transform(self, raw_documents): X : sparse matrix, [n_samples, n_features] Document-term matrix. """ + if not hasattr(self, 'vocabulary_'): + self._check_vocabulary() + if not hasattr(self, 'vocabulary_') or len(self.vocabulary_) == 0: raise ValueError("Vocabulary wasn't fitted or is empty!") @@ -1128,7 +1140,7 @@ class TfidfVectorizer(CountVectorizer): Attributes ---------- - ``idf_`` : array, shape = [n_features], or None + idf_ : array, shape = [n_features], or None The learned idf vector (global term weights) when ``use_idf`` is set to True, None otherwise. diff --git a/sklearn/feature_selection/rfe.py b/sklearn/feature_selection/rfe.py index 86c56e1f3264a..b36d8505aabad 100644 --- a/sklearn/feature_selection/rfe.py +++ b/sklearn/feature_selection/rfe.py @@ -58,18 +58,18 @@ class RFE(BaseEstimator, MetaEstimatorMixin, SelectorMixin): Attributes ---------- - `n_features_` : int + n_features_ : int The number of selected features. - `support_` : array of shape [n_features] + support_ : array of shape [n_features] The mask of selected features. - `ranking_` : array of shape [n_features] + ranking_ : array of shape [n_features] The feature ranking, such that `ranking_[i]` corresponds to the \ ranking position of the i-th feature. Selected (i.e., estimated \ best) features are assigned rank 1. - `estimator_` : object + estimator_ : object The external estimator fit on the reduced dataset. Examples @@ -252,24 +252,24 @@ class RFECV(RFE, MetaEstimatorMixin): Attributes ---------- - `n_features_` : int + n_features_ : int The number of selected features with cross-validation. - `support_` : array of shape [n_features] + support_ : array of shape [n_features] The mask of selected features. - `ranking_` : array of shape [n_features] + ranking_ : array of shape [n_features] The feature ranking, such that `ranking_[i]` corresponds to the ranking position of the i-th feature. Selected (i.e., estimated best) features are assigned rank 1. - `grid_scores_` : array of shape [n_subsets_of_features] + grid_scores_ : array of shape [n_subsets_of_features] The cross-validation scores such that `grid_scores_[i]` corresponds to the CV score of the i-th subset of features. - `estimator_` : object + estimator_ : object The external estimator fit on the reduced dataset. Examples @@ -346,7 +346,7 @@ def fit(self, X, y): if self.verbose > 0: print("Finished fold with %d / %d feature ranks, score=%f" - % (k, max(ranking_), score)) + % (k + 1, max(ranking_), score)) scores[k] += score # Pick the best number of features on average diff --git a/sklearn/feature_selection/tests/test_feature_select.py b/sklearn/feature_selection/tests/test_feature_select.py index 5ef88c41a7b61..61013e9c9ec17 100644 --- a/sklearn/feature_selection/tests/test_feature_select.py +++ b/sklearn/feature_selection/tests/test_feature_select.py @@ -42,7 +42,8 @@ def test_f_oneway_vs_scipy_stats(): def test_f_oneway_ints(): # Smoke test f_oneway on integers: that it does raise casting errors # with recent numpys - X = np.random.randint(10, size=(10, 10)) + rng = np.random.RandomState(0) + X = rng.randint(10, size=(10, 10)) y = np.arange(10) fint, pint = f_oneway(X, y) diff --git a/sklearn/feature_selection/univariate_selection.py b/sklearn/feature_selection/univariate_selection.py index e4dfc5945fd0e..702cb23410dbb 100644 --- a/sklearn/feature_selection/univariate_selection.py +++ b/sklearn/feature_selection/univariate_selection.py @@ -323,10 +323,10 @@ class SelectPercentile(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. Notes @@ -379,10 +379,10 @@ class SelectKBest(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. Notes @@ -434,10 +434,10 @@ class SelectFpr(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. """ @@ -467,10 +467,10 @@ class SelectFdr(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. """ @@ -499,10 +499,10 @@ class SelectFwe(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. """ @@ -537,10 +537,10 @@ class GenericUnivariateSelect(_BaseFilter): Attributes ---------- - `scores_` : array-like, shape=(n_features,) + scores_ : array-like, shape=(n_features,) Scores of features. - `pvalues_` : array-like, shape=(n_features,) + pvalues_ : array-like, shape=(n_features,) p-values of feature scores. """ diff --git a/sklearn/feature_selection/variance_threshold.py b/sklearn/feature_selection/variance_threshold.py index ae38e8519c220..a60b1ace256ac 100644 --- a/sklearn/feature_selection/variance_threshold.py +++ b/sklearn/feature_selection/variance_threshold.py @@ -5,7 +5,7 @@ from ..base import BaseEstimator from .base import SelectorMixin from ..utils import check_array -from ..utils.sparsefuncs_fast import csr_mean_variance_axis0 +from ..utils.sparsefuncs import mean_variance_axis class VarianceThreshold(BaseEstimator, SelectorMixin): @@ -23,7 +23,7 @@ class VarianceThreshold(BaseEstimator, SelectorMixin): Attributes ---------- - `variances_` : array, shape (n_features,) + variances_ : array, shape (n_features,) Variances of individual features. Examples @@ -58,10 +58,10 @@ def fit(self, X, y=None): ------- self """ - X = check_array(X, 'csr', dtype=np.float64) + X = check_array(X, ('csr', 'csc'), dtype=np.float64) if hasattr(X, "toarray"): # sparse matrix - _, self.variances_ = csr_mean_variance_axis0(X) + _, self.variances_ = mean_variance_axis(X, axis=0) else: self.variances_ = np.var(X, axis=0) diff --git a/sklearn/gaussian_process/gaussian_process.py b/sklearn/gaussian_process/gaussian_process.py index ff2c7ff837d16..07a334b14388f 100644 --- a/sklearn/gaussian_process/gaussian_process.py +++ b/sklearn/gaussian_process/gaussian_process.py @@ -7,7 +7,7 @@ from __future__ import print_function import numpy as np -from scipy import linalg, optimize, rand +from scipy import linalg, optimize from ..base import BaseEstimator, RegressorMixin from ..metrics.pairwise import manhattan_distances @@ -165,11 +165,11 @@ class GaussianProcess(BaseEstimator, RegressorMixin): Attributes ---------- - `theta_`: array + theta_ : array Specified theta OR the best set of autocorrelation parameters (the \ sought maximizer of the reduced likelihood function). - `reduced_likelihood_function_value_`: array + reduced_likelihood_function_value_ : array The optimal reduced likelihood function value. Examples @@ -299,7 +299,7 @@ def fit(self, X, y): if (np.min(np.sum(D, axis=1)) == 0. and self.corr != correlation.pure_nugget): raise Exception("Multiple input features cannot have the same" - " value.") + " target value.") # Regression matrix and parameters F = self.regr(X) @@ -715,8 +715,9 @@ def minus_reduced_likelihood_function(log10t): # Generate a random starting point log10-uniformly # distributed between bounds log10theta0 = np.log10(self.thetaL) \ - + rand(self.theta0.size).reshape(self.theta0.shape) \ - * np.log10(self.thetaU / self.thetaL) + + self.random_state.rand(self.theta0.size).reshape( + self.theta0.shape) * np.log10(self.thetaU + / self.thetaL) theta0 = 10. ** log10theta0 # Run Cobyla @@ -730,9 +731,8 @@ def minus_reduced_likelihood_function(log10t): raise ve optimal_theta = 10. ** log10_optimal_theta - optimal_minus_rlf_value, optimal_par = \ + optimal_rlf_value, optimal_par = \ self.reduced_likelihood_function(theta=optimal_theta) - optimal_rlf_value = - optimal_minus_rlf_value # Compare the new optimizer to the best previous one if k > 0: diff --git a/sklearn/gaussian_process/tests/test_gaussian_process.py b/sklearn/gaussian_process/tests/test_gaussian_process.py index ef31237bb4571..517fcb047aadf 100644 --- a/sklearn/gaussian_process/tests/test_gaussian_process.py +++ b/sklearn/gaussian_process/tests/test_gaussian_process.py @@ -13,6 +13,7 @@ from sklearn.gaussian_process import GaussianProcess from sklearn.gaussian_process import regression_models as regression from sklearn.gaussian_process import correlation_models as correlation +from sklearn.utils.testing import assert_greater f = lambda x: x * np.sin(x) @@ -141,3 +142,26 @@ def test_no_normalize(): gp = GaussianProcess(normalize=False).fit(X, y) y_pred = gp.predict(X) assert_true(np.allclose(y_pred, y)) + + +def test_random_starts(): + """ + Test that an increasing number of random-starts of GP fitting only + increases the reduced likelihood function of the optimal theta. + """ + n_samples, n_features = 50, 3 + np.random.seed(0) + rng = np.random.RandomState(0) + X = rng.randn(n_samples, n_features) * 2 - 1 + y = np.sin(X).sum(axis=1) + np.sin(3 * X).sum(axis=1) + best_likelihood = -np.inf + for random_start in range(1, 5): + gp = GaussianProcess(regr="constant", corr="squared_exponential", + theta0=[1e-0] * n_features, + thetaL=[1e-4] * n_features, + thetaU=[1e+1] * n_features, + random_start=random_start, random_state=0, + verbose=False).fit(X, y) + rlf = gp.reduced_likelihood_function()[0] + assert_greater(rlf, best_likelihood - np.finfo(np.float32).eps) + best_likelihood = rlf diff --git a/sklearn/grid_search.py b/sklearn/grid_search.py index 280dbb32b1e54..5bc3fec1e318e 100644 --- a/sklearn/grid_search.py +++ b/sklearn/grid_search.py @@ -15,6 +15,7 @@ from functools import partial, reduce from itertools import product import operator +import warnings import numpy as np @@ -272,6 +273,10 @@ def __repr__(self): self.parameters) +class ChangedBehaviorWarning(UserWarning): + pass + + class BaseSearchCV(six.with_metaclass(ABCMeta, BaseEstimator, MetaEstimatorMixin)): """Base class for hyper parameter search with cross-validation.""" @@ -292,9 +297,10 @@ def __init__(self, estimator, scoring=None, self.pre_dispatch = pre_dispatch def score(self, X, y=None): - """Returns the score on the given test data and labels, if the search - estimator has been refit. The ``score`` function of the best estimator - is used, or the ``scoring`` parameter where unavailable. + """Returns the score on the given data, if the estimator has been refit + + This uses the score defined by ``scoring`` where provided, and the + ``best_estimator_.score`` method otherwise. Parameters ---------- @@ -310,13 +316,23 @@ def score(self, X, y=None): ------- score : float + Notes + ----- + * The long-standing behavior of this method changed in version 0.16. + * It no longer uses the metric provided by ``estimator.score`` if the + ``scoring`` parameter was set when fitting. + """ - if hasattr(self.best_estimator_, 'score'): - return self.best_estimator_.score(X, y) if self.scorer_ is None: raise ValueError("No score function explicitly defined, " "and the estimator doesn't provide one %s" % self.best_estimator_) + if self.scoring is not None and hasattr(self.best_estimator_, 'score'): + warnings.warn("The long-standing behavior to use the estimator's " + "score function in {0}.score has changed. The " + "scoring parameter is now used." + "".format(self.__class__.__name__), + ChangedBehaviorWarning) return self.scorer_(self.best_estimator_, X, y) @property @@ -511,7 +527,7 @@ class GridSearchCV(BaseSearchCV): Attributes ---------- - `grid_scores_` : list of named tuples + grid_scores_ : list of named tuples Contains scores for all parameter combinations in param_grid. Each entry corresponds to one parameter setting. Each named tuple has the attributes: @@ -521,18 +537,18 @@ class GridSearchCV(BaseSearchCV): cross-validation folds * ``cv_validation_scores``, the list of scores for each fold - `best_estimator_` : estimator + best_estimator_ : estimator Estimator that was chosen by the search, i.e. estimator which gave highest score (or smallest loss if specified) on the left out data. - `best_score_` : float + best_score_ : float Score of best_estimator on the left out data. - `best_params_` : dict + best_params_ : dict Parameter setting that gave the best results on the hold out data. - `scorer_` : function + scorer_ : function Scorer function used on the held out data to choose the best parameters for the model. @@ -667,7 +683,7 @@ class RandomizedSearchCV(BaseSearchCV): Attributes ---------- - `grid_scores_` : list of named tuples + grid_scores_ : list of named tuples Contains scores for all parameter combinations in param_grid. Each entry corresponds to one parameter setting. Each named tuple has the attributes: @@ -677,15 +693,15 @@ class RandomizedSearchCV(BaseSearchCV): cross-validation folds * ``cv_validation_scores``, the list of scores for each fold - `best_estimator_` : estimator + best_estimator_ : estimator Estimator that was chosen by the search, i.e. estimator which gave highest score (or smallest loss if specified) on the left out data. - `best_score_` : float + best_score_ : float Score of best_estimator on the left out data. - `best_params_` : dict + best_params_ : dict Parameter setting that gave the best results on the hold out data. Notes diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py index 9c560277395ce..e3bf4e4c19fc8 100644 --- a/sklearn/isotonic.py +++ b/sklearn/isotonic.py @@ -104,7 +104,7 @@ def isotonic_regression(y, sample_weight=None, y_min=None, y_max=None, Returns ------- - `y_` : list of floating-point values + y_ : list of floating-point values Isotonic fit of y. References @@ -184,19 +184,19 @@ class IsotonicRegression(BaseEstimator, TransformerMixin, RegressorMixin): Attributes ---------- - `X_` : ndarray (n_samples, ) + X_ : ndarray (n_samples, ) A copy of the input X. - `y_` : ndarray (n_samples, ) + y_ : ndarray (n_samples, ) Isotonic fit of y. - `X_min_` : float + X_min_ : float Minimum value of input array `X_` for left bound. - `X_max_` : float + X_max_ : float Maximum value of input array `X_` for right bound. - `f_` : function + f_ : function The stepwise interpolating function that covers the domain X_. @@ -302,7 +302,7 @@ def transform(self, T): Returns ------- - `T_` : array, shape=(n_samples,) + T_ : array, shape=(n_samples,) The transformed data """ T = as_float_array(T) @@ -336,7 +336,7 @@ def fit_transform(self, X, y, sample_weight=None): Returns ------- - `y_` : array, shape=(n_samples,) + y_ : array, shape=(n_samples,) The transformed data. Notes @@ -367,7 +367,7 @@ def predict(self, T): Returns ------- - `T_` : array, shape=(n_samples,) + T_ : array, shape=(n_samples,) Transformed data. """ return self.transform(T) diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index 5e975b0aefde0..4a68ed8673901 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -124,7 +124,7 @@ class SkewedChi2Sampler(BaseEstimator, TransformerMixin): AdditiveChi2Sampler : A different approach for approximating an additive variant of the chi squared kernel. - sklearn.metrics.chi2_kernel : The exact chi squared kernel. + sklearn.metrics.pairwise.chi2_kernel : The exact chi squared kernel. """ def __init__(self, skewedness=1., n_components=100, random_state=None): @@ -219,10 +219,10 @@ class AdditiveChi2Sampler(BaseEstimator, TransformerMixin): SkewedChi2Sampler : A Fourier-approximation to a non-additive variant of the chi squared kernel. - sklearn.metrics.chi2_kernel : The exact chi squared kernel. + sklearn.metrics.pairwise.chi2_kernel : The exact chi squared kernel. - sklearn.metrics.additive_chi2_kernel : The exact additive chi squared - kernel. + sklearn.metrics.pairwise.additive_chi2_kernel : The exact additive chi + squared kernel. References ---------- @@ -378,13 +378,13 @@ class Nystroem(BaseEstimator, TransformerMixin): Attributes ---------- - `components_` : array, shape (n_components, n_features) + components_ : array, shape (n_components, n_features) Subset of training points used to construct the feature map. - `component_indices_` : array, shape (n_components) + component_indices_ : array, shape (n_components) Indices of ``components_`` in the training set. - `normalization_` : array, shape (n_components, n_components) + normalization_ : array, shape (n_components, n_components) Normalization matrix needed for embedding. Square root of the kernel matrix on ``components_``. @@ -406,7 +406,7 @@ class Nystroem(BaseEstimator, TransformerMixin): RBFSampler : An approximation to the RBF kernel using random Fourier features. - sklearn.metric.pairwise.kernel_metrics : List of built-in kernels. + sklearn.metrics.pairwise.kernel_metrics : List of built-in kernels. """ def __init__(self, kernel="rbf", gamma=None, coef0=1, degree=3, kernel_params=None, n_components=100, random_state=None): diff --git a/sklearn/lda.py b/sklearn/lda.py index 0ecb17b6722b9..4b5a937747e4a 100644 --- a/sklearn/lda.py +++ b/sklearn/lda.py @@ -42,26 +42,26 @@ class LDA(BaseEstimator, ClassifierMixin, TransformerMixin): Attributes ---------- - `coef_` : array-like, shape = [rank, n_classes - 1] + coef_ : array-like, shape = [rank, n_classes - 1] Coefficients of the features in the linear decision function. rank is min(rank_features, n_classes) where rank_features is the dimensionality of the spaces spanned by the features (i.e. n_features excluding redundant features). - `covariance_` : array-like, shape = [n_features, n_features] + covariance_ : array-like, shape = [n_features, n_features] Covariance matrix (shared by all classes). - `means_` : array-like, shape = [n_classes, n_features] + means_ : array-like, shape = [n_classes, n_features] Class means. - `priors_` : array-like, shape = [n_classes] + priors_ : array-like, shape = [n_classes] Class priors (sum to 1). - `scalings_` : array-like, shape = [rank, n_classes - 1] + scalings_ : array-like, shape = [rank, n_classes - 1] Scaling of the features in the space spanned by the class centroids. - `xbar_` : float, shape = [n_features] + xbar_ : float, shape = [n_features] Overall mean. Examples @@ -225,9 +225,10 @@ def transform(self, X): """ X = check_array(X) # center and scale data - X = np.dot(X - self.xbar_, self.scalings_) - n_comp = X.shape[1] if self.n_components is None else self.n_components - return np.dot(X, self.coef_[:n_comp].T) + X_new = np.dot(X - self.xbar_, self.scalings_) + n_components = X.shape[1] if self.n_components is None \ + else self.n_components + return X_new[:, :n_components] def predict(self, X): """ diff --git a/sklearn/learning_curve.py b/sklearn/learning_curve.py index 54c97061782c9..55c4cf6547d86 100644 --- a/sklearn/learning_curve.py +++ b/sklearn/learning_curve.py @@ -94,7 +94,8 @@ def learning_curve(estimator, X, y, train_sizes=np.linspace(0.1, 1.0, 5), Notes ----- - See :ref:`examples/plot_learning_curve.py ` + See :ref:`examples/model_selection/plot_learning_curve.py + ` """ if exploit_incremental_learning and not hasattr(estimator, "partial_fit"): raise ValueError("An estimator must support the partial_fit interface " @@ -285,7 +286,8 @@ def validation_curve(estimator, X, y, param_name, param_range, cv=None, Notes ----- See - :ref:`examples/plot_validation_curve.py ` + :ref:`examples/model_selection/plot_validation_curve.py + ` """ X, y = indexable(X, y) cv = _check_cv(cv, X, y, classifier=is_classifier(estimator)) diff --git a/sklearn/linear_model/base.py b/sklearn/linear_model/base.py index f62b1bd2684d9..677f900a9daba 100644 --- a/sklearn/linear_model/base.py +++ b/sklearn/linear_model/base.py @@ -27,7 +27,7 @@ from ..base import BaseEstimator, ClassifierMixin, RegressorMixin from ..utils import as_float_array, check_array from ..utils.extmath import safe_sparse_dot -from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale +from ..utils.sparsefuncs import mean_variance_axis, inplace_column_scale ### @@ -48,14 +48,14 @@ def sparse_center_data(X, y, fit_intercept, normalize=False): if fit_intercept: # we might require not to change the csr matrix sometimes # store a copy if normalize is True. - # Change dtype to float64 since mean_variance_axis0 accepts + # Change dtype to float64 since mean_variance_axis accepts # it that way. if sp.isspmatrix(X) and X.getformat() == 'csr': X = sp.csr_matrix(X, copy=normalize, dtype=np.float64) else: X = sp.csc_matrix(X, copy=normalize, dtype=np.float64) - X_mean, X_var = mean_variance_axis0(X) + X_mean, X_var = mean_variance_axis(X, axis=0) if normalize: # transform variance to std in-place # XXX: currently scaled to variance=n_samples to match center_data @@ -309,13 +309,13 @@ class LinearRegression(LinearModel, RegressorMixin): Attributes ---------- - `coef_` : array, shape (n_features, ) or (n_targets, n_features) + coef_ : array, shape (n_features, ) or (n_targets, n_features) Estimated coefficients for the linear regression problem. If multiple targets are passed during the fit (y 2D), this is a 2D array of shape (n_targets, n_features), while if only one target is passed, this is a 1D array of length n_features. - `intercept_` : array + intercept_ : array Independent term in the linear model. Notes diff --git a/sklearn/linear_model/bayes.py b/sklearn/linear_model/bayes.py index 97d6cf04b796a..f37c77c9d5285 100644 --- a/sklearn/linear_model/bayes.py +++ b/sklearn/linear_model/bayes.py @@ -73,16 +73,16 @@ class BayesianRidge(LinearModel, RegressorMixin): Attributes ---------- - `coef_` : array, shape = (n_features) + coef_ : array, shape = (n_features) Coefficients of the regression model (mean of distribution) - `alpha_` : float + alpha_ : float estimated precision of the noise. - `lambda_` : array, shape = (n_features) + lambda_ : array, shape = (n_features) estimated precisions of the weights. - `scores_` : float + scores_ : float if computed, value of the objective function (to be maximized) Examples @@ -274,19 +274,19 @@ class ARDRegression(LinearModel, RegressorMixin): Attributes ---------- - `coef_` : array, shape = (n_features) + coef_ : array, shape = (n_features) Coefficients of the regression model (mean of distribution) - `alpha_` : float + alpha_ : float estimated precision of the noise. - `lambda_` : array, shape = (n_features) + lambda_ : array, shape = (n_features) estimated precisions of the weights. - `sigma_` : array, shape = (n_features, n_features) + sigma_ : array, shape = (n_features, n_features) estimated variance-covariance matrix of the weights - `scores_` : float + scores_ : float if computed, value of the objective function (to be maximized) Examples diff --git a/sklearn/linear_model/cd_fast.c b/sklearn/linear_model/cd_fast.c index 06ae7911f7ca4..ed7402fcc0666 100644 --- a/sklearn/linear_model/cd_fast.c +++ b/sklearn/linear_model/cd_fast.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.20.1post0 (Debian 0.20.1+git90-g0e6e38e-1ubuntu2) on Thu Jul 10 14:42:09 2014 */ +/* Generated by Cython 0.20.1post0 (Debian 0.20.1+git90-g0e6e38e-1ubuntu2) on Wed Sep 10 10:23:29 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -848,10 +848,19 @@ typedef npy_longdouble __pyx_t_5numpy_longdouble_t; * import warnings * * ctypedef np.float64_t DOUBLE # <<<<<<<<<<<<<< - * + * ctypedef np.uint32_t UINT32_t * */ typedef __pyx_t_5numpy_float64_t __pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE; + +/* "sklearn/linear_model/cd_fast.pyx":19 + * + * ctypedef np.float64_t DOUBLE + * ctypedef np.uint32_t UINT32_t # <<<<<<<<<<<<<< + * + * np.import_array() + */ +typedef __pyx_t_5numpy_uint32_t __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t; #if CYTHON_CCOMPLEX #ifdef __cplusplus typedef ::std::complex< float > __pyx_t_float_complex; @@ -915,6 +924,17 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; */ typedef npy_cdouble __pyx_t_5numpy_complex_t; +/* "sklearn/linear_model/cd_fast.pyx":25 + * # The following two functions are shamelessly copied from the tree code. + * + * cdef enum: # <<<<<<<<<<<<<< + * # Max value for our rand_r replacement (near the bottom). + * # We don't use RAND_MAX because it's different across platforms and + */ +enum { + __pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX = 0x7FFFFFFF +}; + /* "View.MemoryView":99 * * @cname("__pyx_array") @@ -1103,6 +1123,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/ +static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */ + +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename, + int full_traceback); /*proto*/ + static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ @@ -1130,9 +1163,6 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*pr static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/ #define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - #define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d #define __Pyx_MEMVIEW_DIRECT 1 #define __Pyx_MEMVIEW_PTR 2 @@ -1180,10 +1210,6 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); /* proto */ -#ifndef __PYX_FORCE_INIT_THREADS - #define __PYX_FORCE_INIT_THREADS 0 -#endif - #define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ @@ -1282,10 +1308,6 @@ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ static PyObject *__pyx_memoryviewslice__get__base(PyObject *__pyx_v_self); /*proto*/ -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename, - int full_traceback); /*proto*/ - static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ typedef struct { @@ -1341,6 +1363,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value); +static CYTHON_INLINE npy_uint32 __Pyx_PyInt_As_npy_uint32(PyObject *); + static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); @@ -1620,6 +1644,8 @@ static PyObject *strided = 0; static PyObject *indirect = 0; static PyObject *contiguous = 0; static PyObject *indirect_contiguous = 0; +static CYTHON_INLINE __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_f_7sklearn_12linear_model_7cd_fast_our_rand_r(__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *); /*proto*/ +static CYTHON_INLINE __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t, __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *); /*proto*/ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double, double); /*proto*/ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(double); /*proto*/ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int, double *); /*proto*/ @@ -1674,10 +1700,10 @@ static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_xrange; static PyObject *__pyx_builtin_id; static PyObject *__pyx_builtin_IndexError; -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive); /* proto */ -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_X_data, __Pyx_memviewslice __pyx_v_X_indices, __Pyx_memviewslice __pyx_v_X_indptr, __Pyx_memviewslice __pyx_v_y, __Pyx_memviewslice __pyx_v_X_mean, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive); /* proto */ -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_Q, __Pyx_memviewslice __pyx_v_q, __Pyx_memviewslice __pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive); /* proto */ -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_W, double __pyx_v_l1_reg, double __pyx_v_l2_reg, __Pyx_memviewslice __pyx_v_X, __Pyx_memviewslice __pyx_v_Y, int __pyx_v_max_iter, double __pyx_v_tol); /* proto */ +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive); /* proto */ +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_X_data, __Pyx_memviewslice __pyx_v_X_indices, __Pyx_memviewslice __pyx_v_X_indptr, __Pyx_memviewslice __pyx_v_y, __Pyx_memviewslice __pyx_v_X_mean, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive); /* proto */ +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_Q, __Pyx_memviewslice __pyx_v_q, __Pyx_memviewslice __pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive); /* proto */ +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_W, double __pyx_v_l1_reg, double __pyx_v_l2_reg, __Pyx_memviewslice __pyx_v_X, __Pyx_memviewslice __pyx_v_Y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static int __pyx_array_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */ @@ -1750,6 +1776,7 @@ static char __pyx_k__21[] = "*"; static char __pyx_k_dot[] = "dot"; static char __pyx_k_gap[] = "gap"; static char __pyx_k_obj[] = "obj"; +static char __pyx_k_rng[] = "rng"; static char __pyx_k_sum[] = "sum"; static char __pyx_k_tmp[] = "tmp"; static char __pyx_k_tol[] = "tol"; @@ -1795,6 +1822,7 @@ static char __pyx_k_X_mean[] = "X_mean"; static char __pyx_k_center[] = "center"; static char __pyx_k_d_w_ii[] = "d_w_ii"; static char __pyx_k_endptr[] = "endptr"; +static char __pyx_k_f_iter[] = "f_iter"; static char __pyx_k_format[] = "format"; static char __pyx_k_import[] = "__import__"; static char __pyx_k_l1_reg[] = "l1_reg"; @@ -1802,6 +1830,7 @@ static char __pyx_k_l2_reg[] = "l2_reg"; static char __pyx_k_linalg[] = "linalg"; static char __pyx_k_n_iter[] = "n_iter"; static char __pyx_k_name_2[] = "__name__"; +static char __pyx_k_random[] = "random"; static char __pyx_k_ry_sum[] = "ry_sum"; static char __pyx_k_struct[] = "struct"; static char __pyx_k_unpack[] = "unpack"; @@ -1819,6 +1848,7 @@ static char __pyx_k_l1_norm[] = "l1_norm"; static char __pyx_k_memview[] = "memview"; static char __pyx_k_n_tasks[] = "n_tasks"; static char __pyx_k_q_dot_w[] = "q_dot_w"; +static char __pyx_k_randint[] = "randint"; static char __pyx_k_w_norm2[] = "w_norm2"; static char __pyx_k_wii_ptr[] = "wii_ptr"; static char __pyx_k_y_norm2[] = "y_norm2"; @@ -1844,6 +1874,7 @@ static char __pyx_k_norm_cols_X[] = "norm_cols_X"; static char __pyx_k_RuntimeError[] = "RuntimeError"; static char __pyx_k_W_ii_abs_max[] = "W_ii_abs_max"; static char __pyx_k_numpy_linalg[] = "numpy.linalg"; +static char __pyx_k_rand_r_state[] = "rand_r_state"; static char __pyx_k_XtA_axis1norm[] = "XtA_axis1norm"; static char __pyx_k_dual_norm_XtA[] = "dual_norm_XtA"; static char __pyx_k_normalize_sum[] = "normalize_sum"; @@ -1851,6 +1882,7 @@ static char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; static char __pyx_k_allocate_buffer[] = "allocate_buffer"; static char __pyx_k_dtype_is_object[] = "dtype_is_object"; static char __pyx_k_pyx_releasebuffer[] = "__pyx_releasebuffer"; +static char __pyx_k_rand_r_state_seed[] = "rand_r_state_seed"; static char __pyx_k_strided_and_direct[] = ""; static char __pyx_k_strided_and_indirect[] = ""; static char __pyx_k_contiguous_and_direct[] = ""; @@ -1968,6 +2000,7 @@ static PyObject *__pyx_n_s_enet_coordinate_descent_gram; static PyObject *__pyx_n_s_enet_coordinate_descent_multi_ta; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_n_s_error; +static PyObject *__pyx_n_s_f_iter; static PyObject *__pyx_n_s_flags; static PyObject *__pyx_n_s_float; static PyObject *__pyx_n_s_float64; @@ -2016,7 +2049,12 @@ static PyObject *__pyx_n_s_pyx_releasebuffer; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_q; static PyObject *__pyx_n_s_q_dot_w; +static PyObject *__pyx_n_s_rand_r_state; +static PyObject *__pyx_n_s_rand_r_state_seed; +static PyObject *__pyx_n_s_randint; +static PyObject *__pyx_n_s_random; static PyObject *__pyx_n_s_range; +static PyObject *__pyx_n_s_rng; static PyObject *__pyx_n_s_ry_sum; static PyObject *__pyx_n_s_shape; static PyObject *__pyx_n_s_size; @@ -2088,7 +2126,141 @@ static PyObject *__pyx_codeobj__25; static PyObject *__pyx_codeobj__27; static PyObject *__pyx_codeobj__29; -/* "sklearn/linear_model/cd_fast.pyx":24 +/* "sklearn/linear_model/cd_fast.pyx":32 + * + * + * cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil: # <<<<<<<<<<<<<< + * seed[0] ^= (seed[0] << 13) + * seed[0] ^= (seed[0] >> 17) + */ + +static CYTHON_INLINE __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_f_7sklearn_12linear_model_7cd_fast_our_rand_r(__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_seed) { + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_r; + long __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "sklearn/linear_model/cd_fast.pyx":33 + * + * cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil: + * seed[0] ^= (seed[0] << 13) # <<<<<<<<<<<<<< + * seed[0] ^= (seed[0] >> 17) + * seed[0] ^= (seed[0] << 5) + */ + __pyx_t_1 = 0; + (__pyx_v_seed[__pyx_t_1]) = ((__pyx_v_seed[__pyx_t_1]) ^ ((__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t)((__pyx_v_seed[0]) << 13))); + + /* "sklearn/linear_model/cd_fast.pyx":34 + * cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil: + * seed[0] ^= (seed[0] << 13) + * seed[0] ^= (seed[0] >> 17) # <<<<<<<<<<<<<< + * seed[0] ^= (seed[0] << 5) + * + */ + __pyx_t_1 = 0; + (__pyx_v_seed[__pyx_t_1]) = ((__pyx_v_seed[__pyx_t_1]) ^ ((__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t)((__pyx_v_seed[0]) >> 17))); + + /* "sklearn/linear_model/cd_fast.pyx":35 + * seed[0] ^= (seed[0] << 13) + * seed[0] ^= (seed[0] >> 17) + * seed[0] ^= (seed[0] << 5) # <<<<<<<<<<<<<< + * + * return seed[0] % (RAND_R_MAX + 1) + */ + __pyx_t_1 = 0; + (__pyx_v_seed[__pyx_t_1]) = ((__pyx_v_seed[__pyx_t_1]) ^ ((__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t)((__pyx_v_seed[0]) << 5))); + + /* "sklearn/linear_model/cd_fast.pyx":37 + * seed[0] ^= (seed[0] << 5) + * + * return seed[0] % (RAND_R_MAX + 1) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = (((__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t)__pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX) + 1); + if (unlikely(__pyx_t_1 == 0)) { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); + #endif + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + #ifdef WITH_THREAD + PyGILState_Release(__pyx_gilstate_save); + #endif + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_r = __Pyx_mod_long((__pyx_v_seed[0]), __pyx_t_1); + goto __pyx_L0; + + /* "sklearn/linear_model/cd_fast.pyx":32 + * + * + * cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil: # <<<<<<<<<<<<<< + * seed[0] ^= (seed[0] << 13) + * seed[0] ^= (seed[0] >> 17) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("sklearn.linear_model.cd_fast.our_rand_r", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); + __pyx_r = 0; + __pyx_L0:; + return __pyx_r; +} + +/* "sklearn/linear_model/cd_fast.pyx":40 + * + * + * cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) nogil: # <<<<<<<<<<<<<< + * """Generate a random integer in [0; end).""" + * return our_rand_r(random_state) % end + */ + +static CYTHON_INLINE __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_v_end, __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_random_state) { + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_r; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + + /* "sklearn/linear_model/cd_fast.pyx":42 + * cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) nogil: + * """Generate a random integer in [0; end).""" + * return our_rand_r(random_state) % end # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __pyx_f_7sklearn_12linear_model_7cd_fast_our_rand_r(__pyx_v_random_state); + if (unlikely(__pyx_v_end == 0)) { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); + #endif + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + #ifdef WITH_THREAD + PyGILState_Release(__pyx_gilstate_save); + #endif + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_r = (__pyx_t_1 % __pyx_v_end); + goto __pyx_L0; + + /* "sklearn/linear_model/cd_fast.pyx":40 + * + * + * cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) nogil: # <<<<<<<<<<<<<< + * """Generate a random integer in [0; end).""" + * return our_rand_r(random_state) % end + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("sklearn.linear_model.cd_fast.rand_int", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); + __pyx_r = 0; + __pyx_L0:; + return __pyx_r; +} + +/* "sklearn/linear_model/cd_fast.pyx":45 * * * cdef inline double fmax(double x, double y) nogil: # <<<<<<<<<<<<<< @@ -2100,7 +2272,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double double __pyx_r; int __pyx_t_1; - /* "sklearn/linear_model/cd_fast.pyx":25 + /* "sklearn/linear_model/cd_fast.pyx":46 * * cdef inline double fmax(double x, double y) nogil: * if x > y: # <<<<<<<<<<<<<< @@ -2110,7 +2282,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double __pyx_t_1 = ((__pyx_v_x > __pyx_v_y) != 0); if (__pyx_t_1) { - /* "sklearn/linear_model/cd_fast.pyx":26 + /* "sklearn/linear_model/cd_fast.pyx":47 * cdef inline double fmax(double x, double y) nogil: * if x > y: * return x # <<<<<<<<<<<<<< @@ -2121,7 +2293,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double goto __pyx_L0; } - /* "sklearn/linear_model/cd_fast.pyx":27 + /* "sklearn/linear_model/cd_fast.pyx":48 * if x > y: * return x * return y # <<<<<<<<<<<<<< @@ -2131,7 +2303,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double __pyx_r = __pyx_v_y; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":24 + /* "sklearn/linear_model/cd_fast.pyx":45 * * * cdef inline double fmax(double x, double y) nogil: # <<<<<<<<<<<<<< @@ -2144,7 +2316,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fmax(double return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":30 +/* "sklearn/linear_model/cd_fast.pyx":51 * * * cdef inline double fsign(double f) nogil: # <<<<<<<<<<<<<< @@ -2156,7 +2328,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl double __pyx_r; int __pyx_t_1; - /* "sklearn/linear_model/cd_fast.pyx":31 + /* "sklearn/linear_model/cd_fast.pyx":52 * * cdef inline double fsign(double f) nogil: * if f == 0: # <<<<<<<<<<<<<< @@ -2166,7 +2338,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl __pyx_t_1 = ((__pyx_v_f == 0.0) != 0); if (__pyx_t_1) { - /* "sklearn/linear_model/cd_fast.pyx":32 + /* "sklearn/linear_model/cd_fast.pyx":53 * cdef inline double fsign(double f) nogil: * if f == 0: * return 0 # <<<<<<<<<<<<<< @@ -2177,7 +2349,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl goto __pyx_L0; } - /* "sklearn/linear_model/cd_fast.pyx":33 + /* "sklearn/linear_model/cd_fast.pyx":54 * if f == 0: * return 0 * elif f > 0: # <<<<<<<<<<<<<< @@ -2187,7 +2359,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl __pyx_t_1 = ((__pyx_v_f > 0.0) != 0); if (__pyx_t_1) { - /* "sklearn/linear_model/cd_fast.pyx":34 + /* "sklearn/linear_model/cd_fast.pyx":55 * return 0 * elif f > 0: * return 1.0 # <<<<<<<<<<<<<< @@ -2199,7 +2371,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":36 + /* "sklearn/linear_model/cd_fast.pyx":57 * return 1.0 * else: * return -1.0 # <<<<<<<<<<<<<< @@ -2210,7 +2382,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl goto __pyx_L0; } - /* "sklearn/linear_model/cd_fast.pyx":30 + /* "sklearn/linear_model/cd_fast.pyx":51 * * * cdef inline double fsign(double f) nogil: # <<<<<<<<<<<<<< @@ -2223,7 +2395,7 @@ static CYTHON_INLINE double __pyx_f_7sklearn_12linear_model_7cd_fast_fsign(doubl return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":39 +/* "sklearn/linear_model/cd_fast.pyx":60 * * * cdef double abs_max(int n, double* a) nogil: # <<<<<<<<<<<<<< @@ -2240,7 +2412,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do int __pyx_t_2; int __pyx_t_3; - /* "sklearn/linear_model/cd_fast.pyx":42 + /* "sklearn/linear_model/cd_fast.pyx":63 * """np.max(np.abs(a))""" * cdef int i * cdef double m = fabs(a[0]) # <<<<<<<<<<<<<< @@ -2249,7 +2421,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do */ __pyx_v_m = fabs((__pyx_v_a[0])); - /* "sklearn/linear_model/cd_fast.pyx":44 + /* "sklearn/linear_model/cd_fast.pyx":65 * cdef double m = fabs(a[0]) * cdef double d * for i in range(1, n): # <<<<<<<<<<<<<< @@ -2260,7 +2432,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "sklearn/linear_model/cd_fast.pyx":45 + /* "sklearn/linear_model/cd_fast.pyx":66 * cdef double d * for i in range(1, n): * d = fabs(a[i]) # <<<<<<<<<<<<<< @@ -2269,7 +2441,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do */ __pyx_v_d = fabs((__pyx_v_a[__pyx_v_i])); - /* "sklearn/linear_model/cd_fast.pyx":46 + /* "sklearn/linear_model/cd_fast.pyx":67 * for i in range(1, n): * d = fabs(a[i]) * if d > m: # <<<<<<<<<<<<<< @@ -2279,7 +2451,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do __pyx_t_3 = ((__pyx_v_d > __pyx_v_m) != 0); if (__pyx_t_3) { - /* "sklearn/linear_model/cd_fast.pyx":47 + /* "sklearn/linear_model/cd_fast.pyx":68 * d = fabs(a[i]) * if d > m: * m = d # <<<<<<<<<<<<<< @@ -2292,7 +2464,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do __pyx_L5:; } - /* "sklearn/linear_model/cd_fast.pyx":48 + /* "sklearn/linear_model/cd_fast.pyx":69 * if d > m: * m = d * return m # <<<<<<<<<<<<<< @@ -2302,7 +2474,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do __pyx_r = __pyx_v_m; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":39 + /* "sklearn/linear_model/cd_fast.pyx":60 * * * cdef double abs_max(int n, double* a) nogil: # <<<<<<<<<<<<<< @@ -2315,7 +2487,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(int __pyx_v_n, do return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":51 +/* "sklearn/linear_model/cd_fast.pyx":72 * * * cdef double max(int n, double* a) nogil: # <<<<<<<<<<<<<< @@ -2332,7 +2504,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double int __pyx_t_2; int __pyx_t_3; - /* "sklearn/linear_model/cd_fast.pyx":54 + /* "sklearn/linear_model/cd_fast.pyx":75 * """np.max(a)""" * cdef int i * cdef double m = a[0] # <<<<<<<<<<<<<< @@ -2341,7 +2513,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double */ __pyx_v_m = (__pyx_v_a[0]); - /* "sklearn/linear_model/cd_fast.pyx":56 + /* "sklearn/linear_model/cd_fast.pyx":77 * cdef double m = a[0] * cdef double d * for i in range(1, n): # <<<<<<<<<<<<<< @@ -2352,7 +2524,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "sklearn/linear_model/cd_fast.pyx":57 + /* "sklearn/linear_model/cd_fast.pyx":78 * cdef double d * for i in range(1, n): * d = a[i] # <<<<<<<<<<<<<< @@ -2361,7 +2533,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double */ __pyx_v_d = (__pyx_v_a[__pyx_v_i]); - /* "sklearn/linear_model/cd_fast.pyx":58 + /* "sklearn/linear_model/cd_fast.pyx":79 * for i in range(1, n): * d = a[i] * if d > m: # <<<<<<<<<<<<<< @@ -2371,7 +2543,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double __pyx_t_3 = ((__pyx_v_d > __pyx_v_m) != 0); if (__pyx_t_3) { - /* "sklearn/linear_model/cd_fast.pyx":59 + /* "sklearn/linear_model/cd_fast.pyx":80 * d = a[i] * if d > m: * m = d # <<<<<<<<<<<<<< @@ -2384,7 +2556,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double __pyx_L5:; } - /* "sklearn/linear_model/cd_fast.pyx":60 + /* "sklearn/linear_model/cd_fast.pyx":81 * if d > m: * m = d * return m # <<<<<<<<<<<<<< @@ -2394,7 +2566,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double __pyx_r = __pyx_v_m; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":51 + /* "sklearn/linear_model/cd_fast.pyx":72 * * * cdef double max(int n, double* a) nogil: # <<<<<<<<<<<<<< @@ -2407,7 +2579,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_max(int __pyx_v_n, double return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":63 +/* "sklearn/linear_model/cd_fast.pyx":84 * * * cdef double diff_abs_max(int n, double* a, double* b) nogil: # <<<<<<<<<<<<<< @@ -2424,7 +2596,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ int __pyx_t_2; int __pyx_t_3; - /* "sklearn/linear_model/cd_fast.pyx":66 + /* "sklearn/linear_model/cd_fast.pyx":87 * """np.max(np.abs(a - b))""" * cdef int i * cdef double m = fabs(a[0] - b[0]) # <<<<<<<<<<<<<< @@ -2433,7 +2605,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ */ __pyx_v_m = fabs(((__pyx_v_a[0]) - (__pyx_v_b[0]))); - /* "sklearn/linear_model/cd_fast.pyx":68 + /* "sklearn/linear_model/cd_fast.pyx":89 * cdef double m = fabs(a[0] - b[0]) * cdef double d * for i in range(1, n): # <<<<<<<<<<<<<< @@ -2444,7 +2616,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "sklearn/linear_model/cd_fast.pyx":69 + /* "sklearn/linear_model/cd_fast.pyx":90 * cdef double d * for i in range(1, n): * d = fabs(a[i] - b[i]) # <<<<<<<<<<<<<< @@ -2453,7 +2625,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ */ __pyx_v_d = fabs(((__pyx_v_a[__pyx_v_i]) - (__pyx_v_b[__pyx_v_i]))); - /* "sklearn/linear_model/cd_fast.pyx":70 + /* "sklearn/linear_model/cd_fast.pyx":91 * for i in range(1, n): * d = fabs(a[i] - b[i]) * if d > m: # <<<<<<<<<<<<<< @@ -2463,7 +2635,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ __pyx_t_3 = ((__pyx_v_d > __pyx_v_m) != 0); if (__pyx_t_3) { - /* "sklearn/linear_model/cd_fast.pyx":71 + /* "sklearn/linear_model/cd_fast.pyx":92 * d = fabs(a[i] - b[i]) * if d > m: * m = d # <<<<<<<<<<<<<< @@ -2476,7 +2648,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ __pyx_L5:; } - /* "sklearn/linear_model/cd_fast.pyx":72 + /* "sklearn/linear_model/cd_fast.pyx":93 * if d > m: * m = d * return m # <<<<<<<<<<<<<< @@ -2486,7 +2658,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ __pyx_r = __pyx_v_m; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":63 + /* "sklearn/linear_model/cd_fast.pyx":84 * * * cdef double diff_abs_max(int n, double* a, double* b) nogil: # <<<<<<<<<<<<<< @@ -2499,7 +2671,7 @@ static double __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(int __pyx_v_ return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":105 +/* "sklearn/linear_model/cd_fast.pyx":126 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, # <<<<<<<<<<<<<< @@ -2519,6 +2691,8 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_1enet_coordinate_desc PyArrayObject *__pyx_v_y = 0; int __pyx_v_max_iter; double __pyx_v_tol; + PyObject *__pyx_v_rng = 0; + int __pyx_v_random; int __pyx_v_positive; int __pyx_lineno = 0; const char *__pyx_filename = NULL; @@ -2527,12 +2701,14 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_1enet_coordinate_desc __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("enet_coordinate_descent (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_X,&__pyx_n_s_y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_positive,0}; - PyObject* values[8] = {0,0,0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_X,&__pyx_n_s_y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_rng,&__pyx_n_s_random,&__pyx_n_s_positive,0}; + PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); @@ -2552,46 +2728,58 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_1enet_coordinate_desc case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alpha)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_beta)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iter)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: + if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rng)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_random); + if (value) { values[8] = value; kw_args--; } + } + case 9: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_positive); - if (value) { values[7] = value; kw_args--; } + if (value) { values[9] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -2603,30 +2791,36 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_1enet_coordinate_desc } } __pyx_v_w = ((PyArrayObject *)values[0]); - __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_X = ((PyArrayObject *)values[3]); __pyx_v_y = ((PyArrayObject *)values[4]); - __pyx_v_max_iter = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_tol = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - if (values[7]) { - __pyx_v_positive = __Pyx_PyObject_IsTrue(values[7]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_max_iter = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_tol = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_rng = values[7]; + if (values[8]) { + __pyx_v_random = __Pyx_PyObject_IsTrue(values[8]); if (unlikely((__pyx_v_random == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_random = ((int)0); + } + if (values[9]) { + __pyx_v_positive = __Pyx_PyObject_IsTrue(values[9]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_positive = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 7, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent", 0, 8, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.linear_model.cd_fast.enet_coordinate_descent", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_w), __pyx_ptype_5numpy_ndarray, 1, "w", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5numpy_ndarray, 1, "y", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_X, __pyx_v_y, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_positive); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_w), __pyx_ptype_5numpy_ndarray, 1, "w", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5numpy_ndarray, 1, "y", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_X, __pyx_v_y, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_rng, __pyx_v_random, __pyx_v_positive); /* function exit code */ goto __pyx_L0; @@ -2637,7 +2831,7 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_1enet_coordinate_desc return __pyx_r; } -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive) { +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, PyArrayObject *__pyx_v_X, PyArrayObject *__pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive) { unsigned int __pyx_v_n_samples; unsigned int __pyx_v_n_features; unsigned int __pyx_v_n_tasks; @@ -2658,6 +2852,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce unsigned int __pyx_v_ii; unsigned int __pyx_v_i; unsigned int __pyx_v_n_iter; + unsigned int __pyx_v_f_iter; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_v_rand_r_state_seed; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_rand_r_state; double __pyx_v_const; double __pyx_v_A_norm2; __Pyx_LocalBuf_ND __pyx_pybuffernd_R; @@ -2680,17 +2877,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce PyArrayObject *__pyx_t_4 = NULL; PyArrayObject *__pyx_t_5 = NULL; PyArrayObject *__pyx_t_6 = NULL; - int __pyx_t_7; - unsigned int __pyx_t_8; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_t_7; + int __pyx_t_8; unsigned int __pyx_t_9; unsigned int __pyx_t_10; unsigned int __pyx_t_11; - int __pyx_t_12; - unsigned int __pyx_t_13; + unsigned int __pyx_t_12; + int __pyx_t_13; unsigned int __pyx_t_14; unsigned int __pyx_t_15; - int __pyx_t_16; - unsigned int __pyx_t_17; + unsigned int __pyx_t_16; + int __pyx_t_17; unsigned int __pyx_t_18; unsigned int __pyx_t_19; unsigned int __pyx_t_20; @@ -2698,11 +2895,12 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce unsigned int __pyx_t_22; unsigned int __pyx_t_23; unsigned int __pyx_t_24; - int __pyx_t_25; + unsigned int __pyx_t_25; int __pyx_t_26; - unsigned int __pyx_t_27; + int __pyx_t_27; unsigned int __pyx_t_28; - PyObject *__pyx_t_29 = NULL; + unsigned int __pyx_t_29; + PyObject *__pyx_t_30 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2733,21 +2931,21 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce __pyx_pybuffernd_y.rcbuffer = &__pyx_pybuffer_y; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_X.rcbuffer->pybuffer, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_X.diminfo[0].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_X.diminfo[0].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_X.diminfo[1].strides = __pyx_pybuffernd_X.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_X.diminfo[1].shape = __pyx_pybuffernd_X.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_y.rcbuffer->pybuffer, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_y.diminfo[0].strides = __pyx_pybuffernd_y.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_y.diminfo[0].shape = __pyx_pybuffernd_y.rcbuffer->pybuffer.shape[0]; - /* "sklearn/linear_model/cd_fast.pyx":122 + /* "sklearn/linear_model/cd_fast.pyx":144 * * # get the data information into easy vars * cdef unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< @@ -2756,7 +2954,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_n_samples = (__pyx_v_X->dimensions[0]); - /* "sklearn/linear_model/cd_fast.pyx":123 + /* "sklearn/linear_model/cd_fast.pyx":145 * # get the data information into easy vars * cdef unsigned int n_samples = X.shape[0] * cdef unsigned int n_features = X.shape[1] # <<<<<<<<<<<<<< @@ -2765,7 +2963,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_n_features = (__pyx_v_X->dimensions[1]); - /* "sklearn/linear_model/cd_fast.pyx":126 + /* "sklearn/linear_model/cd_fast.pyx":148 * * # get the number of tasks indirectly, using strides * cdef unsigned int n_tasks = y.strides[0] / sizeof(DOUBLE) # <<<<<<<<<<<<<< @@ -2774,32 +2972,32 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_n_tasks = ((__pyx_v_y->strides[0]) / (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))); - /* "sklearn/linear_model/cd_fast.pyx":129 + /* "sklearn/linear_model/cd_fast.pyx":151 * * # compute norms of the columns of X * cdef np.ndarray[DOUBLE, ndim=1] norm_cols_X = (X**2).sum(axis=0) # <<<<<<<<<<<<<< * * # initial value of the residuals */ - __pyx_t_1 = PyNumber_Power(((PyObject *)__pyx_v_X), __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Power(((PyObject *)__pyx_v_X), __pyx_int_2, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_axis, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_axis, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = ((PyArrayObject *)__pyx_t_3); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_norm_cols_X = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_norm_cols_X.diminfo[0].strides = __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_norm_cols_X.diminfo[0].shape = __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.shape[0]; } } @@ -2807,36 +3005,36 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce __pyx_v_norm_cols_X = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/linear_model/cd_fast.pyx":132 + /* "sklearn/linear_model/cd_fast.pyx":154 * * # initial value of the residuals * cdef np.ndarray[DOUBLE, ndim=1] R = np.empty(n_samples) # <<<<<<<<<<<<<< * * cdef np.ndarray[DOUBLE, ndim=1] XtA = np.empty(n_features) */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_5 = ((PyArrayObject *)__pyx_t_3); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_R.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_R = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_R.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_R.diminfo[0].strides = __pyx_pybuffernd_R.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_R.diminfo[0].shape = __pyx_pybuffernd_R.rcbuffer->pybuffer.shape[0]; } } @@ -2844,36 +3042,36 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce __pyx_v_R = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/linear_model/cd_fast.pyx":134 + /* "sklearn/linear_model/cd_fast.pyx":156 * cdef np.ndarray[DOUBLE, ndim=1] R = np.empty(n_samples) * * cdef np.ndarray[DOUBLE, ndim=1] XtA = np.empty(n_features) # <<<<<<<<<<<<<< * cdef double tmp * cdef double w_ii */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = ((PyArrayObject *)__pyx_t_3); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_XtA.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_XtA = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_XtA.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_XtA.diminfo[0].strides = __pyx_pybuffernd_XtA.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_XtA.diminfo[0].shape = __pyx_pybuffernd_XtA.rcbuffer->pybuffer.shape[0]; } } @@ -2881,7 +3079,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce __pyx_v_XtA = ((PyArrayObject *)__pyx_t_3); __pyx_t_3 = 0; - /* "sklearn/linear_model/cd_fast.pyx":140 + /* "sklearn/linear_model/cd_fast.pyx":162 * cdef double w_max * cdef double d_w_ii * cdef double gap = tol + 1.0 # <<<<<<<<<<<<<< @@ -2890,7 +3088,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_gap = (__pyx_v_tol + 1.0); - /* "sklearn/linear_model/cd_fast.pyx":141 + /* "sklearn/linear_model/cd_fast.pyx":163 * cdef double d_w_ii * cdef double gap = tol + 1.0 * cdef double d_w_tol = tol # <<<<<<<<<<<<<< @@ -2899,37 +3097,73 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_d_w_tol = __pyx_v_tol; - /* "sklearn/linear_model/cd_fast.pyx":150 + /* "sklearn/linear_model/cd_fast.pyx":172 * cdef unsigned int n_iter + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) # <<<<<<<<<<<<<< + * cdef UINT32_t* rand_r_state = &rand_r_state_seed + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s_randint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyInt_As_npy_uint32(__pyx_t_1); if (unlikely((__pyx_t_7 == (npy_uint32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_rand_r_state_seed = __pyx_t_7; + + /* "sklearn/linear_model/cd_fast.pyx":173 + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + * cdef UINT32_t* rand_r_state = &rand_r_state_seed # <<<<<<<<<<<<<< + * + * if alpha == 0: + */ + __pyx_v_rand_r_state = (&__pyx_v_rand_r_state_seed); + + /* "sklearn/linear_model/cd_fast.pyx":175 + * cdef UINT32_t* rand_r_state = &rand_r_state_seed * * if alpha == 0: # <<<<<<<<<<<<<< * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" * " results and is discouraged.") */ - __pyx_t_7 = ((__pyx_v_alpha == 0.0) != 0); - if (__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_alpha == 0.0) != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":151 + /* "sklearn/linear_model/cd_fast.pyx":176 * * if alpha == 0: * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_warn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L3; } __pyx_L3:; - /* "sklearn/linear_model/cd_fast.pyx":154 + /* "sklearn/linear_model/cd_fast.pyx":179 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -2943,38 +3177,38 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce #endif /*try:*/ { - /* "sklearn/linear_model/cd_fast.pyx":157 + /* "sklearn/linear_model/cd_fast.pyx":182 * * # R = y - np.dot(X, w) * for i in range(n_samples): # <<<<<<<<<<<<<< * R[i] = y[i] - ddot(n_features, * (X.data + i * sizeof(DOUBLE)), */ - __pyx_t_8 = __pyx_v_n_samples; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_9 = __pyx_v_n_samples; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "sklearn/linear_model/cd_fast.pyx":158 + /* "sklearn/linear_model/cd_fast.pyx":183 * # R = y - np.dot(X, w) * for i in range(n_samples): * R[i] = y[i] - ddot(n_features, # <<<<<<<<<<<<<< * (X.data + i * sizeof(DOUBLE)), * n_samples, w.data, 1) */ - __pyx_t_10 = __pyx_v_i; + __pyx_t_11 = __pyx_v_i; - /* "sklearn/linear_model/cd_fast.pyx":160 + /* "sklearn/linear_model/cd_fast.pyx":185 * R[i] = y[i] - ddot(n_features, * (X.data + i * sizeof(DOUBLE)), * n_samples, w.data, 1) # <<<<<<<<<<<<<< * * # tol *= np.dot(y, y) */ - __pyx_t_11 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_R.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_R.diminfo[0].strides) = ((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_y.diminfo[0].strides)) - cblas_ddot(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + (__pyx_v_i * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), __pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_w->data), 1)); + __pyx_t_12 = __pyx_v_i; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_R.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_R.diminfo[0].strides) = ((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_y.diminfo[0].strides)) - cblas_ddot(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + (__pyx_v_i * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), __pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_w->data), 1)); } - /* "sklearn/linear_model/cd_fast.pyx":163 + /* "sklearn/linear_model/cd_fast.pyx":188 * * # tol *= np.dot(y, y) * tol *= ddot(n_samples, y.data, n_tasks, # <<<<<<<<<<<<<< @@ -2983,59 +3217,92 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_tol = (__pyx_v_tol * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_y->data), __pyx_v_n_tasks, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_y->data), __pyx_v_n_tasks)); - /* "sklearn/linear_model/cd_fast.pyx":166 + /* "sklearn/linear_model/cd_fast.pyx":191 * y.data, n_tasks) * * for n_iter in range(max_iter): # <<<<<<<<<<<<<< * w_max = 0.0 * d_w_max = 0.0 */ - __pyx_t_12 = __pyx_v_max_iter; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_12; __pyx_t_8+=1) { - __pyx_v_n_iter = __pyx_t_8; + __pyx_t_13 = __pyx_v_max_iter; + for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_13; __pyx_t_9+=1) { + __pyx_v_n_iter = __pyx_t_9; - /* "sklearn/linear_model/cd_fast.pyx":167 + /* "sklearn/linear_model/cd_fast.pyx":192 * * for n_iter in range(max_iter): * w_max = 0.0 # <<<<<<<<<<<<<< * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates */ __pyx_v_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":168 + /* "sklearn/linear_model/cd_fast.pyx":193 * for n_iter in range(max_iter): * w_max = 0.0 * d_w_max = 0.0 # <<<<<<<<<<<<<< - * for ii in range(n_features): # Loop over coordinates - * if norm_cols_X[ii] == 0.0: + * for f_iter in range(n_features): # Loop over coordinates + * if random: */ __pyx_v_d_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":169 + /* "sklearn/linear_model/cd_fast.pyx":194 * w_max = 0.0 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< - * if norm_cols_X[ii] == 0.0: - * continue + * for f_iter in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< + * if random: + * ii = rand_int(n_features, rand_r_state) */ - __pyx_t_9 = __pyx_v_n_features; - for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_9; __pyx_t_13+=1) { - __pyx_v_ii = __pyx_t_13; + __pyx_t_10 = __pyx_v_n_features; + for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_10; __pyx_t_14+=1) { + __pyx_v_f_iter = __pyx_t_14; - /* "sklearn/linear_model/cd_fast.pyx":170 + /* "sklearn/linear_model/cd_fast.pyx":195 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates + * if random: # <<<<<<<<<<<<<< + * ii = rand_int(n_features, rand_r_state) + * else: + */ + __pyx_t_8 = (__pyx_v_random != 0); + if (__pyx_t_8) { + + /* "sklearn/linear_model/cd_fast.pyx":196 + * for f_iter in range(n_features): # Loop over coordinates + * if random: + * ii = rand_int(n_features, rand_r_state) # <<<<<<<<<<<<<< + * else: + * ii = f_iter + */ + __pyx_v_ii = __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_v_n_features, __pyx_v_rand_r_state); + goto __pyx_L13; + } + /*else*/ { + + /* "sklearn/linear_model/cd_fast.pyx":198 + * ii = rand_int(n_features, rand_r_state) + * else: + * ii = f_iter # <<<<<<<<<<<<<< + * + * if norm_cols_X[ii] == 0.0: + */ + __pyx_v_ii = __pyx_v_f_iter; + } + __pyx_L13:; + + /* "sklearn/linear_model/cd_fast.pyx":200 + * ii = f_iter + * * if norm_cols_X[ii] == 0.0: # <<<<<<<<<<<<<< * continue * */ - __pyx_t_14 = __pyx_v_ii; - __pyx_t_7 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_norm_cols_X.diminfo[0].strides)) == 0.0) != 0); - if (__pyx_t_7) { + __pyx_t_15 = __pyx_v_ii; + __pyx_t_8 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_norm_cols_X.diminfo[0].strides)) == 0.0) != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":171 - * for ii in range(n_features): # Loop over coordinates + /* "sklearn/linear_model/cd_fast.pyx":201 + * * if norm_cols_X[ii] == 0.0: * continue # <<<<<<<<<<<<<< * @@ -3044,27 +3311,27 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce goto __pyx_L11_continue; } - /* "sklearn/linear_model/cd_fast.pyx":173 + /* "sklearn/linear_model/cd_fast.pyx":203 * continue * * w_ii = w[ii] # Store previous value # <<<<<<<<<<<<<< * * if w_ii != 0.0: */ - __pyx_t_15 = __pyx_v_ii; - __pyx_v_w_ii = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_w.diminfo[0].strides)); + __pyx_t_16 = __pyx_v_ii; + __pyx_v_w_ii = (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_w.diminfo[0].strides)); - /* "sklearn/linear_model/cd_fast.pyx":175 + /* "sklearn/linear_model/cd_fast.pyx":205 * w_ii = w[ii] # Store previous value * * if w_ii != 0.0: # <<<<<<<<<<<<<< * # R += w_ii * X[:,ii] * daxpy(n_samples, w_ii, */ - __pyx_t_7 = ((__pyx_v_w_ii != 0.0) != 0); - if (__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_w_ii != 0.0) != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":177 + /* "sklearn/linear_model/cd_fast.pyx":207 * if w_ii != 0.0: * # R += w_ii * X[:,ii] * daxpy(n_samples, w_ii, # <<<<<<<<<<<<<< @@ -3072,11 +3339,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * 1, R.data, 1) */ cblas_daxpy(__pyx_v_n_samples, __pyx_v_w_ii, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_ii * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1); - goto __pyx_L14; + goto __pyx_L15; } - __pyx_L14:; + __pyx_L15:; - /* "sklearn/linear_model/cd_fast.pyx":182 + /* "sklearn/linear_model/cd_fast.pyx":212 * * # tmp = (X[:,ii]*R).sum() * tmp = ddot(n_samples, # <<<<<<<<<<<<<< @@ -3085,7 +3352,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_tmp = cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_ii * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1); - /* "sklearn/linear_model/cd_fast.pyx":186 + /* "sklearn/linear_model/cd_fast.pyx":216 * 1, R.data, 1) * * if positive and tmp < 0: # <<<<<<<<<<<<<< @@ -3093,100 +3360,100 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * else: */ if ((__pyx_v_positive != 0)) { - __pyx_t_7 = ((__pyx_v_tmp < 0.0) != 0); - __pyx_t_16 = __pyx_t_7; + __pyx_t_8 = ((__pyx_v_tmp < 0.0) != 0); + __pyx_t_17 = __pyx_t_8; } else { - __pyx_t_16 = (__pyx_v_positive != 0); + __pyx_t_17 = (__pyx_v_positive != 0); } - if (__pyx_t_16) { + if (__pyx_t_17) { - /* "sklearn/linear_model/cd_fast.pyx":187 + /* "sklearn/linear_model/cd_fast.pyx":217 * * if positive and tmp < 0: * w[ii] = 0.0 # <<<<<<<<<<<<<< * else: * w[ii] = (fsign(tmp) * fmax(fabs(tmp) - alpha, 0) */ - __pyx_t_17 = __pyx_v_ii; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_w.diminfo[0].strides) = 0.0; - goto __pyx_L15; + __pyx_t_18 = __pyx_v_ii; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_w.diminfo[0].strides) = 0.0; + goto __pyx_L16; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":190 + /* "sklearn/linear_model/cd_fast.pyx":220 * else: * w[ii] = (fsign(tmp) * fmax(fabs(tmp) - alpha, 0) * / (norm_cols_X[ii] + beta)) # <<<<<<<<<<<<<< * * if w[ii] != 0.0: */ - __pyx_t_18 = __pyx_v_ii; + __pyx_t_19 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":189 + /* "sklearn/linear_model/cd_fast.pyx":219 * w[ii] = 0.0 * else: * w[ii] = (fsign(tmp) * fmax(fabs(tmp) - alpha, 0) # <<<<<<<<<<<<<< * / (norm_cols_X[ii] + beta)) * */ - __pyx_t_19 = __pyx_v_ii; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_w.diminfo[0].strides) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_norm_cols_X.diminfo[0].strides)) + __pyx_v_beta)); + __pyx_t_20 = __pyx_v_ii; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_norm_cols_X.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_norm_cols_X.diminfo[0].strides)) + __pyx_v_beta)); } - __pyx_L15:; + __pyx_L16:; - /* "sklearn/linear_model/cd_fast.pyx":192 + /* "sklearn/linear_model/cd_fast.pyx":222 * / (norm_cols_X[ii] + beta)) * * if w[ii] != 0.0: # <<<<<<<<<<<<<< * # R -= w[ii] * X[:,ii] # Update residual * daxpy(n_samples, -w[ii], */ - __pyx_t_20 = __pyx_v_ii; - __pyx_t_16 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides)) != 0.0) != 0); - if (__pyx_t_16) { + __pyx_t_21 = __pyx_v_ii; + __pyx_t_17 = (((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_w.diminfo[0].strides)) != 0.0) != 0); + if (__pyx_t_17) { - /* "sklearn/linear_model/cd_fast.pyx":194 + /* "sklearn/linear_model/cd_fast.pyx":224 * if w[ii] != 0.0: * # R -= w[ii] * X[:,ii] # Update residual * daxpy(n_samples, -w[ii], # <<<<<<<<<<<<<< * (X.data + ii * n_samples * sizeof(DOUBLE)), * 1, R.data, 1) */ - __pyx_t_21 = __pyx_v_ii; + __pyx_t_22 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":196 + /* "sklearn/linear_model/cd_fast.pyx":226 * daxpy(n_samples, -w[ii], * (X.data + ii * n_samples * sizeof(DOUBLE)), * 1, R.data, 1) # <<<<<<<<<<<<<< * * # update the maximum absolute coefficient update */ - cblas_daxpy(__pyx_v_n_samples, (-(*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_w.diminfo[0].strides))), ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_ii * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1); - goto __pyx_L16; + cblas_daxpy(__pyx_v_n_samples, (-(*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_w.diminfo[0].strides))), ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_ii * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1); + goto __pyx_L17; } - __pyx_L16:; + __pyx_L17:; - /* "sklearn/linear_model/cd_fast.pyx":199 + /* "sklearn/linear_model/cd_fast.pyx":229 * * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) # <<<<<<<<<<<<<< * if d_w_ii > d_w_max: * d_w_max = d_w_ii */ - __pyx_t_22 = __pyx_v_ii; - __pyx_v_d_w_ii = fabs(((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_w.diminfo[0].strides)) - __pyx_v_w_ii)); + __pyx_t_23 = __pyx_v_ii; + __pyx_v_d_w_ii = fabs(((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_w.diminfo[0].strides)) - __pyx_v_w_ii)); - /* "sklearn/linear_model/cd_fast.pyx":200 + /* "sklearn/linear_model/cd_fast.pyx":230 * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: # <<<<<<<<<<<<<< * d_w_max = d_w_ii * */ - __pyx_t_16 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); - if (__pyx_t_16) { + __pyx_t_17 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); + if (__pyx_t_17) { - /* "sklearn/linear_model/cd_fast.pyx":201 + /* "sklearn/linear_model/cd_fast.pyx":231 * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: * d_w_max = d_w_ii # <<<<<<<<<<<<<< @@ -3194,116 +3461,116 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * if fabs(w[ii]) > w_max: */ __pyx_v_d_w_max = __pyx_v_d_w_ii; - goto __pyx_L17; + goto __pyx_L18; } - __pyx_L17:; + __pyx_L18:; - /* "sklearn/linear_model/cd_fast.pyx":203 + /* "sklearn/linear_model/cd_fast.pyx":233 * d_w_max = d_w_ii * * if fabs(w[ii]) > w_max: # <<<<<<<<<<<<<< * w_max = fabs(w[ii]) * */ - __pyx_t_23 = __pyx_v_ii; - __pyx_t_16 = ((fabs((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_w.diminfo[0].strides))) > __pyx_v_w_max) != 0); - if (__pyx_t_16) { + __pyx_t_24 = __pyx_v_ii; + __pyx_t_17 = ((fabs((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_w.diminfo[0].strides))) > __pyx_v_w_max) != 0); + if (__pyx_t_17) { - /* "sklearn/linear_model/cd_fast.pyx":204 + /* "sklearn/linear_model/cd_fast.pyx":234 * * if fabs(w[ii]) > w_max: * w_max = fabs(w[ii]) # <<<<<<<<<<<<<< * * if (w_max == 0.0 */ - __pyx_t_24 = __pyx_v_ii; - __pyx_v_w_max = fabs((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_w.diminfo[0].strides))); - goto __pyx_L18; + __pyx_t_25 = __pyx_v_ii; + __pyx_v_w_max = fabs((*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_w.diminfo[0].strides))); + goto __pyx_L19; } - __pyx_L18:; + __pyx_L19:; __pyx_L11_continue:; } - /* "sklearn/linear_model/cd_fast.pyx":206 + /* "sklearn/linear_model/cd_fast.pyx":236 * w_max = fabs(w[ii]) * * if (w_max == 0.0 # <<<<<<<<<<<<<< * or d_w_max / w_max < d_w_tol * or n_iter == max_iter - 1): */ - __pyx_t_16 = ((__pyx_v_w_max == 0.0) != 0); - if (!__pyx_t_16) { + __pyx_t_17 = ((__pyx_v_w_max == 0.0) != 0); + if (!__pyx_t_17) { - /* "sklearn/linear_model/cd_fast.pyx":207 + /* "sklearn/linear_model/cd_fast.pyx":237 * * if (w_max == 0.0 * or d_w_max / w_max < d_w_tol # <<<<<<<<<<<<<< * or n_iter == max_iter - 1): * # the biggest coordinate update of this iteration was smaller */ - __pyx_t_7 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); - if (!__pyx_t_7) { + __pyx_t_8 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); + if (!__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":208 + /* "sklearn/linear_model/cd_fast.pyx":238 * if (w_max == 0.0 * or d_w_max / w_max < d_w_tol * or n_iter == max_iter - 1): # <<<<<<<<<<<<<< * # the biggest coordinate update of this iteration was smaller * # than the tolerance: check the duality gap as ultimate */ - __pyx_t_25 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); - __pyx_t_26 = __pyx_t_25; + __pyx_t_26 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); + __pyx_t_27 = __pyx_t_26; } else { - __pyx_t_26 = __pyx_t_7; + __pyx_t_27 = __pyx_t_8; } - __pyx_t_7 = __pyx_t_26; + __pyx_t_8 = __pyx_t_27; } else { - __pyx_t_7 = __pyx_t_16; + __pyx_t_8 = __pyx_t_17; } - if (__pyx_t_7) { + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":214 + /* "sklearn/linear_model/cd_fast.pyx":244 * * # XtA = np.dot(X.T, R) - beta * w * for i in range(n_features): # <<<<<<<<<<<<<< * XtA[i] = ddot( * n_samples, */ - __pyx_t_9 = __pyx_v_n_features; - for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_9; __pyx_t_13+=1) { - __pyx_v_i = __pyx_t_13; + __pyx_t_10 = __pyx_v_n_features; + for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_10; __pyx_t_14+=1) { + __pyx_v_i = __pyx_t_14; - /* "sklearn/linear_model/cd_fast.pyx":218 + /* "sklearn/linear_model/cd_fast.pyx":248 * n_samples, * (X.data + i * n_samples *sizeof(DOUBLE)), * 1, R.data, 1) - beta * w[i] # <<<<<<<<<<<<<< * * if positive: */ - __pyx_t_27 = __pyx_v_i; + __pyx_t_28 = __pyx_v_i; - /* "sklearn/linear_model/cd_fast.pyx":215 + /* "sklearn/linear_model/cd_fast.pyx":245 * # XtA = np.dot(X.T, R) - beta * w * for i in range(n_features): * XtA[i] = ddot( # <<<<<<<<<<<<<< * n_samples, * (X.data + i * n_samples *sizeof(DOUBLE)), */ - __pyx_t_28 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_XtA.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_XtA.diminfo[0].strides) = (cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_i * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1) - (__pyx_v_beta * (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_w.diminfo[0].strides)))); + __pyx_t_29 = __pyx_v_i; + *__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_XtA.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_XtA.diminfo[0].strides) = (cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(__pyx_v_X->data + ((__pyx_v_i * __pyx_v_n_samples) * (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1) - (__pyx_v_beta * (*__Pyx_BufPtrStrided1d(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_w.diminfo[0].strides)))); } - /* "sklearn/linear_model/cd_fast.pyx":220 + /* "sklearn/linear_model/cd_fast.pyx":250 * 1, R.data, 1) - beta * w[i] * * if positive: # <<<<<<<<<<<<<< * dual_norm_XtA = max(n_features, XtA.data) * else: */ - __pyx_t_7 = (__pyx_v_positive != 0); - if (__pyx_t_7) { + __pyx_t_8 = (__pyx_v_positive != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":221 + /* "sklearn/linear_model/cd_fast.pyx":251 * * if positive: * dual_norm_XtA = max(n_features, XtA.data) # <<<<<<<<<<<<<< @@ -3311,11 +3578,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * dual_norm_XtA = abs_max(n_features, XtA.data) */ __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_max(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_XtA->data)); - goto __pyx_L22; + goto __pyx_L23; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":223 + /* "sklearn/linear_model/cd_fast.pyx":253 * dual_norm_XtA = max(n_features, XtA.data) * else: * dual_norm_XtA = abs_max(n_features, XtA.data) # <<<<<<<<<<<<<< @@ -3324,9 +3591,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_XtA->data)); } - __pyx_L22:; + __pyx_L23:; - /* "sklearn/linear_model/cd_fast.pyx":226 + /* "sklearn/linear_model/cd_fast.pyx":256 * * # R_norm2 = np.dot(R, R) * R_norm2 = ddot(n_samples, R.data, 1, # <<<<<<<<<<<<<< @@ -3335,7 +3602,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_R_norm2 = cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1); - /* "sklearn/linear_model/cd_fast.pyx":230 + /* "sklearn/linear_model/cd_fast.pyx":260 * * # w_norm2 = np.dot(w, w) * w_norm2 = ddot(n_features, w.data, 1, # <<<<<<<<<<<<<< @@ -3344,17 +3611,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_w_norm2 = cblas_ddot(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_w->data), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_w->data), 1); - /* "sklearn/linear_model/cd_fast.pyx":233 + /* "sklearn/linear_model/cd_fast.pyx":263 * w.data, 1) * * if (dual_norm_XtA > alpha): # <<<<<<<<<<<<<< * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) */ - __pyx_t_7 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); - if (__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":234 + /* "sklearn/linear_model/cd_fast.pyx":264 * * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA # <<<<<<<<<<<<<< @@ -3363,7 +3630,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_const = (__pyx_v_alpha / __pyx_v_dual_norm_XtA); - /* "sklearn/linear_model/cd_fast.pyx":235 + /* "sklearn/linear_model/cd_fast.pyx":265 * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) # <<<<<<<<<<<<<< @@ -3372,7 +3639,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_A_norm2 = (__pyx_v_R_norm2 * pow(__pyx_v_const, 2.0)); - /* "sklearn/linear_model/cd_fast.pyx":236 + /* "sklearn/linear_model/cd_fast.pyx":266 * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) * gap = 0.5 * (R_norm2 + A_norm2) # <<<<<<<<<<<<<< @@ -3380,11 +3647,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * const = 1.0 */ __pyx_v_gap = (0.5 * (__pyx_v_R_norm2 + __pyx_v_A_norm2)); - goto __pyx_L23; + goto __pyx_L24; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":238 + /* "sklearn/linear_model/cd_fast.pyx":268 * gap = 0.5 * (R_norm2 + A_norm2) * else: * const = 1.0 # <<<<<<<<<<<<<< @@ -3393,7 +3660,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_const = 1.0; - /* "sklearn/linear_model/cd_fast.pyx":239 + /* "sklearn/linear_model/cd_fast.pyx":269 * else: * const = 1.0 * gap = R_norm2 # <<<<<<<<<<<<<< @@ -3402,9 +3669,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_gap = __pyx_v_R_norm2; } - __pyx_L23:; + __pyx_L24:; - /* "sklearn/linear_model/cd_fast.pyx":241 + /* "sklearn/linear_model/cd_fast.pyx":271 * gap = R_norm2 * * l1_norm = dasum(n_features, w.data, 1) # <<<<<<<<<<<<<< @@ -3413,7 +3680,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_l1_norm = cblas_dasum(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_w->data), 1); - /* "sklearn/linear_model/cd_fast.pyx":244 + /* "sklearn/linear_model/cd_fast.pyx":274 * * # np.dot(R.T, y) * gap += (alpha * l1_norm - const * ddot( # <<<<<<<<<<<<<< @@ -3422,17 +3689,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ __pyx_v_gap = (__pyx_v_gap + (((__pyx_v_alpha * __pyx_v_l1_norm) - (__pyx_v_const * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_R->data), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)__pyx_v_y->data), __pyx_v_n_tasks))) + (((0.5 * __pyx_v_beta) * (1.0 + pow(__pyx_v_const, 2.0))) * __pyx_v_w_norm2))); - /* "sklearn/linear_model/cd_fast.pyx":250 + /* "sklearn/linear_model/cd_fast.pyx":280 * + 0.5 * beta * (1 + const ** 2) * (w_norm2)) * * if gap < tol: # <<<<<<<<<<<<<< * # return if we reached desired tolerance * break */ - __pyx_t_7 = ((__pyx_v_gap < __pyx_v_tol) != 0); - if (__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_gap < __pyx_v_tol) != 0); + if (__pyx_t_8) { - /* "sklearn/linear_model/cd_fast.pyx":252 + /* "sklearn/linear_model/cd_fast.pyx":282 * if gap < tol: * # return if we reached desired tolerance * break # <<<<<<<<<<<<<< @@ -3441,14 +3708,14 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce */ goto __pyx_L10_break; } - goto __pyx_L19; + goto __pyx_L20; } - __pyx_L19:; + __pyx_L20:; } __pyx_L10_break:; } - /* "sklearn/linear_model/cd_fast.pyx":154 + /* "sklearn/linear_model/cd_fast.pyx":179 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -3466,7 +3733,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce } } - /* "sklearn/linear_model/cd_fast.pyx":254 + /* "sklearn/linear_model/cd_fast.pyx":284 * break * * return w, gap, tol, n_iter + 1 # <<<<<<<<<<<<<< @@ -3474,31 +3741,31 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_29 = PyTuple_New(4); if (unlikely(!__pyx_t_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_29); + __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_30 = PyTuple_New(4); if (unlikely(!__pyx_t_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_30); __Pyx_INCREF(((PyObject *)__pyx_v_w)); - PyTuple_SET_ITEM(__pyx_t_29, 0, ((PyObject *)__pyx_v_w)); + PyTuple_SET_ITEM(__pyx_t_30, 0, ((PyObject *)__pyx_v_w)); __Pyx_GIVEREF(((PyObject *)__pyx_v_w)); - PyTuple_SET_ITEM(__pyx_t_29, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_29, 2, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_30, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_29, 3, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_30, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_3 = 0; + PyTuple_SET_ITEM(__pyx_t_30, 3, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_r = __pyx_t_29; - __pyx_t_29 = 0; + __pyx_t_3 = 0; + __pyx_r = __pyx_t_30; + __pyx_t_30 = 0; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":105 + /* "sklearn/linear_model/cd_fast.pyx":126 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, # <<<<<<<<<<<<<< @@ -3511,7 +3778,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_29); + __Pyx_XDECREF(__pyx_t_30); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_R.rcbuffer->pybuffer); @@ -3540,7 +3807,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_enet_coordinate_desce return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":260 +/* "sklearn/linear_model/cd_fast.pyx":290 * @cython.wraparound(False) * @cython.cdivision(True) * def sparse_enet_coordinate_descent(double[:] w, # <<<<<<<<<<<<<< @@ -3563,6 +3830,8 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordina __Pyx_memviewslice __pyx_v_X_mean = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_max_iter; double __pyx_v_tol; + PyObject *__pyx_v_rng = 0; + int __pyx_v_random; int __pyx_v_positive; int __pyx_lineno = 0; const char *__pyx_filename = NULL; @@ -3571,12 +3840,14 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordina __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sparse_enet_coordinate_descent (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_X_data,&__pyx_n_s_X_indices,&__pyx_n_s_X_indptr,&__pyx_n_s_y,&__pyx_n_s_X_mean,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_positive,0}; - PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_X_data,&__pyx_n_s_X_indices,&__pyx_n_s_X_indptr,&__pyx_n_s_y,&__pyx_n_s_X_mean,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_rng,&__pyx_n_s_random,&__pyx_n_s_positive,0}; + PyObject* values[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); @@ -3599,61 +3870,73 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordina case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alpha)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_beta)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X_data)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X_indices)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X_indptr)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X_mean)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 8: if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iter)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 9: if (likely((values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 10: + if (likely((values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rng)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, 10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 11: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_random); + if (value) { values[11] = value; kw_args--; } + } + case 12: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_positive); - if (value) { values[10] = value; kw_args--; } + if (value) { values[12] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sparse_enet_coordinate_descent") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sparse_enet_coordinate_descent") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + values[9] = PyTuple_GET_ITEM(__pyx_args, 9); values[8] = PyTuple_GET_ITEM(__pyx_args, 8); values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); @@ -3667,38 +3950,44 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordina default: goto __pyx_L5_argtuple_error; } } - __pyx_v_w = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[0]); if (unlikely(!__pyx_v_w.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_X_data = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[3]); if (unlikely(!__pyx_v_X_data.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_X_indices = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[4]); if (unlikely(!__pyx_v_X_indices.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_X_indptr = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[5]); if (unlikely(!__pyx_v_X_indptr.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_y = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[6]); if (unlikely(!__pyx_v_y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_X_mean = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[7]); if (unlikely(!__pyx_v_X_mean.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_max_iter = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_tol = __pyx_PyFloat_AsDouble(values[9]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - if (values[10]) { - __pyx_v_positive = __Pyx_PyObject_IsTrue(values[10]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_w = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[0]); if (unlikely(!__pyx_v_w.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_X_data = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[3]); if (unlikely(!__pyx_v_X_data.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_X_indices = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[4]); if (unlikely(!__pyx_v_X_indices.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_X_indptr = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[5]); if (unlikely(!__pyx_v_X_indptr.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_y = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[6]); if (unlikely(!__pyx_v_y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_X_mean = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[7]); if (unlikely(!__pyx_v_X_mean.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_max_iter = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_tol = __pyx_PyFloat_AsDouble(values[9]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_rng = values[10]; + if (values[11]) { + __pyx_v_random = __Pyx_PyObject_IsTrue(values[11]); if (unlikely((__pyx_v_random == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_random = ((int)0); + } + if (values[12]) { + __pyx_v_positive = __Pyx_PyObject_IsTrue(values[12]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_positive = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 10, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sparse_enet_coordinate_descent", 0, 11, 13, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.linear_model.cd_fast.sparse_enet_coordinate_descent", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_X_data, __pyx_v_X_indices, __pyx_v_X_indptr, __pyx_v_y, __pyx_v_X_mean, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_positive); + __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_X_data, __pyx_v_X_indices, __pyx_v_X_indptr, __pyx_v_y, __pyx_v_X_mean, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_rng, __pyx_v_random, __pyx_v_positive); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_X_data, __Pyx_memviewslice __pyx_v_X_indices, __Pyx_memviewslice __pyx_v_X_indptr, __Pyx_memviewslice __pyx_v_y, __Pyx_memviewslice __pyx_v_X_mean, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive) { +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordinate_descent(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_X_data, __Pyx_memviewslice __pyx_v_X_indices, __Pyx_memviewslice __pyx_v_X_indptr, __Pyx_memviewslice __pyx_v_y, __Pyx_memviewslice __pyx_v_X_mean, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive) { unsigned int __pyx_v_n_samples; unsigned int __pyx_v_n_features; unsigned int __pyx_v_ii; @@ -3721,6 +4010,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina double __pyx_v_d_w_tol; unsigned int __pyx_v_jj; unsigned int __pyx_v_n_iter; + unsigned int __pyx_v_f_iter; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_v_rand_r_state_seed; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_rand_r_state; int __pyx_v_center; double __pyx_v_dual_norm_XtA; double __pyx_v_R_norm2; @@ -3739,67 +4031,67 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_t_8 = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } }; - unsigned int __pyx_t_10; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_t_10; unsigned int __pyx_t_11; unsigned int __pyx_t_12; - int __pyx_t_13; - unsigned int __pyx_t_14; - long __pyx_t_15; - unsigned int __pyx_t_16; + unsigned int __pyx_t_13; + int __pyx_t_14; + unsigned int __pyx_t_15; + long __pyx_t_16; unsigned int __pyx_t_17; unsigned int __pyx_t_18; unsigned int __pyx_t_19; unsigned int __pyx_t_20; unsigned int __pyx_t_21; - int __pyx_t_22; - unsigned int __pyx_t_23; + unsigned int __pyx_t_22; + int __pyx_t_23; unsigned int __pyx_t_24; - Py_ssize_t __pyx_t_25; + unsigned int __pyx_t_25; Py_ssize_t __pyx_t_26; - int __pyx_t_27; - Py_ssize_t __pyx_t_28; - long __pyx_t_29; - unsigned int __pyx_t_30; + Py_ssize_t __pyx_t_27; + int __pyx_t_28; + unsigned int __pyx_t_29; + long __pyx_t_30; unsigned int __pyx_t_31; unsigned int __pyx_t_32; unsigned int __pyx_t_33; unsigned int __pyx_t_34; unsigned int __pyx_t_35; - int __pyx_t_36; - unsigned int __pyx_t_37; + unsigned int __pyx_t_36; + int __pyx_t_37; unsigned int __pyx_t_38; - int __pyx_t_39; - unsigned int __pyx_t_40; + unsigned int __pyx_t_39; + int __pyx_t_40; unsigned int __pyx_t_41; - int __pyx_t_42; - unsigned int __pyx_t_43; + unsigned int __pyx_t_42; + int __pyx_t_43; unsigned int __pyx_t_44; unsigned int __pyx_t_45; unsigned int __pyx_t_46; unsigned int __pyx_t_47; unsigned int __pyx_t_48; unsigned int __pyx_t_49; - int __pyx_t_50; - unsigned int __pyx_t_51; + unsigned int __pyx_t_50; + int __pyx_t_51; unsigned int __pyx_t_52; unsigned int __pyx_t_53; - int __pyx_t_54; + unsigned int __pyx_t_54; int __pyx_t_55; - long __pyx_t_56; - int __pyx_t_57; - unsigned int __pyx_t_58; - unsigned int __pyx_t_59; + int __pyx_t_56; + unsigned int __pyx_t_57; + long __pyx_t_58; + int __pyx_t_59; unsigned int __pyx_t_60; unsigned int __pyx_t_61; - int __pyx_t_62; + unsigned int __pyx_t_62; unsigned int __pyx_t_63; - unsigned int __pyx_t_64; + int __pyx_t_64; unsigned int __pyx_t_65; unsigned int __pyx_t_66; unsigned int __pyx_t_67; unsigned int __pyx_t_68; - Py_ssize_t __pyx_t_69; - Py_ssize_t __pyx_t_70; + unsigned int __pyx_t_69; + unsigned int __pyx_t_70; Py_ssize_t __pyx_t_71; Py_ssize_t __pyx_t_72; Py_ssize_t __pyx_t_73; @@ -3807,13 +4099,15 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina Py_ssize_t __pyx_t_75; Py_ssize_t __pyx_t_76; Py_ssize_t __pyx_t_77; - PyObject *__pyx_t_78 = NULL; + Py_ssize_t __pyx_t_78; + Py_ssize_t __pyx_t_79; + PyObject *__pyx_t_80 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("sparse_enet_coordinate_descent", 0); - /* "sklearn/linear_model/cd_fast.pyx":277 + /* "sklearn/linear_model/cd_fast.pyx":308 * * # get the data information into easy vars * cdef unsigned int n_samples = y.shape[0] # <<<<<<<<<<<<<< @@ -3822,7 +4116,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_n_samples = (__pyx_v_y.shape[0]); - /* "sklearn/linear_model/cd_fast.pyx":278 + /* "sklearn/linear_model/cd_fast.pyx":309 * # get the data information into easy vars * cdef unsigned int n_samples = y.shape[0] * cdef unsigned int n_features = w.shape[0] # <<<<<<<<<<<<<< @@ -3831,26 +4125,26 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_n_features = (__pyx_v_w.shape[0]); - /* "sklearn/linear_model/cd_fast.pyx":282 + /* "sklearn/linear_model/cd_fast.pyx":313 * # compute norms of the columns of X * cdef unsigned int ii * cdef double[:] norm_cols_X = np.zeros(n_features, np.float64) # <<<<<<<<<<<<<< * * cdef unsigned int startptr = X_indptr[0] */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -3858,18 +4152,18 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina __Pyx_GIVEREF(__pyx_t_4); __pyx_t_1 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_4); - if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_norm_cols_X = __pyx_t_5; __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":284 + /* "sklearn/linear_model/cd_fast.pyx":315 * cdef double[:] norm_cols_X = np.zeros(n_features, np.float64) * * cdef unsigned int startptr = X_indptr[0] # <<<<<<<<<<<<<< @@ -3879,7 +4173,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina __pyx_t_6 = 0; __pyx_v_startptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_6 * __pyx_v_X_indptr.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":288 + /* "sklearn/linear_model/cd_fast.pyx":319 * * # get the number of tasks indirectly, using strides * cdef unsigned int n_tasks = y.strides[0] / sizeof(DOUBLE) # <<<<<<<<<<<<<< @@ -3888,79 +4182,79 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_n_tasks = ((__pyx_v_y.strides[0]) / (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))); - /* "sklearn/linear_model/cd_fast.pyx":291 + /* "sklearn/linear_model/cd_fast.pyx":322 * * # initial value of the residuals * cdef double[:] R = y.copy() # <<<<<<<<<<<<<< * * cdef double[:] X_T_R = np.zeros(n_features) */ - __pyx_t_7 = __pyx_memoryview_copy_slice_dc_double_c(__pyx_v_y); if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = __pyx_memoryview_copy_slice_dc_double_c(__pyx_v_y); if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_R = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":293 + /* "sklearn/linear_model/cd_fast.pyx":324 * cdef double[:] R = y.copy() * * cdef double[:] X_T_R = np.zeros(n_features) # <<<<<<<<<<<<<< * cdef double[:] XtA = np.zeros(n_features) * */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_4); - if (unlikely(!__pyx_t_8.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_8.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_X_T_R = __pyx_t_8; __pyx_t_8.memview = NULL; __pyx_t_8.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":294 + /* "sklearn/linear_model/cd_fast.pyx":325 * * cdef double[:] X_T_R = np.zeros(n_features) * cdef double[:] XtA = np.zeros(n_features) # <<<<<<<<<<<<<< * * cdef double tmp */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_4); - if (unlikely(!__pyx_t_9.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_9.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_XtA = __pyx_t_9; __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":304 + /* "sklearn/linear_model/cd_fast.pyx":335 * cdef double R_sum * cdef double normalize_sum * cdef double gap = tol + 1.0 # <<<<<<<<<<<<<< @@ -3969,7 +4263,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_gap = (__pyx_v_tol + 1.0); - /* "sklearn/linear_model/cd_fast.pyx":305 + /* "sklearn/linear_model/cd_fast.pyx":336 * cdef double normalize_sum * cdef double gap = tol + 1.0 * cdef double d_w_tol = tol # <<<<<<<<<<<<<< @@ -3978,21 +4272,57 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_d_w_tol = __pyx_v_tol; - /* "sklearn/linear_model/cd_fast.pyx":308 - * cdef unsigned int jj + /* "sklearn/linear_model/cd_fast.pyx":340 * cdef unsigned int n_iter + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) # <<<<<<<<<<<<<< + * cdef UINT32_t* rand_r_state = &rand_r_state_seed + * cdef bint center = False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s_randint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyInt_As_npy_uint32(__pyx_t_3); if (unlikely((__pyx_t_10 == (npy_uint32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_rand_r_state_seed = __pyx_t_10; + + /* "sklearn/linear_model/cd_fast.pyx":341 + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + * cdef UINT32_t* rand_r_state = &rand_r_state_seed # <<<<<<<<<<<<<< + * cdef bint center = False + * + */ + __pyx_v_rand_r_state = (&__pyx_v_rand_r_state_seed); + + /* "sklearn/linear_model/cd_fast.pyx":342 + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + * cdef UINT32_t* rand_r_state = &rand_r_state_seed * cdef bint center = False # <<<<<<<<<<<<<< * * with nogil: */ __pyx_v_center = 0; - /* "sklearn/linear_model/cd_fast.pyx":310 + /* "sklearn/linear_model/cd_fast.pyx":344 * cdef bint center = False * * with nogil: # <<<<<<<<<<<<<< * # center = (X_mean != 0).any() - * for ii in range(n_samples): + * for ii in range(n_features): */ { #ifdef WITH_THREAD @@ -4001,30 +4331,30 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina #endif /*try:*/ { - /* "sklearn/linear_model/cd_fast.pyx":312 + /* "sklearn/linear_model/cd_fast.pyx":346 * with nogil: * # center = (X_mean != 0).any() - * for ii in range(n_samples): # <<<<<<<<<<<<<< + * for ii in range(n_features): # <<<<<<<<<<<<<< * if X_mean[ii]: * center = True */ - __pyx_t_10 = __pyx_v_n_samples; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_ii = __pyx_t_11; + __pyx_t_11 = __pyx_v_n_features; + for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { + __pyx_v_ii = __pyx_t_12; - /* "sklearn/linear_model/cd_fast.pyx":313 + /* "sklearn/linear_model/cd_fast.pyx":347 * # center = (X_mean != 0).any() - * for ii in range(n_samples): + * for ii in range(n_features): * if X_mean[ii]: # <<<<<<<<<<<<<< * center = True * break */ - __pyx_t_12 = __pyx_v_ii; - __pyx_t_13 = ((*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_12 * __pyx_v_X_mean.strides[0]) ))) != 0); - if (__pyx_t_13) { + __pyx_t_13 = __pyx_v_ii; + __pyx_t_14 = ((*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_13 * __pyx_v_X_mean.strides[0]) ))) != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":314 - * for ii in range(n_samples): + /* "sklearn/linear_model/cd_fast.pyx":348 + * for ii in range(n_features): * if X_mean[ii]: * center = True # <<<<<<<<<<<<<< * break @@ -4032,7 +4362,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_center = 1; - /* "sklearn/linear_model/cd_fast.pyx":315 + /* "sklearn/linear_model/cd_fast.pyx":349 * if X_mean[ii]: * center = True * break # <<<<<<<<<<<<<< @@ -4044,38 +4374,38 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina } __pyx_L7_break:; - /* "sklearn/linear_model/cd_fast.pyx":317 + /* "sklearn/linear_model/cd_fast.pyx":351 * break * * for ii in range(n_features): # <<<<<<<<<<<<<< * X_mean_ii = X_mean[ii] * endptr = X_indptr[ii + 1] */ - __pyx_t_10 = __pyx_v_n_features; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_ii = __pyx_t_11; + __pyx_t_11 = __pyx_v_n_features; + for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { + __pyx_v_ii = __pyx_t_12; - /* "sklearn/linear_model/cd_fast.pyx":318 + /* "sklearn/linear_model/cd_fast.pyx":352 * * for ii in range(n_features): * X_mean_ii = X_mean[ii] # <<<<<<<<<<<<<< * endptr = X_indptr[ii + 1] * normalize_sum = 0.0 */ - __pyx_t_14 = __pyx_v_ii; - __pyx_v_X_mean_ii = (*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_14 * __pyx_v_X_mean.strides[0]) ))); + __pyx_t_15 = __pyx_v_ii; + __pyx_v_X_mean_ii = (*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_15 * __pyx_v_X_mean.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":319 + /* "sklearn/linear_model/cd_fast.pyx":353 * for ii in range(n_features): * X_mean_ii = X_mean[ii] * endptr = X_indptr[ii + 1] # <<<<<<<<<<<<<< * normalize_sum = 0.0 * w_ii = w[ii] */ - __pyx_t_15 = (__pyx_v_ii + 1); - __pyx_v_endptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_15 * __pyx_v_X_indptr.strides[0]) ))); + __pyx_t_16 = (__pyx_v_ii + 1); + __pyx_v_endptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_16 * __pyx_v_X_indptr.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":320 + /* "sklearn/linear_model/cd_fast.pyx":354 * X_mean_ii = X_mean[ii] * endptr = X_indptr[ii + 1] * normalize_sum = 0.0 # <<<<<<<<<<<<<< @@ -4084,96 +4414,96 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_normalize_sum = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":321 + /* "sklearn/linear_model/cd_fast.pyx":355 * endptr = X_indptr[ii + 1] * normalize_sum = 0.0 * w_ii = w[ii] # <<<<<<<<<<<<<< * * for jj in range(startptr, endptr): */ - __pyx_t_16 = __pyx_v_ii; - __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_16 * __pyx_v_w.strides[0]) ))); + __pyx_t_17 = __pyx_v_ii; + __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_17 * __pyx_v_w.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":323 + /* "sklearn/linear_model/cd_fast.pyx":357 * w_ii = w[ii] * * for jj in range(startptr, endptr): # <<<<<<<<<<<<<< * normalize_sum += (X_data[jj] - X_mean_ii) ** 2 * R[X_indices[jj]] -= X_data[jj] * w_ii */ - __pyx_t_17 = __pyx_v_endptr; - for (__pyx_t_18 = __pyx_v_startptr; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) { - __pyx_v_jj = __pyx_t_18; + __pyx_t_18 = __pyx_v_endptr; + for (__pyx_t_19 = __pyx_v_startptr; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) { + __pyx_v_jj = __pyx_t_19; - /* "sklearn/linear_model/cd_fast.pyx":324 + /* "sklearn/linear_model/cd_fast.pyx":358 * * for jj in range(startptr, endptr): * normalize_sum += (X_data[jj] - X_mean_ii) ** 2 # <<<<<<<<<<<<<< * R[X_indices[jj]] -= X_data[jj] * w_ii * norm_cols_X[ii] = normalize_sum + \ */ - __pyx_t_19 = __pyx_v_jj; - __pyx_v_normalize_sum = (__pyx_v_normalize_sum + pow(((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_19 * __pyx_v_X_data.strides[0]) ))) - __pyx_v_X_mean_ii), 2.0)); + __pyx_t_20 = __pyx_v_jj; + __pyx_v_normalize_sum = (__pyx_v_normalize_sum + pow(((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_20 * __pyx_v_X_data.strides[0]) ))) - __pyx_v_X_mean_ii), 2.0)); - /* "sklearn/linear_model/cd_fast.pyx":325 + /* "sklearn/linear_model/cd_fast.pyx":359 * for jj in range(startptr, endptr): * normalize_sum += (X_data[jj] - X_mean_ii) ** 2 * R[X_indices[jj]] -= X_data[jj] * w_ii # <<<<<<<<<<<<<< * norm_cols_X[ii] = normalize_sum + \ * (n_samples - endptr + startptr) * X_mean_ii ** 2 */ - __pyx_t_20 = __pyx_v_jj; __pyx_t_21 = __pyx_v_jj; - __pyx_t_22 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_21 * __pyx_v_X_indices.strides[0]) ))); - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_22 * __pyx_v_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_20 * __pyx_v_X_data.strides[0]) ))) * __pyx_v_w_ii); + __pyx_t_22 = __pyx_v_jj; + __pyx_t_23 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_22 * __pyx_v_X_indices.strides[0]) ))); + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_23 * __pyx_v_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_21 * __pyx_v_X_data.strides[0]) ))) * __pyx_v_w_ii); } - /* "sklearn/linear_model/cd_fast.pyx":326 + /* "sklearn/linear_model/cd_fast.pyx":360 * normalize_sum += (X_data[jj] - X_mean_ii) ** 2 * R[X_indices[jj]] -= X_data[jj] * w_ii * norm_cols_X[ii] = normalize_sum + \ # <<<<<<<<<<<<<< * (n_samples - endptr + startptr) * X_mean_ii ** 2 * */ - __pyx_t_17 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_17 * __pyx_v_norm_cols_X.strides[0]) )) = (__pyx_v_normalize_sum + (((__pyx_v_n_samples - __pyx_v_endptr) + __pyx_v_startptr) * pow(__pyx_v_X_mean_ii, 2.0))); + __pyx_t_18 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_18 * __pyx_v_norm_cols_X.strides[0]) )) = (__pyx_v_normalize_sum + (((__pyx_v_n_samples - __pyx_v_endptr) + __pyx_v_startptr) * pow(__pyx_v_X_mean_ii, 2.0))); - /* "sklearn/linear_model/cd_fast.pyx":329 + /* "sklearn/linear_model/cd_fast.pyx":363 * (n_samples - endptr + startptr) * X_mean_ii ** 2 * * if center: # <<<<<<<<<<<<<< * for jj in range(n_samples): * R[jj] += X_mean_ii * w_ii */ - __pyx_t_13 = (__pyx_v_center != 0); - if (__pyx_t_13) { + __pyx_t_14 = (__pyx_v_center != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":330 + /* "sklearn/linear_model/cd_fast.pyx":364 * * if center: * for jj in range(n_samples): # <<<<<<<<<<<<<< * R[jj] += X_mean_ii * w_ii * startptr = endptr */ - __pyx_t_18 = __pyx_v_n_samples; - for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_18; __pyx_t_23+=1) { - __pyx_v_jj = __pyx_t_23; + __pyx_t_19 = __pyx_v_n_samples; + for (__pyx_t_24 = 0; __pyx_t_24 < __pyx_t_19; __pyx_t_24+=1) { + __pyx_v_jj = __pyx_t_24; - /* "sklearn/linear_model/cd_fast.pyx":331 + /* "sklearn/linear_model/cd_fast.pyx":365 * if center: * for jj in range(n_samples): * R[jj] += X_mean_ii * w_ii # <<<<<<<<<<<<<< * startptr = endptr * */ - __pyx_t_24 = __pyx_v_jj; - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_24 * __pyx_v_R.strides[0]) )) += (__pyx_v_X_mean_ii * __pyx_v_w_ii); + __pyx_t_25 = __pyx_v_jj; + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_25 * __pyx_v_R.strides[0]) )) += (__pyx_v_X_mean_ii * __pyx_v_w_ii); } goto __pyx_L13; } __pyx_L13:; - /* "sklearn/linear_model/cd_fast.pyx":332 + /* "sklearn/linear_model/cd_fast.pyx":366 * for jj in range(n_samples): * R[jj] += X_mean_ii * w_ii * startptr = endptr # <<<<<<<<<<<<<< @@ -4183,191 +4513,224 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina __pyx_v_startptr = __pyx_v_endptr; } - /* "sklearn/linear_model/cd_fast.pyx":335 + /* "sklearn/linear_model/cd_fast.pyx":369 * * # tol *= np.dot(y, y) * tol *= ddot(n_samples, &y[0], 1, &y[0], 1) # <<<<<<<<<<<<<< * * for n_iter in range(max_iter): */ - __pyx_t_25 = 0; __pyx_t_26 = 0; - __pyx_v_tol = (__pyx_v_tol * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_25 * __pyx_v_y.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_26 * __pyx_v_y.strides[0]) ))))), 1)); + __pyx_t_27 = 0; + __pyx_v_tol = (__pyx_v_tol * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_26 * __pyx_v_y.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_27 * __pyx_v_y.strides[0]) ))))), 1)); - /* "sklearn/linear_model/cd_fast.pyx":337 + /* "sklearn/linear_model/cd_fast.pyx":371 * tol *= ddot(n_samples, &y[0], 1, &y[0], 1) * * for n_iter in range(max_iter): # <<<<<<<<<<<<<< * * w_max = 0.0 */ - __pyx_t_27 = __pyx_v_max_iter; - for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_27; __pyx_t_10+=1) { - __pyx_v_n_iter = __pyx_t_10; + __pyx_t_28 = __pyx_v_max_iter; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_28; __pyx_t_11+=1) { + __pyx_v_n_iter = __pyx_t_11; - /* "sklearn/linear_model/cd_fast.pyx":339 + /* "sklearn/linear_model/cd_fast.pyx":373 * for n_iter in range(max_iter): * * w_max = 0.0 # <<<<<<<<<<<<<< * d_w_max = 0.0 - * startptr = X_indptr[0] + * */ __pyx_v_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":340 + /* "sklearn/linear_model/cd_fast.pyx":374 * * w_max = 0.0 * d_w_max = 0.0 # <<<<<<<<<<<<<< - * startptr = X_indptr[0] * + * for f_iter in range(n_features): # Loop over coordinates */ __pyx_v_d_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":341 - * w_max = 0.0 + /* "sklearn/linear_model/cd_fast.pyx":376 * d_w_max = 0.0 - * startptr = X_indptr[0] # <<<<<<<<<<<<<< * - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< + * if random: + * ii = rand_int(n_features, rand_r_state) */ - __pyx_t_28 = 0; - __pyx_v_startptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_28 * __pyx_v_X_indptr.strides[0]) ))); + __pyx_t_12 = __pyx_v_n_features; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_12; __pyx_t_19+=1) { + __pyx_v_f_iter = __pyx_t_19; - /* "sklearn/linear_model/cd_fast.pyx":343 - * startptr = X_indptr[0] + /* "sklearn/linear_model/cd_fast.pyx":377 * - * for ii in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< + * for f_iter in range(n_features): # Loop over coordinates + * if random: # <<<<<<<<<<<<<< + * ii = rand_int(n_features, rand_r_state) + * else: + */ + __pyx_t_14 = (__pyx_v_random != 0); + if (__pyx_t_14) { + + /* "sklearn/linear_model/cd_fast.pyx":378 + * for f_iter in range(n_features): # Loop over coordinates + * if random: + * ii = rand_int(n_features, rand_r_state) # <<<<<<<<<<<<<< + * else: + * ii = f_iter + */ + __pyx_v_ii = __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_v_n_features, __pyx_v_rand_r_state); + goto __pyx_L20; + } + /*else*/ { + + /* "sklearn/linear_model/cd_fast.pyx":380 + * ii = rand_int(n_features, rand_r_state) + * else: + * ii = f_iter # <<<<<<<<<<<<<< * * if norm_cols_X[ii] == 0.0: */ - __pyx_t_11 = __pyx_v_n_features; - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_11; __pyx_t_18+=1) { - __pyx_v_ii = __pyx_t_18; + __pyx_v_ii = __pyx_v_f_iter; + } + __pyx_L20:; - /* "sklearn/linear_model/cd_fast.pyx":345 - * for ii in range(n_features): # Loop over coordinates + /* "sklearn/linear_model/cd_fast.pyx":382 + * ii = f_iter * * if norm_cols_X[ii] == 0.0: # <<<<<<<<<<<<<< * continue * */ - __pyx_t_23 = __pyx_v_ii; - __pyx_t_13 = (((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_23 * __pyx_v_norm_cols_X.strides[0]) ))) == 0.0) != 0); - if (__pyx_t_13) { + __pyx_t_24 = __pyx_v_ii; + __pyx_t_14 = (((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_24 * __pyx_v_norm_cols_X.strides[0]) ))) == 0.0) != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":346 + /* "sklearn/linear_model/cd_fast.pyx":383 * * if norm_cols_X[ii] == 0.0: * continue # <<<<<<<<<<<<<< * - * endptr = X_indptr[ii + 1] + * startptr = X_indptr[ii] */ goto __pyx_L18_continue; } - /* "sklearn/linear_model/cd_fast.pyx":348 + /* "sklearn/linear_model/cd_fast.pyx":385 * continue * + * startptr = X_indptr[ii] # <<<<<<<<<<<<<< + * endptr = X_indptr[ii + 1] + * w_ii = w[ii] # Store previous value + */ + __pyx_t_29 = __pyx_v_ii; + __pyx_v_startptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_29 * __pyx_v_X_indptr.strides[0]) ))); + + /* "sklearn/linear_model/cd_fast.pyx":386 + * + * startptr = X_indptr[ii] * endptr = X_indptr[ii + 1] # <<<<<<<<<<<<<< * w_ii = w[ii] # Store previous value * X_mean_ii = X_mean[ii] */ - __pyx_t_29 = (__pyx_v_ii + 1); - __pyx_v_endptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_29 * __pyx_v_X_indptr.strides[0]) ))); + __pyx_t_30 = (__pyx_v_ii + 1); + __pyx_v_endptr = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_30 * __pyx_v_X_indptr.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":349 - * + /* "sklearn/linear_model/cd_fast.pyx":387 + * startptr = X_indptr[ii] * endptr = X_indptr[ii + 1] * w_ii = w[ii] # Store previous value # <<<<<<<<<<<<<< * X_mean_ii = X_mean[ii] * */ - __pyx_t_30 = __pyx_v_ii; - __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_30 * __pyx_v_w.strides[0]) ))); + __pyx_t_31 = __pyx_v_ii; + __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_31 * __pyx_v_w.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":350 + /* "sklearn/linear_model/cd_fast.pyx":388 * endptr = X_indptr[ii + 1] * w_ii = w[ii] # Store previous value * X_mean_ii = X_mean[ii] # <<<<<<<<<<<<<< * * if w_ii != 0.0: */ - __pyx_t_31 = __pyx_v_ii; - __pyx_v_X_mean_ii = (*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_31 * __pyx_v_X_mean.strides[0]) ))); + __pyx_t_32 = __pyx_v_ii; + __pyx_v_X_mean_ii = (*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_32 * __pyx_v_X_mean.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":352 + /* "sklearn/linear_model/cd_fast.pyx":390 * X_mean_ii = X_mean[ii] * * if w_ii != 0.0: # <<<<<<<<<<<<<< * # R += w_ii * X[:,ii] * for jj in range(startptr, endptr): */ - __pyx_t_13 = ((__pyx_v_w_ii != 0.0) != 0); - if (__pyx_t_13) { + __pyx_t_14 = ((__pyx_v_w_ii != 0.0) != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":354 + /* "sklearn/linear_model/cd_fast.pyx":392 * if w_ii != 0.0: * # R += w_ii * X[:,ii] * for jj in range(startptr, endptr): # <<<<<<<<<<<<<< * R[X_indices[jj]] += X_data[jj] * w_ii * if center: */ - __pyx_t_32 = __pyx_v_endptr; - for (__pyx_t_33 = __pyx_v_startptr; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) { - __pyx_v_jj = __pyx_t_33; + __pyx_t_33 = __pyx_v_endptr; + for (__pyx_t_34 = __pyx_v_startptr; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) { + __pyx_v_jj = __pyx_t_34; - /* "sklearn/linear_model/cd_fast.pyx":355 + /* "sklearn/linear_model/cd_fast.pyx":393 * # R += w_ii * X[:,ii] * for jj in range(startptr, endptr): * R[X_indices[jj]] += X_data[jj] * w_ii # <<<<<<<<<<<<<< * if center: * for jj in range(n_samples): */ - __pyx_t_34 = __pyx_v_jj; __pyx_t_35 = __pyx_v_jj; - __pyx_t_36 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_35 * __pyx_v_X_indices.strides[0]) ))); - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_36 * __pyx_v_R.strides[0]) )) += ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_34 * __pyx_v_X_data.strides[0]) ))) * __pyx_v_w_ii); + __pyx_t_36 = __pyx_v_jj; + __pyx_t_37 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_36 * __pyx_v_X_indices.strides[0]) ))); + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_37 * __pyx_v_R.strides[0]) )) += ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_35 * __pyx_v_X_data.strides[0]) ))) * __pyx_v_w_ii); } - /* "sklearn/linear_model/cd_fast.pyx":356 + /* "sklearn/linear_model/cd_fast.pyx":394 * for jj in range(startptr, endptr): * R[X_indices[jj]] += X_data[jj] * w_ii * if center: # <<<<<<<<<<<<<< * for jj in range(n_samples): * R[jj] -= X_mean_ii * w_ii */ - __pyx_t_13 = (__pyx_v_center != 0); - if (__pyx_t_13) { + __pyx_t_14 = (__pyx_v_center != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":357 + /* "sklearn/linear_model/cd_fast.pyx":395 * R[X_indices[jj]] += X_data[jj] * w_ii * if center: * for jj in range(n_samples): # <<<<<<<<<<<<<< * R[jj] -= X_mean_ii * w_ii * */ - __pyx_t_32 = __pyx_v_n_samples; - for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) { - __pyx_v_jj = __pyx_t_33; + __pyx_t_33 = __pyx_v_n_samples; + for (__pyx_t_34 = 0; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) { + __pyx_v_jj = __pyx_t_34; - /* "sklearn/linear_model/cd_fast.pyx":358 + /* "sklearn/linear_model/cd_fast.pyx":396 * if center: * for jj in range(n_samples): * R[jj] -= X_mean_ii * w_ii # <<<<<<<<<<<<<< * * # tmp = (X[:,ii] * R).sum() */ - __pyx_t_37 = __pyx_v_jj; - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_37 * __pyx_v_R.strides[0]) )) -= (__pyx_v_X_mean_ii * __pyx_v_w_ii); + __pyx_t_38 = __pyx_v_jj; + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_38 * __pyx_v_R.strides[0]) )) -= (__pyx_v_X_mean_ii * __pyx_v_w_ii); } - goto __pyx_L24; + goto __pyx_L25; } - __pyx_L24:; - goto __pyx_L21; + __pyx_L25:; + goto __pyx_L22; } - __pyx_L21:; + __pyx_L22:; - /* "sklearn/linear_model/cd_fast.pyx":361 + /* "sklearn/linear_model/cd_fast.pyx":399 * * # tmp = (X[:,ii] * R).sum() * tmp = 0.0 # <<<<<<<<<<<<<< @@ -4376,41 +4739,41 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_tmp = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":362 + /* "sklearn/linear_model/cd_fast.pyx":400 * # tmp = (X[:,ii] * R).sum() * tmp = 0.0 * for jj in range(startptr, endptr): # <<<<<<<<<<<<<< * tmp += R[X_indices[jj]] * X_data[jj] * */ - __pyx_t_32 = __pyx_v_endptr; - for (__pyx_t_33 = __pyx_v_startptr; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) { - __pyx_v_jj = __pyx_t_33; + __pyx_t_33 = __pyx_v_endptr; + for (__pyx_t_34 = __pyx_v_startptr; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) { + __pyx_v_jj = __pyx_t_34; - /* "sklearn/linear_model/cd_fast.pyx":363 + /* "sklearn/linear_model/cd_fast.pyx":401 * tmp = 0.0 * for jj in range(startptr, endptr): * tmp += R[X_indices[jj]] * X_data[jj] # <<<<<<<<<<<<<< * * if center: */ - __pyx_t_38 = __pyx_v_jj; - __pyx_t_39 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_38 * __pyx_v_X_indices.strides[0]) ))); - __pyx_t_40 = __pyx_v_jj; - __pyx_v_tmp = (__pyx_v_tmp + ((*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_39 * __pyx_v_R.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_40 * __pyx_v_X_data.strides[0]) ))))); + __pyx_t_39 = __pyx_v_jj; + __pyx_t_40 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_39 * __pyx_v_X_indices.strides[0]) ))); + __pyx_t_41 = __pyx_v_jj; + __pyx_v_tmp = (__pyx_v_tmp + ((*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_40 * __pyx_v_R.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_41 * __pyx_v_X_data.strides[0]) ))))); } - /* "sklearn/linear_model/cd_fast.pyx":365 + /* "sklearn/linear_model/cd_fast.pyx":403 * tmp += R[X_indices[jj]] * X_data[jj] * * if center: # <<<<<<<<<<<<<< * R_sum = 0.0 * for jj in range(n_samples): */ - __pyx_t_13 = (__pyx_v_center != 0); - if (__pyx_t_13) { + __pyx_t_14 = (__pyx_v_center != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":366 + /* "sklearn/linear_model/cd_fast.pyx":404 * * if center: * R_sum = 0.0 # <<<<<<<<<<<<<< @@ -4419,29 +4782,29 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_R_sum = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":367 + /* "sklearn/linear_model/cd_fast.pyx":405 * if center: * R_sum = 0.0 * for jj in range(n_samples): # <<<<<<<<<<<<<< * R_sum += R[jj] * tmp -= R_sum * X_mean_ii */ - __pyx_t_32 = __pyx_v_n_samples; - for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) { - __pyx_v_jj = __pyx_t_33; + __pyx_t_33 = __pyx_v_n_samples; + for (__pyx_t_34 = 0; __pyx_t_34 < __pyx_t_33; __pyx_t_34+=1) { + __pyx_v_jj = __pyx_t_34; - /* "sklearn/linear_model/cd_fast.pyx":368 + /* "sklearn/linear_model/cd_fast.pyx":406 * R_sum = 0.0 * for jj in range(n_samples): * R_sum += R[jj] # <<<<<<<<<<<<<< * tmp -= R_sum * X_mean_ii * */ - __pyx_t_41 = __pyx_v_jj; - __pyx_v_R_sum = (__pyx_v_R_sum + (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_41 * __pyx_v_R.strides[0]) )))); + __pyx_t_42 = __pyx_v_jj; + __pyx_v_R_sum = (__pyx_v_R_sum + (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_42 * __pyx_v_R.strides[0]) )))); } - /* "sklearn/linear_model/cd_fast.pyx":369 + /* "sklearn/linear_model/cd_fast.pyx":407 * for jj in range(n_samples): * R_sum += R[jj] * tmp -= R_sum * X_mean_ii # <<<<<<<<<<<<<< @@ -4449,11 +4812,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina * if positive and tmp < 0.0: */ __pyx_v_tmp = (__pyx_v_tmp - (__pyx_v_R_sum * __pyx_v_X_mean_ii)); - goto __pyx_L29; + goto __pyx_L30; } - __pyx_L29:; + __pyx_L30:; - /* "sklearn/linear_model/cd_fast.pyx":371 + /* "sklearn/linear_model/cd_fast.pyx":409 * tmp -= R_sum * X_mean_ii * * if positive and tmp < 0.0: # <<<<<<<<<<<<<< @@ -4461,143 +4824,143 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina * else: */ if ((__pyx_v_positive != 0)) { - __pyx_t_13 = ((__pyx_v_tmp < 0.0) != 0); - __pyx_t_42 = __pyx_t_13; + __pyx_t_14 = ((__pyx_v_tmp < 0.0) != 0); + __pyx_t_43 = __pyx_t_14; } else { - __pyx_t_42 = (__pyx_v_positive != 0); + __pyx_t_43 = (__pyx_v_positive != 0); } - if (__pyx_t_42) { + if (__pyx_t_43) { - /* "sklearn/linear_model/cd_fast.pyx":372 + /* "sklearn/linear_model/cd_fast.pyx":410 * * if positive and tmp < 0.0: * w[ii] = 0.0 # <<<<<<<<<<<<<< * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ */ - __pyx_t_32 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_32 * __pyx_v_w.strides[0]) )) = 0.0; - goto __pyx_L32; + __pyx_t_33 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_33 * __pyx_v_w.strides[0]) )) = 0.0; + goto __pyx_L33; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":375 + /* "sklearn/linear_model/cd_fast.pyx":413 * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ * / (norm_cols_X[ii] + beta) # <<<<<<<<<<<<<< * * if w[ii] != 0.0: */ - __pyx_t_33 = __pyx_v_ii; + __pyx_t_34 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":374 + /* "sklearn/linear_model/cd_fast.pyx":412 * w[ii] = 0.0 * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ # <<<<<<<<<<<<<< * / (norm_cols_X[ii] + beta) * */ - __pyx_t_43 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_43 * __pyx_v_w.strides[0]) )) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_33 * __pyx_v_norm_cols_X.strides[0]) ))) + __pyx_v_beta)); + __pyx_t_44 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_44 * __pyx_v_w.strides[0]) )) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_34 * __pyx_v_norm_cols_X.strides[0]) ))) + __pyx_v_beta)); } - __pyx_L32:; + __pyx_L33:; - /* "sklearn/linear_model/cd_fast.pyx":377 + /* "sklearn/linear_model/cd_fast.pyx":415 * / (norm_cols_X[ii] + beta) * * if w[ii] != 0.0: # <<<<<<<<<<<<<< * # R -= w[ii] * X[:,ii] # Update residual * for jj in range(startptr, endptr): */ - __pyx_t_44 = __pyx_v_ii; - __pyx_t_42 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_44 * __pyx_v_w.strides[0]) ))) != 0.0) != 0); - if (__pyx_t_42) { + __pyx_t_45 = __pyx_v_ii; + __pyx_t_43 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_45 * __pyx_v_w.strides[0]) ))) != 0.0) != 0); + if (__pyx_t_43) { - /* "sklearn/linear_model/cd_fast.pyx":379 + /* "sklearn/linear_model/cd_fast.pyx":417 * if w[ii] != 0.0: * # R -= w[ii] * X[:,ii] # Update residual * for jj in range(startptr, endptr): # <<<<<<<<<<<<<< * R[X_indices[jj]] -= X_data[jj] * w[ii] * */ - __pyx_t_45 = __pyx_v_endptr; - for (__pyx_t_46 = __pyx_v_startptr; __pyx_t_46 < __pyx_t_45; __pyx_t_46+=1) { - __pyx_v_jj = __pyx_t_46; + __pyx_t_46 = __pyx_v_endptr; + for (__pyx_t_47 = __pyx_v_startptr; __pyx_t_47 < __pyx_t_46; __pyx_t_47+=1) { + __pyx_v_jj = __pyx_t_47; - /* "sklearn/linear_model/cd_fast.pyx":380 + /* "sklearn/linear_model/cd_fast.pyx":418 * # R -= w[ii] * X[:,ii] # Update residual * for jj in range(startptr, endptr): * R[X_indices[jj]] -= X_data[jj] * w[ii] # <<<<<<<<<<<<<< * * if center: */ - __pyx_t_47 = __pyx_v_jj; - __pyx_t_48 = __pyx_v_ii; - __pyx_t_49 = __pyx_v_jj; - __pyx_t_50 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_49 * __pyx_v_X_indices.strides[0]) ))); - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_50 * __pyx_v_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_47 * __pyx_v_X_data.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_48 * __pyx_v_w.strides[0]) )))); + __pyx_t_48 = __pyx_v_jj; + __pyx_t_49 = __pyx_v_ii; + __pyx_t_50 = __pyx_v_jj; + __pyx_t_51 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_50 * __pyx_v_X_indices.strides[0]) ))); + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_51 * __pyx_v_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_48 * __pyx_v_X_data.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_49 * __pyx_v_w.strides[0]) )))); } - /* "sklearn/linear_model/cd_fast.pyx":382 + /* "sklearn/linear_model/cd_fast.pyx":420 * R[X_indices[jj]] -= X_data[jj] * w[ii] * * if center: # <<<<<<<<<<<<<< * for jj in range(n_samples): * R[jj] += X_mean_ii * w[ii] */ - __pyx_t_42 = (__pyx_v_center != 0); - if (__pyx_t_42) { + __pyx_t_43 = (__pyx_v_center != 0); + if (__pyx_t_43) { - /* "sklearn/linear_model/cd_fast.pyx":383 + /* "sklearn/linear_model/cd_fast.pyx":421 * * if center: * for jj in range(n_samples): # <<<<<<<<<<<<<< * R[jj] += X_mean_ii * w[ii] * */ - __pyx_t_45 = __pyx_v_n_samples; - for (__pyx_t_46 = 0; __pyx_t_46 < __pyx_t_45; __pyx_t_46+=1) { - __pyx_v_jj = __pyx_t_46; + __pyx_t_46 = __pyx_v_n_samples; + for (__pyx_t_47 = 0; __pyx_t_47 < __pyx_t_46; __pyx_t_47+=1) { + __pyx_v_jj = __pyx_t_47; - /* "sklearn/linear_model/cd_fast.pyx":384 + /* "sklearn/linear_model/cd_fast.pyx":422 * if center: * for jj in range(n_samples): * R[jj] += X_mean_ii * w[ii] # <<<<<<<<<<<<<< * * # update the maximum absolute coefficient update */ - __pyx_t_51 = __pyx_v_ii; - __pyx_t_52 = __pyx_v_jj; - *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_52 * __pyx_v_R.strides[0]) )) += (__pyx_v_X_mean_ii * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_51 * __pyx_v_w.strides[0]) )))); + __pyx_t_52 = __pyx_v_ii; + __pyx_t_53 = __pyx_v_jj; + *((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_53 * __pyx_v_R.strides[0]) )) += (__pyx_v_X_mean_ii * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_52 * __pyx_v_w.strides[0]) )))); } - goto __pyx_L36; + goto __pyx_L37; } - __pyx_L36:; - goto __pyx_L33; + __pyx_L37:; + goto __pyx_L34; } - __pyx_L33:; + __pyx_L34:; - /* "sklearn/linear_model/cd_fast.pyx":387 + /* "sklearn/linear_model/cd_fast.pyx":425 * * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) # <<<<<<<<<<<<<< * if d_w_ii > d_w_max: * d_w_max = d_w_ii */ - __pyx_t_45 = __pyx_v_ii; - __pyx_v_d_w_ii = fabs(((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_45 * __pyx_v_w.strides[0]) ))) - __pyx_v_w_ii)); + __pyx_t_46 = __pyx_v_ii; + __pyx_v_d_w_ii = fabs(((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_46 * __pyx_v_w.strides[0]) ))) - __pyx_v_w_ii)); - /* "sklearn/linear_model/cd_fast.pyx":388 + /* "sklearn/linear_model/cd_fast.pyx":426 * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: # <<<<<<<<<<<<<< * d_w_max = d_w_ii * */ - __pyx_t_42 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); - if (__pyx_t_42) { + __pyx_t_43 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); + if (__pyx_t_43) { - /* "sklearn/linear_model/cd_fast.pyx":389 + /* "sklearn/linear_model/cd_fast.pyx":427 * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: * d_w_max = d_w_ii # <<<<<<<<<<<<<< @@ -4605,106 +4968,107 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina * if w[ii] > w_max: */ __pyx_v_d_w_max = __pyx_v_d_w_ii; - goto __pyx_L39; + goto __pyx_L40; } - __pyx_L39:; + __pyx_L40:; - /* "sklearn/linear_model/cd_fast.pyx":391 + /* "sklearn/linear_model/cd_fast.pyx":429 * d_w_max = d_w_ii * * if w[ii] > w_max: # <<<<<<<<<<<<<< * w_max = w[ii] - * startptr = endptr + * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: */ - __pyx_t_46 = __pyx_v_ii; - __pyx_t_42 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_46 * __pyx_v_w.strides[0]) ))) > __pyx_v_w_max) != 0); - if (__pyx_t_42) { + __pyx_t_47 = __pyx_v_ii; + __pyx_t_43 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_47 * __pyx_v_w.strides[0]) ))) > __pyx_v_w_max) != 0); + if (__pyx_t_43) { - /* "sklearn/linear_model/cd_fast.pyx":392 + /* "sklearn/linear_model/cd_fast.pyx":430 * * if w[ii] > w_max: * w_max = w[ii] # <<<<<<<<<<<<<< - * startptr = endptr - * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: - */ - __pyx_t_53 = __pyx_v_ii; - __pyx_v_w_max = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_53 * __pyx_v_w.strides[0]) ))); - goto __pyx_L40; - } - __pyx_L40:; - - /* "sklearn/linear_model/cd_fast.pyx":393 - * if w[ii] > w_max: - * w_max = w[ii] - * startptr = endptr # <<<<<<<<<<<<<< * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: * # the biggest coordinate update of this iteration was smaller than */ - __pyx_v_startptr = __pyx_v_endptr; + __pyx_t_54 = __pyx_v_ii; + __pyx_v_w_max = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_54 * __pyx_v_w.strides[0]) ))); + goto __pyx_L41; + } + __pyx_L41:; __pyx_L18_continue:; } - /* "sklearn/linear_model/cd_fast.pyx":394 + /* "sklearn/linear_model/cd_fast.pyx":431 + * if w[ii] > w_max: * w_max = w[ii] - * startptr = endptr * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: # <<<<<<<<<<<<<< * # the biggest coordinate update of this iteration was smaller than * # the tolerance: check the duality gap as ultimate stopping */ - __pyx_t_42 = ((__pyx_v_w_max == 0.0) != 0); - if (!__pyx_t_42) { - __pyx_t_13 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); - if (!__pyx_t_13) { - __pyx_t_54 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); - __pyx_t_55 = __pyx_t_54; + __pyx_t_43 = ((__pyx_v_w_max == 0.0) != 0); + if (!__pyx_t_43) { + __pyx_t_14 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); + if (!__pyx_t_14) { + __pyx_t_55 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); + __pyx_t_56 = __pyx_t_55; } else { - __pyx_t_55 = __pyx_t_13; + __pyx_t_56 = __pyx_t_14; } - __pyx_t_13 = __pyx_t_55; + __pyx_t_14 = __pyx_t_56; } else { - __pyx_t_13 = __pyx_t_42; + __pyx_t_14 = __pyx_t_43; } - if (__pyx_t_13) { + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":400 + /* "sklearn/linear_model/cd_fast.pyx":437 * * # sparse X.T / dense R dot product * for ii in range(n_features): # <<<<<<<<<<<<<< + * X_T_R[ii] = 0.0 * for jj in range(X_indptr[ii], X_indptr[ii + 1]): - * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] */ - __pyx_t_11 = __pyx_v_n_features; - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_11; __pyx_t_18+=1) { - __pyx_v_ii = __pyx_t_18; + __pyx_t_12 = __pyx_v_n_features; + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_12; __pyx_t_19+=1) { + __pyx_v_ii = __pyx_t_19; - /* "sklearn/linear_model/cd_fast.pyx":401 + /* "sklearn/linear_model/cd_fast.pyx":438 * # sparse X.T / dense R dot product * for ii in range(n_features): + * X_T_R[ii] = 0.0 # <<<<<<<<<<<<<< + * for jj in range(X_indptr[ii], X_indptr[ii + 1]): + * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] + */ + __pyx_t_57 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_57 * __pyx_v_X_T_R.strides[0]) )) = 0.0; + + /* "sklearn/linear_model/cd_fast.pyx":439 + * for ii in range(n_features): + * X_T_R[ii] = 0.0 * for jj in range(X_indptr[ii], X_indptr[ii + 1]): # <<<<<<<<<<<<<< * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] * R_sum = 0.0 */ - __pyx_t_56 = (__pyx_v_ii + 1); - __pyx_t_57 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_56 * __pyx_v_X_indptr.strides[0]) ))); - __pyx_t_58 = __pyx_v_ii; - for (__pyx_t_59 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_58 * __pyx_v_X_indptr.strides[0]) ))); __pyx_t_59 < __pyx_t_57; __pyx_t_59+=1) { - __pyx_v_jj = __pyx_t_59; + __pyx_t_58 = (__pyx_v_ii + 1); + __pyx_t_59 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_58 * __pyx_v_X_indptr.strides[0]) ))); + __pyx_t_60 = __pyx_v_ii; + for (__pyx_t_61 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indptr.data + __pyx_t_60 * __pyx_v_X_indptr.strides[0]) ))); __pyx_t_61 < __pyx_t_59; __pyx_t_61+=1) { + __pyx_v_jj = __pyx_t_61; - /* "sklearn/linear_model/cd_fast.pyx":402 - * for ii in range(n_features): + /* "sklearn/linear_model/cd_fast.pyx":440 + * X_T_R[ii] = 0.0 * for jj in range(X_indptr[ii], X_indptr[ii + 1]): * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] # <<<<<<<<<<<<<< * R_sum = 0.0 * for jj in range(n_samples): */ - __pyx_t_60 = __pyx_v_jj; - __pyx_t_61 = __pyx_v_jj; - __pyx_t_62 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_61 * __pyx_v_X_indices.strides[0]) ))); - __pyx_t_63 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_63 * __pyx_v_X_T_R.strides[0]) )) += ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_60 * __pyx_v_X_data.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_62 * __pyx_v_R.strides[0]) )))); + __pyx_t_62 = __pyx_v_jj; + __pyx_t_63 = __pyx_v_jj; + __pyx_t_64 = (*((int *) ( /* dim=0 */ (__pyx_v_X_indices.data + __pyx_t_63 * __pyx_v_X_indices.strides[0]) ))); + __pyx_t_65 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_65 * __pyx_v_X_T_R.strides[0]) )) += ((*((double *) ( /* dim=0 */ (__pyx_v_X_data.data + __pyx_t_62 * __pyx_v_X_data.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_64 * __pyx_v_R.strides[0]) )))); } - /* "sklearn/linear_model/cd_fast.pyx":403 + /* "sklearn/linear_model/cd_fast.pyx":441 * for jj in range(X_indptr[ii], X_indptr[ii + 1]): * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] * R_sum = 0.0 # <<<<<<<<<<<<<< @@ -4713,132 +5077,120 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_R_sum = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":404 + /* "sklearn/linear_model/cd_fast.pyx":442 * X_T_R[ii] += X_data[jj] * R[X_indices[jj]] * R_sum = 0.0 * for jj in range(n_samples): # <<<<<<<<<<<<<< * R_sum += R[jj] * X_T_R[ii] -= X_mean[ii] * R_sum */ - __pyx_t_59 = __pyx_v_n_samples; - for (__pyx_t_64 = 0; __pyx_t_64 < __pyx_t_59; __pyx_t_64+=1) { - __pyx_v_jj = __pyx_t_64; + __pyx_t_61 = __pyx_v_n_samples; + for (__pyx_t_66 = 0; __pyx_t_66 < __pyx_t_61; __pyx_t_66+=1) { + __pyx_v_jj = __pyx_t_66; - /* "sklearn/linear_model/cd_fast.pyx":405 + /* "sklearn/linear_model/cd_fast.pyx":443 * R_sum = 0.0 * for jj in range(n_samples): * R_sum += R[jj] # <<<<<<<<<<<<<< * X_T_R[ii] -= X_mean[ii] * R_sum - * + * XtA[ii] = X_T_R[ii] - beta * w[ii] */ - __pyx_t_65 = __pyx_v_jj; - __pyx_v_R_sum = (__pyx_v_R_sum + (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_65 * __pyx_v_R.strides[0]) )))); + __pyx_t_67 = __pyx_v_jj; + __pyx_v_R_sum = (__pyx_v_R_sum + (*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_67 * __pyx_v_R.strides[0]) )))); } - /* "sklearn/linear_model/cd_fast.pyx":406 + /* "sklearn/linear_model/cd_fast.pyx":444 * for jj in range(n_samples): * R_sum += R[jj] * X_T_R[ii] -= X_mean[ii] * R_sum # <<<<<<<<<<<<<< + * XtA[ii] = X_T_R[ii] - beta * w[ii] * - * for jj in range(n_features): */ - __pyx_t_59 = __pyx_v_ii; - __pyx_t_64 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_64 * __pyx_v_X_T_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_59 * __pyx_v_X_mean.strides[0]) ))) * __pyx_v_R_sum); - } + __pyx_t_61 = __pyx_v_ii; + __pyx_t_66 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_66 * __pyx_v_X_T_R.strides[0]) )) -= ((*((double *) ( /* dim=0 */ (__pyx_v_X_mean.data + __pyx_t_61 * __pyx_v_X_mean.strides[0]) ))) * __pyx_v_R_sum); - /* "sklearn/linear_model/cd_fast.pyx":408 + /* "sklearn/linear_model/cd_fast.pyx":445 + * R_sum += R[jj] * X_T_R[ii] -= X_mean[ii] * R_sum + * XtA[ii] = X_T_R[ii] - beta * w[ii] # <<<<<<<<<<<<<< * - * for jj in range(n_features): # <<<<<<<<<<<<<< - * XtA[jj] = X_T_R[jj] - beta * w[jj] - * if positive: - */ - __pyx_t_11 = __pyx_v_n_features; - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_11; __pyx_t_18+=1) { - __pyx_v_jj = __pyx_t_18; - - /* "sklearn/linear_model/cd_fast.pyx":409 - * - * for jj in range(n_features): - * XtA[jj] = X_T_R[jj] - beta * w[jj] # <<<<<<<<<<<<<< * if positive: - * dual_norm_XtA = max(n_features, &XtA[0]) */ - __pyx_t_66 = __pyx_v_jj; - __pyx_t_67 = __pyx_v_jj; - __pyx_t_68 = __pyx_v_jj; - *((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_68 * __pyx_v_XtA.strides[0]) )) = ((*((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_66 * __pyx_v_X_T_R.strides[0]) ))) - (__pyx_v_beta * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_67 * __pyx_v_w.strides[0]) ))))); + __pyx_t_68 = __pyx_v_ii; + __pyx_t_69 = __pyx_v_ii; + __pyx_t_70 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_70 * __pyx_v_XtA.strides[0]) )) = ((*((double *) ( /* dim=0 */ (__pyx_v_X_T_R.data + __pyx_t_68 * __pyx_v_X_T_R.strides[0]) ))) - (__pyx_v_beta * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_69 * __pyx_v_w.strides[0]) ))))); } - /* "sklearn/linear_model/cd_fast.pyx":410 - * for jj in range(n_features): - * XtA[jj] = X_T_R[jj] - beta * w[jj] + /* "sklearn/linear_model/cd_fast.pyx":447 + * XtA[ii] = X_T_R[ii] - beta * w[ii] + * * if positive: # <<<<<<<<<<<<<< * dual_norm_XtA = max(n_features, &XtA[0]) * else: */ - __pyx_t_13 = (__pyx_v_positive != 0); - if (__pyx_t_13) { + __pyx_t_14 = (__pyx_v_positive != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":411 - * XtA[jj] = X_T_R[jj] - beta * w[jj] + /* "sklearn/linear_model/cd_fast.pyx":448 + * * if positive: * dual_norm_XtA = max(n_features, &XtA[0]) # <<<<<<<<<<<<<< * else: * dual_norm_XtA = abs_max(n_features, &XtA[0]) */ - __pyx_t_69 = 0; - __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_max(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_69 * __pyx_v_XtA.strides[0]) ))))); - goto __pyx_L50; + __pyx_t_71 = 0; + __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_max(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_71 * __pyx_v_XtA.strides[0]) ))))); + goto __pyx_L49; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":413 + /* "sklearn/linear_model/cd_fast.pyx":450 * dual_norm_XtA = max(n_features, &XtA[0]) * else: * dual_norm_XtA = abs_max(n_features, &XtA[0]) # <<<<<<<<<<<<<< * * # R_norm2 = np.dot(R, R) */ - __pyx_t_70 = 0; - __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_70 * __pyx_v_XtA.strides[0]) ))))); + __pyx_t_72 = 0; + __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_72 * __pyx_v_XtA.strides[0]) ))))); } - __pyx_L50:; + __pyx_L49:; - /* "sklearn/linear_model/cd_fast.pyx":416 + /* "sklearn/linear_model/cd_fast.pyx":453 * * # R_norm2 = np.dot(R, R) * R_norm2 = ddot(n_samples, &R[0], 1, &R[0], 1) # <<<<<<<<<<<<<< * * # w_norm2 = np.dot(w, w) */ - __pyx_t_71 = 0; - __pyx_t_72 = 0; - __pyx_v_R_norm2 = cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_71 * __pyx_v_R.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_72 * __pyx_v_R.strides[0]) ))))), 1); + __pyx_t_73 = 0; + __pyx_t_74 = 0; + __pyx_v_R_norm2 = cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_73 * __pyx_v_R.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_74 * __pyx_v_R.strides[0]) ))))), 1); - /* "sklearn/linear_model/cd_fast.pyx":419 + /* "sklearn/linear_model/cd_fast.pyx":456 * * # w_norm2 = np.dot(w, w) * w_norm2 = ddot(n_features, &w[0], 1, &w[0], 1) # <<<<<<<<<<<<<< * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA */ - __pyx_t_73 = 0; - __pyx_t_74 = 0; - __pyx_v_w_norm2 = cblas_ddot(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_73 * __pyx_v_w.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_74 * __pyx_v_w.strides[0]) ))))), 1); + __pyx_t_75 = 0; + __pyx_t_76 = 0; + __pyx_v_w_norm2 = cblas_ddot(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_75 * __pyx_v_w.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_76 * __pyx_v_w.strides[0]) ))))), 1); - /* "sklearn/linear_model/cd_fast.pyx":420 + /* "sklearn/linear_model/cd_fast.pyx":457 * # w_norm2 = np.dot(w, w) * w_norm2 = ddot(n_features, &w[0], 1, &w[0], 1) * if (dual_norm_XtA > alpha): # <<<<<<<<<<<<<< * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * const**2 */ - __pyx_t_13 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); - if (__pyx_t_13) { + __pyx_t_14 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":421 + /* "sklearn/linear_model/cd_fast.pyx":458 * w_norm2 = ddot(n_features, &w[0], 1, &w[0], 1) * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA # <<<<<<<<<<<<<< @@ -4847,7 +5199,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_const = (__pyx_v_alpha / __pyx_v_dual_norm_XtA); - /* "sklearn/linear_model/cd_fast.pyx":422 + /* "sklearn/linear_model/cd_fast.pyx":459 * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * const**2 # <<<<<<<<<<<<<< @@ -4856,7 +5208,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_A_norm2 = (__pyx_v_R_norm2 * pow(__pyx_v_const, 2.0)); - /* "sklearn/linear_model/cd_fast.pyx":423 + /* "sklearn/linear_model/cd_fast.pyx":460 * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * const**2 * gap = 0.5 * (R_norm2 + A_norm2) # <<<<<<<<<<<<<< @@ -4864,11 +5216,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina * const = 1.0 */ __pyx_v_gap = (0.5 * (__pyx_v_R_norm2 + __pyx_v_A_norm2)); - goto __pyx_L51; + goto __pyx_L50; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":425 + /* "sklearn/linear_model/cd_fast.pyx":462 * gap = 0.5 * (R_norm2 + A_norm2) * else: * const = 1.0 # <<<<<<<<<<<<<< @@ -4877,7 +5229,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_const = 1.0; - /* "sklearn/linear_model/cd_fast.pyx":426 + /* "sklearn/linear_model/cd_fast.pyx":463 * else: * const = 1.0 * gap = R_norm2 # <<<<<<<<<<<<<< @@ -4886,56 +5238,56 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ __pyx_v_gap = __pyx_v_R_norm2; } - __pyx_L51:; + __pyx_L50:; - /* "sklearn/linear_model/cd_fast.pyx":428 + /* "sklearn/linear_model/cd_fast.pyx":465 * gap = R_norm2 * * l1_norm = dasum(n_features, &w[0], 1) # <<<<<<<<<<<<<< * * # The expression inside ddot is equivalent to np.dot(R.T, y) */ - __pyx_t_75 = 0; - __pyx_v_l1_norm = cblas_dasum(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_75 * __pyx_v_w.strides[0]) ))))), 1); + __pyx_t_77 = 0; + __pyx_v_l1_norm = cblas_dasum(__pyx_v_n_features, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_77 * __pyx_v_w.strides[0]) ))))), 1); - /* "sklearn/linear_model/cd_fast.pyx":433 + /* "sklearn/linear_model/cd_fast.pyx":470 * gap += (alpha * l1_norm - const * ddot( * n_samples, * &R[0], 1, # <<<<<<<<<<<<<< * &y[0], n_tasks * ) */ - __pyx_t_76 = 0; + __pyx_t_78 = 0; - /* "sklearn/linear_model/cd_fast.pyx":434 + /* "sklearn/linear_model/cd_fast.pyx":471 * n_samples, * &R[0], 1, * &y[0], n_tasks # <<<<<<<<<<<<<< * ) * + 0.5 * beta * (1 + const ** 2) * w_norm2) */ - __pyx_t_77 = 0; + __pyx_t_79 = 0; - /* "sklearn/linear_model/cd_fast.pyx":431 + /* "sklearn/linear_model/cd_fast.pyx":468 * * # The expression inside ddot is equivalent to np.dot(R.T, y) * gap += (alpha * l1_norm - const * ddot( # <<<<<<<<<<<<<< * n_samples, * &R[0], 1, */ - __pyx_v_gap = (__pyx_v_gap + (((__pyx_v_alpha * __pyx_v_l1_norm) - (__pyx_v_const * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_76 * __pyx_v_R.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_77 * __pyx_v_y.strides[0]) ))))), __pyx_v_n_tasks))) + (((0.5 * __pyx_v_beta) * (1.0 + pow(__pyx_v_const, 2.0))) * __pyx_v_w_norm2))); + __pyx_v_gap = (__pyx_v_gap + (((__pyx_v_alpha * __pyx_v_l1_norm) - (__pyx_v_const * cblas_ddot(__pyx_v_n_samples, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_78 * __pyx_v_R.strides[0]) ))))), 1, ((__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE *)(&(*((double *) ( /* dim=0 */ (__pyx_v_y.data + __pyx_t_79 * __pyx_v_y.strides[0]) ))))), __pyx_v_n_tasks))) + (((0.5 * __pyx_v_beta) * (1.0 + pow(__pyx_v_const, 2.0))) * __pyx_v_w_norm2))); - /* "sklearn/linear_model/cd_fast.pyx":438 + /* "sklearn/linear_model/cd_fast.pyx":475 * + 0.5 * beta * (1 + const ** 2) * w_norm2) * * if gap < tol: # <<<<<<<<<<<<<< * # return if we reached desired tolerance * break */ - __pyx_t_13 = ((__pyx_v_gap < __pyx_v_tol) != 0); - if (__pyx_t_13) { + __pyx_t_14 = ((__pyx_v_gap < __pyx_v_tol) != 0); + if (__pyx_t_14) { - /* "sklearn/linear_model/cd_fast.pyx":440 + /* "sklearn/linear_model/cd_fast.pyx":477 * if gap < tol: * # return if we reached desired tolerance * break # <<<<<<<<<<<<<< @@ -4944,19 +5296,19 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina */ goto __pyx_L17_break; } - goto __pyx_L41; + goto __pyx_L42; } - __pyx_L41:; + __pyx_L42:; } __pyx_L17_break:; } - /* "sklearn/linear_model/cd_fast.pyx":310 + /* "sklearn/linear_model/cd_fast.pyx":344 * cdef bint center = False * * with nogil: # <<<<<<<<<<<<<< * # center = (X_mean != 0).any() - * for ii in range(n_samples): + * for ii in range(n_features): */ /*finally:*/ { /*normal exit:*/{ @@ -4969,7 +5321,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina } } - /* "sklearn/linear_model/cd_fast.pyx":442 + /* "sklearn/linear_model/cd_fast.pyx":479 * break * * return w, gap, tol, n_iter + 1 # <<<<<<<<<<<<<< @@ -4977,33 +5329,33 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_78 = PyTuple_New(4); if (unlikely(!__pyx_t_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_78); - PyTuple_SET_ITEM(__pyx_t_78, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_78, 1, __pyx_t_3); + __pyx_t_80 = PyTuple_New(4); if (unlikely(!__pyx_t_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_80); + PyTuple_SET_ITEM(__pyx_t_80, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_78, 2, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_80, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_78, 3, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_80, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_80, 3, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_2 = 0; + __pyx_t_4 = 0; __pyx_t_1 = 0; - __pyx_r = __pyx_t_78; - __pyx_t_78 = 0; + __pyx_r = __pyx_t_80; + __pyx_t_80 = 0; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":260 + /* "sklearn/linear_model/cd_fast.pyx":290 * @cython.wraparound(False) * @cython.cdivision(True) * def sparse_enet_coordinate_descent(double[:] w, # <<<<<<<<<<<<<< @@ -5021,7 +5373,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1); - __Pyx_XDECREF(__pyx_t_78); + __Pyx_XDECREF(__pyx_t_80); __Pyx_AddTraceback("sklearn.linear_model.cd_fast.sparse_enet_coordinate_descent", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -5040,12 +5392,12 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_2sparse_enet_coordina return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":448 +/* "sklearn/linear_model/cd_fast.pyx":485 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, # <<<<<<<<<<<<<< * double[:, :] Q, double[:] q, double[:] y, - * int max_iter, double tol, bint positive=0): + * int max_iter, double tol, object rng, */ /* Python wrapper */ @@ -5061,6 +5413,8 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_5enet_coordinate_desc __Pyx_memviewslice __pyx_v_y = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_max_iter; double __pyx_v_tol; + PyObject *__pyx_v_rng = 0; + int __pyx_v_random; int __pyx_v_positive; int __pyx_lineno = 0; const char *__pyx_filename = NULL; @@ -5069,12 +5423,14 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_5enet_coordinate_desc __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("enet_coordinate_descent_gram (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_Q,&__pyx_n_s_q,&__pyx_n_s_y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_positive,0}; - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_w,&__pyx_n_s_alpha,&__pyx_n_s_beta,&__pyx_n_s_Q,&__pyx_n_s_q,&__pyx_n_s_y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_rng,&__pyx_n_s_random,&__pyx_n_s_positive,0}; + PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); @@ -5095,51 +5451,63 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_5enet_coordinate_desc case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alpha)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_beta)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_Q)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_q)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iter)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 8: + if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rng)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 9: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_random); + if (value) { values[9] = value; kw_args--; } + } + case 10: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_positive); - if (value) { values[8] = value; kw_args--; } + if (value) { values[10] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent_gram") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent_gram") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -5151,36 +5519,42 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_5enet_coordinate_desc default: goto __pyx_L5_argtuple_error; } } - __pyx_v_w = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[0]); if (unlikely(!__pyx_v_w.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_Q = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(values[3]); if (unlikely(!__pyx_v_Q.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_q = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[4]); if (unlikely(!__pyx_v_q.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_y = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[5]); if (unlikely(!__pyx_v_y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_max_iter = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_tol = __pyx_PyFloat_AsDouble(values[7]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - if (values[8]) { - __pyx_v_positive = __Pyx_PyObject_IsTrue(values[8]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_w = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[0]); if (unlikely(!__pyx_v_w.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_alpha = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_alpha == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_beta = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_beta == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_Q = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(values[3]); if (unlikely(!__pyx_v_Q.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_q = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[4]); if (unlikely(!__pyx_v_q.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_y = __Pyx_PyObject_to_MemoryviewSlice_ds_double(values[5]); if (unlikely(!__pyx_v_y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_max_iter = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_tol = __pyx_PyFloat_AsDouble(values[7]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_rng = values[8]; + if (values[9]) { + __pyx_v_random = __Pyx_PyObject_IsTrue(values[9]); if (unlikely((__pyx_v_random == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_random = ((int)0); + } + if (values[10]) { + __pyx_v_positive = __Pyx_PyObject_IsTrue(values[10]); if (unlikely((__pyx_v_positive == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_positive = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 8, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_gram", 0, 9, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.linear_model.cd_fast.enet_coordinate_descent_gram", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_Q, __pyx_v_q, __pyx_v_y, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_positive); + __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(__pyx_self, __pyx_v_w, __pyx_v_alpha, __pyx_v_beta, __pyx_v_Q, __pyx_v_q, __pyx_v_y, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_rng, __pyx_v_random, __pyx_v_positive); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_Q, __Pyx_memviewslice __pyx_v_q, __Pyx_memviewslice __pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, int __pyx_v_positive) { +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_descent_gram(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_w, double __pyx_v_alpha, double __pyx_v_beta, __Pyx_memviewslice __pyx_v_Q, __Pyx_memviewslice __pyx_v_q, __Pyx_memviewslice __pyx_v_y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random, int __pyx_v_positive) { CYTHON_UNUSED unsigned int __pyx_v_n_samples; unsigned int __pyx_v_n_features; unsigned int __pyx_v_n_tasks; @@ -5196,6 +5570,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc double __pyx_v_dual_norm_XtA; unsigned int __pyx_v_ii; unsigned int __pyx_v_n_iter; + unsigned int __pyx_v_f_iter; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_v_rand_r_state_seed; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_rand_r_state; double __pyx_v_y_norm2; double *__pyx_v_Q_ptr; double *__pyx_v_H_ptr; @@ -5213,14 +5590,14 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc PyObject *__pyx_t_4 = NULL; __Pyx_memviewslice __pyx_t_5 = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_t_6 = { 0, 0, { 0 }, { 0 }, { 0 } }; - double __pyx_t_7; - Py_ssize_t __pyx_t_8; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_t_7; + double __pyx_t_8; Py_ssize_t __pyx_t_9; Py_ssize_t __pyx_t_10; Py_ssize_t __pyx_t_11; - int __pyx_t_12; + Py_ssize_t __pyx_t_12; int __pyx_t_13; - unsigned int __pyx_t_14; + int __pyx_t_14; unsigned int __pyx_t_15; unsigned int __pyx_t_16; unsigned int __pyx_t_17; @@ -5228,8 +5605,8 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc unsigned int __pyx_t_19; unsigned int __pyx_t_20; unsigned int __pyx_t_21; - int __pyx_t_22; - unsigned int __pyx_t_23; + unsigned int __pyx_t_22; + int __pyx_t_23; unsigned int __pyx_t_24; unsigned int __pyx_t_25; unsigned int __pyx_t_26; @@ -5238,26 +5615,27 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc unsigned int __pyx_t_29; unsigned int __pyx_t_30; unsigned int __pyx_t_31; - int __pyx_t_32; + unsigned int __pyx_t_32; int __pyx_t_33; - Py_ssize_t __pyx_t_34; + int __pyx_t_34; Py_ssize_t __pyx_t_35; - unsigned int __pyx_t_36; + Py_ssize_t __pyx_t_36; unsigned int __pyx_t_37; unsigned int __pyx_t_38; unsigned int __pyx_t_39; unsigned int __pyx_t_40; unsigned int __pyx_t_41; - Py_ssize_t __pyx_t_42; + unsigned int __pyx_t_42; Py_ssize_t __pyx_t_43; Py_ssize_t __pyx_t_44; - PyObject *__pyx_t_45 = NULL; + Py_ssize_t __pyx_t_45; + PyObject *__pyx_t_46 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("enet_coordinate_descent_gram", 0); - /* "sklearn/linear_model/cd_fast.pyx":466 + /* "sklearn/linear_model/cd_fast.pyx":504 * * # get the data information into easy vars * cdef unsigned int n_samples = y.shape[0] # <<<<<<<<<<<<<< @@ -5266,7 +5644,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_n_samples = (__pyx_v_y.shape[0]); - /* "sklearn/linear_model/cd_fast.pyx":467 + /* "sklearn/linear_model/cd_fast.pyx":505 * # get the data information into easy vars * cdef unsigned int n_samples = y.shape[0] * cdef unsigned int n_features = Q.shape[0] # <<<<<<<<<<<<<< @@ -5275,7 +5653,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_n_features = (__pyx_v_Q.shape[0]); - /* "sklearn/linear_model/cd_fast.pyx":468 + /* "sklearn/linear_model/cd_fast.pyx":506 * cdef unsigned int n_samples = y.shape[0] * cdef unsigned int n_features = Q.shape[0] * cdef unsigned int n_tasks = y.strides[0] / sizeof(DOUBLE) # <<<<<<<<<<<<<< @@ -5284,23 +5662,23 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_n_tasks = ((__pyx_v_y.strides[0]) / (sizeof(__pyx_t_7sklearn_12linear_model_7cd_fast_DOUBLE))); - /* "sklearn/linear_model/cd_fast.pyx":471 + /* "sklearn/linear_model/cd_fast.pyx":509 * * # initial value "Q w" which will be kept of up to date in the iterations * cdef double[:] H = np.dot(Q, w) # <<<<<<<<<<<<<< * * cdef double[:] XtA = np.zeros(n_features) */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_Q, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_Q, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -5308,48 +5686,48 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_3); - if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_H = __pyx_t_5; __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":473 + /* "sklearn/linear_model/cd_fast.pyx":511 * cdef double[:] H = np.dot(Q, w) * * cdef double[:] XtA = np.zeros(n_features) # <<<<<<<<<<<<<< * cdef double tmp * cdef double w_ii */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_3); - if (unlikely(!__pyx_t_6.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_6.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_XtA = __pyx_t_6; __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":479 + /* "sklearn/linear_model/cd_fast.pyx":517 * cdef double w_max * cdef double d_w_ii * cdef double gap = tol + 1.0 # <<<<<<<<<<<<<< @@ -5358,7 +5736,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_gap = (__pyx_v_tol + 1.0); - /* "sklearn/linear_model/cd_fast.pyx":480 + /* "sklearn/linear_model/cd_fast.pyx":518 * cdef double d_w_ii * cdef double gap = tol + 1.0 * cdef double d_w_tol = tol # <<<<<<<<<<<<<< @@ -5367,70 +5745,106 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_d_w_tol = __pyx_v_tol; - /* "sklearn/linear_model/cd_fast.pyx":485 + /* "sklearn/linear_model/cd_fast.pyx":523 * cdef unsigned int n_iter + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) # <<<<<<<<<<<<<< + * cdef UINT32_t* rand_r_state = &rand_r_state_seed + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s_randint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = __Pyx_PyInt_As_npy_uint32(__pyx_t_2); if (unlikely((__pyx_t_7 == (npy_uint32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_rand_r_state_seed = __pyx_t_7; + + /* "sklearn/linear_model/cd_fast.pyx":524 + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + * cdef UINT32_t* rand_r_state = &rand_r_state_seed # <<<<<<<<<<<<<< + * + * cdef double y_norm2 = np.dot(y, y) + */ + __pyx_v_rand_r_state = (&__pyx_v_rand_r_state_seed); + + /* "sklearn/linear_model/cd_fast.pyx":526 + * cdef UINT32_t* rand_r_state = &rand_r_state_seed * * cdef double y_norm2 = np.dot(y, y) # <<<<<<<<<<<<<< * cdef double* Q_ptr = &Q[0, 0] * cdef double* H_ptr = &H[0] */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_dot); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_y, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_y, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dot); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_y, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_y, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_2 = 0; __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_y_norm2 = __pyx_t_7; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_8 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_y_norm2 = __pyx_t_8; - /* "sklearn/linear_model/cd_fast.pyx":486 + /* "sklearn/linear_model/cd_fast.pyx":527 * * cdef double y_norm2 = np.dot(y, y) * cdef double* Q_ptr = &Q[0, 0] # <<<<<<<<<<<<<< * cdef double* H_ptr = &H[0] * cdef double* XtA_ptr = &XtA[0] */ - __pyx_t_8 = 0; __pyx_t_9 = 0; - __pyx_v_Q_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_8 * __pyx_v_Q.strides[0]) ) + __pyx_t_9 * __pyx_v_Q.strides[1]) )))); + __pyx_t_10 = 0; + __pyx_v_Q_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_9 * __pyx_v_Q.strides[0]) ) + __pyx_t_10 * __pyx_v_Q.strides[1]) )))); - /* "sklearn/linear_model/cd_fast.pyx":487 + /* "sklearn/linear_model/cd_fast.pyx":528 * cdef double y_norm2 = np.dot(y, y) * cdef double* Q_ptr = &Q[0, 0] * cdef double* H_ptr = &H[0] # <<<<<<<<<<<<<< * cdef double* XtA_ptr = &XtA[0] * tol = tol * y_norm2 */ - __pyx_t_10 = 0; - __pyx_v_H_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_10 * __pyx_v_H.strides[0]) )))); + __pyx_t_11 = 0; + __pyx_v_H_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_11 * __pyx_v_H.strides[0]) )))); - /* "sklearn/linear_model/cd_fast.pyx":488 + /* "sklearn/linear_model/cd_fast.pyx":529 * cdef double* Q_ptr = &Q[0, 0] * cdef double* H_ptr = &H[0] * cdef double* XtA_ptr = &XtA[0] # <<<<<<<<<<<<<< * tol = tol * y_norm2 * */ - __pyx_t_11 = 0; - __pyx_v_XtA_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_11 * __pyx_v_XtA.strides[0]) )))); + __pyx_t_12 = 0; + __pyx_v_XtA_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_12 * __pyx_v_XtA.strides[0]) )))); - /* "sklearn/linear_model/cd_fast.pyx":489 + /* "sklearn/linear_model/cd_fast.pyx":530 * cdef double* H_ptr = &H[0] * cdef double* XtA_ptr = &XtA[0] * tol = tol * y_norm2 # <<<<<<<<<<<<<< @@ -5439,37 +5853,37 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_tol = (__pyx_v_tol * __pyx_v_y_norm2); - /* "sklearn/linear_model/cd_fast.pyx":491 + /* "sklearn/linear_model/cd_fast.pyx":532 * tol = tol * y_norm2 * * if alpha == 0: # <<<<<<<<<<<<<< * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" * " results and is discouraged.") */ - __pyx_t_12 = ((__pyx_v_alpha == 0.0) != 0); - if (__pyx_t_12) { + __pyx_t_13 = ((__pyx_v_alpha == 0.0) != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":492 + /* "sklearn/linear_model/cd_fast.pyx":533 * * if alpha == 0: * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_warn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L3; } __pyx_L3:; - /* "sklearn/linear_model/cd_fast.pyx":495 + /* "sklearn/linear_model/cd_fast.pyx":536 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -5483,60 +5897,93 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc #endif /*try:*/ { - /* "sklearn/linear_model/cd_fast.pyx":496 + /* "sklearn/linear_model/cd_fast.pyx":537 * * with nogil: * for n_iter in range(max_iter): # <<<<<<<<<<<<<< * w_max = 0.0 * d_w_max = 0.0 */ - __pyx_t_13 = __pyx_v_max_iter; - for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { - __pyx_v_n_iter = __pyx_t_14; + __pyx_t_14 = __pyx_v_max_iter; + for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) { + __pyx_v_n_iter = __pyx_t_15; - /* "sklearn/linear_model/cd_fast.pyx":497 + /* "sklearn/linear_model/cd_fast.pyx":538 * with nogil: * for n_iter in range(max_iter): * w_max = 0.0 # <<<<<<<<<<<<<< * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates */ __pyx_v_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":498 + /* "sklearn/linear_model/cd_fast.pyx":539 * for n_iter in range(max_iter): * w_max = 0.0 * d_w_max = 0.0 # <<<<<<<<<<<<<< - * for ii in range(n_features): # Loop over coordinates - * if Q[ii, ii] == 0.0: + * for f_iter in range(n_features): # Loop over coordinates + * if random: */ __pyx_v_d_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":499 + /* "sklearn/linear_model/cd_fast.pyx":540 * w_max = 0.0 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< - * if Q[ii, ii] == 0.0: - * continue + * for f_iter in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< + * if random: + * ii = rand_int(n_features, rand_r_state) */ - __pyx_t_15 = __pyx_v_n_features; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { - __pyx_v_ii = __pyx_t_16; + __pyx_t_16 = __pyx_v_n_features; + for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { + __pyx_v_f_iter = __pyx_t_17; - /* "sklearn/linear_model/cd_fast.pyx":500 + /* "sklearn/linear_model/cd_fast.pyx":541 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates + * if random: # <<<<<<<<<<<<<< + * ii = rand_int(n_features, rand_r_state) + * else: + */ + __pyx_t_13 = (__pyx_v_random != 0); + if (__pyx_t_13) { + + /* "sklearn/linear_model/cd_fast.pyx":542 + * for f_iter in range(n_features): # Loop over coordinates + * if random: + * ii = rand_int(n_features, rand_r_state) # <<<<<<<<<<<<<< + * else: + * ii = f_iter + */ + __pyx_v_ii = __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_v_n_features, __pyx_v_rand_r_state); + goto __pyx_L11; + } + /*else*/ { + + /* "sklearn/linear_model/cd_fast.pyx":544 + * ii = rand_int(n_features, rand_r_state) + * else: + * ii = f_iter # <<<<<<<<<<<<<< + * + * if Q[ii, ii] == 0.0: + */ + __pyx_v_ii = __pyx_v_f_iter; + } + __pyx_L11:; + + /* "sklearn/linear_model/cd_fast.pyx":546 + * ii = f_iter + * * if Q[ii, ii] == 0.0: # <<<<<<<<<<<<<< * continue * */ - __pyx_t_17 = __pyx_v_ii; __pyx_t_18 = __pyx_v_ii; - __pyx_t_12 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_17 * __pyx_v_Q.strides[0]) ) + __pyx_t_18 * __pyx_v_Q.strides[1]) ))) == 0.0) != 0); - if (__pyx_t_12) { + __pyx_t_19 = __pyx_v_ii; + __pyx_t_13 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_18 * __pyx_v_Q.strides[0]) ) + __pyx_t_19 * __pyx_v_Q.strides[1]) ))) == 0.0) != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":501 - * for ii in range(n_features): # Loop over coordinates + /* "sklearn/linear_model/cd_fast.pyx":547 + * * if Q[ii, ii] == 0.0: * continue # <<<<<<<<<<<<<< * @@ -5545,27 +5992,27 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc goto __pyx_L9_continue; } - /* "sklearn/linear_model/cd_fast.pyx":503 + /* "sklearn/linear_model/cd_fast.pyx":549 * continue * * w_ii = w[ii] # Store previous value # <<<<<<<<<<<<<< * * if w_ii != 0.0: */ - __pyx_t_19 = __pyx_v_ii; - __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_19 * __pyx_v_w.strides[0]) ))); + __pyx_t_20 = __pyx_v_ii; + __pyx_v_w_ii = (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_20 * __pyx_v_w.strides[0]) ))); - /* "sklearn/linear_model/cd_fast.pyx":505 + /* "sklearn/linear_model/cd_fast.pyx":551 * w_ii = w[ii] # Store previous value * * if w_ii != 0.0: # <<<<<<<<<<<<<< * # H -= w_ii * Q[ii] * daxpy(n_features, -w_ii, Q_ptr + ii * n_features, 1, */ - __pyx_t_12 = ((__pyx_v_w_ii != 0.0) != 0); - if (__pyx_t_12) { + __pyx_t_13 = ((__pyx_v_w_ii != 0.0) != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":507 + /* "sklearn/linear_model/cd_fast.pyx":553 * if w_ii != 0.0: * # H -= w_ii * Q[ii] * daxpy(n_features, -w_ii, Q_ptr + ii * n_features, 1, # <<<<<<<<<<<<<< @@ -5573,22 +6020,22 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * */ cblas_daxpy(__pyx_v_n_features, (-__pyx_v_w_ii), (__pyx_v_Q_ptr + (__pyx_v_ii * __pyx_v_n_features)), 1, __pyx_v_H_ptr, 1); - goto __pyx_L12; + goto __pyx_L13; } - __pyx_L12:; + __pyx_L13:; - /* "sklearn/linear_model/cd_fast.pyx":510 + /* "sklearn/linear_model/cd_fast.pyx":556 * H_ptr, 1) * * tmp = q[ii] - H[ii] # <<<<<<<<<<<<<< * * if positive and tmp < 0: */ - __pyx_t_20 = __pyx_v_ii; __pyx_t_21 = __pyx_v_ii; - __pyx_v_tmp = ((*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_20 * __pyx_v_q.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_21 * __pyx_v_H.strides[0]) )))); + __pyx_t_22 = __pyx_v_ii; + __pyx_v_tmp = ((*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_21 * __pyx_v_q.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_22 * __pyx_v_H.strides[0]) )))); - /* "sklearn/linear_model/cd_fast.pyx":512 + /* "sklearn/linear_model/cd_fast.pyx":558 * tmp = q[ii] - H[ii] * * if positive and tmp < 0: # <<<<<<<<<<<<<< @@ -5596,101 +6043,101 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * else: */ if ((__pyx_v_positive != 0)) { - __pyx_t_12 = ((__pyx_v_tmp < 0.0) != 0); - __pyx_t_22 = __pyx_t_12; + __pyx_t_13 = ((__pyx_v_tmp < 0.0) != 0); + __pyx_t_23 = __pyx_t_13; } else { - __pyx_t_22 = (__pyx_v_positive != 0); + __pyx_t_23 = (__pyx_v_positive != 0); } - if (__pyx_t_22) { + if (__pyx_t_23) { - /* "sklearn/linear_model/cd_fast.pyx":513 + /* "sklearn/linear_model/cd_fast.pyx":559 * * if positive and tmp < 0: * w[ii] = 0.0 # <<<<<<<<<<<<<< * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ */ - __pyx_t_23 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_23 * __pyx_v_w.strides[0]) )) = 0.0; - goto __pyx_L13; + __pyx_t_24 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_24 * __pyx_v_w.strides[0]) )) = 0.0; + goto __pyx_L14; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":516 + /* "sklearn/linear_model/cd_fast.pyx":562 * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ * / (Q[ii, ii] + beta) # <<<<<<<<<<<<<< * * if w[ii] != 0.0: */ - __pyx_t_24 = __pyx_v_ii; __pyx_t_25 = __pyx_v_ii; + __pyx_t_26 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":515 + /* "sklearn/linear_model/cd_fast.pyx":561 * w[ii] = 0.0 * else: * w[ii] = fsign(tmp) * fmax(fabs(tmp) - alpha, 0) \ # <<<<<<<<<<<<<< * / (Q[ii, ii] + beta) * */ - __pyx_t_26 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_26 * __pyx_v_w.strides[0]) )) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_24 * __pyx_v_Q.strides[0]) ) + __pyx_t_25 * __pyx_v_Q.strides[1]) ))) + __pyx_v_beta)); + __pyx_t_27 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_27 * __pyx_v_w.strides[0]) )) = ((__pyx_f_7sklearn_12linear_model_7cd_fast_fsign(__pyx_v_tmp) * __pyx_f_7sklearn_12linear_model_7cd_fast_fmax((fabs(__pyx_v_tmp) - __pyx_v_alpha), 0.0)) / ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Q.data + __pyx_t_25 * __pyx_v_Q.strides[0]) ) + __pyx_t_26 * __pyx_v_Q.strides[1]) ))) + __pyx_v_beta)); } - __pyx_L13:; + __pyx_L14:; - /* "sklearn/linear_model/cd_fast.pyx":518 + /* "sklearn/linear_model/cd_fast.pyx":564 * / (Q[ii, ii] + beta) * * if w[ii] != 0.0: # <<<<<<<<<<<<<< * # H += w[ii] * Q[ii] # Update H = X.T X w * daxpy(n_features, w[ii], Q_ptr + ii * n_features, 1, */ - __pyx_t_27 = __pyx_v_ii; - __pyx_t_22 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_27 * __pyx_v_w.strides[0]) ))) != 0.0) != 0); - if (__pyx_t_22) { + __pyx_t_28 = __pyx_v_ii; + __pyx_t_23 = (((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_28 * __pyx_v_w.strides[0]) ))) != 0.0) != 0); + if (__pyx_t_23) { - /* "sklearn/linear_model/cd_fast.pyx":520 + /* "sklearn/linear_model/cd_fast.pyx":566 * if w[ii] != 0.0: * # H += w[ii] * Q[ii] # Update H = X.T X w * daxpy(n_features, w[ii], Q_ptr + ii * n_features, 1, # <<<<<<<<<<<<<< * H_ptr, 1) * */ - __pyx_t_28 = __pyx_v_ii; + __pyx_t_29 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":521 + /* "sklearn/linear_model/cd_fast.pyx":567 * # H += w[ii] * Q[ii] # Update H = X.T X w * daxpy(n_features, w[ii], Q_ptr + ii * n_features, 1, * H_ptr, 1) # <<<<<<<<<<<<<< * * # update the maximum absolute coefficient update */ - cblas_daxpy(__pyx_v_n_features, (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_28 * __pyx_v_w.strides[0]) ))), (__pyx_v_Q_ptr + (__pyx_v_ii * __pyx_v_n_features)), 1, __pyx_v_H_ptr, 1); - goto __pyx_L14; + cblas_daxpy(__pyx_v_n_features, (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_29 * __pyx_v_w.strides[0]) ))), (__pyx_v_Q_ptr + (__pyx_v_ii * __pyx_v_n_features)), 1, __pyx_v_H_ptr, 1); + goto __pyx_L15; } - __pyx_L14:; + __pyx_L15:; - /* "sklearn/linear_model/cd_fast.pyx":524 + /* "sklearn/linear_model/cd_fast.pyx":570 * * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) # <<<<<<<<<<<<<< * if d_w_ii > d_w_max: * d_w_max = d_w_ii */ - __pyx_t_29 = __pyx_v_ii; - __pyx_v_d_w_ii = fabs(((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_29 * __pyx_v_w.strides[0]) ))) - __pyx_v_w_ii)); + __pyx_t_30 = __pyx_v_ii; + __pyx_v_d_w_ii = fabs(((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_30 * __pyx_v_w.strides[0]) ))) - __pyx_v_w_ii)); - /* "sklearn/linear_model/cd_fast.pyx":525 + /* "sklearn/linear_model/cd_fast.pyx":571 * # update the maximum absolute coefficient update * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: # <<<<<<<<<<<<<< * d_w_max = d_w_ii * */ - __pyx_t_22 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); - if (__pyx_t_22) { + __pyx_t_23 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); + if (__pyx_t_23) { - /* "sklearn/linear_model/cd_fast.pyx":526 + /* "sklearn/linear_model/cd_fast.pyx":572 * d_w_ii = fabs(w[ii] - w_ii) * if d_w_ii > d_w_max: * d_w_max = d_w_ii # <<<<<<<<<<<<<< @@ -5698,105 +6145,105 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * if fabs(w[ii]) > w_max: */ __pyx_v_d_w_max = __pyx_v_d_w_ii; - goto __pyx_L15; + goto __pyx_L16; } - __pyx_L15:; + __pyx_L16:; - /* "sklearn/linear_model/cd_fast.pyx":528 + /* "sklearn/linear_model/cd_fast.pyx":574 * d_w_max = d_w_ii * * if fabs(w[ii]) > w_max: # <<<<<<<<<<<<<< * w_max = fabs(w[ii]) * */ - __pyx_t_30 = __pyx_v_ii; - __pyx_t_22 = ((fabs((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_30 * __pyx_v_w.strides[0]) )))) > __pyx_v_w_max) != 0); - if (__pyx_t_22) { + __pyx_t_31 = __pyx_v_ii; + __pyx_t_23 = ((fabs((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_31 * __pyx_v_w.strides[0]) )))) > __pyx_v_w_max) != 0); + if (__pyx_t_23) { - /* "sklearn/linear_model/cd_fast.pyx":529 + /* "sklearn/linear_model/cd_fast.pyx":575 * * if fabs(w[ii]) > w_max: * w_max = fabs(w[ii]) # <<<<<<<<<<<<<< * * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: */ - __pyx_t_31 = __pyx_v_ii; - __pyx_v_w_max = fabs((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_31 * __pyx_v_w.strides[0]) )))); - goto __pyx_L16; + __pyx_t_32 = __pyx_v_ii; + __pyx_v_w_max = fabs((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_32 * __pyx_v_w.strides[0]) )))); + goto __pyx_L17; } - __pyx_L16:; + __pyx_L17:; __pyx_L9_continue:; } - /* "sklearn/linear_model/cd_fast.pyx":531 + /* "sklearn/linear_model/cd_fast.pyx":577 * w_max = fabs(w[ii]) * * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: # <<<<<<<<<<<<<< * # the biggest coordinate update of this iteration was smaller than * # the tolerance: check the duality gap as ultimate stopping */ - __pyx_t_22 = ((__pyx_v_w_max == 0.0) != 0); - if (!__pyx_t_22) { - __pyx_t_12 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); - if (!__pyx_t_12) { - __pyx_t_32 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); - __pyx_t_33 = __pyx_t_32; + __pyx_t_23 = ((__pyx_v_w_max == 0.0) != 0); + if (!__pyx_t_23) { + __pyx_t_13 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); + if (!__pyx_t_13) { + __pyx_t_33 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); + __pyx_t_34 = __pyx_t_33; } else { - __pyx_t_33 = __pyx_t_12; + __pyx_t_34 = __pyx_t_13; } - __pyx_t_12 = __pyx_t_33; + __pyx_t_13 = __pyx_t_34; } else { - __pyx_t_12 = __pyx_t_22; + __pyx_t_13 = __pyx_t_23; } - if (__pyx_t_12) { + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":539 + /* "sklearn/linear_model/cd_fast.pyx":585 * # Note that increment in q is not 1 because the strides * # vary if q is sliced from a 2-D array. * q_dot_w = ddot(n_features, &w[0], 1, &q[0], n_tasks) # <<<<<<<<<<<<<< * * for ii in range(n_features): */ - __pyx_t_34 = 0; __pyx_t_35 = 0; - __pyx_v_q_dot_w = cblas_ddot(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_34 * __pyx_v_w.strides[0]) )))), 1, (&(*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_35 * __pyx_v_q.strides[0]) )))), __pyx_v_n_tasks); + __pyx_t_36 = 0; + __pyx_v_q_dot_w = cblas_ddot(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_35 * __pyx_v_w.strides[0]) )))), 1, (&(*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_36 * __pyx_v_q.strides[0]) )))), __pyx_v_n_tasks); - /* "sklearn/linear_model/cd_fast.pyx":541 + /* "sklearn/linear_model/cd_fast.pyx":587 * q_dot_w = ddot(n_features, &w[0], 1, &q[0], n_tasks) * * for ii in range(n_features): # <<<<<<<<<<<<<< * XtA[ii] = q[ii] - H[ii] - beta * w[ii] * if positive: */ - __pyx_t_15 = __pyx_v_n_features; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { - __pyx_v_ii = __pyx_t_16; + __pyx_t_16 = __pyx_v_n_features; + for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { + __pyx_v_ii = __pyx_t_17; - /* "sklearn/linear_model/cd_fast.pyx":542 + /* "sklearn/linear_model/cd_fast.pyx":588 * * for ii in range(n_features): * XtA[ii] = q[ii] - H[ii] - beta * w[ii] # <<<<<<<<<<<<<< * if positive: * dual_norm_XtA = max(n_features, XtA_ptr) */ - __pyx_t_36 = __pyx_v_ii; __pyx_t_37 = __pyx_v_ii; __pyx_t_38 = __pyx_v_ii; __pyx_t_39 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_39 * __pyx_v_XtA.strides[0]) )) = (((*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_36 * __pyx_v_q.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_37 * __pyx_v_H.strides[0]) )))) - (__pyx_v_beta * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_38 * __pyx_v_w.strides[0]) ))))); + __pyx_t_40 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_40 * __pyx_v_XtA.strides[0]) )) = (((*((double *) ( /* dim=0 */ (__pyx_v_q.data + __pyx_t_37 * __pyx_v_q.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_38 * __pyx_v_H.strides[0]) )))) - (__pyx_v_beta * (*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_39 * __pyx_v_w.strides[0]) ))))); } - /* "sklearn/linear_model/cd_fast.pyx":543 + /* "sklearn/linear_model/cd_fast.pyx":589 * for ii in range(n_features): * XtA[ii] = q[ii] - H[ii] - beta * w[ii] * if positive: # <<<<<<<<<<<<<< * dual_norm_XtA = max(n_features, XtA_ptr) * else: */ - __pyx_t_12 = (__pyx_v_positive != 0); - if (__pyx_t_12) { + __pyx_t_13 = (__pyx_v_positive != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":544 + /* "sklearn/linear_model/cd_fast.pyx":590 * XtA[ii] = q[ii] - H[ii] - beta * w[ii] * if positive: * dual_norm_XtA = max(n_features, XtA_ptr) # <<<<<<<<<<<<<< @@ -5804,11 +6251,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * dual_norm_XtA = abs_max(n_features, XtA_ptr) */ __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_max(__pyx_v_n_features, __pyx_v_XtA_ptr); - goto __pyx_L20; + goto __pyx_L21; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":546 + /* "sklearn/linear_model/cd_fast.pyx":592 * dual_norm_XtA = max(n_features, XtA_ptr) * else: * dual_norm_XtA = abs_max(n_features, XtA_ptr) # <<<<<<<<<<<<<< @@ -5817,9 +6264,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_dual_norm_XtA = __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(__pyx_v_n_features, __pyx_v_XtA_ptr); } - __pyx_L20:; + __pyx_L21:; - /* "sklearn/linear_model/cd_fast.pyx":549 + /* "sklearn/linear_model/cd_fast.pyx":595 * * # temp = np.sum(w * H) * tmp = 0.0 # <<<<<<<<<<<<<< @@ -5828,30 +6275,30 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_tmp = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":550 + /* "sklearn/linear_model/cd_fast.pyx":596 * # temp = np.sum(w * H) * tmp = 0.0 * for ii in range(n_features): # <<<<<<<<<<<<<< * tmp += w[ii] * H[ii] * R_norm2 = y_norm2 + tmp - 2.0 * q_dot_w */ - __pyx_t_15 = __pyx_v_n_features; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { - __pyx_v_ii = __pyx_t_16; + __pyx_t_16 = __pyx_v_n_features; + for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { + __pyx_v_ii = __pyx_t_17; - /* "sklearn/linear_model/cd_fast.pyx":551 + /* "sklearn/linear_model/cd_fast.pyx":597 * tmp = 0.0 * for ii in range(n_features): * tmp += w[ii] * H[ii] # <<<<<<<<<<<<<< * R_norm2 = y_norm2 + tmp - 2.0 * q_dot_w * */ - __pyx_t_40 = __pyx_v_ii; __pyx_t_41 = __pyx_v_ii; - __pyx_v_tmp = (__pyx_v_tmp + ((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_40 * __pyx_v_w.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_41 * __pyx_v_H.strides[0]) ))))); + __pyx_t_42 = __pyx_v_ii; + __pyx_v_tmp = (__pyx_v_tmp + ((*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_41 * __pyx_v_w.strides[0]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_H.data + __pyx_t_42 * __pyx_v_H.strides[0]) ))))); } - /* "sklearn/linear_model/cd_fast.pyx":552 + /* "sklearn/linear_model/cd_fast.pyx":598 * for ii in range(n_features): * tmp += w[ii] * H[ii] * R_norm2 = y_norm2 + tmp - 2.0 * q_dot_w # <<<<<<<<<<<<<< @@ -5860,28 +6307,28 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_R_norm2 = ((__pyx_v_y_norm2 + __pyx_v_tmp) - (2.0 * __pyx_v_q_dot_w)); - /* "sklearn/linear_model/cd_fast.pyx":555 + /* "sklearn/linear_model/cd_fast.pyx":601 * * # w_norm2 = np.dot(w, w) * w_norm2 = ddot(n_features, &w[0], 1, &w[0], 1) # <<<<<<<<<<<<<< * * if (dual_norm_XtA > alpha): */ - __pyx_t_42 = 0; __pyx_t_43 = 0; - __pyx_v_w_norm2 = cblas_ddot(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_42 * __pyx_v_w.strides[0]) )))), 1, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_43 * __pyx_v_w.strides[0]) )))), 1); + __pyx_t_44 = 0; + __pyx_v_w_norm2 = cblas_ddot(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_43 * __pyx_v_w.strides[0]) )))), 1, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_44 * __pyx_v_w.strides[0]) )))), 1); - /* "sklearn/linear_model/cd_fast.pyx":557 + /* "sklearn/linear_model/cd_fast.pyx":603 * w_norm2 = ddot(n_features, &w[0], 1, &w[0], 1) * * if (dual_norm_XtA > alpha): # <<<<<<<<<<<<<< * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) */ - __pyx_t_12 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); - if (__pyx_t_12) { + __pyx_t_13 = ((__pyx_v_dual_norm_XtA > __pyx_v_alpha) != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":558 + /* "sklearn/linear_model/cd_fast.pyx":604 * * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA # <<<<<<<<<<<<<< @@ -5890,7 +6337,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_const = (__pyx_v_alpha / __pyx_v_dual_norm_XtA); - /* "sklearn/linear_model/cd_fast.pyx":559 + /* "sklearn/linear_model/cd_fast.pyx":605 * if (dual_norm_XtA > alpha): * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) # <<<<<<<<<<<<<< @@ -5899,7 +6346,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_A_norm2 = (__pyx_v_R_norm2 * pow(__pyx_v_const, 2.0)); - /* "sklearn/linear_model/cd_fast.pyx":560 + /* "sklearn/linear_model/cd_fast.pyx":606 * const = alpha / dual_norm_XtA * A_norm2 = R_norm2 * (const ** 2) * gap = 0.5 * (R_norm2 + A_norm2) # <<<<<<<<<<<<<< @@ -5907,11 +6354,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * const = 1.0 */ __pyx_v_gap = (0.5 * (__pyx_v_R_norm2 + __pyx_v_A_norm2)); - goto __pyx_L23; + goto __pyx_L24; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":562 + /* "sklearn/linear_model/cd_fast.pyx":608 * gap = 0.5 * (R_norm2 + A_norm2) * else: * const = 1.0 # <<<<<<<<<<<<<< @@ -5920,7 +6367,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_const = 1.0; - /* "sklearn/linear_model/cd_fast.pyx":563 + /* "sklearn/linear_model/cd_fast.pyx":609 * else: * const = 1.0 * gap = R_norm2 # <<<<<<<<<<<<<< @@ -5929,37 +6376,37 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ __pyx_v_gap = __pyx_v_R_norm2; } - __pyx_L23:; + __pyx_L24:; - /* "sklearn/linear_model/cd_fast.pyx":566 + /* "sklearn/linear_model/cd_fast.pyx":612 * * # The call to dasum is equivalent to the L1 norm of w * gap += (alpha * dasum(n_features, &w[0], 1) - # <<<<<<<<<<<<<< * const * y_norm2 + const * q_dot_w + * 0.5 * beta * (1 + const ** 2) * w_norm2) */ - __pyx_t_44 = 0; + __pyx_t_45 = 0; - /* "sklearn/linear_model/cd_fast.pyx":567 + /* "sklearn/linear_model/cd_fast.pyx":613 * # The call to dasum is equivalent to the L1 norm of w * gap += (alpha * dasum(n_features, &w[0], 1) - * const * y_norm2 + const * q_dot_w + # <<<<<<<<<<<<<< * 0.5 * beta * (1 + const ** 2) * w_norm2) * */ - __pyx_v_gap = (__pyx_v_gap + ((((__pyx_v_alpha * cblas_dasum(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_44 * __pyx_v_w.strides[0]) )))), 1)) - (__pyx_v_const * __pyx_v_y_norm2)) + (__pyx_v_const * __pyx_v_q_dot_w)) + (((0.5 * __pyx_v_beta) * (1.0 + pow(__pyx_v_const, 2.0))) * __pyx_v_w_norm2))); + __pyx_v_gap = (__pyx_v_gap + ((((__pyx_v_alpha * cblas_dasum(__pyx_v_n_features, (&(*((double *) ( /* dim=0 */ (__pyx_v_w.data + __pyx_t_45 * __pyx_v_w.strides[0]) )))), 1)) - (__pyx_v_const * __pyx_v_y_norm2)) + (__pyx_v_const * __pyx_v_q_dot_w)) + (((0.5 * __pyx_v_beta) * (1.0 + pow(__pyx_v_const, 2.0))) * __pyx_v_w_norm2))); - /* "sklearn/linear_model/cd_fast.pyx":570 + /* "sklearn/linear_model/cd_fast.pyx":616 * 0.5 * beta * (1 + const ** 2) * w_norm2) * * if gap < tol: # <<<<<<<<<<<<<< * # return if we reached desired tolerance * break */ - __pyx_t_12 = ((__pyx_v_gap < __pyx_v_tol) != 0); - if (__pyx_t_12) { + __pyx_t_13 = ((__pyx_v_gap < __pyx_v_tol) != 0); + if (__pyx_t_13) { - /* "sklearn/linear_model/cd_fast.pyx":572 + /* "sklearn/linear_model/cd_fast.pyx":618 * if gap < tol: * # return if we reached desired tolerance * break # <<<<<<<<<<<<<< @@ -5968,14 +6415,14 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc */ goto __pyx_L8_break; } - goto __pyx_L17; + goto __pyx_L18; } - __pyx_L17:; + __pyx_L18:; } __pyx_L8_break:; } - /* "sklearn/linear_model/cd_fast.pyx":495 + /* "sklearn/linear_model/cd_fast.pyx":536 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -5993,7 +6440,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc } } - /* "sklearn/linear_model/cd_fast.pyx":574 + /* "sklearn/linear_model/cd_fast.pyx":620 * break * * return np.asarray(w), gap, tol, n_iter + 1 # <<<<<<<<<<<<<< @@ -6001,52 +6448,52 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_asarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_w, 1, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_45 = PyTuple_New(4); if (unlikely(!__pyx_t_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_45); - PyTuple_SET_ITEM(__pyx_t_45, 0, __pyx_t_4); + __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_46 = PyTuple_New(4); if (unlikely(!__pyx_t_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_46); + PyTuple_SET_ITEM(__pyx_t_46, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_46, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_45, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_45, 2, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_46, 2, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_45, 3, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_46, 3, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_3 = 0; __pyx_t_4 = 0; - __pyx_t_2 = 0; __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_r = __pyx_t_45; - __pyx_t_45 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_46; + __pyx_t_46 = 0; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":448 + /* "sklearn/linear_model/cd_fast.pyx":485 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, # <<<<<<<<<<<<<< * double[:, :] Q, double[:] q, double[:] y, - * int max_iter, double tol, bint positive=0): + * int max_iter, double tol, object rng, */ /* function exit code */ @@ -6057,7 +6504,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc __Pyx_XDECREF(__pyx_t_4); __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1); __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1); - __Pyx_XDECREF(__pyx_t_45); + __Pyx_XDECREF(__pyx_t_46); __Pyx_AddTraceback("sklearn.linear_model.cd_fast.enet_coordinate_descent_gram", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -6072,7 +6519,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_4enet_coordinate_desc return __pyx_r; } -/* "sklearn/linear_model/cd_fast.pyx":580 +/* "sklearn/linear_model/cd_fast.pyx":626 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, # <<<<<<<<<<<<<< @@ -6092,6 +6539,8 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_7enet_coordinate_desc __Pyx_memviewslice __pyx_v_Y = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_max_iter; double __pyx_v_tol; + PyObject *__pyx_v_rng = 0; + int __pyx_v_random; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -6099,12 +6548,14 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_7enet_coordinate_desc __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("enet_coordinate_descent_multi_task (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_W,&__pyx_n_s_l1_reg,&__pyx_n_s_l2_reg,&__pyx_n_s_X,&__pyx_n_s_Y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,0}; - PyObject* values[7] = {0,0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_W,&__pyx_n_s_l1_reg,&__pyx_n_s_l2_reg,&__pyx_n_s_X,&__pyx_n_s_Y,&__pyx_n_s_max_iter,&__pyx_n_s_tol,&__pyx_n_s_rng,&__pyx_n_s_random,0}; + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -6123,72 +6574,92 @@ static PyObject *__pyx_pw_7sklearn_12linear_model_7cd_fast_7enet_coordinate_desc case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_l1_reg)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_l2_reg)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_Y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iter)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 7: + if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rng)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_random); + if (value) { values[8] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent_multi_task") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "enet_coordinate_descent_multi_task") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { - goto __pyx_L5_argtuple_error; } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - } - __pyx_v_W = __Pyx_PyObject_to_MemoryviewSlice_dcd__double(values[0]); if (unlikely(!__pyx_v_W.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_l1_reg = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_l1_reg == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_l2_reg = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_l2_reg == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_X = __Pyx_PyObject_to_MemoryviewSlice_dcd__double(values[3]); if (unlikely(!__pyx_v_X.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_Y = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(values[4]); if (unlikely(!__pyx_v_Y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_max_iter = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_tol = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_W = __Pyx_PyObject_to_MemoryviewSlice_dcd__double(values[0]); if (unlikely(!__pyx_v_W.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_l1_reg = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_l1_reg == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_l2_reg = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_l2_reg == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_X = __Pyx_PyObject_to_MemoryviewSlice_dcd__double(values[3]); if (unlikely(!__pyx_v_X.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_Y = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(values[4]); if (unlikely(!__pyx_v_Y.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_max_iter = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_tol = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_rng = values[7]; + if (values[8]) { + __pyx_v_random = __Pyx_PyObject_IsTrue(values[8]); if (unlikely((__pyx_v_random == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_random = ((int)0); + } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("enet_coordinate_descent_multi_task", 0, 8, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.linear_model.cd_fast.enet_coordinate_descent_multi_task", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(__pyx_self, __pyx_v_W, __pyx_v_l1_reg, __pyx_v_l2_reg, __pyx_v_X, __pyx_v_Y, __pyx_v_max_iter, __pyx_v_tol); + __pyx_r = __pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(__pyx_self, __pyx_v_W, __pyx_v_l1_reg, __pyx_v_l2_reg, __pyx_v_X, __pyx_v_Y, __pyx_v_max_iter, __pyx_v_tol, __pyx_v_rng, __pyx_v_random); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_W, double __pyx_v_l1_reg, double __pyx_v_l2_reg, __Pyx_memviewslice __pyx_v_X, __Pyx_memviewslice __pyx_v_Y, int __pyx_v_max_iter, double __pyx_v_tol) { +static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_descent_multi_task(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_W, double __pyx_v_l1_reg, double __pyx_v_l2_reg, __Pyx_memviewslice __pyx_v_X, __Pyx_memviewslice __pyx_v_Y, int __pyx_v_max_iter, double __pyx_v_tol, PyObject *__pyx_v_rng, int __pyx_v_random) { unsigned int __pyx_v_n_samples; unsigned int __pyx_v_n_features; unsigned int __pyx_v_n_tasks; @@ -6211,6 +6682,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc unsigned int __pyx_v_ii; unsigned int __pyx_v_jj; unsigned int __pyx_v_n_iter; + unsigned int __pyx_v_f_iter; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_v_rand_r_state_seed; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t *__pyx_v_rand_r_state; double *__pyx_v_X_ptr; double *__pyx_v_W_ptr; double *__pyx_v_Y_ptr; @@ -6231,15 +6705,15 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc PyObject *__pyx_t_8 = NULL; __Pyx_memviewslice __pyx_t_9 = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_t_10 = { 0, 0, { 0 }, { 0 }, { 0 } }; - Py_ssize_t __pyx_t_11; + __pyx_t_7sklearn_12linear_model_7cd_fast_UINT32_t __pyx_t_11; Py_ssize_t __pyx_t_12; Py_ssize_t __pyx_t_13; Py_ssize_t __pyx_t_14; Py_ssize_t __pyx_t_15; Py_ssize_t __pyx_t_16; Py_ssize_t __pyx_t_17; - int __pyx_t_18; - unsigned int __pyx_t_19; + Py_ssize_t __pyx_t_18; + int __pyx_t_19; unsigned int __pyx_t_20; unsigned int __pyx_t_21; unsigned int __pyx_t_22; @@ -6250,42 +6724,43 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc unsigned int __pyx_t_27; unsigned int __pyx_t_28; unsigned int __pyx_t_29; - int __pyx_t_30; - Py_ssize_t __pyx_t_31; + unsigned int __pyx_t_30; + int __pyx_t_31; Py_ssize_t __pyx_t_32; Py_ssize_t __pyx_t_33; Py_ssize_t __pyx_t_34; Py_ssize_t __pyx_t_35; Py_ssize_t __pyx_t_36; Py_ssize_t __pyx_t_37; - unsigned int __pyx_t_38; - Py_ssize_t __pyx_t_39; + Py_ssize_t __pyx_t_38; + unsigned int __pyx_t_39; Py_ssize_t __pyx_t_40; - int __pyx_t_41; + Py_ssize_t __pyx_t_41; int __pyx_t_42; int __pyx_t_43; - unsigned int __pyx_t_44; + int __pyx_t_44; unsigned int __pyx_t_45; - Py_ssize_t __pyx_t_46; + unsigned int __pyx_t_46; Py_ssize_t __pyx_t_47; - unsigned int __pyx_t_48; + Py_ssize_t __pyx_t_48; unsigned int __pyx_t_49; unsigned int __pyx_t_50; unsigned int __pyx_t_51; - Py_ssize_t __pyx_t_52; + unsigned int __pyx_t_52; Py_ssize_t __pyx_t_53; Py_ssize_t __pyx_t_54; Py_ssize_t __pyx_t_55; - unsigned int __pyx_t_56; + Py_ssize_t __pyx_t_56; unsigned int __pyx_t_57; unsigned int __pyx_t_58; unsigned int __pyx_t_59; + unsigned int __pyx_t_60; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("enet_coordinate_descent_multi_task", 0); - /* "sklearn/linear_model/cd_fast.pyx":595 + /* "sklearn/linear_model/cd_fast.pyx":642 * """ * # get the data information into easy vars * cdef unsigned int n_samples = X.shape[0] # <<<<<<<<<<<<<< @@ -6294,7 +6769,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_n_samples = (__pyx_v_X.shape[0]); - /* "sklearn/linear_model/cd_fast.pyx":596 + /* "sklearn/linear_model/cd_fast.pyx":643 * # get the data information into easy vars * cdef unsigned int n_samples = X.shape[0] * cdef unsigned int n_features = X.shape[1] # <<<<<<<<<<<<<< @@ -6303,7 +6778,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_n_features = (__pyx_v_X.shape[1]); - /* "sklearn/linear_model/cd_fast.pyx":597 + /* "sklearn/linear_model/cd_fast.pyx":644 * cdef unsigned int n_samples = X.shape[0] * cdef unsigned int n_features = X.shape[1] * cdef unsigned int n_tasks = Y.shape[1] # <<<<<<<<<<<<<< @@ -6312,23 +6787,23 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_n_tasks = (__pyx_v_Y.shape[1]); - /* "sklearn/linear_model/cd_fast.pyx":600 + /* "sklearn/linear_model/cd_fast.pyx":647 * * # to store XtA * cdef double[:, ::1] XtA = np.zeros((n_features, n_tasks)) # <<<<<<<<<<<<<< * cdef double XtA_axis1norm * cdef double dual_norm_XtA */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -6336,39 +6811,39 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(__pyx_t_4); - if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_5.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_XtA = __pyx_t_5; __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":605 + /* "sklearn/linear_model/cd_fast.pyx":652 * * # initial value of the residuals * cdef double[:, ::1] R = np.zeros((n_samples, n_tasks)) # <<<<<<<<<<<<<< * * cdef double[:] norm_cols_X = np.zeros(n_features) */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_samples); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_samples); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); @@ -6376,133 +6851,133 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc __Pyx_GIVEREF(__pyx_t_2); __pyx_t_4 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(__pyx_t_1); - if (unlikely(!__pyx_t_6.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_6.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_R = __pyx_t_6; __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":607 + /* "sklearn/linear_model/cd_fast.pyx":654 * cdef double[:, ::1] R = np.zeros((n_samples, n_tasks)) * * cdef double[:] norm_cols_X = np.zeros(n_features) # <<<<<<<<<<<<<< * cdef double[::1] tmp = np.zeros(n_tasks, dtype=np.float) * cdef double[:] w_ii = np.zeros(n_tasks, dtype=np.float) */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_features); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_1); - if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_norm_cols_X = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":608 + /* "sklearn/linear_model/cd_fast.pyx":655 * * cdef double[:] norm_cols_X = np.zeros(n_features) * cdef double[::1] tmp = np.zeros(n_tasks, dtype=np.float) # <<<<<<<<<<<<<< * cdef double[:] w_ii = np.zeros(n_tasks, dtype=np.float) * cdef double d_w_max */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dc_double(__pyx_t_8); - if (unlikely(!__pyx_t_9.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_9.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_tmp = __pyx_t_9; __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":609 + /* "sklearn/linear_model/cd_fast.pyx":656 * cdef double[:] norm_cols_X = np.zeros(n_features) * cdef double[::1] tmp = np.zeros(n_tasks, dtype=np.float) * cdef double[:] w_ii = np.zeros(n_tasks, dtype=np.float) # <<<<<<<<<<<<<< * cdef double d_w_max * cdef double w_max */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_v_n_tasks); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_4); - if (unlikely(!__pyx_t_10.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_10.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_w_ii = __pyx_t_10; __pyx_t_10.memview = NULL; __pyx_t_10.data = NULL; - /* "sklearn/linear_model/cd_fast.pyx":615 + /* "sklearn/linear_model/cd_fast.pyx":662 * cdef double nn * cdef double W_ii_abs_max * cdef double gap = tol + 1.0 # <<<<<<<<<<<<<< @@ -6511,7 +6986,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_gap = (__pyx_v_tol + 1.0); - /* "sklearn/linear_model/cd_fast.pyx":616 + /* "sklearn/linear_model/cd_fast.pyx":663 * cdef double W_ii_abs_max * cdef double gap = tol + 1.0 * cdef double d_w_tol = tol # <<<<<<<<<<<<<< @@ -6520,80 +6995,116 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_d_w_tol = __pyx_v_tol; - /* "sklearn/linear_model/cd_fast.pyx":623 + /* "sklearn/linear_model/cd_fast.pyx":670 * cdef unsigned int n_iter + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) # <<<<<<<<<<<<<< + * cdef UINT32_t* rand_r_state = &rand_r_state_seed + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s_randint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_e_7sklearn_12linear_model_7cd_fast_RAND_R_MAX); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_PyInt_As_npy_uint32(__pyx_t_8); if (unlikely((__pyx_t_11 == (npy_uint32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_rand_r_state_seed = __pyx_t_11; + + /* "sklearn/linear_model/cd_fast.pyx":671 + * cdef unsigned int f_iter + * cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + * cdef UINT32_t* rand_r_state = &rand_r_state_seed # <<<<<<<<<<<<<< + * + * cdef double* X_ptr = &X[0, 0] + */ + __pyx_v_rand_r_state = (&__pyx_v_rand_r_state_seed); + + /* "sklearn/linear_model/cd_fast.pyx":673 + * cdef UINT32_t* rand_r_state = &rand_r_state_seed * * cdef double* X_ptr = &X[0, 0] # <<<<<<<<<<<<<< * cdef double* W_ptr = &W[0, 0] * cdef double* Y_ptr = &Y[0, 0] */ - __pyx_t_11 = 0; __pyx_t_12 = 0; - __pyx_v_X_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_X.data) + __pyx_t_11)) ) + __pyx_t_12 * __pyx_v_X.strides[1]) )))); + __pyx_t_13 = 0; + __pyx_v_X_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_X.data) + __pyx_t_12)) ) + __pyx_t_13 * __pyx_v_X.strides[1]) )))); - /* "sklearn/linear_model/cd_fast.pyx":624 + /* "sklearn/linear_model/cd_fast.pyx":674 * * cdef double* X_ptr = &X[0, 0] * cdef double* W_ptr = &W[0, 0] # <<<<<<<<<<<<<< * cdef double* Y_ptr = &Y[0, 0] * cdef double* wii_ptr = &w_ii[0] */ - __pyx_t_13 = 0; __pyx_t_14 = 0; - __pyx_v_W_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_W.data) + __pyx_t_13)) ) + __pyx_t_14 * __pyx_v_W.strides[1]) )))); + __pyx_t_15 = 0; + __pyx_v_W_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_W.data) + __pyx_t_14)) ) + __pyx_t_15 * __pyx_v_W.strides[1]) )))); - /* "sklearn/linear_model/cd_fast.pyx":625 + /* "sklearn/linear_model/cd_fast.pyx":675 * cdef double* X_ptr = &X[0, 0] * cdef double* W_ptr = &W[0, 0] * cdef double* Y_ptr = &Y[0, 0] # <<<<<<<<<<<<<< * cdef double* wii_ptr = &w_ii[0] * */ - __pyx_t_15 = 0; __pyx_t_16 = 0; - __pyx_v_Y_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_15 * __pyx_v_Y.strides[0]) ) + __pyx_t_16 * __pyx_v_Y.strides[1]) )))); + __pyx_t_17 = 0; + __pyx_v_Y_ptr = (&(*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_16 * __pyx_v_Y.strides[0]) ) + __pyx_t_17 * __pyx_v_Y.strides[1]) )))); - /* "sklearn/linear_model/cd_fast.pyx":626 + /* "sklearn/linear_model/cd_fast.pyx":676 * cdef double* W_ptr = &W[0, 0] * cdef double* Y_ptr = &Y[0, 0] * cdef double* wii_ptr = &w_ii[0] # <<<<<<<<<<<<<< * * if l1_reg == 0: */ - __pyx_t_17 = 0; - __pyx_v_wii_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_w_ii.data + __pyx_t_17 * __pyx_v_w_ii.strides[0]) )))); + __pyx_t_18 = 0; + __pyx_v_wii_ptr = (&(*((double *) ( /* dim=0 */ (__pyx_v_w_ii.data + __pyx_t_18 * __pyx_v_w_ii.strides[0]) )))); - /* "sklearn/linear_model/cd_fast.pyx":628 + /* "sklearn/linear_model/cd_fast.pyx":678 * cdef double* wii_ptr = &w_ii[0] * * if l1_reg == 0: # <<<<<<<<<<<<<< * warnings.warn("Coordinate descent with l1_reg=0 may lead to unexpected" * " results and is discouraged.") */ - __pyx_t_18 = ((__pyx_v_l1_reg == 0.0) != 0); - if (__pyx_t_18) { + __pyx_t_19 = ((__pyx_v_l1_reg == 0.0) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":629 + /* "sklearn/linear_model/cd_fast.pyx":679 * * if l1_reg == 0: * warnings.warn("Coordinate descent with l1_reg=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L3; } __pyx_L3:; - /* "sklearn/linear_model/cd_fast.pyx":632 + /* "sklearn/linear_model/cd_fast.pyx":682 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -6607,88 +7118,88 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc #endif /*try:*/ { - /* "sklearn/linear_model/cd_fast.pyx":634 + /* "sklearn/linear_model/cd_fast.pyx":684 * with nogil: * # norm_cols_X = (np.asarray(X) ** 2).sum(axis=0) * for ii in range(n_features): # <<<<<<<<<<<<<< * for jj in range(n_samples): * norm_cols_X[ii] += X[jj, ii] ** 2 */ - __pyx_t_19 = __pyx_v_n_features; - for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) { - __pyx_v_ii = __pyx_t_20; + __pyx_t_20 = __pyx_v_n_features; + for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { + __pyx_v_ii = __pyx_t_21; - /* "sklearn/linear_model/cd_fast.pyx":635 + /* "sklearn/linear_model/cd_fast.pyx":685 * # norm_cols_X = (np.asarray(X) ** 2).sum(axis=0) * for ii in range(n_features): * for jj in range(n_samples): # <<<<<<<<<<<<<< * norm_cols_X[ii] += X[jj, ii] ** 2 * */ - __pyx_t_21 = __pyx_v_n_samples; - for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { - __pyx_v_jj = __pyx_t_22; + __pyx_t_22 = __pyx_v_n_samples; + for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { + __pyx_v_jj = __pyx_t_23; - /* "sklearn/linear_model/cd_fast.pyx":636 + /* "sklearn/linear_model/cd_fast.pyx":686 * for ii in range(n_features): * for jj in range(n_samples): * norm_cols_X[ii] += X[jj, ii] ** 2 # <<<<<<<<<<<<<< * * # R = Y - np.dot(X, W.T) */ - __pyx_t_23 = __pyx_v_jj; - __pyx_t_24 = __pyx_v_ii; + __pyx_t_24 = __pyx_v_jj; __pyx_t_25 = __pyx_v_ii; - *((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_25 * __pyx_v_norm_cols_X.strides[0]) )) += pow((*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_X.data) + __pyx_t_23)) ) + __pyx_t_24 * __pyx_v_X.strides[1]) ))), 2.0); + __pyx_t_26 = __pyx_v_ii; + *((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_26 * __pyx_v_norm_cols_X.strides[0]) )) += pow((*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_X.data) + __pyx_t_24)) ) + __pyx_t_25 * __pyx_v_X.strides[1]) ))), 2.0); } } - /* "sklearn/linear_model/cd_fast.pyx":639 + /* "sklearn/linear_model/cd_fast.pyx":689 * * # R = Y - np.dot(X, W.T) * for ii in range(n_samples): # <<<<<<<<<<<<<< * for jj in range(n_tasks): * R[ii, jj] = Y[ii, jj] - ( */ - __pyx_t_19 = __pyx_v_n_samples; - for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) { - __pyx_v_ii = __pyx_t_20; + __pyx_t_20 = __pyx_v_n_samples; + for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { + __pyx_v_ii = __pyx_t_21; - /* "sklearn/linear_model/cd_fast.pyx":640 + /* "sklearn/linear_model/cd_fast.pyx":690 * # R = Y - np.dot(X, W.T) * for ii in range(n_samples): * for jj in range(n_tasks): # <<<<<<<<<<<<<< * R[ii, jj] = Y[ii, jj] - ( * ddot(n_features, X_ptr + ii, n_samples, W_ptr + jj, n_tasks) */ - __pyx_t_21 = __pyx_v_n_tasks; - for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { - __pyx_v_jj = __pyx_t_22; + __pyx_t_22 = __pyx_v_n_tasks; + for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) { + __pyx_v_jj = __pyx_t_23; - /* "sklearn/linear_model/cd_fast.pyx":641 + /* "sklearn/linear_model/cd_fast.pyx":691 * for ii in range(n_samples): * for jj in range(n_tasks): * R[ii, jj] = Y[ii, jj] - ( # <<<<<<<<<<<<<< * ddot(n_features, X_ptr + ii, n_samples, W_ptr + jj, n_tasks) * ) */ - __pyx_t_26 = __pyx_v_ii; - __pyx_t_27 = __pyx_v_jj; + __pyx_t_27 = __pyx_v_ii; + __pyx_t_28 = __pyx_v_jj; - /* "sklearn/linear_model/cd_fast.pyx":642 + /* "sklearn/linear_model/cd_fast.pyx":692 * for jj in range(n_tasks): * R[ii, jj] = Y[ii, jj] - ( * ddot(n_features, X_ptr + ii, n_samples, W_ptr + jj, n_tasks) # <<<<<<<<<<<<<< * ) * */ - __pyx_t_28 = __pyx_v_ii; - __pyx_t_29 = __pyx_v_jj; - *((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_28 * __pyx_v_R.strides[0]) )) + __pyx_t_29)) )) = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_26 * __pyx_v_Y.strides[0]) ) + __pyx_t_27 * __pyx_v_Y.strides[1]) ))) - cblas_ddot(__pyx_v_n_features, (__pyx_v_X_ptr + __pyx_v_ii), __pyx_v_n_samples, (__pyx_v_W_ptr + __pyx_v_jj), __pyx_v_n_tasks)); + __pyx_t_29 = __pyx_v_ii; + __pyx_t_30 = __pyx_v_jj; + *((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_29 * __pyx_v_R.strides[0]) )) + __pyx_t_30)) )) = ((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_27 * __pyx_v_Y.strides[0]) ) + __pyx_t_28 * __pyx_v_Y.strides[1]) ))) - cblas_ddot(__pyx_v_n_features, (__pyx_v_X_ptr + __pyx_v_ii), __pyx_v_n_samples, (__pyx_v_W_ptr + __pyx_v_jj), __pyx_v_n_tasks)); } } - /* "sklearn/linear_model/cd_fast.pyx":646 + /* "sklearn/linear_model/cd_fast.pyx":696 * * # tol = tol * linalg.norm(Y, ord='fro') ** 2 * tol = tol * dnrm2(n_samples * n_tasks, Y_ptr, 1) ** 2 # <<<<<<<<<<<<<< @@ -6697,59 +7208,92 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_tol = (__pyx_v_tol * pow(cblas_dnrm2((__pyx_v_n_samples * __pyx_v_n_tasks), __pyx_v_Y_ptr, 1), 2.0)); - /* "sklearn/linear_model/cd_fast.pyx":648 + /* "sklearn/linear_model/cd_fast.pyx":698 * tol = tol * dnrm2(n_samples * n_tasks, Y_ptr, 1) ** 2 * * for n_iter in range(max_iter): # <<<<<<<<<<<<<< * w_max = 0.0 * d_w_max = 0.0 */ - __pyx_t_30 = __pyx_v_max_iter; - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_30; __pyx_t_19+=1) { - __pyx_v_n_iter = __pyx_t_19; + __pyx_t_31 = __pyx_v_max_iter; + for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_31; __pyx_t_20+=1) { + __pyx_v_n_iter = __pyx_t_20; - /* "sklearn/linear_model/cd_fast.pyx":649 + /* "sklearn/linear_model/cd_fast.pyx":699 * * for n_iter in range(max_iter): * w_max = 0.0 # <<<<<<<<<<<<<< * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates */ __pyx_v_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":650 + /* "sklearn/linear_model/cd_fast.pyx":700 * for n_iter in range(max_iter): * w_max = 0.0 * d_w_max = 0.0 # <<<<<<<<<<<<<< - * for ii in range(n_features): # Loop over coordinates - * if norm_cols_X[ii] == 0.0: + * for f_iter in range(n_features): # Loop over coordinates + * if random: */ __pyx_v_d_w_max = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":651 + /* "sklearn/linear_model/cd_fast.pyx":701 * w_max = 0.0 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< - * if norm_cols_X[ii] == 0.0: - * continue + * for f_iter in range(n_features): # Loop over coordinates # <<<<<<<<<<<<<< + * if random: + * ii = rand_int(n_features, rand_r_state) */ - __pyx_t_20 = __pyx_v_n_features; - for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { - __pyx_v_ii = __pyx_t_21; + __pyx_t_21 = __pyx_v_n_features; + for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { + __pyx_v_f_iter = __pyx_t_22; - /* "sklearn/linear_model/cd_fast.pyx":652 + /* "sklearn/linear_model/cd_fast.pyx":702 * d_w_max = 0.0 - * for ii in range(n_features): # Loop over coordinates + * for f_iter in range(n_features): # Loop over coordinates + * if random: # <<<<<<<<<<<<<< + * ii = rand_int(n_features, rand_r_state) + * else: + */ + __pyx_t_19 = (__pyx_v_random != 0); + if (__pyx_t_19) { + + /* "sklearn/linear_model/cd_fast.pyx":703 + * for f_iter in range(n_features): # Loop over coordinates + * if random: + * ii = rand_int(n_features, rand_r_state) # <<<<<<<<<<<<<< + * else: + * ii = f_iter + */ + __pyx_v_ii = __pyx_f_7sklearn_12linear_model_7cd_fast_rand_int(__pyx_v_n_features, __pyx_v_rand_r_state); + goto __pyx_L19; + } + /*else*/ { + + /* "sklearn/linear_model/cd_fast.pyx":705 + * ii = rand_int(n_features, rand_r_state) + * else: + * ii = f_iter # <<<<<<<<<<<<<< + * + * if norm_cols_X[ii] == 0.0: + */ + __pyx_v_ii = __pyx_v_f_iter; + } + __pyx_L19:; + + /* "sklearn/linear_model/cd_fast.pyx":707 + * ii = f_iter + * * if norm_cols_X[ii] == 0.0: # <<<<<<<<<<<<<< * continue * */ - __pyx_t_22 = __pyx_v_ii; - __pyx_t_18 = (((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_22 * __pyx_v_norm_cols_X.strides[0]) ))) == 0.0) != 0); - if (__pyx_t_18) { + __pyx_t_23 = __pyx_v_ii; + __pyx_t_19 = (((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_23 * __pyx_v_norm_cols_X.strides[0]) ))) == 0.0) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":653 - * for ii in range(n_features): # Loop over coordinates + /* "sklearn/linear_model/cd_fast.pyx":708 + * * if norm_cols_X[ii] == 0.0: * continue # <<<<<<<<<<<<<< * @@ -6758,7 +7302,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc goto __pyx_L17_continue; } - /* "sklearn/linear_model/cd_fast.pyx":656 + /* "sklearn/linear_model/cd_fast.pyx":711 * * # w_ii = W[:, ii] # Store previous value * dcopy(n_tasks, W_ptr + ii * n_tasks, 1, wii_ptr, 1) # <<<<<<<<<<<<<< @@ -6767,137 +7311,137 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ cblas_dcopy(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1, __pyx_v_wii_ptr, 1); - /* "sklearn/linear_model/cd_fast.pyx":659 + /* "sklearn/linear_model/cd_fast.pyx":714 * * # if np.sum(w_ii ** 2) != 0.0: # can do better * if dnrm2(n_tasks, wii_ptr, 1) != 0.0: # <<<<<<<<<<<<<< * # R += np.dot(X[:, ii][:, None], w_ii[None, :]) # rank 1 update * dger(CblasRowMajor, n_samples, n_tasks, 1.0, */ - __pyx_t_18 = ((cblas_dnrm2(__pyx_v_n_tasks, __pyx_v_wii_ptr, 1) != 0.0) != 0); - if (__pyx_t_18) { + __pyx_t_19 = ((cblas_dnrm2(__pyx_v_n_tasks, __pyx_v_wii_ptr, 1) != 0.0) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":663 + /* "sklearn/linear_model/cd_fast.pyx":718 * dger(CblasRowMajor, n_samples, n_tasks, 1.0, * X_ptr + ii * n_samples, 1, * wii_ptr, 1, &R[0, 0], n_tasks) # <<<<<<<<<<<<<< * * # tmp = np.dot(X[:, ii][None, :], R).ravel() */ - __pyx_t_31 = 0; __pyx_t_32 = 0; + __pyx_t_33 = 0; - /* "sklearn/linear_model/cd_fast.pyx":661 + /* "sklearn/linear_model/cd_fast.pyx":716 * if dnrm2(n_tasks, wii_ptr, 1) != 0.0: * # R += np.dot(X[:, ii][:, None], w_ii[None, :]) # rank 1 update * dger(CblasRowMajor, n_samples, n_tasks, 1.0, # <<<<<<<<<<<<<< * X_ptr + ii * n_samples, 1, * wii_ptr, 1, &R[0, 0], n_tasks) */ - cblas_dger(CblasRowMajor, __pyx_v_n_samples, __pyx_v_n_tasks, 1.0, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, __pyx_v_wii_ptr, 1, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_31 * __pyx_v_R.strides[0]) )) + __pyx_t_32)) )))), __pyx_v_n_tasks); - goto __pyx_L20; + cblas_dger(CblasRowMajor, __pyx_v_n_samples, __pyx_v_n_tasks, 1.0, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, __pyx_v_wii_ptr, 1, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_32 * __pyx_v_R.strides[0]) )) + __pyx_t_33)) )))), __pyx_v_n_tasks); + goto __pyx_L21; } - __pyx_L20:; + __pyx_L21:; - /* "sklearn/linear_model/cd_fast.pyx":667 + /* "sklearn/linear_model/cd_fast.pyx":722 * # tmp = np.dot(X[:, ii][None, :], R).ravel() * dgemv(CblasRowMajor, CblasTrans, * n_samples, n_tasks, 1.0, &R[0, 0], n_tasks, # <<<<<<<<<<<<<< * X_ptr + ii * n_samples, 1, 0.0, &tmp[0], 1) * */ - __pyx_t_33 = 0; __pyx_t_34 = 0; + __pyx_t_35 = 0; - /* "sklearn/linear_model/cd_fast.pyx":668 + /* "sklearn/linear_model/cd_fast.pyx":723 * dgemv(CblasRowMajor, CblasTrans, * n_samples, n_tasks, 1.0, &R[0, 0], n_tasks, * X_ptr + ii * n_samples, 1, 0.0, &tmp[0], 1) # <<<<<<<<<<<<<< * * # nn = sqrt(np.sum(tmp ** 2)) */ - __pyx_t_35 = 0; + __pyx_t_36 = 0; - /* "sklearn/linear_model/cd_fast.pyx":666 + /* "sklearn/linear_model/cd_fast.pyx":721 * * # tmp = np.dot(X[:, ii][None, :], R).ravel() * dgemv(CblasRowMajor, CblasTrans, # <<<<<<<<<<<<<< * n_samples, n_tasks, 1.0, &R[0, 0], n_tasks, * X_ptr + ii * n_samples, 1, 0.0, &tmp[0], 1) */ - cblas_dgemv(CblasRowMajor, CblasTrans, __pyx_v_n_samples, __pyx_v_n_tasks, 1.0, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_33 * __pyx_v_R.strides[0]) )) + __pyx_t_34)) )))), __pyx_v_n_tasks, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, 0.0, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_35)) )))), 1); + cblas_dgemv(CblasRowMajor, CblasTrans, __pyx_v_n_samples, __pyx_v_n_tasks, 1.0, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_34 * __pyx_v_R.strides[0]) )) + __pyx_t_35)) )))), __pyx_v_n_tasks, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, 0.0, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_36)) )))), 1); - /* "sklearn/linear_model/cd_fast.pyx":671 + /* "sklearn/linear_model/cd_fast.pyx":726 * * # nn = sqrt(np.sum(tmp ** 2)) * nn = dnrm2(n_tasks, &tmp[0], 1) # <<<<<<<<<<<<<< * * # W[:, ii] = tmp * fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg) */ - __pyx_t_36 = 0; - __pyx_v_nn = cblas_dnrm2(__pyx_v_n_tasks, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_36)) )))), 1); + __pyx_t_37 = 0; + __pyx_v_nn = cblas_dnrm2(__pyx_v_n_tasks, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_37)) )))), 1); - /* "sklearn/linear_model/cd_fast.pyx":674 + /* "sklearn/linear_model/cd_fast.pyx":729 * * # W[:, ii] = tmp * fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg) * dcopy(n_tasks, &tmp[0], 1, W_ptr + ii * n_tasks, 1) # <<<<<<<<<<<<<< * dscal(n_tasks, fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg), * W_ptr + ii * n_tasks, 1) */ - __pyx_t_37 = 0; - cblas_dcopy(__pyx_v_n_tasks, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_37)) )))), 1, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1); + __pyx_t_38 = 0; + cblas_dcopy(__pyx_v_n_tasks, (&(*((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_tmp.data) + __pyx_t_38)) )))), 1, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1); - /* "sklearn/linear_model/cd_fast.pyx":675 + /* "sklearn/linear_model/cd_fast.pyx":730 * # W[:, ii] = tmp * fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg) * dcopy(n_tasks, &tmp[0], 1, W_ptr + ii * n_tasks, 1) * dscal(n_tasks, fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg), # <<<<<<<<<<<<<< * W_ptr + ii * n_tasks, 1) * */ - __pyx_t_38 = __pyx_v_ii; + __pyx_t_39 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":676 + /* "sklearn/linear_model/cd_fast.pyx":731 * dcopy(n_tasks, &tmp[0], 1, W_ptr + ii * n_tasks, 1) * dscal(n_tasks, fmax(1. - l1_reg / nn, 0) / (norm_cols_X[ii] + l2_reg), * W_ptr + ii * n_tasks, 1) # <<<<<<<<<<<<<< * * # if np.sum(W[:, ii] ** 2) != 0.0: # can do better */ - cblas_dscal(__pyx_v_n_tasks, (__pyx_f_7sklearn_12linear_model_7cd_fast_fmax((1. - (__pyx_v_l1_reg / __pyx_v_nn)), 0.0) / ((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_38 * __pyx_v_norm_cols_X.strides[0]) ))) + __pyx_v_l2_reg)), (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1); + cblas_dscal(__pyx_v_n_tasks, (__pyx_f_7sklearn_12linear_model_7cd_fast_fmax((1. - (__pyx_v_l1_reg / __pyx_v_nn)), 0.0) / ((*((double *) ( /* dim=0 */ (__pyx_v_norm_cols_X.data + __pyx_t_39 * __pyx_v_norm_cols_X.strides[0]) ))) + __pyx_v_l2_reg)), (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1); - /* "sklearn/linear_model/cd_fast.pyx":679 + /* "sklearn/linear_model/cd_fast.pyx":734 * * # if np.sum(W[:, ii] ** 2) != 0.0: # can do better * if dnrm2(n_tasks, W_ptr + ii * n_tasks, 1) != 0.0: # <<<<<<<<<<<<<< * # R -= np.dot(X[:, ii][:, None], W[:, ii][None, :]) # Update residual : rank 1 update * dger(CblasRowMajor, n_samples, n_tasks, -1.0, */ - __pyx_t_18 = ((cblas_dnrm2(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1) != 0.0) != 0); - if (__pyx_t_18) { + __pyx_t_19 = ((cblas_dnrm2(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1) != 0.0) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":683 + /* "sklearn/linear_model/cd_fast.pyx":738 * dger(CblasRowMajor, n_samples, n_tasks, -1.0, * X_ptr + ii * n_samples, 1, W_ptr + ii * n_tasks, 1, * &R[0, 0], n_tasks) # <<<<<<<<<<<<<< * * # update the maximum absolute coefficient update */ - __pyx_t_39 = 0; __pyx_t_40 = 0; + __pyx_t_41 = 0; - /* "sklearn/linear_model/cd_fast.pyx":681 + /* "sklearn/linear_model/cd_fast.pyx":736 * if dnrm2(n_tasks, W_ptr + ii * n_tasks, 1) != 0.0: * # R -= np.dot(X[:, ii][:, None], W[:, ii][None, :]) # Update residual : rank 1 update * dger(CblasRowMajor, n_samples, n_tasks, -1.0, # <<<<<<<<<<<<<< * X_ptr + ii * n_samples, 1, W_ptr + ii * n_tasks, 1, * &R[0, 0], n_tasks) */ - cblas_dger(CblasRowMajor, __pyx_v_n_samples, __pyx_v_n_tasks, -1.0, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_39 * __pyx_v_R.strides[0]) )) + __pyx_t_40)) )))), __pyx_v_n_tasks); - goto __pyx_L21; + cblas_dger(CblasRowMajor, __pyx_v_n_samples, __pyx_v_n_tasks, -1.0, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), 1, (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_40 * __pyx_v_R.strides[0]) )) + __pyx_t_41)) )))), __pyx_v_n_tasks); + goto __pyx_L22; } - __pyx_L21:; + __pyx_L22:; - /* "sklearn/linear_model/cd_fast.pyx":686 + /* "sklearn/linear_model/cd_fast.pyx":741 * * # update the maximum absolute coefficient update * d_w_ii = diff_abs_max(n_tasks, W_ptr + ii * n_tasks, wii_ptr) # <<<<<<<<<<<<<< @@ -6906,17 +7450,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_d_w_ii = __pyx_f_7sklearn_12linear_model_7cd_fast_diff_abs_max(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks)), __pyx_v_wii_ptr); - /* "sklearn/linear_model/cd_fast.pyx":688 + /* "sklearn/linear_model/cd_fast.pyx":743 * d_w_ii = diff_abs_max(n_tasks, W_ptr + ii * n_tasks, wii_ptr) * * if d_w_ii > d_w_max: # <<<<<<<<<<<<<< * d_w_max = d_w_ii * */ - __pyx_t_18 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); - if (__pyx_t_18) { + __pyx_t_19 = ((__pyx_v_d_w_ii > __pyx_v_d_w_max) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":689 + /* "sklearn/linear_model/cd_fast.pyx":744 * * if d_w_ii > d_w_max: * d_w_max = d_w_ii # <<<<<<<<<<<<<< @@ -6924,11 +7468,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc * W_ii_abs_max = abs_max(n_tasks, W_ptr + ii * n_tasks) */ __pyx_v_d_w_max = __pyx_v_d_w_ii; - goto __pyx_L22; + goto __pyx_L23; } - __pyx_L22:; + __pyx_L23:; - /* "sklearn/linear_model/cd_fast.pyx":691 + /* "sklearn/linear_model/cd_fast.pyx":746 * d_w_max = d_w_ii * * W_ii_abs_max = abs_max(n_tasks, W_ptr + ii * n_tasks) # <<<<<<<<<<<<<< @@ -6937,17 +7481,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_W_ii_abs_max = __pyx_f_7sklearn_12linear_model_7cd_fast_abs_max(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_ii * __pyx_v_n_tasks))); - /* "sklearn/linear_model/cd_fast.pyx":692 + /* "sklearn/linear_model/cd_fast.pyx":747 * * W_ii_abs_max = abs_max(n_tasks, W_ptr + ii * n_tasks) * if W_ii_abs_max > w_max: # <<<<<<<<<<<<<< * w_max = W_ii_abs_max * */ - __pyx_t_18 = ((__pyx_v_W_ii_abs_max > __pyx_v_w_max) != 0); - if (__pyx_t_18) { + __pyx_t_19 = ((__pyx_v_W_ii_abs_max > __pyx_v_w_max) != 0); + if (__pyx_t_19) { - /* "sklearn/linear_model/cd_fast.pyx":693 + /* "sklearn/linear_model/cd_fast.pyx":748 * W_ii_abs_max = abs_max(n_tasks, W_ptr + ii * n_tasks) * if W_ii_abs_max > w_max: * w_max = W_ii_abs_max # <<<<<<<<<<<<<< @@ -6955,90 +7499,90 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: */ __pyx_v_w_max = __pyx_v_W_ii_abs_max; - goto __pyx_L23; + goto __pyx_L24; } - __pyx_L23:; + __pyx_L24:; __pyx_L17_continue:; } - /* "sklearn/linear_model/cd_fast.pyx":695 + /* "sklearn/linear_model/cd_fast.pyx":750 * w_max = W_ii_abs_max * * if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: # <<<<<<<<<<<<<< * # the biggest coordinate update of this iteration was smaller than * # the tolerance: check the duality gap as ultimate stopping */ - __pyx_t_18 = ((__pyx_v_w_max == 0.0) != 0); - if (!__pyx_t_18) { - __pyx_t_41 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); - if (!__pyx_t_41) { - __pyx_t_42 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); - __pyx_t_43 = __pyx_t_42; + __pyx_t_19 = ((__pyx_v_w_max == 0.0) != 0); + if (!__pyx_t_19) { + __pyx_t_42 = (((__pyx_v_d_w_max / __pyx_v_w_max) < __pyx_v_d_w_tol) != 0); + if (!__pyx_t_42) { + __pyx_t_43 = ((__pyx_v_n_iter == (__pyx_v_max_iter - 1)) != 0); + __pyx_t_44 = __pyx_t_43; } else { - __pyx_t_43 = __pyx_t_41; + __pyx_t_44 = __pyx_t_42; } - __pyx_t_41 = __pyx_t_43; + __pyx_t_42 = __pyx_t_44; } else { - __pyx_t_41 = __pyx_t_18; + __pyx_t_42 = __pyx_t_19; } - if (__pyx_t_41) { + if (__pyx_t_42) { - /* "sklearn/linear_model/cd_fast.pyx":701 + /* "sklearn/linear_model/cd_fast.pyx":756 * * # XtA = np.dot(X.T, R) - l2_reg * W.T * for ii in range(n_features): # <<<<<<<<<<<<<< * for jj in range(n_tasks): * XtA[ii, jj] = ddot( */ - __pyx_t_20 = __pyx_v_n_features; - for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { - __pyx_v_ii = __pyx_t_21; + __pyx_t_21 = __pyx_v_n_features; + for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { + __pyx_v_ii = __pyx_t_22; - /* "sklearn/linear_model/cd_fast.pyx":702 + /* "sklearn/linear_model/cd_fast.pyx":757 * # XtA = np.dot(X.T, R) - l2_reg * W.T * for ii in range(n_features): * for jj in range(n_tasks): # <<<<<<<<<<<<<< * XtA[ii, jj] = ddot( * n_samples, X_ptr + ii * n_samples, 1, */ - __pyx_t_44 = __pyx_v_n_tasks; - for (__pyx_t_45 = 0; __pyx_t_45 < __pyx_t_44; __pyx_t_45+=1) { - __pyx_v_jj = __pyx_t_45; + __pyx_t_45 = __pyx_v_n_tasks; + for (__pyx_t_46 = 0; __pyx_t_46 < __pyx_t_45; __pyx_t_46+=1) { + __pyx_v_jj = __pyx_t_46; - /* "sklearn/linear_model/cd_fast.pyx":705 + /* "sklearn/linear_model/cd_fast.pyx":760 * XtA[ii, jj] = ddot( * n_samples, X_ptr + ii * n_samples, 1, * &R[0, 0] + jj, n_tasks # <<<<<<<<<<<<<< * ) - l2_reg * W[jj, ii] * */ - __pyx_t_46 = 0; __pyx_t_47 = 0; + __pyx_t_48 = 0; - /* "sklearn/linear_model/cd_fast.pyx":706 + /* "sklearn/linear_model/cd_fast.pyx":761 * n_samples, X_ptr + ii * n_samples, 1, * &R[0, 0] + jj, n_tasks * ) - l2_reg * W[jj, ii] # <<<<<<<<<<<<<< * * # dual_norm_XtA = np.max(np.sqrt(np.sum(XtA ** 2, axis=1))) */ - __pyx_t_48 = __pyx_v_jj; - __pyx_t_49 = __pyx_v_ii; + __pyx_t_49 = __pyx_v_jj; + __pyx_t_50 = __pyx_v_ii; - /* "sklearn/linear_model/cd_fast.pyx":703 + /* "sklearn/linear_model/cd_fast.pyx":758 * for ii in range(n_features): * for jj in range(n_tasks): * XtA[ii, jj] = ddot( # <<<<<<<<<<<<<< * n_samples, X_ptr + ii * n_samples, 1, * &R[0, 0] + jj, n_tasks */ - __pyx_t_50 = __pyx_v_ii; - __pyx_t_51 = __pyx_v_jj; - *((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_50 * __pyx_v_XtA.strides[0]) )) + __pyx_t_51)) )) = (cblas_ddot(__pyx_v_n_samples, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, ((&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_46 * __pyx_v_R.strides[0]) )) + __pyx_t_47)) )))) + __pyx_v_jj), __pyx_v_n_tasks) - (__pyx_v_l2_reg * (*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_W.data) + __pyx_t_48)) ) + __pyx_t_49 * __pyx_v_W.strides[1]) ))))); + __pyx_t_51 = __pyx_v_ii; + __pyx_t_52 = __pyx_v_jj; + *((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_51 * __pyx_v_XtA.strides[0]) )) + __pyx_t_52)) )) = (cblas_ddot(__pyx_v_n_samples, (__pyx_v_X_ptr + (__pyx_v_ii * __pyx_v_n_samples)), 1, ((&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_47 * __pyx_v_R.strides[0]) )) + __pyx_t_48)) )))) + __pyx_v_jj), __pyx_v_n_tasks) - (__pyx_v_l2_reg * (*((double *) ( /* dim=1 */ (( /* dim=0 */ ((char *) (((double *) __pyx_v_W.data) + __pyx_t_49)) ) + __pyx_t_50 * __pyx_v_W.strides[1]) ))))); } } - /* "sklearn/linear_model/cd_fast.pyx":709 + /* "sklearn/linear_model/cd_fast.pyx":764 * * # dual_norm_XtA = np.max(np.sqrt(np.sum(XtA ** 2, axis=1))) * dual_norm_XtA = 0.0 # <<<<<<<<<<<<<< @@ -7047,39 +7591,39 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_dual_norm_XtA = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":710 + /* "sklearn/linear_model/cd_fast.pyx":765 * # dual_norm_XtA = np.max(np.sqrt(np.sum(XtA ** 2, axis=1))) * dual_norm_XtA = 0.0 * for ii in range(n_features): # <<<<<<<<<<<<<< * # np.sqrt(np.sum(XtA ** 2, axis=1)) * XtA_axis1norm = dnrm2(n_tasks, &XtA[0, 0] + ii * n_tasks, 1) */ - __pyx_t_20 = __pyx_v_n_features; - for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { - __pyx_v_ii = __pyx_t_21; + __pyx_t_21 = __pyx_v_n_features; + for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { + __pyx_v_ii = __pyx_t_22; - /* "sklearn/linear_model/cd_fast.pyx":712 + /* "sklearn/linear_model/cd_fast.pyx":767 * for ii in range(n_features): * # np.sqrt(np.sum(XtA ** 2, axis=1)) * XtA_axis1norm = dnrm2(n_tasks, &XtA[0, 0] + ii * n_tasks, 1) # <<<<<<<<<<<<<< * if XtA_axis1norm > dual_norm_XtA: * dual_norm_XtA = XtA_axis1norm */ - __pyx_t_52 = 0; __pyx_t_53 = 0; - __pyx_v_XtA_axis1norm = cblas_dnrm2(__pyx_v_n_tasks, ((&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_52 * __pyx_v_XtA.strides[0]) )) + __pyx_t_53)) )))) + (__pyx_v_ii * __pyx_v_n_tasks)), 1); + __pyx_t_54 = 0; + __pyx_v_XtA_axis1norm = cblas_dnrm2(__pyx_v_n_tasks, ((&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_XtA.data + __pyx_t_53 * __pyx_v_XtA.strides[0]) )) + __pyx_t_54)) )))) + (__pyx_v_ii * __pyx_v_n_tasks)), 1); - /* "sklearn/linear_model/cd_fast.pyx":713 + /* "sklearn/linear_model/cd_fast.pyx":768 * # np.sqrt(np.sum(XtA ** 2, axis=1)) * XtA_axis1norm = dnrm2(n_tasks, &XtA[0, 0] + ii * n_tasks, 1) * if XtA_axis1norm > dual_norm_XtA: # <<<<<<<<<<<<<< * dual_norm_XtA = XtA_axis1norm * */ - __pyx_t_41 = ((__pyx_v_XtA_axis1norm > __pyx_v_dual_norm_XtA) != 0); - if (__pyx_t_41) { + __pyx_t_42 = ((__pyx_v_XtA_axis1norm > __pyx_v_dual_norm_XtA) != 0); + if (__pyx_t_42) { - /* "sklearn/linear_model/cd_fast.pyx":714 + /* "sklearn/linear_model/cd_fast.pyx":769 * XtA_axis1norm = dnrm2(n_tasks, &XtA[0, 0] + ii * n_tasks, 1) * if XtA_axis1norm > dual_norm_XtA: * dual_norm_XtA = XtA_axis1norm # <<<<<<<<<<<<<< @@ -7087,23 +7631,23 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc * # TODO: use squared L2 norm directly */ __pyx_v_dual_norm_XtA = __pyx_v_XtA_axis1norm; - goto __pyx_L31; + goto __pyx_L32; } - __pyx_L31:; + __pyx_L32:; } - /* "sklearn/linear_model/cd_fast.pyx":719 + /* "sklearn/linear_model/cd_fast.pyx":774 * # R_norm = linalg.norm(R, ord='fro') * # w_norm = linalg.norm(W, ord='fro') * R_norm = dnrm2(n_samples * n_tasks, &R[0, 0], 1) # <<<<<<<<<<<<<< * w_norm = dnrm2(n_features * n_tasks, W_ptr, 1) * if (dual_norm_XtA > l1_reg): */ - __pyx_t_54 = 0; __pyx_t_55 = 0; - __pyx_v_R_norm = cblas_dnrm2((__pyx_v_n_samples * __pyx_v_n_tasks), (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_54 * __pyx_v_R.strides[0]) )) + __pyx_t_55)) )))), 1); + __pyx_t_56 = 0; + __pyx_v_R_norm = cblas_dnrm2((__pyx_v_n_samples * __pyx_v_n_tasks), (&(*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_55 * __pyx_v_R.strides[0]) )) + __pyx_t_56)) )))), 1); - /* "sklearn/linear_model/cd_fast.pyx":720 + /* "sklearn/linear_model/cd_fast.pyx":775 * # w_norm = linalg.norm(W, ord='fro') * R_norm = dnrm2(n_samples * n_tasks, &R[0, 0], 1) * w_norm = dnrm2(n_features * n_tasks, W_ptr, 1) # <<<<<<<<<<<<<< @@ -7112,17 +7656,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_w_norm = cblas_dnrm2((__pyx_v_n_features * __pyx_v_n_tasks), __pyx_v_W_ptr, 1); - /* "sklearn/linear_model/cd_fast.pyx":721 + /* "sklearn/linear_model/cd_fast.pyx":776 * R_norm = dnrm2(n_samples * n_tasks, &R[0, 0], 1) * w_norm = dnrm2(n_features * n_tasks, W_ptr, 1) * if (dual_norm_XtA > l1_reg): # <<<<<<<<<<<<<< * const = l1_reg / dual_norm_XtA * A_norm = R_norm * const */ - __pyx_t_41 = ((__pyx_v_dual_norm_XtA > __pyx_v_l1_reg) != 0); - if (__pyx_t_41) { + __pyx_t_42 = ((__pyx_v_dual_norm_XtA > __pyx_v_l1_reg) != 0); + if (__pyx_t_42) { - /* "sklearn/linear_model/cd_fast.pyx":722 + /* "sklearn/linear_model/cd_fast.pyx":777 * w_norm = dnrm2(n_features * n_tasks, W_ptr, 1) * if (dual_norm_XtA > l1_reg): * const = l1_reg / dual_norm_XtA # <<<<<<<<<<<<<< @@ -7131,7 +7675,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_const = (__pyx_v_l1_reg / __pyx_v_dual_norm_XtA); - /* "sklearn/linear_model/cd_fast.pyx":723 + /* "sklearn/linear_model/cd_fast.pyx":778 * if (dual_norm_XtA > l1_reg): * const = l1_reg / dual_norm_XtA * A_norm = R_norm * const # <<<<<<<<<<<<<< @@ -7140,7 +7684,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_A_norm = (__pyx_v_R_norm * __pyx_v_const); - /* "sklearn/linear_model/cd_fast.pyx":724 + /* "sklearn/linear_model/cd_fast.pyx":779 * const = l1_reg / dual_norm_XtA * A_norm = R_norm * const * gap = 0.5 * (R_norm ** 2 + A_norm ** 2) # <<<<<<<<<<<<<< @@ -7148,11 +7692,11 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc * const = 1.0 */ __pyx_v_gap = (0.5 * (pow(__pyx_v_R_norm, 2.0) + pow(__pyx_v_A_norm, 2.0))); - goto __pyx_L32; + goto __pyx_L33; } /*else*/ { - /* "sklearn/linear_model/cd_fast.pyx":726 + /* "sklearn/linear_model/cd_fast.pyx":781 * gap = 0.5 * (R_norm ** 2 + A_norm ** 2) * else: * const = 1.0 # <<<<<<<<<<<<<< @@ -7161,7 +7705,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_const = 1.0; - /* "sklearn/linear_model/cd_fast.pyx":727 + /* "sklearn/linear_model/cd_fast.pyx":782 * else: * const = 1.0 * gap = R_norm ** 2 # <<<<<<<<<<<<<< @@ -7170,9 +7714,9 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_gap = pow(__pyx_v_R_norm, 2.0); } - __pyx_L32:; + __pyx_L33:; - /* "sklearn/linear_model/cd_fast.pyx":730 + /* "sklearn/linear_model/cd_fast.pyx":785 * * # ry_sum = np.sum(R * y) * ry_sum = 0.0 # <<<<<<<<<<<<<< @@ -7181,44 +7725,44 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_ry_sum = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":731 + /* "sklearn/linear_model/cd_fast.pyx":786 * # ry_sum = np.sum(R * y) * ry_sum = 0.0 * for ii in range(n_samples): # <<<<<<<<<<<<<< * for jj in range(n_tasks): * ry_sum += R[ii, jj] * Y[ii, jj] */ - __pyx_t_20 = __pyx_v_n_samples; - for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { - __pyx_v_ii = __pyx_t_21; + __pyx_t_21 = __pyx_v_n_samples; + for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { + __pyx_v_ii = __pyx_t_22; - /* "sklearn/linear_model/cd_fast.pyx":732 + /* "sklearn/linear_model/cd_fast.pyx":787 * ry_sum = 0.0 * for ii in range(n_samples): * for jj in range(n_tasks): # <<<<<<<<<<<<<< * ry_sum += R[ii, jj] * Y[ii, jj] * */ - __pyx_t_44 = __pyx_v_n_tasks; - for (__pyx_t_45 = 0; __pyx_t_45 < __pyx_t_44; __pyx_t_45+=1) { - __pyx_v_jj = __pyx_t_45; + __pyx_t_45 = __pyx_v_n_tasks; + for (__pyx_t_46 = 0; __pyx_t_46 < __pyx_t_45; __pyx_t_46+=1) { + __pyx_v_jj = __pyx_t_46; - /* "sklearn/linear_model/cd_fast.pyx":733 + /* "sklearn/linear_model/cd_fast.pyx":788 * for ii in range(n_samples): * for jj in range(n_tasks): * ry_sum += R[ii, jj] * Y[ii, jj] # <<<<<<<<<<<<<< * * # l21_norm = np.sqrt(np.sum(W ** 2, axis=0)).sum() */ - __pyx_t_56 = __pyx_v_ii; - __pyx_t_57 = __pyx_v_jj; - __pyx_t_58 = __pyx_v_ii; - __pyx_t_59 = __pyx_v_jj; - __pyx_v_ry_sum = (__pyx_v_ry_sum + ((*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_56 * __pyx_v_R.strides[0]) )) + __pyx_t_57)) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_58 * __pyx_v_Y.strides[0]) ) + __pyx_t_59 * __pyx_v_Y.strides[1]) ))))); + __pyx_t_57 = __pyx_v_ii; + __pyx_t_58 = __pyx_v_jj; + __pyx_t_59 = __pyx_v_ii; + __pyx_t_60 = __pyx_v_jj; + __pyx_v_ry_sum = (__pyx_v_ry_sum + ((*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_R.data + __pyx_t_57 * __pyx_v_R.strides[0]) )) + __pyx_t_58)) ))) * (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_Y.data + __pyx_t_59 * __pyx_v_Y.strides[0]) ) + __pyx_t_60 * __pyx_v_Y.strides[1]) ))))); } } - /* "sklearn/linear_model/cd_fast.pyx":736 + /* "sklearn/linear_model/cd_fast.pyx":791 * * # l21_norm = np.sqrt(np.sum(W ** 2, axis=0)).sum() * l21_norm = 0.0 # <<<<<<<<<<<<<< @@ -7227,18 +7771,18 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_l21_norm = 0.0; - /* "sklearn/linear_model/cd_fast.pyx":737 + /* "sklearn/linear_model/cd_fast.pyx":792 * # l21_norm = np.sqrt(np.sum(W ** 2, axis=0)).sum() * l21_norm = 0.0 * for ii in range(n_features): # <<<<<<<<<<<<<< * # np.sqrt(np.sum(W ** 2, axis=0)) * l21_norm += dnrm2(n_tasks, W_ptr + n_tasks * ii, 1) */ - __pyx_t_20 = __pyx_v_n_features; - for (__pyx_t_21 = 0; __pyx_t_21 < __pyx_t_20; __pyx_t_21+=1) { - __pyx_v_ii = __pyx_t_21; + __pyx_t_21 = __pyx_v_n_features; + for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) { + __pyx_v_ii = __pyx_t_22; - /* "sklearn/linear_model/cd_fast.pyx":739 + /* "sklearn/linear_model/cd_fast.pyx":794 * for ii in range(n_features): * # np.sqrt(np.sum(W ** 2, axis=0)) * l21_norm += dnrm2(n_tasks, W_ptr + n_tasks * ii, 1) # <<<<<<<<<<<<<< @@ -7248,7 +7792,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc __pyx_v_l21_norm = (__pyx_v_l21_norm + cblas_dnrm2(__pyx_v_n_tasks, (__pyx_v_W_ptr + (__pyx_v_n_tasks * __pyx_v_ii)), 1)); } - /* "sklearn/linear_model/cd_fast.pyx":741 + /* "sklearn/linear_model/cd_fast.pyx":796 * l21_norm += dnrm2(n_tasks, W_ptr + n_tasks * ii, 1) * * gap += l1_reg * l21_norm - const * ry_sum + \ # <<<<<<<<<<<<<< @@ -7257,17 +7801,17 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ __pyx_v_gap = (__pyx_v_gap + (((__pyx_v_l1_reg * __pyx_v_l21_norm) - (__pyx_v_const * __pyx_v_ry_sum)) + (((0.5 * __pyx_v_l2_reg) * (1.0 + pow(__pyx_v_const, 2.0))) * pow(__pyx_v_w_norm, 2.0)))); - /* "sklearn/linear_model/cd_fast.pyx":744 + /* "sklearn/linear_model/cd_fast.pyx":799 * 0.5 * l2_reg * (1 + const ** 2) * (w_norm ** 2) * * if gap < tol: # <<<<<<<<<<<<<< * # return if we reached desired tolerance * break */ - __pyx_t_41 = ((__pyx_v_gap < __pyx_v_tol) != 0); - if (__pyx_t_41) { + __pyx_t_42 = ((__pyx_v_gap < __pyx_v_tol) != 0); + if (__pyx_t_42) { - /* "sklearn/linear_model/cd_fast.pyx":746 + /* "sklearn/linear_model/cd_fast.pyx":801 * if gap < tol: * # return if we reached desired tolerance * break # <<<<<<<<<<<<<< @@ -7276,14 +7820,14 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc */ goto __pyx_L16_break; } - goto __pyx_L24; + goto __pyx_L25; } - __pyx_L24:; + __pyx_L25:; } __pyx_L16_break:; } - /* "sklearn/linear_model/cd_fast.pyx":632 + /* "sklearn/linear_model/cd_fast.pyx":682 * " results and is discouraged.") * * with nogil: # <<<<<<<<<<<<<< @@ -7301,53 +7845,53 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_7cd_fast_6enet_coordinate_desc } } - /* "sklearn/linear_model/cd_fast.pyx":748 + /* "sklearn/linear_model/cd_fast.pyx":803 * break * * return np.asarray(W), gap, tol, n_iter + 1 # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_asarray); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_v_W, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_W, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_gap); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = PyFloat_FromDouble(__pyx_v_tol); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_n_iter + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_8 = 0; __pyx_t_4 = 0; __pyx_t_2 = 0; - __pyx_t_8 = 0; __pyx_t_1 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "sklearn/linear_model/cd_fast.pyx":580 + /* "sklearn/linear_model/cd_fast.pyx":626 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, # <<<<<<<<<<<<<< @@ -20653,6 +21197,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_enet_coordinate_descent_multi_ta, __pyx_k_enet_coordinate_descent_multi_ta, sizeof(__pyx_k_enet_coordinate_descent_multi_ta), 0, 0, 1, 1}, {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_f_iter, __pyx_k_f_iter, sizeof(__pyx_k_f_iter), 0, 0, 1, 1}, {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, {&__pyx_n_s_float, __pyx_k_float, sizeof(__pyx_k_float), 0, 0, 1, 1}, {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1}, @@ -20701,7 +21246,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 1, 1}, {&__pyx_n_s_q_dot_w, __pyx_k_q_dot_w, sizeof(__pyx_k_q_dot_w), 0, 0, 1, 1}, + {&__pyx_n_s_rand_r_state, __pyx_k_rand_r_state, sizeof(__pyx_k_rand_r_state), 0, 0, 1, 1}, + {&__pyx_n_s_rand_r_state_seed, __pyx_k_rand_r_state_seed, sizeof(__pyx_k_rand_r_state_seed), 0, 0, 1, 1}, + {&__pyx_n_s_randint, __pyx_k_randint, sizeof(__pyx_k_randint), 0, 0, 1, 1}, + {&__pyx_n_s_random, __pyx_k_random, sizeof(__pyx_k_random), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_rng, __pyx_k_rng, sizeof(__pyx_k_rng), 0, 0, 1, 1}, {&__pyx_n_s_ry_sum, __pyx_k_ry_sum, sizeof(__pyx_k_ry_sum), 0, 0, 1, 1}, {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, @@ -20738,7 +21288,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -20761,36 +21311,36 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "sklearn/linear_model/cd_fast.pyx":151 + /* "sklearn/linear_model/cd_fast.pyx":176 * * if alpha == 0: * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_alpha_0); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_alpha_0); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "sklearn/linear_model/cd_fast.pyx":492 + /* "sklearn/linear_model/cd_fast.pyx":533 * * if alpha == 0: * warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_alpha_0); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_alpha_0); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "sklearn/linear_model/cd_fast.pyx":629 + /* "sklearn/linear_model/cd_fast.pyx":679 * * if l1_reg == 0: * warnings.warn("Coordinate descent with l1_reg=0 may lead to unexpected" # <<<<<<<<<<<<<< * " results and is discouraged.") * */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_l1_reg_0); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_Coordinate_descent_with_l1_reg_0); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); @@ -20981,53 +21531,53 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__20); __Pyx_GIVEREF(__pyx_tuple__20); - /* "sklearn/linear_model/cd_fast.pyx":105 + /* "sklearn/linear_model/cd_fast.pyx":126 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, # <<<<<<<<<<<<<< * double alpha, double beta, * np.ndarray[DOUBLE, ndim=2] X, */ - __pyx_tuple__22 = PyTuple_Pack(30, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_X, __pyx_n_s_y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_norm_cols_X, __pyx_n_s_R, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_l1_norm, __pyx_n_s_ii, __pyx_n_s_i, __pyx_n_s_n_iter, __pyx_n_s_const, __pyx_n_s_A_norm2); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__22 = PyTuple_Pack(35, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_X, __pyx_n_s_y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_rng, __pyx_n_s_random, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_norm_cols_X, __pyx_n_s_R, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_l1_norm, __pyx_n_s_ii, __pyx_n_s_i, __pyx_n_s_n_iter, __pyx_n_s_f_iter, __pyx_n_s_rand_r_state_seed, __pyx_n_s_rand_r_state, __pyx_n_s_const, __pyx_n_s_A_norm2); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); - __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(8, 0, 30, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent, 105, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(10, 0, 35, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent, 126, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/linear_model/cd_fast.pyx":260 + /* "sklearn/linear_model/cd_fast.pyx":290 * @cython.wraparound(False) * @cython.cdivision(True) * def sparse_enet_coordinate_descent(double[:] w, # <<<<<<<<<<<<<< * double alpha, double beta, * double[:] X_data, int[:] X_indices, */ - __pyx_tuple__24 = PyTuple_Pack(40, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_X_data, __pyx_n_s_X_indices, __pyx_n_s_X_indptr, __pyx_n_s_y, __pyx_n_s_X_mean, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_ii, __pyx_n_s_norm_cols_X, __pyx_n_s_startptr, __pyx_n_s_endptr, __pyx_n_s_n_tasks, __pyx_n_s_R, __pyx_n_s_X_T_R, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_X_mean_ii, __pyx_n_s_R_sum, __pyx_n_s_normalize_sum, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_jj, __pyx_n_s_n_iter, __pyx_n_s_center, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_const, __pyx_n_s_A_norm2, __pyx_n_s_l1_norm); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__24 = PyTuple_Pack(45, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_X_data, __pyx_n_s_X_indices, __pyx_n_s_X_indptr, __pyx_n_s_y, __pyx_n_s_X_mean, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_rng, __pyx_n_s_random, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_ii, __pyx_n_s_norm_cols_X, __pyx_n_s_startptr, __pyx_n_s_endptr, __pyx_n_s_n_tasks, __pyx_n_s_R, __pyx_n_s_X_T_R, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_X_mean_ii, __pyx_n_s_R_sum, __pyx_n_s_normalize_sum, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_jj, __pyx_n_s_n_iter, __pyx_n_s_f_iter, __pyx_n_s_rand_r_state_seed, __pyx_n_s_rand_r_state, __pyx_n_s_center, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_const, __pyx_n_s_A_norm2, __pyx_n_s_l1_norm); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__24); __Pyx_GIVEREF(__pyx_tuple__24); - __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(11, 0, 40, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_sparse_enet_coordinate_descent, 260, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(13, 0, 45, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_sparse_enet_coordinate_descent, 290, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/linear_model/cd_fast.pyx":448 + /* "sklearn/linear_model/cd_fast.pyx":485 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, # <<<<<<<<<<<<<< * double[:, :] Q, double[:] q, double[:] y, - * int max_iter, double tol, bint positive=0): + * int max_iter, double tol, object rng, */ - __pyx_tuple__26 = PyTuple_Pack(33, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_Q, __pyx_n_s_q, __pyx_n_s_y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_H, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_dual_norm_XtA, __pyx_n_s_ii, __pyx_n_s_n_iter, __pyx_n_s_y_norm2, __pyx_n_s_Q_ptr, __pyx_n_s_H_ptr, __pyx_n_s_XtA_ptr, __pyx_n_s_q_dot_w, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_const, __pyx_n_s_A_norm2); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__26 = PyTuple_Pack(38, __pyx_n_s_w, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_Q, __pyx_n_s_q, __pyx_n_s_y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_rng, __pyx_n_s_random, __pyx_n_s_positive, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_H, __pyx_n_s_XtA, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_dual_norm_XtA, __pyx_n_s_ii, __pyx_n_s_n_iter, __pyx_n_s_f_iter, __pyx_n_s_rand_r_state_seed, __pyx_n_s_rand_r_state, __pyx_n_s_y_norm2, __pyx_n_s_Q_ptr, __pyx_n_s_H_ptr, __pyx_n_s_XtA_ptr, __pyx_n_s_q_dot_w, __pyx_n_s_R_norm2, __pyx_n_s_w_norm2, __pyx_n_s_const, __pyx_n_s_A_norm2); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); - __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(9, 0, 33, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent_gram, 448, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(11, 0, 38, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent_gram, 485, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/linear_model/cd_fast.pyx":580 + /* "sklearn/linear_model/cd_fast.pyx":626 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, # <<<<<<<<<<<<<< * double l2_reg, double[::1, :] X, * double[:, :] Y, int max_iter, */ - __pyx_tuple__28 = PyTuple_Pack(37, __pyx_n_s_W, __pyx_n_s_l1_reg, __pyx_n_s_l2_reg, __pyx_n_s_X, __pyx_n_s_Y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_XtA, __pyx_n_s_XtA_axis1norm, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R, __pyx_n_s_norm_cols_X, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_nn, __pyx_n_s_W_ii_abs_max, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_ry_sum, __pyx_n_s_l21_norm, __pyx_n_s_ii, __pyx_n_s_jj, __pyx_n_s_n_iter, __pyx_n_s_X_ptr, __pyx_n_s_W_ptr, __pyx_n_s_Y_ptr, __pyx_n_s_wii_ptr, __pyx_n_s_R_norm, __pyx_n_s_w_norm, __pyx_n_s_const, __pyx_n_s_A_norm); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__28 = PyTuple_Pack(42, __pyx_n_s_W, __pyx_n_s_l1_reg, __pyx_n_s_l2_reg, __pyx_n_s_X, __pyx_n_s_Y, __pyx_n_s_max_iter, __pyx_n_s_tol, __pyx_n_s_rng, __pyx_n_s_random, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_tasks, __pyx_n_s_XtA, __pyx_n_s_XtA_axis1norm, __pyx_n_s_dual_norm_XtA, __pyx_n_s_R, __pyx_n_s_norm_cols_X, __pyx_n_s_tmp, __pyx_n_s_w_ii, __pyx_n_s_d_w_max, __pyx_n_s_w_max, __pyx_n_s_d_w_ii, __pyx_n_s_nn, __pyx_n_s_W_ii_abs_max, __pyx_n_s_gap, __pyx_n_s_d_w_tol, __pyx_n_s_ry_sum, __pyx_n_s_l21_norm, __pyx_n_s_ii, __pyx_n_s_jj, __pyx_n_s_n_iter, __pyx_n_s_f_iter, __pyx_n_s_rand_r_state_seed, __pyx_n_s_rand_r_state, __pyx_n_s_X_ptr, __pyx_n_s_W_ptr, __pyx_n_s_Y_ptr, __pyx_n_s_wii_ptr, __pyx_n_s_R_norm, __pyx_n_s_w_norm, __pyx_n_s_const, __pyx_n_s_A_norm); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); - __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(7, 0, 37, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent_multi_ta, 580, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(9, 0, 42, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_enet_coordinate_descent_multi_ta, 626, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "View.MemoryView":276 * return self.name @@ -21276,60 +21826,60 @@ PyMODINIT_FUNC PyInit_cd_fast(void) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "sklearn/linear_model/cd_fast.pyx":21 - * + * ctypedef np.uint32_t UINT32_t * * np.import_array() # <<<<<<<<<<<<<< * - * + * # The following two functions are shamelessly copied from the tree code. */ import_array(); - /* "sklearn/linear_model/cd_fast.pyx":105 + /* "sklearn/linear_model/cd_fast.pyx":126 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, # <<<<<<<<<<<<<< * double alpha, double beta, * np.ndarray[DOUBLE, ndim=2] X, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_1enet_coordinate_descent, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_1enet_coordinate_descent, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/linear_model/cd_fast.pyx":260 + /* "sklearn/linear_model/cd_fast.pyx":290 * @cython.wraparound(False) * @cython.cdivision(True) * def sparse_enet_coordinate_descent(double[:] w, # <<<<<<<<<<<<<< * double alpha, double beta, * double[:] X_data, int[:] X_indices, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordinate_descent, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_3sparse_enet_coordinate_descent, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sparse_enet_coordinate_descent, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sparse_enet_coordinate_descent, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/linear_model/cd_fast.pyx":448 + /* "sklearn/linear_model/cd_fast.pyx":485 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, # <<<<<<<<<<<<<< * double[:, :] Q, double[:] q, double[:] y, - * int max_iter, double tol, bint positive=0): + * int max_iter, double tol, object rng, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_5enet_coordinate_descent_gram, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_5enet_coordinate_descent_gram, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent_gram, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent_gram, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/linear_model/cd_fast.pyx":580 + /* "sklearn/linear_model/cd_fast.pyx":626 * @cython.wraparound(False) * @cython.cdivision(True) * def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, # <<<<<<<<<<<<<< * double l2_reg, double[::1, :] X, * double[:, :] Y, int max_iter, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_7enet_coordinate_descent_multi_task, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_12linear_model_7cd_fast_7enet_coordinate_descent_multi_task, NULL, __pyx_n_s_sklearn_linear_model_cd_fast); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent_multi_ta, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_enet_coordinate_descent_multi_ta, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "sklearn/linear_model/cd_fast.pyx":1 @@ -21507,6 +22057,70 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { return result; } +static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { + long r = a % b; + r += ((r != 0) & ((r ^ b) < 0)) * b; + return r; +} + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_Restore(type, value, tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(type, value, tb); +#endif +} + +static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, + int full_traceback) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + if (full_traceback) { + Py_XINCREF(old_exc); + Py_XINCREF(old_val); + Py_XINCREF(old_tb); + __Pyx_ErrRestore(old_exc, old_val, old_tb); + PyErr_PrintEx(1); + } + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, @@ -22273,37 +22887,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { return result; } -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - static int __Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview, int ndim, @@ -22982,33 +23565,6 @@ static CYTHON_INLINE long __Pyx_div_long(long a, long b) { return q; } -static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, - CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, - int full_traceback) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - if (full_traceback) { - Py_XINCREF(old_exc); - Py_XINCREF(old_val); - Py_XINCREF(old_tb); - __Pyx_ErrRestore(old_exc, old_val, old_tb); - PyErr_PrintEx(1); - } - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) PyObject *ob = PyCapsule_New(vtable, 0, 0); @@ -23652,6 +24208,106 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) } } +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE npy_uint32 __Pyx_PyInt_As_npy_uint32(PyObject *x) { + const npy_uint32 neg_one = (npy_uint32) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(npy_uint32) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(npy_uint32, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to npy_uint32"); + return (npy_uint32) -1; + } + return (npy_uint32) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(npy_uint32)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (npy_uint32) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to npy_uint32"); + return (npy_uint32) -1; + } + if (sizeof(npy_uint32) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(npy_uint32) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(npy_uint32, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(npy_uint32)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(npy_uint32) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(npy_uint32) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(npy_uint32) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(npy_uint32, long, PyLong_AsLong) + } else if (sizeof(npy_uint32) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(npy_uint32, long long, PyLong_AsLongLong) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + npy_uint32 val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (npy_uint32) -1; + } + } else { + npy_uint32 val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (npy_uint32) -1; + val = __Pyx_PyInt_As_npy_uint32(tmp); + Py_DECREF(tmp); + return val; + } +} + #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" diff --git a/sklearn/linear_model/cd_fast.pyx b/sklearn/linear_model/cd_fast.pyx index 62ec7e2886ff9..5b7f85cbd7b9f 100644 --- a/sklearn/linear_model/cd_fast.pyx +++ b/sklearn/linear_model/cd_fast.pyx @@ -16,10 +16,31 @@ from cpython cimport bool import warnings ctypedef np.float64_t DOUBLE - +ctypedef np.uint32_t UINT32_t np.import_array() +# The following two functions are shamelessly copied from the tree code. + +cdef enum: + # Max value for our rand_r replacement (near the bottom). + # We don't use RAND_MAX because it's different across platforms and + # particularly tiny on Windows/MSVC. + RAND_R_MAX = 0x7FFFFFFF + + +cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil: + seed[0] ^= (seed[0] << 13) + seed[0] ^= (seed[0] >> 17) + seed[0] ^= (seed[0] << 5) + + return seed[0] % (RAND_R_MAX + 1) + + +cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) nogil: + """Generate a random integer in [0; end).""" + return our_rand_r(random_state) % end + cdef inline double fmax(double x, double y) nogil: if x > y: @@ -106,7 +127,8 @@ def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, double alpha, double beta, np.ndarray[DOUBLE, ndim=2] X, np.ndarray[DOUBLE, ndim=1] y, - int max_iter, double tol, bint positive=0): + int max_iter, double tol, + object rng, bint random=0, bint positive=0): """Cython version of the coordinate descent algorithm for Elastic-Net regression @@ -146,6 +168,9 @@ def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, cdef unsigned int ii cdef unsigned int i cdef unsigned int n_iter + cdef unsigned int f_iter + cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + cdef UINT32_t* rand_r_state = &rand_r_state_seed if alpha == 0: warnings.warn("Coordinate descent with alpha=0 may lead to unexpected" @@ -166,7 +191,12 @@ def enet_coordinate_descent(np.ndarray[DOUBLE, ndim=1] w, for n_iter in range(max_iter): w_max = 0.0 d_w_max = 0.0 - for ii in range(n_features): # Loop over coordinates + for f_iter in range(n_features): # Loop over coordinates + if random: + ii = rand_int(n_features, rand_r_state) + else: + ii = f_iter + if norm_cols_X[ii] == 0.0: continue @@ -262,7 +292,8 @@ def sparse_enet_coordinate_descent(double[:] w, double[:] X_data, int[:] X_indices, int[:] X_indptr, double[:] y, double[:] X_mean, int max_iter, - double tol, bint positive=0): + double tol, object rng, bint random=0, + bint positive=0): """Cython version of the coordinate descent algorithm for Elastic-Net We minimize: @@ -305,11 +336,14 @@ def sparse_enet_coordinate_descent(double[:] w, cdef double d_w_tol = tol cdef unsigned int jj cdef unsigned int n_iter + cdef unsigned int f_iter + cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + cdef UINT32_t* rand_r_state = &rand_r_state_seed cdef bint center = False with nogil: # center = (X_mean != 0).any() - for ii in range(n_samples): + for ii in range(n_features): if X_mean[ii]: center = True break @@ -338,13 +372,17 @@ def sparse_enet_coordinate_descent(double[:] w, w_max = 0.0 d_w_max = 0.0 - startptr = X_indptr[0] - for ii in range(n_features): # Loop over coordinates + for f_iter in range(n_features): # Loop over coordinates + if random: + ii = rand_int(n_features, rand_r_state) + else: + ii = f_iter if norm_cols_X[ii] == 0.0: continue + startptr = X_indptr[ii] endptr = X_indptr[ii + 1] w_ii = w[ii] # Store previous value X_mean_ii = X_mean[ii] @@ -390,7 +428,6 @@ def sparse_enet_coordinate_descent(double[:] w, if w[ii] > w_max: w_max = w[ii] - startptr = endptr if w_max == 0.0 or d_w_max / w_max < d_w_tol or n_iter == max_iter - 1: # the biggest coordinate update of this iteration was smaller than # the tolerance: check the duality gap as ultimate stopping @@ -398,15 +435,15 @@ def sparse_enet_coordinate_descent(double[:] w, # sparse X.T / dense R dot product for ii in range(n_features): + X_T_R[ii] = 0.0 for jj in range(X_indptr[ii], X_indptr[ii + 1]): X_T_R[ii] += X_data[jj] * R[X_indices[jj]] R_sum = 0.0 for jj in range(n_samples): R_sum += R[jj] X_T_R[ii] -= X_mean[ii] * R_sum + XtA[ii] = X_T_R[ii] - beta * w[ii] - for jj in range(n_features): - XtA[jj] = X_T_R[jj] - beta * w[jj] if positive: dual_norm_XtA = max(n_features, &XtA[0]) else: @@ -447,7 +484,8 @@ def sparse_enet_coordinate_descent(double[:] w, @cython.cdivision(True) def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, double[:, :] Q, double[:] q, double[:] y, - int max_iter, double tol, bint positive=0): + int max_iter, double tol, object rng, + bint random=0, bint positive=0): """Cython version of the coordinate descent algorithm for Elastic-Net regression @@ -481,6 +519,9 @@ def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, cdef double dual_norm_XtA cdef unsigned int ii cdef unsigned int n_iter + cdef unsigned int f_iter + cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + cdef UINT32_t* rand_r_state = &rand_r_state_seed cdef double y_norm2 = np.dot(y, y) cdef double* Q_ptr = &Q[0, 0] @@ -496,7 +537,12 @@ def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, for n_iter in range(max_iter): w_max = 0.0 d_w_max = 0.0 - for ii in range(n_features): # Loop over coordinates + for f_iter in range(n_features): # Loop over coordinates + if random: + ii = rand_int(n_features, rand_r_state) + else: + ii = f_iter + if Q[ii, ii] == 0.0: continue @@ -580,7 +626,8 @@ def enet_coordinate_descent_gram(double[:] w, double alpha, double beta, def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, double l2_reg, double[::1, :] X, double[:, :] Y, int max_iter, - double tol): + double tol, object rng, + bint random=0): """Cython version of the coordinate descent algorithm for Elastic-Net mult-task regression @@ -619,6 +666,9 @@ def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, cdef unsigned int ii cdef unsigned int jj cdef unsigned int n_iter + cdef unsigned int f_iter + cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX) + cdef UINT32_t* rand_r_state = &rand_r_state_seed cdef double* X_ptr = &X[0, 0] cdef double* W_ptr = &W[0, 0] @@ -648,7 +698,12 @@ def enet_coordinate_descent_multi_task(double[::1, :] W, double l1_reg, for n_iter in range(max_iter): w_max = 0.0 d_w_max = 0.0 - for ii in range(n_features): # Loop over coordinates + for f_iter in range(n_features): # Loop over coordinates + if random: + ii = rand_int(n_features, rand_r_state) + else: + ii = f_iter + if norm_cols_X[ii] == 0.0: continue diff --git a/sklearn/linear_model/coordinate_descent.py b/sklearn/linear_model/coordinate_descent.py index 5f6c621e47c28..929f7c8507e0d 100644 --- a/sklearn/linear_model/coordinate_descent.py +++ b/sklearn/linear_model/coordinate_descent.py @@ -16,6 +16,7 @@ from ..base import RegressorMixin from .base import center_data, sparse_center_data from ..utils import check_array +from ..utils.validation import check_random_state from ..cross_validation import _check_cv as check_cv from ..externals.joblib import Parallel, delayed from ..externals import six @@ -86,7 +87,7 @@ def _alpha_grid(X, y, Xy=None, l1_ratio=1.0, fit_intercept=True, # since we should not destroy the sparsity of such matrices. _, _, X_mean, _, X_std = sparse_center_data(X, y, fit_intercept, normalize) - mean_dot = np.sum(X_mean[:, np.newaxis] * y, axis=1) + mean_dot = X_mean * np.sum(y) if Xy.ndim == 1: Xy = Xy[:, np.newaxis] @@ -462,6 +463,12 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, max_iter = params.get('max_iter', 1000) dual_gaps = np.empty(n_alphas) n_iters = [] + + rng = check_random_state(params.get('random_state', None)) + selection = params.get('selection', 'cyclic') + if selection not in ['random', 'cyclic']: + raise ValueError("selection should be either random or cyclic.") + random = (selection == 'random') models = [] if not multi_output: @@ -482,17 +489,18 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, model = cd_fast.sparse_enet_coordinate_descent( coef_, l1_reg, l2_reg, X.data, X.indices, X.indptr, y, X_sparse_scaling, - max_iter, tol, positive) + max_iter, tol, rng, random, positive) elif multi_output: model = cd_fast.enet_coordinate_descent_multi_task( - coef_, l1_reg, l2_reg, X, y, max_iter, tol) + coef_, l1_reg, l2_reg, X, y, max_iter, tol, rng, random) elif isinstance(precompute, np.ndarray): model = cd_fast.enet_coordinate_descent_gram( coef_, l1_reg, l2_reg, precompute, Xy, y, max_iter, - tol, positive) + tol, rng, random, positive) elif precompute is False: model = cd_fast.enet_coordinate_descent( - coef_, l1_reg, l2_reg, X, y, max_iter, tol, positive) + coef_, l1_reg, l2_reg, X, y, max_iter, tol, rng, random, + positive) else: raise ValueError("Precompute should be one of True, False, " "'auto' or array-like") @@ -616,19 +624,30 @@ class ElasticNet(LinearModel, RegressorMixin): positive: bool, optional When set to ``True``, forces the coefficients to be positive. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``coef_`` : array, shape = (n_features,) | (n_targets, n_features) + coef_ : array, shape = (n_features,) | (n_targets, n_features) parameter vector (w in the cost function formula) - ``sparse_coef_`` : scipy.sparse matrix, shape = (n_features, 1) | \ + sparse_coef_ : scipy.sparse matrix, shape = (n_features, 1) | \ (n_targets, n_features) ``sparse_coef_`` is a readonly property derived from ``coef_`` - ``intercept_`` : float | array, shape = (n_targets,) + intercept_ : float | array, shape = (n_targets,) independent term in decision function. - ``n_iter_`` : array-like, shape (n_targets,) + n_iter_ : array-like, shape (n_targets,) number of iterations run by the coordinate descent solver to reach the specified tolerance. @@ -647,7 +666,8 @@ class ElasticNet(LinearModel, RegressorMixin): def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, precompute='auto', max_iter=1000, - copy_X=True, tol=1e-4, warm_start=False, positive=False): + copy_X=True, tol=1e-4, warm_start=False, positive=False, + random_state=None, selection='cyclic'): self.alpha = alpha self.l1_ratio = l1_ratio self.coef_ = None @@ -660,6 +680,8 @@ def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, self.warm_start = warm_start self.positive = positive self.intercept_ = 0.0 + self.random_state = random_state + self.selection = selection def fit(self, X, y): """Fit model with coordinate descent. @@ -703,6 +725,9 @@ def fit(self, X, y): n_samples, n_features = X.shape n_targets = y.shape[1] + if self.selection not in ['cyclic', 'random']: + raise ValueError("selection should be either random or cyclic.") + if not self.warm_start or self.coef_ is None: coef_ = np.zeros((n_targets, n_features), dtype=np.float64, order='F') @@ -727,7 +752,9 @@ def fit(self, X, y): fit_intercept=False, normalize=False, copy_X=True, verbose=False, tol=self.tol, positive=self.positive, X_mean=X_mean, X_std=X_std, return_n_iter=True, - coef_init=coef_[k], max_iter=self.max_iter) + coef_init=coef_[k], max_iter=self.max_iter, + random_state=self.random_state, + selection=self.selection) coef_[k] = this_coef[:, 0] dual_gaps_[k] = this_dual_gap[0] self.n_iter_.append(this_iter[0]) @@ -820,19 +847,30 @@ class Lasso(ElasticNet): positive : bool, optional When set to ``True``, forces the coefficients to be positive. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``coef_`` : array, shape = (n_features,) | (n_targets, n_features) + coef_ : array, shape = (n_features,) | (n_targets, n_features) parameter vector (w in the cost function formula) - ``sparse_coef_`` : scipy.sparse matrix, shape = (n_features, 1) | \ + sparse_coef_ : scipy.sparse matrix, shape = (n_features, 1) | \ (n_targets, n_features) ``sparse_coef_`` is a readonly property derived from ``coef_`` - ``intercept_`` : float | array, shape = (n_targets,) + intercept_ : float | array, shape = (n_targets,) independent term in decision function. - ``n_iter_`` : int | array-like, shape (n_targets,) + n_iter_ : int | array-like, shape (n_targets,) number of iterations run by the coordinate descent solver to reach the specified tolerance. @@ -842,8 +880,8 @@ class Lasso(ElasticNet): >>> clf = linear_model.Lasso(alpha=0.1) >>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2]) Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000, - normalize=False, positive=False, precompute='auto', tol=0.0001, - warm_start=False) + normalize=False, positive=False, precompute='auto', random_state=None, + selection='cyclic', tol=0.0001, warm_start=False) >>> print(clf.coef_) [ 0.85 0. ] >>> print(clf.intercept_) @@ -869,12 +907,14 @@ class Lasso(ElasticNet): def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, precompute='auto', copy_X=True, max_iter=1000, - tol=1e-4, warm_start=False, positive=False): + tol=1e-4, warm_start=False, positive=False, + random_state=None, selection='cyclic'): super(Lasso, self).__init__( alpha=alpha, l1_ratio=1.0, fit_intercept=fit_intercept, normalize=normalize, precompute=precompute, copy_X=copy_X, max_iter=max_iter, tol=tol, warm_start=warm_start, - positive=positive) + positive=positive, random_state=random_state, + selection=selection) ############################################################################### @@ -994,7 +1034,7 @@ class LinearModelCV(six.with_metaclass(ABCMeta, LinearModel)): def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, normalize=False, precompute='auto', max_iter=1000, tol=1e-4, copy_X=True, cv=None, verbose=False, n_jobs=1, - positive=False): + positive=False, random_state=None, selection='cyclic'): self.eps = eps self.n_alphas = n_alphas self.alphas = alphas @@ -1008,6 +1048,8 @@ def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, self.verbose = verbose self.n_jobs = n_jobs self.positive = positive + self.random_state = random_state + self.selection = selection def fit(self, X, y): """Fit linear model with coordinate descent @@ -1051,6 +1093,9 @@ def fit(self, X, y): else: model = MultiTaskLasso() + if self.selection not in ["random", "cyclic"]: + raise ValueError("selection should be either random or cyclic.") + # This makes sure that there is no duplication in memory. # Dealing right with copy_X is important in the following: # Multiple functions touch X and subsamples of X and can induce a @@ -1225,28 +1270,39 @@ class LassoCV(LinearModelCV, RegressorMixin): positive : bool, optional If positive, restrict regression coefficients to be positive + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``alpha_`` : float + alpha_ : float The amount of penalization chosen by cross validation - ``coef_`` : array, shape = (n_features,) | (n_targets, n_features) + coef_ : array, shape = (n_features,) | (n_targets, n_features) parameter vector (w in the cost function formula) - ``intercept_`` : float | array, shape = (n_targets,) + intercept_ : float | array, shape = (n_targets,) independent term in decision function. - ``mse_path_`` : array, shape = (n_alphas, n_folds) + mse_path_ : array, shape = (n_alphas, n_folds) mean square error for the test set on each fold, varying alpha - ``alphas_`` : numpy array, shape = (n_alphas,) + alphas_ : numpy array, shape = (n_alphas,) The grid of alphas used for fitting - ``dual_gap_`` : ndarray, shape () + dual_gap_ : ndarray, shape () The dual gap at the end of the optimization for the optimal alpha (``alpha_``). - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. @@ -1271,12 +1327,13 @@ class LassoCV(LinearModelCV, RegressorMixin): def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, normalize=False, precompute='auto', max_iter=1000, tol=1e-4, copy_X=True, cv=None, verbose=False, n_jobs=1, - positive=False): + positive=False, random_state=None, selection='cyclic'): super(LassoCV, self).__init__( eps=eps, n_alphas=n_alphas, alphas=alphas, fit_intercept=fit_intercept, normalize=normalize, precompute=precompute, max_iter=max_iter, tol=tol, copy_X=copy_X, - cv=cv, verbose=verbose, n_jobs=n_jobs, positive=positive) + cv=cv, verbose=verbose, n_jobs=n_jobs, positive=positive, + random_state=random_state, selection=selection) class ElasticNetCV(LinearModelCV, RegressorMixin): @@ -1340,29 +1397,40 @@ class ElasticNetCV(LinearModelCV, RegressorMixin): positive : bool, optional When set to ``True``, forces the coefficients to be positive. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``alpha_`` : float + alpha_ : float The amount of penalization chosen by cross validation - ``l1_ratio_`` : float + l1_ratio_ : float The compromise between l1 and l2 penalization chosen by cross validation - ``coef_`` : array, shape = (n_features,) | (n_targets, n_features) + coef_ : array, shape = (n_features,) | (n_targets, n_features) Parameter vector (w in the cost function formula), - ``intercept_`` : float | array, shape = (n_targets, n_features) + intercept_ : float | array, shape = (n_targets, n_features) Independent term in the decision function. - ``mse_path_`` : array, shape = (n_l1_ratio, n_alpha, n_folds) + mse_path_ : array, shape = (n_l1_ratio, n_alpha, n_folds) Mean square error for the test set on each fold, varying l1_ratio and alpha. - ``alphas_`` : numpy array, shape = (n_alphas,) or (n_l1_ratio, n_alphas) + alphas_ : numpy array, shape = (n_alphas,) or (n_l1_ratio, n_alphas) The grid of alphas used for fitting, for each l1_ratio. - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. @@ -1402,7 +1470,8 @@ class ElasticNetCV(LinearModelCV, RegressorMixin): def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, normalize=False, precompute='auto', max_iter=1000, tol=1e-4, cv=None, copy_X=True, - verbose=0, n_jobs=1, positive=False): + verbose=0, n_jobs=1, positive=False, random_state=None, + selection='cyclic'): self.l1_ratio = l1_ratio self.eps = eps self.n_alphas = n_alphas @@ -1417,7 +1486,8 @@ def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, self.verbose = verbose self.n_jobs = n_jobs self.positive = positive - + self.random_state = random_state + self.selection = selection ############################################################################### # Multi Task ElasticNet and Lasso models (with joint feature selection) @@ -1472,16 +1542,27 @@ class MultiTaskElasticNet(Lasso): When set to ``True``, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``intercept_`` : array, shape = (n_tasks,) + intercept_ : array, shape = (n_tasks,) Independent term in decision function. - ``coef_`` : array, shape = (n_tasks, n_features) + coef_ : array, shape = (n_tasks, n_features) Parameter vector (W in the cost function formula). If a 1D y is \ passed in at fit (non multi-task usage), ``coef_`` is then a 1D array - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance. @@ -1492,8 +1573,8 @@ class MultiTaskElasticNet(Lasso): >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]]) ... #doctest: +NORMALIZE_WHITESPACE MultiTaskElasticNet(alpha=0.1, copy_X=True, fit_intercept=True, - l1_ratio=0.5, max_iter=1000, normalize=False, tol=0.0001, - warm_start=False) + l1_ratio=0.5, max_iter=1000, normalize=False, random_state=None, + selection='cyclic', tol=0.0001, warm_start=False) >>> print(clf.coef_) [[ 0.45663524 0.45612256] [ 0.45663524 0.45612256]] @@ -1513,7 +1594,7 @@ class MultiTaskElasticNet(Lasso): """ def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, copy_X=True, max_iter=1000, tol=1e-4, - warm_start=False): + warm_start=False, random_state=None, selection='cyclic'): self.l1_ratio = l1_ratio self.alpha = alpha self.coef_ = None @@ -1523,6 +1604,8 @@ def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, self.copy_X = copy_X self.tol = tol self.warm_start = warm_start + self.random_state = random_state + self.selection = selection def fit(self, X, y): """Fit MultiTaskLasso model with coordinate descent @@ -1575,9 +1658,14 @@ def fit(self, X, y): self.coef_ = np.asfortranarray(self.coef_) # coef contiguous in memory + if self.selection not in ['random', 'cyclic']: + raise ValueError("selection should be either random or cyclic.") + random = (self.selection == 'random') + self.coef_, self.dual_gap_, self.eps_, self.n_iter_ = \ cd_fast.enet_coordinate_descent_multi_task( - self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol) + self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol, + check_random_state(self.random_state), random) self._set_intercept(X_mean, y_mean, X_std) @@ -1631,15 +1719,26 @@ class MultiTaskLasso(MultiTaskElasticNet): When set to ``True``, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4 + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``coef_`` : array, shape = (n_tasks, n_features) + coef_ : array, shape = (n_tasks, n_features) parameter vector (W in the cost function formula) - ``intercept_`` : array, shape = (n_tasks,) + intercept_ : array, shape = (n_tasks,) independent term in decision function. - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance. @@ -1649,7 +1748,8 @@ class MultiTaskLasso(MultiTaskElasticNet): >>> clf = linear_model.MultiTaskLasso(alpha=0.1) >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]]) MultiTaskLasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000, - normalize=False, tol=0.0001, warm_start=False) + normalize=False, random_state=None, selection='cyclic', tol=0.0001, + warm_start=False) >>> print(clf.coef_) [[ 0.89393398 0. ] [ 0.89393398 0. ]] @@ -1668,7 +1768,8 @@ class MultiTaskLasso(MultiTaskElasticNet): should be directly passed as a Fortran-contiguous numpy array. """ def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, - copy_X=True, max_iter=1000, tol=1e-4, warm_start=False): + copy_X=True, max_iter=1000, tol=1e-4, warm_start=False, + random_state=None, selection='cyclic'): self.alpha = alpha self.coef_ = None self.fit_intercept = fit_intercept @@ -1678,6 +1779,8 @@ def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, self.tol = tol self.warm_start = warm_start self.l1_ratio = 1.0 + self.random_state = random_state + self.selection = selection class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin): @@ -1748,28 +1851,39 @@ class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin): all the CPUs. Note that this is used only if multiple values for l1_ratio are given. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``intercept_`` : array, shape (n_tasks,) + intercept_ : array, shape (n_tasks,) Independent term in decision function. - ``coef_`` : array, shape (n_tasks, n_features) + coef_ : array, shape (n_tasks, n_features) Parameter vector (W in the cost function formula). - ``alpha_`` : float + alpha_ : float The amount of penalization chosen by cross validation - ``mse_path_`` : array, shape (n_alphas, n_folds) or + mse_path_ : array, shape (n_alphas, n_folds) or (n_l1_ratio, n_alphas, n_folds) mean square error for the test set on each fold, varying alpha - ``alphas_`` : numpy array, shape (n_alphas,) or (n_l1_ratio, n_alphas) + alphas_ : numpy array, shape (n_alphas,) or (n_l1_ratio, n_alphas) The grid of alphas used for fitting, for each l1_ratio - ``l1_ratio_`` : float + l1_ratio_ : float best l1_ratio obtained by cross-validation. - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. @@ -1782,7 +1896,8 @@ class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin): ... #doctest: +NORMALIZE_WHITESPACE MultiTaskElasticNetCV(alphas=None, copy_X=True, cv=None, eps=0.001, fit_intercept=True, l1_ratio=0.5, max_iter=1000, n_alphas=100, - n_jobs=1, normalize=False, tol=0.0001, verbose=0) + n_jobs=1, normalize=False, random_state=None, selection='cyclic', + tol=0.0001, verbose=0) >>> print(clf.coef_) [[ 0.52875032 0.46958558] [ 0.52875032 0.46958558]] @@ -1807,7 +1922,7 @@ class MultiTaskElasticNetCV(LinearModelCV, RegressorMixin): def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, normalize=False, max_iter=1000, tol=1e-4, cv=None, copy_X=True, - verbose=0, n_jobs=1): + verbose=0, n_jobs=1, random_state=None, selection='cyclic'): self.l1_ratio = l1_ratio self.eps = eps self.n_alphas = n_alphas @@ -1820,6 +1935,8 @@ def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None, self.copy_X = copy_X self.verbose = verbose self.n_jobs = n_jobs + self.random_state = random_state + self.selection = selection class MultiTaskLassoCV(LinearModelCV, RegressorMixin): @@ -1882,24 +1999,35 @@ class MultiTaskLassoCV(LinearModelCV, RegressorMixin): all the CPUs. Note that this is used only if multiple values for l1_ratio are given. + selection : str, default 'cyclic' + If set to 'random', a random coefficient is updated every iteration + rather than looping over features sequentially by default. This + (setting to 'random') often leads to significantly faster convergence + especially when tol is higher than 1e-4. + + random_state : int, RandomState instance, or None (default) + The seed of the pseudo random number generator that selects + a random feature to update. Useful only when selection is set to + 'random'. + Attributes ---------- - ``intercept_`` : array, shape (n_tasks,) + intercept_ : array, shape (n_tasks,) Independent term in decision function. - ``coef_`` : array, shape (n_tasks, n_features) + coef_ : array, shape (n_tasks, n_features) Parameter vector (W in the cost function formula). - ``alpha_`` : float + alpha_ : float The amount of penalization chosen by cross validation - ``mse_path_`` : array, shape (n_alphas, n_folds) + mse_path_ : array, shape (n_alphas, n_folds) mean square error for the test set on each fold, varying alpha - ``alphas_`` : numpy array, shape (n_alphas,) + alphas_ : numpy array, shape (n_alphas,) The grid of alphas used for fitting. - ``n_iter_`` : int + n_iter_ : int number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha. @@ -1920,9 +2048,11 @@ class MultiTaskLassoCV(LinearModelCV, RegressorMixin): def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True, normalize=False, max_iter=1000, tol=1e-4, copy_X=True, - cv=None, verbose=False, n_jobs=1): + cv=None, verbose=False, n_jobs=1, random_state=None, + selection='cyclic'): super(MultiTaskLassoCV, self).__init__( eps=eps, n_alphas=n_alphas, alphas=alphas, fit_intercept=fit_intercept, normalize=normalize, max_iter=max_iter, tol=tol, copy_X=copy_X, - cv=cv, verbose=verbose, n_jobs=n_jobs) + cv=cv, verbose=verbose, n_jobs=n_jobs, random_state=random_state, + selection=selection) diff --git a/sklearn/linear_model/least_angle.py b/sklearn/linear_model/least_angle.py index 3a589ba023788..4dd214bda2db3 100644 --- a/sklearn/linear_model/least_angle.py +++ b/sklearn/linear_model/least_angle.py @@ -202,7 +202,7 @@ def lars_path(X, y, Xy=None, Gram=None, max_iter=500, alpha[0] = C / n_samples if alpha[0] <= alpha_min: # early stopping - if not (abs(alpha[0] - alpha_min) < tiny): + if not (abs(alpha[0] - alpha_min) < 10 * np.finfo(np.float32).eps): # interpolation factor 0 <= ss < 1 if n_iter > 0: # In the first iteration, all alphas are zero, the formula @@ -494,26 +494,26 @@ class Lars(LinearModel, RegressorMixin): Attributes ---------- - ``alphas_`` : array, shape (n_alphas + 1,) | list of n_targets such arrays + alphas_ : array, shape (n_alphas + 1,) | list of n_targets such arrays Maximum of covariances (in absolute value) at each iteration. \ ``n_alphas`` is either ``n_nonzero_coefs`` or ``n_features``, \ whichever is smaller. - ``active_`` : list, length = n_alphas | list of n_targets such lists + active_ : list, length = n_alphas | list of n_targets such lists Indices of active variables at the end of the path. - ``coef_path_`` : array, shape (n_features, n_alphas + 1) \ + coef_path_ : array, shape (n_features, n_alphas + 1) \ | list of n_targets such arrays The varying values of the coefficients along the path. It is not present if the ``fit_path`` parameter is ``False``. - ``coef_`` : array, shape (n_features,) or (n_targets, n_features) + coef_ : array, shape (n_features,) or (n_targets, n_features) Parameter vector (w in the formulation formula). - ``intercept_`` : float | array, shape (n_targets,) + intercept_ : float | array, shape (n_targets,) Independent term in decision function. - ``n_iter_`` : array-like or int + n_iter_ : array-like or int The number of iterations taken by lars_path to find the grid of alphas for each target. @@ -708,27 +708,27 @@ class LassoLars(Lars): Attributes ---------- - ``alphas_`` : array, shape (n_alphas + 1,) | list of n_targets such arrays + alphas_ : array, shape (n_alphas + 1,) | list of n_targets such arrays Maximum of covariances (in absolute value) at each iteration. \ ``n_alphas`` is either ``max_iter``, ``n_features``, or the number of \ nodes in the path with correlation greater than ``alpha``, whichever \ is smaller. - ``active_`` : list, length = n_alphas | list of n_targets such lists + active_ : list, length = n_alphas | list of n_targets such lists Indices of active variables at the end of the path. - ``coef_path_`` : array, shape (n_features, n_alphas + 1) or list + coef_path_ : array, shape (n_features, n_alphas + 1) or list If a list is passed it's expected to be one of n_targets such arrays. The varying values of the coefficients along the path. It is not present if the ``fit_path`` parameter is ``False``. - ``coef_`` : array, shape (n_features,) or (n_targets, n_features) + coef_ : array, shape (n_features,) or (n_targets, n_features) Parameter vector (w in the formulation formula). - ``intercept_`` : float | array, shape (n_targets,) + intercept_ : float | array, shape (n_targets,) Independent term in decision function. - ``n_iter_`` : array-like or int. + n_iter_ : array-like or int. The number of iterations taken by lars_path to find the grid of alphas for each target. @@ -910,29 +910,29 @@ class LarsCV(Lars): Attributes ---------- - ``coef_`` : array, shape (n_features,) + coef_ : array, shape (n_features,) parameter vector (w in the formulation formula) - ``intercept_`` : float + intercept_ : float independent term in decision function - ``coef_path_`` : array, shape (n_features, n_alphas) + coef_path_ : array, shape (n_features, n_alphas) the varying values of the coefficients along the path - ``alpha_`` : float + alpha_ : float the estimated regularization parameter alpha - ``alphas_`` : array, shape (n_alphas,) + alphas_ : array, shape (n_alphas,) the different values of alpha along the path - ``cv_alphas_`` : array, shape (n_cv_alphas,) + cv_alphas_ : array, shape (n_cv_alphas,) all the values of alpha along the path for the different folds - ``cv_mse_path_`` : array, shape (n_folds, n_cv_alphas) + cv_mse_path_ : array, shape (n_folds, n_cv_alphas) the mean square error on left-out for each fold along the path (alpha values given by ``cv_alphas``) - ``n_iter_`` : array-like or int + n_iter_ : array-like or int the number of iterations run by Lars with the optimal alpha. See also @@ -1085,29 +1085,29 @@ class LassoLarsCV(LarsCV): Attributes ---------- - ``coef_`` : array, shape (n_features,) + coef_ : array, shape (n_features,) parameter vector (w in the formulation formula) - ``intercept_`` : float + intercept_ : float independent term in decision function. - ``coef_path_`` : array, shape (n_features, n_alphas) + coef_path_ : array, shape (n_features, n_alphas) the varying values of the coefficients along the path - ``alpha_`` : float + alpha_ : float the estimated regularization parameter alpha - ``alphas_`` : array, shape (n_alphas,) + alphas_ : array, shape (n_alphas,) the different values of alpha along the path - ``cv_alphas_`` : array, shape (n_cv_alphas,) + cv_alphas_ : array, shape (n_cv_alphas,) all the values of alpha along the path for the different folds - ``cv_mse_path_`` : array, shape (n_folds, n_cv_alphas) + cv_mse_path_ : array, shape (n_folds, n_cv_alphas) the mean square error on left-out for each fold along the path (alpha values given by ``cv_alphas``) - ``n_iter_`` : array-like or int + n_iter_ : array-like or int the number of iterations run by Lars with the optimal alpha. Notes @@ -1181,16 +1181,16 @@ class LassoLarsIC(LassoLars): Attributes ---------- - ``coef_`` : array, shape (n_features,) + coef_ : array, shape (n_features,) parameter vector (w in the formulation formula) - ``intercept_`` : float + intercept_ : float independent term in decision function. - ``alpha_`` : float + alpha_ : float the alpha parameter chosen by the information criterion - ``n_iter_`` : int + n_iter_ : int number of iterations run by lars_path to find the grid of alphas. @@ -1287,7 +1287,8 @@ def fit(self, X, y, copy_X=True): df[k] = np.sum(mask) self.alphas_ = alphas_ - self.criterion_ = n_samples * np.log(mean_squared_error) + K * df + with np.errstate(divide='ignore'): + self.criterion_ = n_samples * np.log(mean_squared_error) + K * df n_best = np.argmin(self.criterion_) self.alpha_ = alphas_[n_best] diff --git a/sklearn/linear_model/logistic.py b/sklearn/linear_model/logistic.py index b567a3aa4d827..d9f3f48f564fb 100644 --- a/sklearn/linear_model/logistic.py +++ b/sklearn/linear_model/logistic.py @@ -6,6 +6,7 @@ # Fabian Pedregosa # Alexandre Gramfort # Manoj Kumar +# Lars Buitinck import numbers import warnings @@ -15,12 +16,14 @@ from .base import LinearClassifierMixin, SparseCoefMixin, BaseEstimator from ..feature_selection.from_model import _LearntSelectorMixin -from ..preprocessing import LabelEncoder -from ..svm.base import BaseLibLinear +from ..preprocessing import LabelEncoder, LabelBinarizer +from ..svm.base import _fit_liblinear from ..utils import check_array, check_consistent_length, compute_class_weight -from ..utils.extmath import log_logistic, safe_sparse_dot +from ..utils.extmath import (logsumexp, log_logistic, safe_sparse_dot, + squared_norm) from ..utils.optimize import newton_cg -from ..utils.validation import as_float_array, DataConversionWarning +from ..utils.validation import (as_float_array, DataConversionWarning, + check_X_y) from ..utils.fixes import expit from ..externals.joblib import Parallel, delayed from ..cross_validation import _check_cv @@ -224,11 +227,72 @@ def Hs(s): return out, grad, Hs +def _multinomial_loss_grad(w, X, Y, alpha, sample_weight): + """Computes the multinomial loss and its gradient. + + Parameters + ---------- + w : ndarray, shape (n_classes * n_features,) or + (n_classes * (n_features + 1),) + Coefficient vector. + + X : {array-like, sparse matrix}, shape (n_samples, n_features) + Training data. + + y : ndarray, shape (n_samples, n_classes) + Transformed labels according to the output of LabelBinarizer. + + alpha : float + Regularization parameter. alpha is equal to 1 / C. + + sample_weight : ndarray, shape (n_samples,) optional + Array of weights that are assigned to individual samples. + + Returns + ------- + loss : float + Multinomial loss. + + grad : ndarray, shape (n_classes * n_features,) or + (n_classes * (n_features + 1),) + Ravelled gradient of the logistic loss. + """ + _, n_classes = Y.shape + _, n_features = X.shape + + fit_intercept = (w.size == n_classes * (n_features + 1)) + w = w.reshape(Y.shape[1], -1) + + sample_weight = sample_weight[:, np.newaxis] + if fit_intercept: + grad = np.zeros((n_classes, n_features + 1)) + intercept = w[:, -1] + w = w[:, :-1] + else: + grad = np.zeros((n_classes, n_features)) + n_features = X.shape[1] + intercept = 0 + + p = safe_sparse_dot(X, w.T) + p += intercept + p -= logsumexp(p, axis=1).reshape(-1, 1) + + loss = -(sample_weight * Y * p).sum() + .5 * alpha * squared_norm(w) + p = np.exp(p, p) + diff = sample_weight * (p - Y) + grad[:, :n_features] = safe_sparse_dot(diff.T, X) + grad[:, :n_features] += alpha * w + if fit_intercept: + grad[:, -1] = diff.sum(axis=0) + + return loss, grad.ravel() + + def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, max_iter=100, tol=1e-4, verbose=0, solver='lbfgs', coef=None, copy=True, class_weight=None, dual=False, penalty='l2', - intercept_scaling=1.): + intercept_scaling=1., multi_class='ovr'): """Compute a Logistic Regression model for a list of regularization parameters. @@ -267,7 +331,8 @@ def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, where ``g_i`` is the i-th component of the gradient. verbose : int - Print convergence message if True. + For the liblinear and lbfgs solvers set verbose to any positive + number for verbosity. solver : {'lbfgs', 'newton-cg', 'liblinear'} Numerical solver to use. @@ -308,6 +373,13 @@ def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased. + multi_class : str, {'ovr', 'multinomial'} + Multiclass option can be either 'ovr' or 'multinomial'. If the option + chosen is 'ovr', then a binary problem is fit for each label. Else + the loss minimised is the multinomial loss fit across + the entire probability distribution. Works only for the 'lbfgs' + solver. + Returns ------- coefs : ndarray, shape (n_cs, n_features) or (n_cs, n_features + 1) @@ -326,78 +398,135 @@ def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, if isinstance(Cs, numbers.Integral): Cs = np.logspace(-4, 4, Cs) + if multi_class not in ['multinomial', 'ovr']: + raise ValueError("multi_class can be either 'multinomial' or 'ovr'" + "got %s" % multi_class) + + if multi_class == 'multinomial' and solver != 'lbfgs': + raise ValueError("Solver %s cannot solve problems with " + "a multinomial backend." % solver) + + if solver not in ['liblinear', 'newton-cg', 'lbfgs']: + raise ValueError("Logistic Regression supports only liblinear," + " newton-cg and lbfgs solvers. got %s" % solver) + + if solver != 'liblinear': + if penalty != 'l2': + raise ValueError("newton-cg and lbfgs solvers support only " + "l2 penalties, got %s penalty." % penalty) + if dual: + raise ValueError("newton-cg and lbfgs solvers support only " + "dual=False, got dual=%s" % dual) + # Preprocessing. X = check_array(X, accept_sparse='csc', dtype=np.float64) y = check_array(y, ensure_2d=False, copy=copy) + _, n_features = X.shape check_consistent_length(X, y) - n_classes = np.unique(y) + classes = np.unique(y) - if pos_class is None: - if (n_classes.size > 2): - raise ValueError('To fit OvA, use the pos_class argument') + if pos_class is None and multi_class != 'multinomial': + if (classes.size > 2): + raise ValueError('To fit OvR, use the pos_class argument') # np.unique(y) gives labels in sorted order. - pos_class = n_classes[1] + pos_class = classes[1] # If class_weights is a dict (provided by the user), the weights # are assigned to the original labels. If it is "auto", then - # the class_weights are assigned after masking the labels with a OvA. + # the class_weights are assigned after masking the labels with a OvR. sample_weight = np.ones(X.shape[0]) le = LabelEncoder() if isinstance(class_weight, dict): if solver == "liblinear": - if n_classes.size == 2: + if classes.size == 2: # Reconstruct the weights with keys 1 and -1 - temp = {} - temp[1] = class_weight[pos_class] - temp[-1] = class_weight[n_classes[0]] + temp = {1: class_weight[pos_class], + -1: class_weight[classes[0]]} class_weight = temp.copy() else: - raise ValueError("In LogisticRegressionCV the liblinear solver " - "cannot handle multiclass with class_weight " - "of type dict. Use the lbfgs, newton-cg " - "solvers or set class_weight='auto'") + raise ValueError("In LogisticRegressionCV the liblinear " + "solver cannot handle multiclass with " + "class_weight of type dict. Use the lbfgs, " + "newton-cg solvers or set " + "class_weight='auto'") else: - class_weight_ = compute_class_weight(class_weight, n_classes, y) + class_weight_ = compute_class_weight(class_weight, classes, y) sample_weight = class_weight_[le.fit_transform(y)] - mask = (y == pos_class) - y[mask] = 1 - y[~mask] = -1 + # For doing a ovr, we need to mask the labels first. for the + # multinomial case this is not necessary. + if multi_class == 'ovr': + w0 = np.zeros(n_features + int(fit_intercept)) + mask_classes = [-1, 1] + mask = (y == pos_class) + y[mask] = 1 + y[~mask] = -1 + # To take care of object dtypes, i.e 1 and -1 are in the form of + # strings. + y = as_float_array(y, copy=False) + + else: + lbin = LabelBinarizer() + Y_bin = lbin.fit_transform(y) + if Y_bin.shape[1] == 1: + Y_bin = np.hstack([1 - Y_bin, Y_bin]) + w0 = np.zeros((Y_bin.shape[1], n_features + int(fit_intercept)), + order='F') + mask_classes = classes - # To take care of object dtypes - y = as_float_array(y, copy=False) if class_weight == "auto": - class_weight_ = compute_class_weight(class_weight, [-1, 1], y) + class_weight_ = compute_class_weight(class_weight, mask_classes, y) sample_weight = class_weight_[le.fit_transform(y)] - if fit_intercept: - w0 = np.zeros(X.shape[1] + 1) - else: - w0 = np.zeros(X.shape[1]) - if coef is not None: # it must work both giving the bias term and not - if not coef.size in (X.shape[1], w0.size): - raise ValueError('Initialization coef is not of correct shape') - w0[:coef.size] = coef + if multi_class == 'ovr': + if not coef.size in (n_features, w0.size): + raise ValueError( + 'Initialization coef is of shape %d, expected shape ' + '%d or %d' % (coef.size, n_features, w0.size) + ) + w0[:coef.size] = coef + else: + if (coef.shape[0] != classes.size or + coef.shape[1] not in (n_features, n_features + 1)): + raise ValueError( + 'Initialization coef is of shape (%d, %d), expected ' + 'shape (%d, %d) or (%d, %d)' % ( + coef.shape[0], coef.shape[1], classes.size, + n_features, classes.size, n_features + 1 + ) + ) + w0[:, :coef.shape[1]] = coef + + # fmin_l_bfgs_b accepts only ravelled parameters. + if multi_class == 'multinomial': + w0 = w0.ravel() + coefs = list() for C in Cs: if solver == 'lbfgs': - func = _logistic_loss_and_grad + if multi_class == 'multinomial': + target = Y_bin + func = _multinomial_loss_grad + else: + target = y + func = _logistic_loss_and_grad try: - out = optimize.fmin_l_bfgs_b( + w0, loss, info = optimize.fmin_l_bfgs_b( func, w0, fprime=None, - args=(X, y, 1. / C, sample_weight), - iprint=(verbose > 0) - 1, pgtol=tol, maxiter=max_iter) + args=(X, target, 1. / C, sample_weight), + iprint=(verbose > 0) - 1, pgtol=tol, maxiter=max_iter + ) except TypeError: # old scipy doesn't have maxiter - out = optimize.fmin_l_bfgs_b( + w0, loss, info = optimize.fmin_l_bfgs_b( func, w0, fprime=None, - args=(X, y, 1. / C, sample_weight), - iprint=(verbose > 0) - 1, pgtol=tol) - w0 = out[0] - if out[2]["warnflag"] == 1: + args=(X, target, 1. / C, sample_weight), + iprint=(verbose > 0) - 1, pgtol=tol + ) + if info["warnflag"] == 1 and verbose > 0: warnings.warn("lbfgs failed to converge. Increase the number " "of iterations.") @@ -407,19 +536,25 @@ def logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, args=(X, y, 1. / C, sample_weight), maxiter=max_iter, tol=tol) elif solver == 'liblinear': - lr = LogisticRegression(C=C, fit_intercept=fit_intercept, tol=tol, - class_weight=class_weight, dual=dual, - penalty=penalty, - intercept_scaling=intercept_scaling) - lr.fit(X, y) + coef_, intercept_, _, = _fit_liblinear( + X, y, C, fit_intercept, intercept_scaling, class_weight, + penalty, dual, verbose, max_iter, tol, + ) if fit_intercept: - w0 = np.concatenate([lr.coef_.ravel(), lr.intercept_]) + w0 = np.concatenate([coef_.ravel(), intercept_]) else: - w0 = lr.coef_.ravel() + w0 = coef_.ravel() else: raise ValueError("solver must be one of {'liblinear', 'lbfgs', " "'newton-cg'}, got '%s' instead" % solver) - coefs.append(w0) + + if multi_class == 'multinomial': + multi_w0 = np.reshape(w0, (classes.size, -1)) + if classes.size == 2: + multi_w0 = multi_w0[1][np.newaxis, :] + coefs.append(multi_w0) + else: + coefs.append(w0) return coefs, np.array(Cs) @@ -428,7 +563,8 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, scoring=None, fit_intercept=False, max_iter=100, tol=1e-4, class_weight=None, verbose=0, solver='lbfgs', penalty='l2', - dual=False, copy=True, intercept_scaling=1.): + dual=False, copy=True, intercept_scaling=1., + multi_class='ovr'): """Computes scores across logistic_regression_path Parameters @@ -477,7 +613,8 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, frequencies in the training set. verbose : int - Amount of verbosity. + For the liblinear and lbfgs solvers set verbose to any positive + number for verbosity. solver : {'lbfgs', 'newton-cg', 'liblinear'} Decides which solver to use. @@ -503,6 +640,13 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased. + multi_class : str, {'ovr', 'multinomial'} + Multiclass option can be either 'ovr' or 'multinomial'. If the option + chosen is 'ovr', then a binary problem is fit for each label. Else + the loss minimised is the multinomial loss fit across + the entire probability distribution. Works only for the 'lbfgs' + solver. + Returns ------- coefs : ndarray, shape (n_cs, n_features) or (n_cs, n_features + 1) @@ -518,14 +662,21 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, """ log_reg = LogisticRegression(fit_intercept=fit_intercept) - log_reg._enc = LabelEncoder() - log_reg._enc.fit_transform([-1, 1]) X_train = X[train] X_test = X[test] y_train = y[train] y_test = y[test] + # The score method of Logistic Regression has a classes_ attribute. + if multi_class == 'ovr': + log_reg.classes_ = np.array([-1, 1]) + elif multi_class == 'multinomial': + log_reg.classes_ = np.unique(y_train) + else: + raise ValueError("multi_class should be either multinomial or ovr, " + "got %d" % multi_class) + if pos_class is not None: mask = (y_test == pos_class) y_test[mask] = 1 @@ -540,6 +691,7 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, max_iter=max_iter, class_weight=class_weight, copy=copy, pos_class=pos_class, + multi_class=multi_class, tol=tol, verbose=verbose, dual=dual, penalty=penalty, intercept_scaling=intercept_scaling) @@ -549,12 +701,15 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, if isinstance(scoring, six.string_types): scoring = SCORERS[scoring] for w in coefs: + if multi_class == 'ovr': + w = w[np.newaxis, :] if fit_intercept: - log_reg.coef_ = w[np.newaxis, :-1] - log_reg.intercept_ = w[-1] + log_reg.coef_ = w[:, :-1] + log_reg.intercept_ = w[:, -1] else: - log_reg.coef_ = w[np.newaxis, :] + log_reg.coef_ = w log_reg.intercept_ = 0. + if scoring is None: scores.append(log_reg.score(X_test, y_test)) else: @@ -562,12 +717,15 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10, return coefs, Cs, np.array(scores) -class LogisticRegression(BaseLibLinear, LinearClassifierMixin, +class LogisticRegression(BaseEstimator, LinearClassifierMixin, _LearntSelectorMixin, SparseCoefMixin): """Logistic Regression (aka logit, MaxEnt) classifier. - In the multiclass case, the training algorithm uses a one-vs.-all (OvA) - scheme, rather than the "true" multinomial LR. + In the multiclass case, the training algorithm uses the one-vs-rest (OvR) + scheme if the 'multi_class' option is set to 'ovr' and uses the + cross-entropy loss, if the 'multi_class' option is set to 'multinomial'. + (Currently the 'multinomial' option is supported only by the 'lbfgs' + solver.) This class implements regularized logistic regression using the `liblinear` library, newton-cg and lbfgs solvers. It can handle both @@ -600,6 +758,7 @@ class LogisticRegression(BaseLibLinear, LinearClassifierMixin, added the decision function. intercept_scaling : float, default: 1 + Useful only if solver is liblinear. when self.fit_intercept is True, instance vector x becomes [x, self.intercept_scaling], i.e. a "synthetic" feature with constant value equals to @@ -630,15 +789,30 @@ class LogisticRegression(BaseLibLinear, LinearClassifierMixin, tol : float, optional Tolerance for stopping criteria. + multi_class : str, {'ovr', 'multinomial'} + Multiclass option can be either 'ovr' or 'multinomial'. If the option + chosen is 'ovr', then a binary problem is fit for each label. Else + the loss minimised is the multinomial loss fit across + the entire probability distribution. Works only for the 'lbfgs' + solver. + + verbose : int + For the liblinear and lbfgs solvers set verbose to any positive + number for verbosity. + Attributes ---------- - `coef_` : array, shape (n_classes, n_features) + coef_ : array, shape (n_classes, n_features) Coefficient of the features in the decision function. - `intercept_` : array, shape (n_classes,) + intercept_ : array, shape (n_classes,) Intercept (a.k.a. bias) added to the decision function. If `fit_intercept` is set to False, the intercept is set to zero. + n_iter_ : int + Maximum of the actual number of iterations across all classes. + Valid only for the liblinear solver. + See also -------- SGDClassifier : incrementally trained logistic regression (when given @@ -652,7 +826,12 @@ class LogisticRegression(BaseLibLinear, LinearClassifierMixin, to have slightly different results for the same input data. If that happens, try with a smaller tol parameter. - References: + Predict output may not match that of standalone liblinear in certain + cases. See :ref:`differences from liblinear ` + in the narrative documentation. + + References + ---------- LIBLINEAR -- A Library for Large Linear Classification http://www.csie.ntu.edu.tw/~cjlin/liblinear/ @@ -661,17 +840,114 @@ class LogisticRegression(BaseLibLinear, LinearClassifierMixin, methods for logistic regression and maximum entropy models. Machine Learning 85(1-2):41-75. http://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf + + + See also + -------- + sklearn.linear_model.SGDClassifier """ def __init__(self, penalty='l2', dual=False, tol=1e-4, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, - random_state=None, solver='liblinear', max_iter=100): + random_state=None, solver='liblinear', max_iter=100, + multi_class='ovr', verbose=0): - super(LogisticRegression, self).__init__( - penalty=penalty, dual=dual, loss='lr', tol=tol, C=C, - fit_intercept=fit_intercept, intercept_scaling=intercept_scaling, - class_weight=class_weight, random_state=random_state, - solver=solver, max_iter=max_iter) + self.penalty = penalty + self.dual = dual + self.tol = tol + self.C = C + self.fit_intercept = fit_intercept + self.intercept_scaling = intercept_scaling + self.class_weight = class_weight + self.random_state = random_state + self.solver = solver + self.max_iter = max_iter + self.multi_class = multi_class + self.verbose = verbose + + def fit(self, X, y): + """Fit the model according to the given training data. + + Parameters + ---------- + X : {array-like, sparse matrix}, shape (n_samples, n_features) + Training vector, where n_samples in the number of samples and + n_features is the number of features. + + y : array-like, shape (n_samples,) + Target vector relative to X. + + Returns + ------- + self : object + Returns self. + """ + if self.C < 0: + raise ValueError("Penalty term must be positive; got (C=%r)" + % self.C) + + X, y = check_X_y(X, y, accept_sparse='csr', dtype=np.float64, order="C") + self.classes_ = np.unique(y) + if self.solver not in ['liblinear', 'newton-cg', 'lbfgs']: + raise ValueError( + "Logistic Regression supports only liblinear, newton-cg and " + "lbfgs solvers, Got solver=%s" % self.solver + ) + + if self.solver != 'lbfgs' and self.multi_class == 'multinomial': + raise ValueError("Solver %s does not support a multinomial " + "backend.") + + if self.multi_class not in ['ovr', 'multinomial']: + raise ValueError("multi_class should be either ovr or multinomial " + "got %s" % self.multi_class) + + if self.solver == 'liblinear': + self.coef_, self.intercept_, self.n_iter_ = _fit_liblinear( + X, y, self.C, self.fit_intercept, self.intercept_scaling, + self.class_weight, self.penalty, self.dual, self.verbose, + self.max_iter, self.tol + ) + return self + + n_classes = len(self.classes_) + classes_ = self.classes_ + if n_classes < 2: + raise ValueError("This solver needs samples of at least 2 classes" + " in the data, but the data contains only one" + " class: %r" % classes_[0]) + + if len(self.classes_) == 2: + n_classes = 1 + classes_ = classes_[1:] + + self.coef_ = list() + self.intercept_ = np.zeros(n_classes) + + # Hack so that we iterate only once for the multinomial case. + if self.multi_class == 'multinomial': + classes_ = [None] + + for ind, class_ in enumerate(classes_): + coef_, _ = logistic_regression_path( + X, y, pos_class=class_, Cs=[self.C], + fit_intercept=self.fit_intercept, tol=self.tol, + verbose=self.verbose, solver=self.solver, + multi_class=self.multi_class, max_iter=self.max_iter, + class_weight=self.class_weight) + self.coef_.append(coef_[0]) + + self.coef_ = np.squeeze(self.coef_) + # For the binary case, this get squeezed to a 1-D array. + if self.coef_.ndim == 1: + self.coef_ = self.coef_[np.newaxis, :] + + self.coef_ = np.asarray(self.coef_) + if self.fit_intercept: + self.intercept_ = self.coef_[:, -1] + self.coef_ = self.coef_[:, :-1] + + return self def predict_proba(self, X): """Probability estimates. @@ -789,8 +1065,9 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, Number of CPU cores used during the cross-validation loop. If given a value of -1, all cores are used. - verbose : bool | int - Amount of verbosity. + verbose : int + For the liblinear and lbfgs solvers set verbose to any positive + number for verbosity. refit : bool If set to True, the scores are averaged across all folds, and the @@ -799,7 +1076,15 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, Otherwise the coefs, intercepts and C that correspond to the best scores across folds are averaged. + multi_class : str, {'ovr', 'multinomial'} + Multiclass option can be either 'ovr' or 'multinomial'. If the option + chosen is 'ovr', then a binary problem is fit for each label. Else + the loss minimised is the multinomial loss fit across + the entire probability distribution. Works only for the 'lbfgs' + solver. + intercept_scaling : float, default 1. + Useful only if solver is liblinear. This parameter is useful only when the solver 'liblinear' is used and self.fit_intercept is set to True. In this case, x becomes [x, self.intercept_scaling], @@ -813,7 +1098,7 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, Attributes ---------- - `coef_` : array, shape (1, n_features) or (n_classes, n_features) + coef_ : array, shape (1, n_features) or (n_classes, n_features) Coefficient of the features in the decision function. `coef_` is of shape (1, n_features) when the given problem @@ -821,31 +1106,35 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, `coef_` is readonly property derived from `raw_coef_` that follows the internal memory layout of liblinear. - `intercept_` : array, shape (1,) or (n_classes,) + intercept_ : array, shape (1,) or (n_classes,) Intercept (a.k.a. bias) added to the decision function. It is available only when parameter intercept is set to True and is of shape(1,) when the problem is binary. - `Cs_` : array + Cs_ : array Array of C i.e. inverse of regularization parameter values used for cross-validation. - `coefs_paths_` : array, shape (n_folds, len(Cs_), n_features) or + coefs_paths_ : array, shape (n_folds, len(Cs_), n_features) or (n_folds, len(Cs_), n_features + 1) dict with classes as the keys, and the path of coefficients obtained during cross-validating across each fold and then across each Cs - after doing an OvA for the corresponding class. + after doing an OvR for the corresponding class as values. + If the 'multi_class' option is set to 'multinomial', then + the coefs_paths are the coefficients corresponding to each class. Each dict value has shape (n_folds, len(Cs_), n_features) or (n_folds, len(Cs_), n_features + 1) depending on whether the intercept is fit or not. - `scores_` : dict + scores_ : dict dict with classes as the keys, and the values as the grid of scores obtained during cross-validating each fold, after doing - an OvA for the corresponding class. + an OvR for the corresponding class. If the 'multi_class' option + given is 'multinomial' then the same scores are repeated across + all classes, since this is the multinomial class. Each dict value has shape (n_folds, len(Cs)) - `C_` : array, shape (n_classes,) or (n_classes - 1,) + C_ : array, shape (n_classes,) or (n_classes - 1,) Array of C that maps to the best scores across every class. If refit is set to False, then for each class, the best C is the average of the C's that correspond to the best scores for each fold. @@ -858,8 +1147,8 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator, def __init__(self, Cs=10, fit_intercept=True, cv=None, dual=False, penalty='l2', scoring=None, solver='lbfgs', tol=1e-4, - max_iter=100, class_weight=None, n_jobs=1, verbose=False, - refit=True, intercept_scaling=1.): + max_iter=100, class_weight=None, n_jobs=1, verbose=0, + refit=True, intercept_scaling=1., multi_class='ovr'): self.Cs = Cs self.fit_intercept = fit_intercept self.cv = cv @@ -873,7 +1162,8 @@ def __init__(self, Cs=10, fit_intercept=True, cv=None, dual=False, self.verbose = verbose self.solver = solver self.refit = refit - self.intercept_scaling = 1. + self.intercept_scaling = intercept_scaling + self.multi_class = multi_class def fit(self, X, y): """Fit the model according to the given training data. @@ -903,6 +1193,11 @@ def fit(self, X, y): X = check_array(X, accept_sparse='csc', dtype=np.float64) y = check_array(y, ensure_2d=False) + if self.multi_class not in ['ovr', 'multinomial']: + raise ValueError("multi_class backend should be either " + "'ovr' or 'multinomial'" + " got %s" % self.multi_class) + if y.ndim == 2 and y.shape[1] == 1: warnings.warn( "A column-vector y was passed when a 1d array was" @@ -921,68 +1216,102 @@ def fit(self, X, y): self._enc = LabelEncoder() self._enc.fit(y) - labels = self.classes_ + labels = self.classes_ = np.unique(y) n_classes = len(labels) if n_classes < 2: - raise ValueError("Number of classes have to be greater than one.") - + raise ValueError("This solver needs samples of at least 2 classes" + " in the data, but the data contains only one" + " class: %r" % self.classes_[0]) if n_classes == 2: - # OvA in case of binary problems is as good as fitting + # OvR in case of binary problems is as good as fitting # the higher label n_classes = 1 labels = labels[1:] + # We need this hack to iterate only once over labels, in the case of + # multi_class = multinomial, without changing the value of the labels. + iter_labels = labels + if self.multi_class == 'multinomial': + iter_labels = [None] + if self.class_weight and not(isinstance(self.class_weight, dict) or self.class_weight == 'auto'): raise ValueError("class_weight provided should be a " "dict or 'auto'") + path_func = delayed(_log_reg_scoring_path) + fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)( - delayed(_log_reg_scoring_path)(X, y, train, test, - pos_class=label, - Cs=self.Cs, - fit_intercept=self.fit_intercept, - penalty=self.penalty, - dual=self.dual, - solver=self.solver, - max_iter=self.max_iter, - tol=self.tol, - class_weight=self.class_weight, - verbose=max(0, self.verbose - 1), - scoring=self.scoring, - intercept_scaling=self.intercept_scaling) - for label in labels - for train, test in folds - ) - coefs_paths, Cs, scores = zip(*fold_coefs_) - - self.Cs_ = Cs[0] - coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), - len(self.Cs_), -1)) + path_func(X, y, train, test, pos_class=label, Cs=self.Cs, + fit_intercept=self.fit_intercept, penalty=self.penalty, + dual=self.dual, solver=self.solver, tol=self.tol, + max_iter=self.max_iter, verbose=self.verbose, + class_weight=self.class_weight, scoring=self.scoring, + multi_class=self.multi_class, + intercept_scaling=self.intercept_scaling + ) + for label in iter_labels + for train, test in folds) + + if self.multi_class == 'multinomial': + multi_coefs_paths, Cs, multi_scores = zip(*fold_coefs_) + multi_coefs_paths = np.asarray(multi_coefs_paths) + multi_scores = np.asarray(multi_scores) + + # This is just to maintain API similarity between the ovr and + # multinomial option. + # Coefs_paths in now n_folds X len(Cs) X n_classes X n_features + # we need it to be n_classes X len(Cs) X n_folds X n_features + # to be similar to "ovr". + coefs_paths = np.rollaxis(multi_coefs_paths, 2, 0) + + # Multinomial has a true score across all labels. Hence the + # shape is n_folds X len(Cs). We need to repeat this score + # across all labels for API similarity. + scores = np.tile(multi_scores, (n_classes, 1, 1)) + self.Cs_ = Cs[0] + + else: + coefs_paths, Cs, scores = zip(*fold_coefs_) + self.Cs_ = Cs[0] + coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), + len(self.Cs_), -1)) + self.coefs_paths_ = dict(zip(labels, coefs_paths)) scores = np.reshape(scores, (n_classes, len(folds), -1)) self.scores_ = dict(zip(labels, scores)) self.C_ = list() - self.coef_ = list() - self.intercept_ = list() + self.coef_ = np.empty((n_classes, X.shape[1])) + self.intercept_ = np.zeros(n_classes) + + # hack to iterate only once for multinomial case. + if self.multi_class == 'multinomial': + scores = multi_scores + coefs_paths = multi_coefs_paths - for label in labels: - scores = self.scores_[label] - coefs_paths = self.coefs_paths_[label] + for index, label in enumerate(iter_labels): + if self.multi_class == 'ovr': + scores = self.scores_[label] + coefs_paths = self.coefs_paths_[label] if self.refit: best_index = scores.sum(axis=0).argmax() + C_ = self.Cs_[best_index] self.C_.append(C_) - coef_init = np.mean(coefs_paths[:, best_index, :], axis=0) - + if self.multi_class == 'multinomial': + coef_init = np.mean(coefs_paths[:, best_index, :, :], + axis=0) + else: + coef_init = np.mean(coefs_paths[:, best_index, :], axis=0) w, _ = logistic_regression_path( X, y, pos_class=label, Cs=[C_], solver=self.solver, fit_intercept=self.fit_intercept, coef=coef_init, max_iter=self.max_iter, tol=self.tol, class_weight=self.class_weight, + multi_class=self.multi_class, verbose=max(0, self.verbose - 1)) w = w[0] @@ -996,13 +1325,15 @@ def fit(self, X, y): ], axis=0) self.C_.append(np.mean(self.Cs_[best_indices])) - if self.fit_intercept: - self.coef_.append(w[:-1]) - self.intercept_.append(w[-1]) + if self.multi_class == 'multinomial': + self.C_ = np.tile(self.C_, n_classes) + self.coef_ = w[:, :X.shape[1]] + if self.fit_intercept: + self.intercept_ = w[:, -1] else: - self.coef_.append(w) - self.intercept_.append(0.) + self.coef_[index] = w[: X.shape[1]] + if self.fit_intercept: + self.intercept_[index] = w[-1] + self.C_ = np.asarray(self.C_) - self.coef_ = np.asarray(self.coef_) - self.intercept_ = np.asarray(self.intercept_) return self diff --git a/sklearn/linear_model/omp.py b/sklearn/linear_model/omp.py index 73c7ebc399207..f72a183e5337f 100644 --- a/sklearn/linear_model/omp.py +++ b/sklearn/linear_model/omp.py @@ -553,13 +553,13 @@ class OrthogonalMatchingPursuit(LinearModel, RegressorMixin): Attributes ---------- - `coef_` : array, shape (n_features,) or (n_features, n_targets) + coef_ : array, shape (n_features,) or (n_features, n_targets) parameter vector (w in the formula) - `intercept_` : float or array, shape (n_targets,) + intercept_ : float or array, shape (n_targets,) independent term in decision function. - `n_iter_` : int or array-like + n_iter_ : int or array-like Number of active features across every target. Notes @@ -752,17 +752,17 @@ class OrthogonalMatchingPursuitCV(LinearModel, RegressorMixin): Attributes ---------- - `intercept_` : float or array, shape (n_targets,) + intercept_ : float or array, shape (n_targets,) Independent term in decision function. - `coef_` : array, shape (n_features,) or (n_features, n_targets) + coef_ : array, shape (n_features,) or (n_features, n_targets) Parameter vector (w in the problem formulation). - `n_nonzero_coefs_` : int + n_nonzero_coefs_ : int Estimated number of non-zero coefficients giving the best mean squared error over the cross-validation folds. - `n_iter_` : int or array-like + n_iter_ : int or array-like Number of active features across every target for the model refit with the best hyperparameters got by cross-validating across all folds. diff --git a/sklearn/linear_model/passive_aggressive.py b/sklearn/linear_model/passive_aggressive.py index d7004beeb0b98..b06c5f3146aba 100644 --- a/sklearn/linear_model/passive_aggressive.py +++ b/sklearn/linear_model/passive_aggressive.py @@ -50,11 +50,11 @@ class PassiveAggressiveClassifier(BaseSGDClassifier): Attributes ---------- - `coef_` : array, shape = [1, n_features] if n_classes == 2 else [n_classes, + coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features] Weights assigned to the features. - `intercept_` : array, shape = [1] if n_classes == 2 else [n_classes] + intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. See also @@ -190,11 +190,11 @@ class PassiveAggressiveRegressor(BaseSGDRegressor): Attributes ---------- - `coef_` : array, shape = [1, n_features] if n_classes == 2 else [n_classes, + coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features] Weights assigned to the features. - `intercept_` : array, shape = [1] if n_classes == 2 else [n_classes] + intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. See also diff --git a/sklearn/linear_model/perceptron.py b/sklearn/linear_model/perceptron.py index e1ea2255a79c2..6775122ecc258 100644 --- a/sklearn/linear_model/perceptron.py +++ b/sklearn/linear_model/perceptron.py @@ -60,11 +60,11 @@ class Perceptron(BaseSGDClassifier, _LearntSelectorMixin): Attributes ---------- - `coef_` : array, shape = [1, n_features] if n_classes == 2 else [n_classes, + coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features] Weights assigned to the features. - `intercept_` : array, shape = [1] if n_classes == 2 else [n_classes] + intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. Notes diff --git a/sklearn/linear_model/randomized_l1.py b/sklearn/linear_model/randomized_l1.py index da1d59a488b33..04954b72c949b 100644 --- a/sklearn/linear_model/randomized_l1.py +++ b/sklearn/linear_model/randomized_l1.py @@ -267,10 +267,10 @@ class RandomizedLasso(BaseRandomizedLinearModel): Attributes ---------- - `scores_` : array, shape = [n_features] + scores_ : array, shape = [n_features] Feature scores between 0 and 1. - `all_scores_` : array, shape = [n_features, n_reg_parameter] + all_scores_ : array, shape = [n_features, n_reg_parameter] Feature scores between 0 and 1 for all values of the regularization \ parameter. The reference article suggests ``scores_`` is the max of \ ``all_scores_``. @@ -435,10 +435,10 @@ class RandomizedLogisticRegression(BaseRandomizedLinearModel): Attributes ---------- - `scores_` : array, shape = [n_features] + scores_ : array, shape = [n_features] Feature scores between 0 and 1. - `all_scores_` : array, shape = [n_features, n_reg_parameter] + all_scores_ : array, shape = [n_features, n_reg_parameter] Feature scores between 0 and 1 for all values of the regularization \ parameter. The reference article suggests ``scores_`` is the max \ of ``all_scores_``. diff --git a/sklearn/linear_model/ridge.py b/sklearn/linear_model/ridge.py index bb5fd8336f5cb..52c8a0cda7ce2 100644 --- a/sklearn/linear_model/ridge.py +++ b/sklearn/linear_model/ridge.py @@ -438,7 +438,7 @@ class Ridge(_BaseRidge, RegressorMixin): Attributes ---------- - `coef_` : array, shape = [n_features] or [n_targets, n_features] + coef_ : array, shape = [n_features] or [n_targets, n_features] Weight vector(s). See also @@ -531,7 +531,7 @@ class RidgeClassifier(LinearClassifierMixin, _BaseRidge): Attributes ---------- - `coef_` : array, shape = [n_features] or [n_classes, n_features] + coef_ : array, shape = [n_features] or [n_classes, n_features] Weight vector(s). See also @@ -923,20 +923,20 @@ class RidgeCV(_BaseRidgeCV, RegressorMixin): Attributes ---------- - `cv_values_` : array, shape = [n_samples, n_alphas] or \ + cv_values_ : array, shape = [n_samples, n_alphas] or \ shape = [n_samples, n_targets, n_alphas], optional Cross-validation values for each alpha (if `store_cv_values=True` and \ `cv=None`). After `fit()` has been called, this attribute will \ contain the mean squared errors (by default) or the values of the \ `{loss,score}_func` function (if provided in the constructor). - `coef_` : array, shape = [n_features] or [n_targets, n_features] + coef_ : array, shape = [n_features] or [n_targets, n_features] Weight vector(s). - `alpha_` : float + alpha_ : float Estimated regularization parameter. - `intercept_` : float | array, shape = (n_targets,) + intercept_ : float | array, shape = (n_targets,) Independent term in decision function. Set to 0.0 if ``fit_intercept = False``. @@ -989,17 +989,17 @@ class RidgeClassifierCV(LinearClassifierMixin, _BaseRidgeCV): Attributes ---------- - `cv_values_` : array, shape = [n_samples, n_alphas] or \ + cv_values_ : array, shape = [n_samples, n_alphas] or \ shape = [n_samples, n_responses, n_alphas], optional Cross-validation values for each alpha (if `store_cv_values=True` and `cv=None`). After `fit()` has been called, this attribute will contain \ the mean squared errors (by default) or the values of the \ `{loss,score}_func` function (if provided in the constructor). - `coef_` : array, shape = [n_features] or [n_targets, n_features] + coef_ : array, shape = [n_features] or [n_targets, n_features] Weight vector(s). - `alpha_` : float + alpha_ : float Estimated regularization parameter See also diff --git a/sklearn/linear_model/sgd_fast.c b/sklearn/linear_model/sgd_fast.c index 121b5eec050a8..67979b6dc760a 100644 --- a/sklearn/linear_model/sgd_fast.c +++ b/sklearn/linear_model/sgd_fast.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.20.1 on Wed Sep 10 09:45:37 2014 */ +/* Generated by Cython 0.20.1 on Wed Sep 10 11:13:19 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -346,7 +346,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include "stdlib.h" #include "numpy/arrayobject.h" #include "numpy/ufuncobject.h" -#include "numpy/npy_math.h" +#include "sgd_fast_helpers.h" #include "cblas.h" #ifdef _OPENMP #include @@ -7333,16 +7333,16 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_8sgd_fast_4_plain_sgd(CYTHON_U /* "sklearn/linear_model/sgd_fast.pyx":719 * * # floating-point under-/overflow check. - * if (not isfinite(intercept) # <<<<<<<<<<<<<< + * if (not skl_isfinite(intercept) # <<<<<<<<<<<<<< * or any_nonfinite(weights.data, n_features)): * infinity = True */ - __pyx_t_5 = ((!(npy_isfinite(__pyx_v_intercept) != 0)) != 0); + __pyx_t_5 = ((!(skl_isfinite(__pyx_v_intercept) != 0)) != 0); if (!__pyx_t_5) { /* "sklearn/linear_model/sgd_fast.pyx":720 * # floating-point under-/overflow check. - * if (not isfinite(intercept) + * if (not skl_isfinite(intercept) * or any_nonfinite(weights.data, n_features)): # <<<<<<<<<<<<<< * infinity = True * break @@ -7355,7 +7355,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_8sgd_fast_4_plain_sgd(CYTHON_U if (__pyx_t_26) { /* "sklearn/linear_model/sgd_fast.pyx":721 - * if (not isfinite(intercept) + * if (not skl_isfinite(intercept) * or any_nonfinite(weights.data, n_features)): * infinity = True # <<<<<<<<<<<<<< * break @@ -7549,7 +7549,7 @@ static PyObject *__pyx_pf_7sklearn_12linear_model_8sgd_fast_4_plain_sgd(CYTHON_U * * cdef bint any_nonfinite(double *w, int n) nogil: # <<<<<<<<<<<<<< * for i in range(n): - * if not isfinite(w[i]): + * if not skl_isfinite(w[i]): */ static int __pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite(double *__pyx_v_w, int __pyx_v_n) { @@ -7563,7 +7563,7 @@ static int __pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite(double *__pyx * * cdef bint any_nonfinite(double *w, int n) nogil: * for i in range(n): # <<<<<<<<<<<<<< - * if not isfinite(w[i]): + * if not skl_isfinite(w[i]): * return True */ __pyx_t_1 = __pyx_v_n; @@ -7573,16 +7573,16 @@ static int __pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite(double *__pyx /* "sklearn/linear_model/sgd_fast.pyx":741 * cdef bint any_nonfinite(double *w, int n) nogil: * for i in range(n): - * if not isfinite(w[i]): # <<<<<<<<<<<<<< + * if not skl_isfinite(w[i]): # <<<<<<<<<<<<<< * return True * return 0 */ - __pyx_t_3 = ((!(npy_isfinite((__pyx_v_w[__pyx_v_i])) != 0)) != 0); + __pyx_t_3 = ((!(skl_isfinite((__pyx_v_w[__pyx_v_i])) != 0)) != 0); if (__pyx_t_3) { /* "sklearn/linear_model/sgd_fast.pyx":742 * for i in range(n): - * if not isfinite(w[i]): + * if not skl_isfinite(w[i]): * return True # <<<<<<<<<<<<<< * return 0 * @@ -7593,7 +7593,7 @@ static int __pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite(double *__pyx } /* "sklearn/linear_model/sgd_fast.pyx":743 - * if not isfinite(w[i]): + * if not skl_isfinite(w[i]): * return True * return 0 # <<<<<<<<<<<<<< * @@ -7607,7 +7607,7 @@ static int __pyx_f_7sklearn_12linear_model_8sgd_fast_any_nonfinite(double *__pyx * * cdef bint any_nonfinite(double *w, int n) nogil: # <<<<<<<<<<<<<< * for i in range(n): - * if not isfinite(w[i]): + * if not skl_isfinite(w[i]): */ /* function exit code */ diff --git a/sklearn/linear_model/sgd_fast.pyx b/sklearn/linear_model/sgd_fast.pyx index 08df73ba43441..4178c1eb134bc 100644 --- a/sklearn/linear_model/sgd_fast.pyx +++ b/sklearn/linear_model/sgd_fast.pyx @@ -17,8 +17,8 @@ from time import time cimport cython from libc.math cimport exp, log, sqrt, pow, fabs cimport numpy as np -cdef extern from "numpy/npy_math.h": - bint isfinite "npy_isfinite"(double) nogil +cdef extern from "sgd_fast_helpers.h": + bint skl_isfinite(double) nogil from sklearn.utils.weight_vector cimport WeightVector from sklearn.utils.seq_dataset cimport SequentialDataset @@ -716,7 +716,7 @@ def _plain_sgd(np.ndarray[double, ndim=1, mode='c'] weights, % (time() - t_start)) # floating-point under-/overflow check. - if (not isfinite(intercept) + if (not skl_isfinite(intercept) or any_nonfinite(weights.data, n_features)): infinity = True break @@ -738,7 +738,7 @@ def _plain_sgd(np.ndarray[double, ndim=1, mode='c'] weights, cdef bint any_nonfinite(double *w, int n) nogil: for i in range(n): - if not isfinite(w[i]): + if not skl_isfinite(w[i]): return True return 0 diff --git a/sklearn/linear_model/sgd_fast_helpers.h b/sklearn/linear_model/sgd_fast_helpers.h new file mode 100644 index 0000000000000..42984c18a3a3f --- /dev/null +++ b/sklearn/linear_model/sgd_fast_helpers.h @@ -0,0 +1,9 @@ +// We cannot directly reuse the npy_isfinite from npy_math.h as numpy +// and scikit-learn are not necessarily built with the same compiler. +#ifdef _MSC_VER +# include +# define skl_isfinite _finite +#else +# include +# define skl_isfinite npy_isfinite +#endif diff --git a/sklearn/linear_model/stochastic_gradient.py b/sklearn/linear_model/stochastic_gradient.py index 5c9ec2376e703..485060450f7e9 100644 --- a/sklearn/linear_model/stochastic_gradient.py +++ b/sklearn/linear_model/stochastic_gradient.py @@ -397,10 +397,8 @@ def _partial_fit(self, X, y, alpha, C, n_classes = self.classes_.shape[0] # Allocate datastructures from input arguments - y_ind = np.searchsorted(self.classes_, y) # XXX use a LabelBinarizer? self._expanded_class_weight = compute_class_weight(self.class_weight, - self.classes_, - y_ind) + self.classes_, y) sample_weight = self._validate_sample_weight(sample_weight, n_samples) if self.coef_ is None or coef_init is not None: @@ -685,11 +683,11 @@ class SGDClassifier(BaseSGDClassifier, _LearntSelectorMixin): Attributes ---------- - `coef_` : array, shape = [1, n_features] if n_classes == 2 else [n_classes, + coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features] Weights assigned to the features. - `intercept_` : array, shape = [1] if n_classes == 2 else [n_classes] + intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. Examples @@ -1175,10 +1173,10 @@ class SGDRegressor(BaseSGDRegressor, _LearntSelectorMixin): Attributes ---------- - `coef_` : array, shape = [n_features] + coef_ : array, shape = [n_features] Weights asigned to the features. - `intercept_` : array, shape = [1] + intercept_ : array, shape = [1] The intercept term. `average_coef_` : array shape = [n_features] diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index c54412d0d856e..7f3f72f0920ff 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -515,6 +515,53 @@ def test_warm_start_convergence_with_regularizer_decrement(): assert_greater(low_reg_model.n_iter_, warm_low_reg_model.n_iter_) +def test_random_descent(): + """Test that both random and cyclic selection give the same results. + + Ensure that the test models fully converge and check a wide + range of conditions. + """ + + # This uses the coordinate descent algo using the gram trick. + X, y, _, _ = build_dataset(n_samples=50, n_features=20) + clf_cyclic = ElasticNet(selection='cyclic', tol=1e-8) + clf_cyclic.fit(X, y) + clf_random = ElasticNet(selection='random', tol=1e-8, random_state=42) + clf_random.fit(X, y) + assert_array_almost_equal(clf_cyclic.coef_, clf_random.coef_) + assert_almost_equal(clf_cyclic.intercept_, clf_random.intercept_) + + # This uses the descent algo without the gram trick + clf_cyclic = ElasticNet(selection='cyclic', tol=1e-8) + clf_cyclic.fit(X.T, y[:20]) + clf_random = ElasticNet(selection='random', tol=1e-8, random_state=42) + clf_random.fit(X.T, y[:20]) + assert_array_almost_equal(clf_cyclic.coef_, clf_random.coef_) + assert_almost_equal(clf_cyclic.intercept_, clf_random.intercept_) + + # Sparse Case + clf_cyclic = ElasticNet(selection='cyclic', tol=1e-8) + clf_cyclic.fit(sparse.csr_matrix(X), y) + clf_random = ElasticNet(selection='random', tol=1e-8, random_state=42) + clf_random.fit(sparse.csr_matrix(X), y) + assert_array_almost_equal(clf_cyclic.coef_, clf_random.coef_) + assert_almost_equal(clf_cyclic.intercept_, clf_random.intercept_) + + # Multioutput case. + new_y = np.hstack((y[:, np.newaxis], y[:, np.newaxis])) + clf_cyclic = MultiTaskElasticNet(selection='cyclic', tol=1e-8) + clf_cyclic.fit(X, new_y) + clf_random = MultiTaskElasticNet(selection='random', tol=1e-8, + random_state=42) + clf_random.fit(X, new_y) + assert_array_almost_equal(clf_cyclic.coef_, clf_random.coef_) + assert_almost_equal(clf_cyclic.intercept_, clf_random.intercept_) + + # Raise error when selection is not in cyclic or random. + clf_random = ElasticNet(selection='invalid') + assert_raises(ValueError, clf_random.fit, X, y) + + if __name__ == '__main__': import nose nose.runmodule() diff --git a/sklearn/linear_model/tests/test_least_angle.py b/sklearn/linear_model/tests/test_least_angle.py index e5a7fd94d9e6b..d0caa3d292e24 100644 --- a/sklearn/linear_model/tests/test_least_angle.py +++ b/sklearn/linear_model/tests/test_least_angle.py @@ -9,7 +9,7 @@ from sklearn.utils.testing import assert_greater from sklearn.utils.testing import assert_raises from sklearn.utils.testing import ignore_warnings, assert_warns_message -from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import assert_no_warnings, assert_warns from sklearn.utils import ConvergenceWarning from sklearn import linear_model, datasets @@ -468,6 +468,15 @@ def test_lasso_lars_ic(): assert_raises(ValueError, lars_broken.fit, X, y) +def test_no_warning_for_zero_mse(): + """LassoLarsIC should not warn for log of zero MSE.""" + y = np.arange(10, dtype=float) + X = y.reshape(-1, 1) + lars = linear_model.LassoLarsIC(normalize=False) + assert_no_warnings(lars.fit, X, y) + assert_true(np.any(np.isinf(lars.criterion_))) + + if __name__ == '__main__': import nose nose.runmodule() diff --git a/sklearn/linear_model/tests/test_logistic.py b/sklearn/linear_model/tests/test_logistic.py index f547e6a939400..2e1e4aea282b4 100644 --- a/sklearn/linear_model/tests/test_logistic.py +++ b/sklearn/linear_model/tests/test_logistic.py @@ -9,8 +9,10 @@ from sklearn.utils.testing import assert_greater from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_true +from sklearn.utils.testing import assert_warns from sklearn.utils.testing import raises from sklearn.utils.testing import ignore_warnings +from sklearn.utils import ConvergenceWarning from sklearn.linear_model.logistic import ( LogisticRegression, @@ -20,6 +22,7 @@ from sklearn.cross_validation import StratifiedKFold from sklearn.datasets import load_iris, make_classification + X = [[-1, 0], [0, 1], [1, 1]] X_sp = sp.csr_matrix(X) Y1 = [0, 1, 1] @@ -77,17 +80,49 @@ def test_predict_iris(): n_samples, n_features = iris.data.shape target = iris.target_names[iris.target] - clf = LogisticRegression(C=len(iris.data)).fit(iris.data, target) - assert_array_equal(np.unique(target), clf.classes_) - pred = clf.predict(iris.data) - assert_greater(np.mean(pred == target), .95) + # Test that both multinomial and OvR solvers handle + # multiclass data correctly and give good accuracy + # score (>0.95) for the training data. + for clf in [LogisticRegression(C=len(iris.data)), + LogisticRegression(C=len(iris.data), solver='lbfgs', + multi_class='multinomial')]: + clf.fit(iris.data, target) + assert_array_equal(np.unique(target), clf.classes_) - probabilities = clf.predict_proba(iris.data) - assert_array_almost_equal(probabilities.sum(axis=1), np.ones(n_samples)) + pred = clf.predict(iris.data) + assert_greater(np.mean(pred == target), .95) + + probabilities = clf.predict_proba(iris.data) + assert_array_almost_equal(probabilities.sum(axis=1), + np.ones(n_samples)) + + pred = iris.target_names[probabilities.argmax(axis=1)] + assert_greater(np.mean(pred == target), .95) + + +def test_multinomial_validation(): + lr = LogisticRegression(C=-1, solver='lbfgs', multi_class='multinomial') + assert_raises(ValueError, lr.fit, [[0, 1], [1, 0]], [0, 1]) - pred = iris.target_names[probabilities.argmax(axis=1)] - assert_greater(np.mean(pred == target), .95) + +def test_multinomial_binary(): + """Test multinomial LR on a binary problem.""" + target = (iris.target > 0).astype(np.intp) + target = np.array(["setosa", "not-setosa"])[target] + + clf = LogisticRegression(solver='lbfgs', multi_class='multinomial') + clf.fit(iris.data, target) + + assert_equal(clf.coef_.shape, (1, iris.data.shape[1])) + assert_equal(clf.intercept_.shape, (1,)) + assert_array_equal(clf.predict(iris.data), target) + + mlr = LogisticRegression(solver='lbfgs', multi_class='multinomial', + fit_intercept=False) + mlr.fit(iris.data, target) + pred = clf.classes_[np.argmax(clf.predict_log_proba(iris.data), axis=1)] + assert_greater(np.mean(pred == target), .9) def test_sparsify(): @@ -137,7 +172,7 @@ def test_write_parameters(): clf.fit(X, Y1) clf.coef_[:] = 0 clf.intercept_[:] = 0 - assert_array_equal(clf.decision_function(X), 0) + assert_array_almost_equal(clf.decision_function(X), 0) @raises(ValueError) @@ -345,8 +380,8 @@ def test_intercept_logistic_helper(): assert_almost_equal(hess_interp[-1] + alpha * grad[-1], hess[-1]) -def test_ova_iris(): - """Test that our OvA implementation is correct using the iris dataset.""" +def test_ovr_multinomial_iris(): + """Test that OvR and multinomial are correct using the iris dataset.""" train, target = iris.data, iris.target n_samples, n_features = train.shape @@ -356,23 +391,40 @@ def test_ova_iris(): clf.fit(train, target) clf1 = LogisticRegressionCV(cv=cv) - target[target == 0] = 1 - clf1.fit(train, target) + target_copy = target.copy() + target_copy[target_copy == 0] = 1 + clf1.fit(train, target_copy) - assert_array_equal(clf.scores_[2], clf1.scores_[2]) - assert_array_equal(clf.intercept_[2:], clf1.intercept_) - assert_array_equal(clf.coef_[2][np.newaxis, :], clf1.coef_) + assert_array_almost_equal(clf.scores_[2], clf1.scores_[2]) + assert_array_almost_equal(clf.intercept_[2:], clf1.intercept_) + assert_array_almost_equal(clf.coef_[2][np.newaxis, :], clf1.coef_) # Test the shape of various attributes. - assert_array_equal(clf.coef_.shape, (3, n_features)) + assert_equal(clf.coef_.shape, (3, n_features)) assert_array_equal(clf.classes_, [0, 1, 2]) - assert_equal(len(clf.classes_), 3) - coefs_paths = np.asarray(list(clf.coefs_paths_.values())) - assert_array_equal(coefs_paths.shape, (3, 3, 10, n_features + 1)) - assert_array_equal(clf.Cs_.shape, (10, )) + assert_array_almost_equal(coefs_paths.shape, (3, 3, 10, n_features + 1)) + assert_equal(clf.Cs_.shape, (10, )) scores = np.asarray(list(clf.scores_.values())) - assert_array_equal(scores.shape, (3, 3, 10)) + assert_equal(scores.shape, (3, 3, 10)) + + # Test that for the iris data multinomial gives a better accuracy than OvR + clf_multi = LogisticRegressionCV( + solver='lbfgs', multi_class='multinomial', max_iter=5 + ) + clf_multi.fit(train, target) + multi_score = clf_multi.score(train, target) + ovr_score = clf.score(train, target) + assert_greater(multi_score, ovr_score) + + # Test attributes of LogisticRegressionCV + assert_equal(clf.coef_.shape, clf_multi.coef_.shape) + assert_array_equal(clf_multi.classes_, [0, 1, 2]) + coefs_paths = np.asarray(list(clf_multi.coefs_paths_.values())) + assert_array_almost_equal(coefs_paths.shape, (3, 3, 10, n_features + 1)) + assert_equal(clf_multi.Cs_.shape, (10, )) + scores = np.asarray(list(clf_multi.scores_.values())) + assert_equal(scores.shape, (3, 3, 10)) def test_logistic_regression_solvers(): @@ -407,10 +459,15 @@ def test_logistic_regressioncv_class_weights(): n_classes=3, random_state=0) # Test the liblinear fails when class_weight of type dict is - # provided, when it is multiclass + # provided, when it is multiclass. However it can handle + # binary problems. clf_lib = LogisticRegressionCV(class_weight={0: 0.1, 1: 0.2}, solver='liblinear') assert_raises(ValueError, clf_lib.fit, X, y) + y_ = y.copy() + y_[y == 2] = 1 + clf_lib.fit(X, y_) + assert_array_equal(clf_lib.classes_, [0, 1]) # Test for class_weight=auto X, y = make_classification(n_samples=20, n_features=20, n_informative=10, @@ -422,3 +479,56 @@ def test_logistic_regressioncv_class_weights(): class_weight='auto') clf_lib.fit(X, y) assert_array_almost_equal(clf_lib.coef_, clf_lbf.coef_, decimal=4) + + +def test_logistic_regression_convergence_warnings(): + """Test that warnings are raised if model does not converge""" + + X, y = make_classification(n_samples=20, n_features=20) + clf_lib = LogisticRegression(solver='liblinear', max_iter=2, verbose=1) + assert_warns(ConvergenceWarning, clf_lib.fit, X, y) + assert_equal(clf_lib.n_iter_, 2) + + +def test_logistic_regression_multinomial(): + """Tests for the multinomial option in logistic regression""" + + # Some basic attributes of Logistic Regression + n_samples, n_features, n_classes = 50, 20, 3 + X, y = make_classification(n_samples=50, n_features=20, n_informative=10, + n_classes=3, random_state=0) + clf_int = LogisticRegression(solver='lbfgs', multi_class='multinomial') + clf_int.fit(X, y) + assert_array_equal(clf_int.coef_.shape, (n_classes, n_features)) + + clf_wint = LogisticRegression(solver='lbfgs', multi_class='multinomial', + fit_intercept=False) + clf_wint.fit(X, y) + assert_array_equal(clf_wint.coef_.shape, (n_classes, n_features)) + + # Test that the path give almost the same results. However since in this + # case we take the average of the coefs after fitting across all the + # folds, it need not be exactly the same. + clf_path = LogisticRegressionCV(solver='lbfgs', multi_class='multinomial', + Cs=[1.]) + clf_path.fit(X, y) + assert_array_almost_equal(clf_path.coef_, clf_int.coef_, decimal=3) + assert_almost_equal(clf_path.intercept_, clf_int.intercept_, decimal=3) + + +def test_liblinear_decision_function_zero(): + """Test negative prediction when decision_function values are zero. + + Liblinear predicts the positive class when decision_function values + are zero. This is a test to verify that we do not do the same. + See Issue: https://github.com/scikit-learn/scikit-learn/issues/3600 + and the PR https://github.com/scikit-learn/scikit-learn/pull/3623 + """ + rng = np.random.RandomState(0) + X, y = make_classification(n_samples=5, n_features=5) + clf = LogisticRegression(fit_intercept=False) + clf.fit(X, y) + + # Dummy data such that the decision function becomes zero. + X = np.zeros((5, 5)) + assert_array_equal(clf.predict(X), np.zeros(5)) diff --git a/sklearn/manifold/isomap.py b/sklearn/manifold/isomap.py index 3354c36db8447..342de7f4b6702 100644 --- a/sklearn/manifold/isomap.py +++ b/sklearn/manifold/isomap.py @@ -53,20 +53,20 @@ class Isomap(BaseEstimator, TransformerMixin): Attributes ---------- - `embedding_` : array-like, shape (n_samples, n_components) + embedding_ : array-like, shape (n_samples, n_components) Stores the embedding vectors. - `kernel_pca_` : object + kernel_pca_ : object `KernelPCA` object used to implement the embedding. - `training_data_` : array-like, shape (n_samples, n_features) + training_data_ : array-like, shape (n_samples, n_features) Stores the training data. - `nbrs_` : sklearn.neighbors.NearestNeighbors instance + nbrs_ : sklearn.neighbors.NearestNeighbors instance Stores nearest neighbors instance, including BallTree or KDtree if applicable. - `dist_matrix_` : array-like, shape (n_samples, n_samples) + dist_matrix_ : array-like, shape (n_samples, n_samples) Stores the geodesic distance matrix of training data. References diff --git a/sklearn/manifold/locally_linear.py b/sklearn/manifold/locally_linear.py index c2731b7392bd7..832278b8862ca 100644 --- a/sklearn/manifold/locally_linear.py +++ b/sklearn/manifold/locally_linear.py @@ -562,13 +562,13 @@ class LocallyLinearEmbedding(BaseEstimator, TransformerMixin): Attributes ---------- - `embedding_vectors_` : array-like, shape [n_components, n_samples] + embedding_vectors_ : array-like, shape [n_components, n_samples] Stores the embedding vectors - `reconstruction_error_` : float + reconstruction_error_ : float Reconstruction error associated with `embedding_vectors_` - `nbrs_` : NearestNeighbors object + nbrs_ : NearestNeighbors object Stores nearest neighbors instance, including BallTree or KDtree if applicable. diff --git a/sklearn/manifold/mds.py b/sklearn/manifold/mds.py index c4b7cc806c417..6be371171fe8b 100644 --- a/sklearn/manifold/mds.py +++ b/sklearn/manifold/mds.py @@ -274,6 +274,7 @@ def smacof(similarities, metric=True, n_components=2, init=None, n_init=8, else: return best_pos, best_stress + class MDS(BaseEstimator): """Multidimensional scaling @@ -323,10 +324,10 @@ class MDS(BaseEstimator): Attributes ---------- - ``embedding_`` : array-like, shape [n_components, n_samples] + embedding_ : array-like, shape [n_components, n_samples] Stores the position of the dataset in the embedding space - ``stress_`` : float + stress_ : float The final value of the stress (sum of squared distance of the disparities and the distances for all constrained points) @@ -366,7 +367,8 @@ def fit(self, X, init=None, y=None): Parameters ---------- - X : array, shape=[n_samples, n_features] + X : array, shape=[n_samples, n_features], or [n_samples, n_samples] \ + if dissimilarity='precomputed' Input data. init : {None or ndarray, shape (n_samples,)}, optional @@ -382,7 +384,8 @@ def fit_transform(self, X, init=None, y=None): Parameters ---------- - X : array, shape=[n_samples, n_features] + X : array, shape=[n_samples, n_features], or [n_samples, n_samples] \ + if dissimilarity='precomputed' Input data. init : {None or ndarray, shape (n_samples,)}, optional diff --git a/sklearn/manifold/spectral_embedding_.py b/sklearn/manifold/spectral_embedding_.py index 09554debf69ee..f93fc97b9aaff 100644 --- a/sklearn/manifold/spectral_embedding_.py +++ b/sklearn/manifold/spectral_embedding_.py @@ -343,10 +343,10 @@ class SpectralEmbedding(BaseEstimator): Attributes ---------- - `embedding_` : array, shape = (n_samples, n_components) + embedding_ : array, shape = (n_samples, n_components) Spectral embedding of the training matrix. - `affinity_matrix_` : array, shape = (n_samples, n_samples) + affinity_matrix_ : array, shape = (n_samples, n_samples) Affinity_matrix constructed from samples or precomputed. References diff --git a/sklearn/manifold/t_sne.py b/sklearn/manifold/t_sne.py index e049938f8855f..30e0f69e9235c 100644 --- a/sklearn/manifold/t_sne.py +++ b/sklearn/manifold/t_sne.py @@ -359,10 +359,10 @@ class TSNE(BaseEstimator): Attributes ---------- - `embedding_` : array-like, shape (n_samples, n_components) + embedding_ : array-like, shape (n_samples, n_components) Stores the embedding vectors. - `training_data_` : array-like, shape (n_samples, n_features) + training_data_ : array-like, shape (n_samples, n_features) Stores the training data. Examples diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py index 08f4f7c0a8013..7540a93f05d6b 100644 --- a/sklearn/metrics/classification.py +++ b/sklearn/metrics/classification.py @@ -15,6 +15,7 @@ # Lars Buitinck # Joel Nothman # Noel Dawe +# Jatin Shah # License: BSD 3 clause from __future__ import division @@ -23,21 +24,24 @@ import numpy as np from scipy.sparse import coo_matrix +from scipy.sparse import csr_matrix from scipy.spatial.distance import hamming as sp_hamming -from ..externals.six.moves import zip -from ..preprocessing import label_binarize from ..preprocessing import LabelBinarizer from ..preprocessing import LabelEncoder -from ..utils import check_array, check_consistent_length +from ..utils import check_array +from ..utils import check_consistent_length +from ..preprocessing import MultiLabelBinarizer from ..utils import column_or_1d from ..utils.multiclass import unique_labels from ..utils.multiclass import type_of_target +from ..utils.validation import _num_samples +from ..utils.sparsefuncs import count_nonzero from .base import UndefinedMetricWarning -def _check_clf_targets(y_true, y_pred): +def _check_targets(y_true, y_pred): """Check that y_true and y_pred belong to the same classification task This converts multiclass or binary types to a common shape, and raises a @@ -45,11 +49,12 @@ def _check_clf_targets(y_true, y_pred): multilabel formats, for the presence of continuous-valued or multioutput targets, or for targets of different lengths. - Column vectors are squeezed to 1d. + Column vectors are squeezed to 1d, while multilabel formats are returned + as CSR sparse label indicators. Parameters ---------- - y_true : array-like, + y_true : array-like y_pred : array-like @@ -88,9 +93,29 @@ def _check_clf_targets(y_true, y_pred): y_true = column_or_1d(y_true) y_pred = column_or_1d(y_pred) + if y_type.startswith('multilabel'): + if y_type == 'multilabel-sequences': + labels = unique_labels(y_true, y_pred) + binarizer = MultiLabelBinarizer(classes=labels, sparse_output=True) + y_true = binarizer.fit_transform(y_true) + y_pred = binarizer.fit_transform(y_pred) + + y_true = csr_matrix(y_true) + y_pred = csr_matrix(y_pred) + y_type = 'multilabel-indicator' + return y_type, y_true, y_pred +def _weighted_sum(sample_score, sample_weight, normalize=False): + if normalize: + return np.average(sample_score, weights=sample_weight) + elif sample_weight is not None: + return np.dot(sample_score, sample_weight) + else: + return sample_score.sum() + + def accuracy_score(y_true, y_pred, normalize=True, sample_weight=None): """Accuracy classification score. @@ -100,10 +125,10 @@ def accuracy_score(y_true, y_pred, normalize=True, sample_weight=None): Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) labels. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Predicted labels, as returned by a classifier. normalize : bool, optional (default=True) @@ -149,23 +174,14 @@ def accuracy_score(y_true, y_pred, normalize=True, sample_weight=None): """ # Compute accuracy for each possible representation - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) - if y_type == 'multilabel-indicator': - score = (y_pred != y_true).sum(axis=1) == 0 - elif y_type == 'multilabel-sequences': - score = np.array([len(set(true) ^ set(pred)) == 0 - for pred, true in zip(y_pred, y_true)]) + y_type, y_true, y_pred = _check_targets(y_true, y_pred) + if y_type.startswith('multilabel'): + differing_labels = count_nonzero(y_true - y_pred, axis=1) + score = differing_labels == 0 else: score = y_true == y_pred - if normalize: - if sample_weight is not None: - return np.average(score, weights=sample_weight) - return np.mean(score) - else: - if sample_weight is not None: - return np.dot(score, sample_weight) - return np.sum(score) + return _weighted_sum(score, sample_weight, normalize) def confusion_matrix(y_true, y_pred, labels=None): @@ -210,7 +226,7 @@ def confusion_matrix(y_true, y_pred, labels=None): [1, 0, 2]]) """ - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) + y_type, y_true, y_pred = _check_targets(y_true, y_pred) if y_type not in ("binary", "multiclass"): raise ValueError("%s is not supported" % y_type) @@ -237,7 +253,8 @@ def confusion_matrix(y_true, y_pred, labels=None): return CM -def jaccard_similarity_score(y_true, y_pred, normalize=True): +def jaccard_similarity_score(y_true, y_pred, normalize=True, + sample_weight=None): """Jaccard similarity coefficient score The Jaccard index [1], or Jaccard similarity coefficient, defined as @@ -247,10 +264,10 @@ def jaccard_similarity_score(y_true, y_pred, normalize=True): Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) labels. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Predicted labels, as returned by a classifier. normalize : bool, optional (default=True) @@ -258,6 +275,9 @@ def jaccard_similarity_score(y_true, y_pred, normalize=True): over the sample set. Otherwise, return the average of Jaccard similarity coefficient. + sample_weight : array-like of shape = [n_samples], optional + Sample weights. + Returns ------- score : float @@ -303,46 +323,22 @@ def jaccard_similarity_score(y_true, y_pred, normalize=True): """ # Compute accuracy for each possible representation - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) - if y_type == 'multilabel-indicator': + y_type, y_true, y_pred = _check_targets(y_true, y_pred) + if y_type.startswith('multilabel'): with np.errstate(divide='ignore', invalid='ignore'): - # oddly, we may get an "invalid" rather than a "divide" - # error here - y_pred_pos_label = y_pred == 1 - y_true_pos_label = y_true == 1 - pred_inter_true = np.sum(np.logical_and(y_pred_pos_label, - y_true_pos_label), - axis=1) - pred_union_true = np.sum(np.logical_or(y_pred_pos_label, - y_true_pos_label), - axis=1) - score = pred_inter_true / pred_union_true + # oddly, we may get an "invalid" rather than a "divide" error here + pred_or_true = count_nonzero(y_true + y_pred, axis=1) + pred_and_true = count_nonzero(y_true.multiply(y_pred), axis=1) + score = pred_and_true / pred_or_true # If there is no label, it results in a Nan instead, we set # the jaccard to 1: lim_{x->0} x/x = 1 # Note with py2.6 and np 1.3: we can't check safely for nan. - score[pred_union_true == 0.0] = 1.0 - - elif y_type == 'multilabel-sequences': - score = np.empty(len(y_true), dtype=np.float) - for i, (true, pred) in enumerate(zip(y_pred, y_true)): - true_set = set(true) - pred_set = set(pred) - size_true_union_pred = len(true_set | pred_set) - # If there is no label, it results in a Nan instead, we set - # the jaccard to 1: lim_{x->0} x/x = 1 - if size_true_union_pred == 0: - score[i] = 1. - else: - score[i] = (len(true_set & pred_set) / - size_true_union_pred) + score[pred_or_true == 0.0] = 1.0 else: score = y_true == y_pred - if normalize: - return np.mean(score) - else: - return np.sum(score) + return _weighted_sum(score, sample_weight, normalize) def matthews_corrcoef(y_true, y_pred): @@ -393,7 +389,7 @@ def matthews_corrcoef(y_true, y_pred): -0.33... """ - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) + y_type, y_true, y_pred = _check_targets(y_true, y_pred) if y_type != "binary": raise ValueError("%s is not supported" % y_type) @@ -420,10 +416,10 @@ def zero_one_loss(y_true, y_pred, normalize=True, sample_weight=None): Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) labels. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Predicted labels, as returned by a classifier. normalize : bool, optional (default=True) @@ -474,7 +470,7 @@ def zero_one_loss(y_true, y_pred, normalize=True, sample_weight=None): if sample_weight is not None: n_samples = np.sum(sample_weight) else: - n_samples = len(y_true) + n_samples = _num_samples(y_true) return n_samples - score @@ -494,10 +490,10 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='weighted', Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. labels : array @@ -577,10 +573,10 @@ def fbeta_score(y_true, y_pred, beta, labels=None, pos_label=1, Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. beta: float @@ -736,10 +732,10 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None, Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. beta : float, 1.0 by default @@ -831,7 +827,7 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None, if beta <= 0: raise ValueError("beta should be >0 in the F-beta score") - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) + y_type, y_true, y_pred = _check_targets(y_true, y_pred) label_order = labels # save this for later if labels is None: @@ -842,28 +838,16 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None, ### Calculate tp_sum, pred_sum, true_sum ### if y_type.startswith('multilabel'): - if y_type == 'multilabel-sequences': - y_true = label_binarize(y_true, labels, multilabel=True) - y_pred = label_binarize(y_pred, labels, multilabel=True) - else: - # set negative labels to zero - y_true = y_true == 1 - y_pred = y_pred == 1 - - if sample_weight is None: - sum_weight = 1 - dtype = int - else: - sum_weight = np.expand_dims(sample_weight, 1) - dtype = float - sum_axis = 1 if average == 'samples' else 0 - tp_sum = np.multiply(np.logical_and(y_true, y_pred), - sum_weight).sum(axis=sum_axis, dtype=dtype) - pred_sum = np.sum(np.multiply(y_pred, sum_weight), - axis=sum_axis, dtype=dtype) - true_sum = np.sum(np.multiply(y_true, sum_weight), - axis=sum_axis, dtype=dtype) + + # calculate weighted counts + true_and_pred = y_true.multiply(y_pred) + tp_sum = count_nonzero(true_and_pred, axis=sum_axis, + sample_weight=sample_weight) + pred_sum = count_nonzero(y_pred, axis=sum_axis, + sample_weight=sample_weight) + true_sum = count_nonzero(y_true, axis=sum_axis, + sample_weight=sample_weight) elif average == 'samples': raise ValueError("Sample-based precision, recall, fscore is " @@ -981,10 +965,10 @@ def precision_score(y_true, y_pred, labels=None, pos_label=1, Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. labels : array @@ -1063,10 +1047,10 @@ def recall_score(y_true, y_pred, labels=None, pos_label=1, average='weighted', Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. labels : array @@ -1138,10 +1122,10 @@ def classification_report(y_true, y_pred, labels=None, target_names=None, Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) target values. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Estimated targets as returned by a classifier. labels : array, shape = [n_labels] @@ -1232,10 +1216,10 @@ def hamming_loss(y_true, y_pred, classes=None): Parameters ---------- - y_true : array-like or label indicator matrix + y_true : 1d array-like, or label indicator array / sparse matrix Ground truth (correct) labels. - y_pred : array-like or label indicator matrix + y_pred : 1d array-like, or label indicator array / sparse matrix Predicted labels, as returned by a classifier. classes : array, shape = [n_labels], optional @@ -1288,20 +1272,16 @@ def hamming_loss(y_true, y_pred, classes=None): >>> hamming_loss(np.array([[0, 1], [1, 1]]), np.zeros((2, 2))) 0.75 """ - y_type, y_true, y_pred = _check_clf_targets(y_true, y_pred) + y_type, y_true, y_pred = _check_targets(y_true, y_pred) if classes is None: classes = unique_labels(y_true, y_pred) else: classes = np.asarray(classes) - if y_type == 'multilabel-indicator': - return np.mean(y_true != y_pred) - elif y_type == 'multilabel-sequences': - loss = np.array([len(set(pred).symmetric_difference(true)) - for pred, true in zip(y_pred, y_true)]) - - return np.mean(loss) / np.size(classes) + if y_type.startswith('multilabel'): + n_differences = count_nonzero(y_true - y_pred) + return (n_differences / (y_true.shape[0] * len(classes))) elif y_type in ["binary", "multiclass"]: return sp_hamming(y_true, y_pred) @@ -1309,7 +1289,7 @@ def hamming_loss(y_true, y_pred, classes=None): raise ValueError("{0} is not supported".format(y_type)) -def log_loss(y_true, y_pred, eps=1e-15, normalize=True): +def log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None): """Log loss, aka logistic loss or cross-entropy loss. This is the loss function used in (multinomial) logistic regression @@ -1337,6 +1317,9 @@ def log_loss(y_true, y_pred, eps=1e-15, normalize=True): If true, return the mean loss per sample. Otherwise, return the sum of the per-sample losses. + sample_weight : array-like of shape = [n_samples], optional + Sample weights. + Returns ------- loss : float @@ -1385,8 +1368,9 @@ def log_loss(y_true, y_pred, eps=1e-15, normalize=True): # Renormalize Y /= Y.sum(axis=1)[:, np.newaxis] - loss = -(T * np.log(Y)).sum() - return loss / T.shape[0] if normalize else loss + loss = -(T * np.log(Y)).sum(axis=1) + + return _weighted_sum(loss, sample_weight, normalize) def hinge_loss(y_true, pred_decision, pos_label=None, neg_label=None): @@ -1425,8 +1409,8 @@ def hinge_loss(y_true, pred_decision, pos_label=None, neg_label=None): >>> est = svm.LinearSVC(random_state=0) >>> est.fit(X, y) LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True, - intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2', - random_state=0, tol=0.0001, verbose=0) + intercept_scaling=1, loss='l2', max_iter=1000, multi_class='ovr', + penalty='l2', random_state=0, tol=0.0001, verbose=0) >>> pred_decision = est.decision_function([[-2], [3], [0.5]]) >>> pred_decision # doctest: +ELLIPSIS array([-2.18..., 2.36..., 0.09...]) diff --git a/sklearn/metrics/metrics.py b/sklearn/metrics/metrics.py index 7a36a69edb6e7..efb86a158d917 100644 --- a/sklearn/metrics/metrics.py +++ b/sklearn/metrics/metrics.py @@ -33,4 +33,3 @@ # Deprecated in 0.16 from .ranking import auc_score - diff --git a/sklearn/metrics/ranking.py b/sklearn/metrics/ranking.py index 848e56f1acaef..47efce7520137 100644 --- a/sklearn/metrics/ranking.py +++ b/sklearn/metrics/ranking.py @@ -21,6 +21,7 @@ import warnings import numpy as np +from scipy.sparse import csr_matrix from ..preprocessing import LabelBinarizer from ..utils import check_consistent_length @@ -562,7 +563,7 @@ def label_ranking_average_precision_score(y_true, y_score): Parameters ---------- - y_true : array, shape = [n_samples, n_labels] + y_true : array or sparse matrix, shape = [n_samples, n_labels] True binary labels in binary indicator format. y_score : array, shape = [n_samples, n_labels] @@ -597,11 +598,14 @@ def label_ranking_average_precision_score(y_true, y_score): and not (y_type == "binary" and y_true.ndim == 2)): raise ValueError("{0} format is not supported".format(y_type)) + y_true = csr_matrix(y_true) + y_score = -y_score + n_samples, n_labels = y_true.shape out = 0. - for i in range(n_samples): - relevant = y_true[i].nonzero()[0] + for i, (start, stop) in enumerate(zip(y_true.indptr, y_true.indptr[1:])): + relevant = y_true.indices[start:stop] if (relevant.size == 0 or relevant.size == n_labels): # If all labels are relevant or unrelevant, the score is also @@ -609,10 +613,9 @@ def label_ranking_average_precision_score(y_true, y_score): out += 1. continue - scores_i = - y_score[i] - true_mask = y_true[i].astype(bool) - rank = rankdata(scores_i, 'max')[true_mask] - L = rankdata(scores_i[true_mask], 'max') + scores_i = y_score[i] + rank = rankdata(scores_i, 'max')[relevant] + L = rankdata(scores_i[relevant], 'max') out += np.divide(L, rank, dtype=float).mean() return out / n_samples diff --git a/sklearn/metrics/tests/test_classification.py b/sklearn/metrics/tests/test_classification.py index c79aeee603677..762a49e14fa18 100644 --- a/sklearn/metrics/tests/test_classification.py +++ b/sklearn/metrics/tests/test_classification.py @@ -42,7 +42,7 @@ from sklearn.metrics import zero_one_loss -from sklearn.metrics.classification import _check_clf_targets +from sklearn.metrics.classification import _check_targets from sklearn.metrics.base import UndefinedMetricWarning @@ -956,8 +956,8 @@ def test_fscore_warnings(): @ignore_warnings # sequence of sequences is deprecated -def test__check_clf_targets(): - """Check that _check_clf_targets correctly merges target types, squeezes +def test__check_targets(): + """Check that _check_targets correctly merges target types, squeezes output and fails if input lengths differ.""" IND = 'multilabel-indicator' SEQ = 'multilabel-sequences' @@ -985,7 +985,7 @@ def test__check_clf_targets(): # (types will be tried in either order) EXPECTED = { (IND, IND): IND, - (SEQ, SEQ): SEQ, + (SEQ, SEQ): IND, (MC, MC): MC, (BIN, BIN): BIN, @@ -1023,27 +1023,30 @@ def test__check_clf_targets(): except KeyError: expected = EXPECTED[type2, type1] if expected is None: - assert_raises(ValueError, _check_clf_targets, y1, y2) + assert_raises(ValueError, _check_targets, y1, y2) if type1 != type2: assert_raise_message( ValueError, "Can't handle mix of {0} and {1}".format(type1, type2), - _check_clf_targets, y1, y2) + _check_targets, y1, y2) else: if type1 not in (BIN, MC, SEQ, IND): assert_raise_message(ValueError, "{0} is not supported".format(type1), - _check_clf_targets, y1, y2) + _check_targets, y1, y2) else: - merged_type, y1out, y2out = _check_clf_targets(y1, y2) + merged_type, y1out, y2out = _check_targets(y1, y2) assert_equal(merged_type, expected) - if not merged_type.startswith('multilabel'): + if merged_type.startswith('multilabel'): + assert_equal(y1out.format, 'csr') + assert_equal(y2out.format, 'csr') + else: assert_array_equal(y1out, np.squeeze(y1)) assert_array_equal(y2out, np.squeeze(y2)) - assert_raises(ValueError, _check_clf_targets, y1[:-1], y2) + assert_raises(ValueError, _check_targets, y1[:-1], y2) def test_hinge_loss_binary(): diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index 82bec50c49048..efbaf244aee56 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1,9 +1,11 @@ from __future__ import division, print_function -import numpy as np from functools import partial from itertools import product +import numpy as np +import scipy.sparse as sp + from sklearn.datasets import make_multilabel_classification from sklearn.preprocessing import LabelBinarizer, MultiLabelBinarizer from sklearn.utils.multiclass import type_of_target @@ -136,6 +138,8 @@ THRESHOLDED_METRICS = { "log_loss": log_loss, + "unnormalized_log_loss": partial(log_loss, normalize=False), + "hinge_loss": hinge_loss, "roc_auc_score": roc_auc_score, @@ -239,6 +243,7 @@ # Threshold-based metrics with "multilabel-indicator" format support THRESHOLDED_MULTILABEL_METRICS = [ "log_loss", + "unnormalized_log_loss", "roc_auc_score", "weighted_roc_auc", "samples_roc_auc", "micro_roc_auc", "macro_roc_auc", @@ -315,8 +320,6 @@ "confusion_matrix", "hamming_loss", "hinge_loss", - "jaccard_similarity_score", "unnormalized_jaccard_similarity_score", - "log_loss", "matthews_corrcoef_score", ] @@ -533,7 +536,7 @@ def test_invariance_string_vs_numbers_labels(): "invariance test".format(name)) for name, metric in THRESHOLDED_METRICS.items(): - if name in ("log_loss", "hinge_loss"): + if name in ("log_loss", "hinge_loss", "unnormalized_log_loss"): measure_with_number = metric(y1, y2) measure_with_str = metric(y1_str, y2) assert_array_equal(measure_with_number, measure_with_str, @@ -613,7 +616,6 @@ def test_multioutput_regression_invariance_to_dimension_shuffling(): def test_multilabel_representation_invariance(): - # Generate some data n_classes = 4 n_samples = 50 @@ -636,7 +638,6 @@ def test_multilabel_representation_invariance(): y2_shuffle = [shuffled(x) for x in y2] # Let's have redundant labels - y1_redundant = [x * rng.randint(1, 4) for x in y1] y2_redundant = [x * rng.randint(1, 4) for x in y2] # Binary indicator matrix format @@ -644,6 +645,9 @@ def test_multilabel_representation_invariance(): y1_binary_indicator = lb.transform(y1) y2_binary_indicator = lb.transform(y2) + y1_sparse_indicator = sp.coo_matrix(y1_binary_indicator) + y2_sparse_indicator = sp.coo_matrix(y2_binary_indicator) + y1_shuffle_binary_indicator = lb.transform(y1_shuffle) y2_shuffle_binary_indicator = lb.transform(y2_shuffle) @@ -654,38 +658,16 @@ def test_multilabel_representation_invariance(): if isinstance(metric, partial): metric.__module__ = 'tmp' metric.__name__ = name - # Check warning for sequence of sequences - measure = assert_warns(DeprecationWarning, metric, y1, y2) - metric = ignore_warnings(metric) + + measure = metric(y1_binary_indicator, y2_binary_indicator) # Check representation invariance - assert_almost_equal(metric(y1_binary_indicator, - y2_binary_indicator), + assert_almost_equal(metric(y1_sparse_indicator, + y2_sparse_indicator), measure, err_msg="%s failed representation invariance " - "between list of list of labels " - "format and dense binary indicator " - "format." % name) - - with ignore_warnings(): # sequence of sequences is deprecated - # Check invariance with redundant labels with list of labels - assert_almost_equal(metric(y1, y2_redundant), measure, - err_msg="%s failed rendundant label invariance" - % name) - - assert_almost_equal(metric(y1_redundant, y2_redundant), measure, - err_msg="%s failed rendundant label invariance" - % name) - - assert_almost_equal(metric(y1_redundant, y2), measure, - err_msg="%s failed rendundant label invariance" - % name) - - # Check shuffling invariance with list of labels - assert_almost_equal(metric(y1_shuffle, y2_shuffle), measure, - err_msg="%s failed shuffling invariance " - "with list of list of labels format." - % name) + "between dense and sparse indicator " + "formats." % name) # Check shuffling invariance with dense binary indicator matrix assert_almost_equal(metric(y1_shuffle_binary_indicator, @@ -694,10 +676,31 @@ def test_multilabel_representation_invariance(): " with dense binary indicator format." % name) - with ignore_warnings(): # sequence of sequences is deprecated - # Check raises error with mix input representation - assert_raises(ValueError, metric, y1, y2_binary_indicator) - assert_raises(ValueError, metric, y1_binary_indicator, y2) + # Check deprecation warnings related to sequence of sequences + deprecated_metric = partial(assert_warns, DeprecationWarning, metric) + + # Check representation invariance + assert_almost_equal(deprecated_metric(y1, y2), + measure, + err_msg="%s failed representation invariance " + "between list of list of labels " + "format and dense binary indicator " + "format." % name) + + # Check invariance with redundant labels with list of labels + assert_almost_equal(deprecated_metric(y1, y2_redundant), measure, + err_msg="%s failed rendundant label invariance" + % name) + + # Check shuffling invariance with list of labels + assert_almost_equal(deprecated_metric(y1_shuffle, y2_shuffle), measure, + err_msg="%s failed shuffling invariance " + "with list of list of labels format." + % name) + + # Check raises error with mix input representation + assert_raises(ValueError, deprecated_metric, y1, y2_binary_indicator) + assert_raises(ValueError, deprecated_metric, y1_binary_indicator, y2) def test_normalize_option_binary_classification(n_samples=20): @@ -904,10 +907,10 @@ def check_sample_weight_invariance(name, metric, y1, y2): # check that unit weights gives the same score as no weight unweighted_score = metric(y1, y2, sample_weight=None) - assert_equal( + assert_almost_equal( unweighted_score, metric(y1, y2, sample_weight=np.ones(shape=len(y1))), - msg="For %s sample_weight=None is not equivalent to " + err_msg="For %s sample_weight=None is not equivalent to " "sample_weight=ones" % name) # check that the weighted and unweighted scores are unequal @@ -920,9 +923,9 @@ def check_sample_weight_invariance(name, metric, y1, y2): # check that sample_weight can be a list weighted_score_list = metric(y1, y2, sample_weight=sample_weight.tolist()) - assert_equal( + assert_almost_equal( weighted_score, weighted_score_list, - msg="Weighted scores for array and list sample_weight input are " + err_msg="Weighted scores for array and list sample_weight input are " "not equal (%f != %f) for %s" % ( weighted_score, weighted_score_list, name)) @@ -969,23 +972,31 @@ def test_sample_weight_invariance(n_samples=50): random_state = check_random_state(0) y_true = random_state.randint(0, 2, size=(n_samples, )) y_pred = random_state.randint(0, 2, size=(n_samples, )) + y_score = random_state.random_sample(size=(n_samples,)) for name in ALL_METRICS: if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or name in METRIC_UNDEFINED_MULTICLASS): continue metric = ALL_METRICS[name] - yield check_sample_weight_invariance, name, metric, y_true, y_pred + if name in THRESHOLDED_METRICS: + yield check_sample_weight_invariance, name, metric, y_true, y_score + else: + yield check_sample_weight_invariance, name, metric, y_true, y_pred # multiclass random_state = check_random_state(0) y_true = random_state.randint(0, 5, size=(n_samples, )) y_pred = random_state.randint(0, 5, size=(n_samples, )) + y_score = random_state.random_sample(size=(n_samples, 5)) for name in ALL_METRICS: if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or name in METRIC_UNDEFINED_MULTICLASS): continue metric = ALL_METRICS[name] - yield check_sample_weight_invariance, name, metric, y_true, y_pred + if name in THRESHOLDED_METRICS: + yield check_sample_weight_invariance, name, metric, y_true, y_score + else: + yield check_sample_weight_invariance, name, metric, y_true, y_pred # multilabel sequence y_true = 2 * [(1, 2, ), (1, ), (0, ), (0, 1), (1, 2)] diff --git a/sklearn/mixture/dpgmm.py b/sklearn/mixture/dpgmm.py index 1ec41ab1448ce..d1b3b5028c3ba 100644 --- a/sklearn/mixture/dpgmm.py +++ b/sklearn/mixture/dpgmm.py @@ -164,13 +164,13 @@ class DPGMM(GMM): n_components : int Number of mixture components. - `weights_` : array, shape (`n_components`,) + weights_ : array, shape (`n_components`,) Mixing weights for each mixture component. - `means_` : array, shape (`n_components`, `n_features`) + means_ : array, shape (`n_components`, `n_features`) Mean parameters for each mixture component. - `precs_` : array + precs_ : array Precision (inverse covariance) parameters for each mixture component. The shape depends on `covariance_type`:: @@ -179,7 +179,7 @@ class DPGMM(GMM): (`n_components`, `n_features`) if 'diag', (`n_components`, `n_features`, `n_features`) if 'full' - `converged_` : bool + converged_ : bool True when convergence was reached in fit(), False otherwise. See Also @@ -619,13 +619,13 @@ class VBGMM(DPGMM): n_components : int (read-only) Number of mixture components. - `weights_` : array, shape (`n_components`,) + weights_ : array, shape (`n_components`,) Mixing weights for each mixture component. - `means_` : array, shape (`n_components`, `n_features`) + means_ : array, shape (`n_components`, `n_features`) Mean parameters for each mixture component. - `precs_` : array + precs_ : array Precision (inverse covariance) parameters for each mixture component. The shape depends on `covariance_type`:: @@ -634,7 +634,7 @@ class VBGMM(DPGMM): (`n_components`, `n_features`) if 'diag', (`n_components`, `n_features`, `n_features`) if 'full' - `converged_` : bool + converged_ : bool True when convergence was reached in fit(), False otherwise. diff --git a/sklearn/mixture/gmm.py b/sklearn/mixture/gmm.py index 1641ff86509ca..2ed1a684d5696 100644 --- a/sklearn/mixture/gmm.py +++ b/sklearn/mixture/gmm.py @@ -155,13 +155,13 @@ class GMM(BaseEstimator): Attributes ---------- - `weights_` : array, shape (`n_components`,) + weights_ : array, shape (`n_components`,) This attribute stores the mixing weights for each mixture component. - `means_` : array, shape (`n_components`, `n_features`) + means_ : array, shape (`n_components`, `n_features`) Mean parameters for each mixture component. - `covars_` : array + covars_ : array Covariance parameters for each mixture component. The shape depends on `covariance_type`:: @@ -170,7 +170,7 @@ class GMM(BaseEstimator): (n_components, n_features) if 'diag', (n_components, n_features, n_features) if 'full' - `converged_` : bool + converged_ : bool True when convergence was reached in fit(), False otherwise. diff --git a/sklearn/multiclass.py b/sklearn/multiclass.py index 5c255c7c7b63a..dcb9f55a7f9e4 100644 --- a/sklearn/multiclass.py +++ b/sklearn/multiclass.py @@ -223,15 +223,15 @@ class OneVsRestClassifier(BaseEstimator, ClassifierMixin, MetaEstimatorMixin): Attributes ---------- - `estimators_` : list of `n_classes` estimators + estimators_ : list of `n_classes` estimators Estimators used for predictions. - `classes_` : array, shape = [`n_classes`] + classes_ : array, shape = [`n_classes`] Class labels. - `label_binarizer_` : LabelBinarizer object + label_binarizer_ : LabelBinarizer object Object used to transform multiclass labels to binary labels and vice-versa. - `multilabel_` : boolean + multilabel_ : boolean Whether a OneVsRestClassifier is a multilabel classifier. """ @@ -460,10 +460,10 @@ class OneVsOneClassifier(BaseEstimator, ClassifierMixin, MetaEstimatorMixin): Attributes ---------- - `estimators_` : list of `n_classes * (n_classes - 1) / 2` estimators + estimators_ : list of `n_classes * (n_classes - 1) / 2` estimators Estimators used for predictions. - `classes_` : numpy array of shape [n_classes] + classes_ : numpy array of shape [n_classes] Array containing labels. """ @@ -566,7 +566,7 @@ def fit_ecoc(estimator, X, y, code_size=1.5, random_state=None, n_jobs=1): classes : numpy array of shape [n_classes] Array containing labels. - `code_book_`: numpy array of shape [n_classes, code_size] + code_book_ : numpy array of shape [n_classes, code_size] Binary array containing the code of each class. """ ecoc = OutputCodeClassifier(estimator, random_state=random_state, @@ -622,13 +622,13 @@ class OutputCodeClassifier(BaseEstimator, ClassifierMixin, MetaEstimatorMixin): Attributes ---------- - `estimators_` : list of `int(n_classes * code_size)` estimators + estimators_ : list of `int(n_classes * code_size)` estimators Estimators used for predictions. - `classes_` : numpy array of shape [n_classes] + classes_ : numpy array of shape [n_classes] Array containing labels. - `code_book_` : numpy array of shape [n_classes, code_size] + code_book_ : numpy array of shape [n_classes, code_size] Binary array containing the code of each class. References diff --git a/sklearn/naive_bayes.py b/sklearn/naive_bayes.py index e025a6f7b9af8..fdd09cbad5a62 100644 --- a/sklearn/naive_bayes.py +++ b/sklearn/naive_bayes.py @@ -112,16 +112,16 @@ class GaussianNB(BaseNB): Attributes ---------- - `class_prior_` : array, shape (n_classes,) + class_prior_ : array, shape (n_classes,) probability of each class. - `class_count_` : array, shape (n_classes,) + class_count_ : array, shape (n_classes,) number of training samples observed in each class. - `theta_` : array, shape (n_classes, n_features) + theta_ : array, shape (n_classes, n_features) mean of each feature per class - `sigma_` : array, shape (n_classes, n_features) + sigma_ : array, shape (n_classes, n_features) variance of each feature per class Examples @@ -323,7 +323,7 @@ def _joint_log_likelihood(self, X): joint_log_likelihood = [] for i in range(np.size(self.classes_)): jointi = np.log(self.class_prior_[i]) - n_ij = - 0.5 * np.sum(np.log(np.pi * self.sigma_[i, :])) + n_ij = - 0.5 * np.sum(np.log(2. * np.pi * self.sigma_[i, :])) n_ij -= 0.5 * np.sum(((X - self.theta_[i, :]) ** 2) / (self.sigma_[i, :]), 1) joint_log_likelihood.append(jointi + n_ij) @@ -517,26 +517,26 @@ class MultinomialNB(BaseDiscreteNB): Attributes ---------- - `class_log_prior_` : array, shape (n_classes, ) + class_log_prior_ : array, shape (n_classes, ) Smoothed empirical log probability for each class. - `intercept_` : property + intercept_ : property Mirrors ``class_log_prior_`` for interpreting MultinomialNB as a linear model. - `feature_log_prob_`: array, shape (n_classes, n_features) + feature_log_prob_ : array, shape (n_classes, n_features) Empirical log probability of features given a class, ``P(x_i|y)``. - `coef_` : property + coef_ : property Mirrors ``feature_log_prob_`` for interpreting MultinomialNB as a linear model. - `class_count_` : array, shape (n_classes,) + class_count_ : array, shape (n_classes,) Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided. - `feature_count_` : array, shape (n_classes, n_features) + feature_count_ : array, shape (n_classes, n_features) Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided. @@ -621,17 +621,17 @@ class BernoulliNB(BaseDiscreteNB): Attributes ---------- - `class_log_prior_` : array, shape = [n_classes] + class_log_prior_ : array, shape = [n_classes] Log probability of each class (smoothed). - `feature_log_prob_` : array, shape = [n_classes, n_features] + feature_log_prob_ : array, shape = [n_classes, n_features] Empirical log probability of features given a class, P(x_i|y). - `class_count_` : array, shape = [n_classes] + class_count_ : array, shape = [n_classes] Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided. - `feature_count_` : array, shape = [n_classes, n_features] + feature_count_ : array, shape = [n_classes, n_features] Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided. diff --git a/sklearn/neighbors/base.py b/sklearn/neighbors/base.py index dbf8126f8a889..b382858493ad1 100644 --- a/sklearn/neighbors/base.py +++ b/sklearn/neighbors/base.py @@ -98,13 +98,23 @@ def __init__(self): def _init_params(self, n_neighbors=None, radius=None, algorithm='auto', leaf_size=30, metric='minkowski', - p=2, **kwargs): + p=2, metric_params=None, **kwargs): + if kwargs: + warnings.warn("Passing additional arguments to the metric " + "function as **kwargs is deprecated " + "and will no longer be supported in 0.18. " + "Use metric_params instead.", + DeprecationWarning, stacklevel=3) + if metric_params is None: + metric_params = {} + metric_params.update(kwargs) + self.n_neighbors = n_neighbors self.radius = radius self.algorithm = algorithm self.leaf_size = leaf_size self.metric = metric - self.metric_kwds = kwargs + self.metric_params = metric_params self.p = p if algorithm not in ['auto', 'brute', @@ -126,24 +136,35 @@ def _init_params(self, n_neighbors=None, radius=None, raise ValueError("Metric '%s' not valid for algorithm '%s'" % (metric, algorithm)) - if self.metric in ['wminkowski', 'minkowski']: - self.metric_kwds['p'] = p - if p < 1: - raise ValueError("p must be greater than one " - "for minkowski metric") + if self.metric_params is not None and 'p' in self.metric_params: + warnings.warn("Parameter p is found in metric_params. " + "The corresponding parameter from __init__ " + "is ignored.", SyntaxWarning, stacklevel=3) + effective_p = metric_params['p'] + else: + effective_p = self.p + + if self.metric in ['wminkowski', 'minkowski'] and effective_p < 1: + raise ValueError("p must be greater than one for minkowski metric") self._fit_X = None self._tree = None self._fit_method = None def _fit(self, X): - self.effective_metric_ = self.metric - self.effective_metric_kwds_ = self.metric_kwds + if self.metric_params is None: + self.effective_metric_params_ = {} + else: + self.effective_metric_params_ = self.metric_params.copy() + effective_p = self.effective_metric_params_.get('p', self.p) + if self.metric in ['wminkowski', 'minkowski']: + self.effective_metric_params_['p'] = effective_p + + self.effective_metric_ = self.metric # For minkowski distance, use more efficient methods where available if self.metric == 'minkowski': - self.effective_metric_kwds_ = self.metric_kwds.copy() - p = self.effective_metric_kwds_.pop('p', 2) + p = self.effective_metric_params_.pop('p', 2) if p < 1: raise ValueError("p must be greater than one " "for minkowski metric") @@ -154,7 +175,7 @@ def _fit(self, X): elif p == np.inf: self.effective_metric_ = 'chebyshev' else: - self.effective_metric_kwds_['p'] = p + self.effective_metric_params_['p'] = p if isinstance(X, NeighborsBase): self._fit_X = X._fit_X @@ -210,11 +231,11 @@ def _fit(self, X): if self._fit_method == 'ball_tree': self._tree = BallTree(X, self.leaf_size, metric=self.effective_metric_, - **self.effective_metric_kwds_) + **self.effective_metric_params_) elif self._fit_method == 'kd_tree': self._tree = KDTree(X, self.leaf_size, metric=self.effective_metric_, - **self.effective_metric_kwds_) + **self.effective_metric_params_) elif self._fit_method == 'brute': self._tree = None else: @@ -292,7 +313,7 @@ class from an array representing our data set and ask who's else: dist = pairwise_distances(X, self._fit_X, self.effective_metric_, - **self.effective_metric_kwds_) + **self.effective_metric_params_) neigh_ind = argpartition(dist, n_neighbors - 1, axis=1) neigh_ind = neigh_ind[:, :n_neighbors] @@ -456,7 +477,7 @@ class from an array representing our data set and ask who's else: dist = pairwise_distances(X, self._fit_X, self.effective_metric_, - **self.effective_metric_kwds_) + **self.effective_metric_params_) neigh_ind = [np.where(d < radius)[0] for d in dist] # if there are the same number of neighbors for each point, diff --git a/sklearn/neighbors/classification.py b/sklearn/neighbors/classification.py index 36d7c07108da0..8ac1050279d89 100644 --- a/sklearn/neighbors/classification.py +++ b/sklearn/neighbors/classification.py @@ -61,7 +61,7 @@ class KNeighborsClassifier(NeighborsBase, KNeighborsMixin, required to store the tree. The optimal value depends on the nature of the problem. - metric : string or DistanceMetric object (default='minkowski') + metric : string or DistanceMetric object (default = 'minkowski') the distance metric to use for the tree. The default metric is minkowski, and with p=2 is equivalent to the standard Euclidean metric. See the documentation of the DistanceMetric class for a @@ -72,9 +72,8 @@ class KNeighborsClassifier(NeighborsBase, KNeighborsMixin, equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used. - **kwargs : - additional keyword arguments are passed to the distance function as - additional arguments. + metric_params: dict, optional (default = None) + additional keyword arguments for the metric function. Examples -------- @@ -113,10 +112,12 @@ class KNeighborsClassifier(NeighborsBase, KNeighborsMixin, def __init__(self, n_neighbors=5, weights='uniform', algorithm='auto', leaf_size=30, - p=2, metric='minkowski', **kwargs): + p=2, metric='minkowski', metric_params=None, **kwargs): + self._init_params(n_neighbors=n_neighbors, algorithm=algorithm, - leaf_size=leaf_size, metric=metric, p=p, **kwargs) + leaf_size=leaf_size, metric=metric, p=p, + metric_params=metric_params, **kwargs) self.weights = _check_weights(weights) def predict(self, X): @@ -277,9 +278,8 @@ class RadiusNeighborsClassifier(NeighborsBase, RadiusNeighborsMixin, neighbors on given radius). If set to None, ValueError is raised, when outlier is detected. - **kwargs : - additional keyword arguments are passed to the distance function as - additional arguments. + metric_params: dict, optional (default = None) + additional keyword arguments for the metric function. Examples -------- @@ -309,11 +309,12 @@ class RadiusNeighborsClassifier(NeighborsBase, RadiusNeighborsMixin, def __init__(self, radius=1.0, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', - outlier_label=None, **kwargs): + outlier_label=None, metric_params=None, **kwargs): self._init_params(radius=radius, algorithm=algorithm, leaf_size=leaf_size, - metric=metric, p=p, **kwargs) + metric=metric, p=p, metric_params=metric_params, + **kwargs) self.weights = _check_weights(weights) self.outlier_label = outlier_label diff --git a/sklearn/neighbors/nearest_centroid.py b/sklearn/neighbors/nearest_centroid.py index 71100fa2c19cf..6ef0896a34d36 100644 --- a/sklearn/neighbors/nearest_centroid.py +++ b/sklearn/neighbors/nearest_centroid.py @@ -35,7 +35,7 @@ class NearestCentroid(BaseEstimator, ClassifierMixin): Attributes ---------- - `centroids_` : array-like, shape = [n_classes, n_features] + centroids_ : array-like, shape = [n_classes, n_features] Centroid of each class Examples diff --git a/sklearn/neighbors/regression.py b/sklearn/neighbors/regression.py index 05bddb2e3c0ff..a6285c77d9fef 100644 --- a/sklearn/neighbors/regression.py +++ b/sklearn/neighbors/regression.py @@ -72,9 +72,8 @@ class KNeighborsRegressor(NeighborsBase, KNeighborsMixin, equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used. - **kwargs : - additional keyword arguments are passed to the distance function as - additional arguments. + metric_params: dict, optional (default = None) + additional keyword arguments for the metric function. Examples -------- @@ -111,10 +110,11 @@ class KNeighborsRegressor(NeighborsBase, KNeighborsMixin, def __init__(self, n_neighbors=5, weights='uniform', algorithm='auto', leaf_size=30, - p=2, metric='minkowski', **kwargs): + p=2, metric='minkowski', metric_params=None, **kwargs): self._init_params(n_neighbors=n_neighbors, algorithm=algorithm, - leaf_size=leaf_size, metric=metric, p=p, **kwargs) + leaf_size=leaf_size, metric=metric, p=p, + metric_params=metric_params, **kwargs) self.weights = _check_weights(weights) def predict(self, X): @@ -213,9 +213,8 @@ class RadiusNeighborsRegressor(NeighborsBase, RadiusNeighborsMixin, equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used. - **kwargs : - additional keyword arguments are passed to the distance function as - additional arguments. + metric_params: dict, optional (default = None) + additional keyword arguments for the metric function. Examples -------- @@ -245,11 +244,12 @@ class RadiusNeighborsRegressor(NeighborsBase, RadiusNeighborsMixin, def __init__(self, radius=1.0, weights='uniform', algorithm='auto', leaf_size=30, - p=2, metric='minkowski', **kwargs): + p=2, metric='minkowski', metric_params=None, **kwargs): self._init_params(radius=radius, algorithm=algorithm, leaf_size=leaf_size, - p=p, metric=metric, **kwargs) + p=p, metric=metric, metric_params=metric_params, + **kwargs) self.weights = _check_weights(weights) def predict(self, X): diff --git a/sklearn/neighbors/tests/test_neighbors.py b/sklearn/neighbors/tests/test_neighbors.py index 4dcb45c488ea1..9c671dc83cd91 100644 --- a/sklearn/neighbors/tests/test_neighbors.py +++ b/sklearn/neighbors/tests/test_neighbors.py @@ -10,6 +10,7 @@ from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_true +from sklearn.utils.testing import assert_warns from sklearn.utils.testing import ignore_warnings from sklearn.utils.validation import check_random_state from sklearn import neighbors, datasets @@ -209,7 +210,6 @@ def test_kneighbors_classifier_predict_proba(): assert_array_almost_equal(real_prob, y_prob) - def test_radius_neighbors_classifier(n_samples=40, n_features=5, n_test_pts=10, @@ -810,9 +810,9 @@ def test_neighbors_metrics(n_samples=20, n_features=3, test = rng.rand(n_query_pts, n_features) - for metric, kwds in metrics: + for metric, metric_params in metrics: results = [] - + p = metric_params.pop('p', 2) for algorithm in algorithms: # KD tree doesn't support all metrics if (algorithm == 'kd_tree' and @@ -820,12 +820,13 @@ def test_neighbors_metrics(n_samples=20, n_features=3, assert_raises(ValueError, neighbors.NearestNeighbors, algorithm=algorithm, - metric=metric, **kwds) + metric=metric, metric_params=metric_params) continue neigh = neighbors.NearestNeighbors(n_neighbors=n_neighbors, algorithm=algorithm, - metric=metric, **kwds) + metric=metric, p=p, + metric_params=metric_params) neigh.fit(X) results.append(neigh.kneighbors(test, return_distance=True)) @@ -849,6 +850,13 @@ def test_callable_metric(): assert_array_almost_equal(dist1, dist2) +def test_metric_params_interface(): + assert_warns(DeprecationWarning, neighbors.KNeighborsClassifier, + metric='wminkowski', w=np.ones(10)) + assert_warns(SyntaxWarning, neighbors.KNeighborsClassifier, + metric_params={'p': 3}) + + if __name__ == '__main__': import nose nose.runmodule() diff --git a/sklearn/neighbors/unsupervised.py b/sklearn/neighbors/unsupervised.py index 175b1c43cc669..0dd5a75861cf1 100644 --- a/sklearn/neighbors/unsupervised.py +++ b/sklearn/neighbors/unsupervised.py @@ -43,6 +43,9 @@ class NearestNeighbors(NeighborsBase, KNeighborsMixin, equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used. + metric_params: dict, optional (default = None) + additional keyword arguments for the metric function. + Examples -------- >>> from sklearn.neighbors import NearestNeighbors @@ -76,8 +79,10 @@ class NearestNeighbors(NeighborsBase, KNeighborsMixin, """ def __init__(self, n_neighbors=5, radius=1.0, - algorithm='auto', leaf_size=30, metric='minkowski', **kwargs): + algorithm='auto', leaf_size=30, metric='minkowski', + p=2, metric_params=None, **kwargs): self._init_params(n_neighbors=n_neighbors, radius=radius, algorithm=algorithm, - leaf_size=leaf_size, metric=metric, **kwargs) + leaf_size=leaf_size, metric=metric, p=p, + metric_params=metric_params, **kwargs) diff --git a/sklearn/neural_network/rbm.py b/sklearn/neural_network/rbm.py index de5c11483be03..4b10e6e24bfe0 100644 --- a/sklearn/neural_network/rbm.py +++ b/sklearn/neural_network/rbm.py @@ -62,13 +62,13 @@ class BernoulliRBM(BaseEstimator, TransformerMixin): Attributes ---------- - `intercept_hidden_` : array-like, shape (n_components,) + intercept_hidden_ : array-like, shape (n_components,) Biases of the hidden units. - `intercept_visible_` : array-like, shape (n_features,) + intercept_visible_ : array-like, shape (n_features,) Biases of the visible units. - `components_` : array-like, shape (n_components, n_features) + components_ : array-like, shape (n_components, n_features) Weight matrix, where n_features in the number of visible units and n_components is the number of hidden units. diff --git a/sklearn/preprocessing/data.py b/sklearn/preprocessing/data.py index c9f192b50989c..d1b8d89b64ec5 100644 --- a/sklearn/preprocessing/data.py +++ b/sklearn/preprocessing/data.py @@ -16,10 +16,9 @@ from ..utils import warn_if_not_float from ..utils.extmath import row_norms from ..utils.fixes import combinations_with_replacement as combinations_w_r -from ..utils.sparsefuncs_fast import inplace_csr_row_normalize_l1 -from ..utils.sparsefuncs_fast import inplace_csr_row_normalize_l2 -from ..utils.sparsefuncs import inplace_column_scale -from ..utils.sparsefuncs import mean_variance_axis0 +from ..utils.sparsefuncs_fast import (inplace_csr_row_normalize_l1, + inplace_csr_row_normalize_l2) +from ..utils.sparsefuncs import (inplace_column_scale, mean_variance_axis) zip = six.moves.zip map = six.moves.map @@ -124,7 +123,7 @@ def scale(X, axis=0, with_mean=True, with_std=True, copy=True): copy = False if copy: X = X.copy() - _, var = mean_variance_axis0(X) + _, var = mean_variance_axis(X, axis=0) var[var == 0.0] = 1.0 inplace_column_scale(X, 1 / np.sqrt(var)) else: @@ -171,10 +170,10 @@ class MinMaxScaler(BaseEstimator, TransformerMixin): Attributes ---------- - `min_` : ndarray, shape (n_features,) + min_ : ndarray, shape (n_features,) Per feature adjustment for minimum. - `scale_` : ndarray, shape (n_features,) + scale_ : ndarray, shape (n_features,) Per feature relative scaling of the data. """ @@ -279,10 +278,10 @@ class StandardScaler(BaseEstimator, TransformerMixin): Attributes ---------- - `mean_` : array of floats with shape [n_features] + mean_ : array of floats with shape [n_features] The mean value for each feature in the training set. - `std_` : array of floats with shape [n_features] + std_ : array of floats with shape [n_features] The standard deviation for each feature in the training set. See also @@ -319,7 +318,7 @@ def fit(self, X, y=None): self.mean_ = None if self.with_std: - var = mean_variance_axis0(X)[1] + var = mean_variance_axis(X, axis=0)[1] self.std_ = np.sqrt(var) self.std_[var == 0.0] = 1.0 else: @@ -432,7 +431,7 @@ class PolynomialFeatures(BaseEstimator, TransformerMixin): Attributes ---------- - `powers_`: + powers_ : powers_[i, j] is the exponent of the jth input in the ith output. Notes @@ -928,17 +927,17 @@ class OneHotEncoder(BaseEstimator, TransformerMixin): Attributes ---------- - `active_features_` : array + active_features_ : array Indices for active features, meaning values that actually occur in the training set. Only available when n_values is ``'auto'``. - `feature_indices_` : array of shape (n_features,) + feature_indices_ : array of shape (n_features,) Indices to feature ranges. Feature ``i`` in the original data is mapped to features from ``feature_indices_[i]`` to ``feature_indices_[i+1]`` (and then potentially masked by `active_features_` afterwards) - `n_values_` : array of shape (n_features,) + n_values_ : array of shape (n_features,) Maximum number of values per feature. Examples diff --git a/sklearn/preprocessing/imputation.py b/sklearn/preprocessing/imputation.py index 48dde45aa071a..17d8b6e40df20 100644 --- a/sklearn/preprocessing/imputation.py +++ b/sklearn/preprocessing/imputation.py @@ -128,7 +128,7 @@ class Imputer(BaseEstimator, TransformerMixin): Attributes ---------- - `statistics_` : array of shape (n_features,) + statistics_ : array of shape (n_features,) The imputation fill value for each feature if axis == 0. Notes diff --git a/sklearn/preprocessing/label.py b/sklearn/preprocessing/label.py index f304bf6104cae..cb9a2f527b40f 100644 --- a/sklearn/preprocessing/label.py +++ b/sklearn/preprocessing/label.py @@ -19,6 +19,7 @@ from ..utils.fixes import np_version from ..utils.fixes import sparse_min_max from ..utils.fixes import astype +from ..utils.fixes import in1d from ..utils import deprecated, column_or_1d from ..utils.validation import check_array from ..utils.multiclass import unique_labels @@ -55,7 +56,7 @@ class LabelEncoder(BaseEstimator, TransformerMixin): Attributes ---------- - `classes_` : array of shape (n_class,) + classes_ : array of shape (n_class,) Holds the label for each class. Examples @@ -198,26 +199,26 @@ class LabelBinarizer(BaseEstimator, TransformerMixin): Attributes ---------- - `classes_` : array of shape [n_class] + classes_ : array of shape [n_class] Holds the label for each class. - `y_type_` : str, + y_type_ : str, Represents the type of the target data as evaluated by utils.multiclass.type_of_target. Possible type are 'continuous', 'continuous-multioutput', 'binary', 'multiclass', 'mutliclass-multioutput', 'multilabel-sequences', 'multilabel-indicator', and 'unknown'. - `multilabel_` : boolean + multilabel_ : boolean True if the transformer was fitted on a multilabel rather than a multiclass set of labels. The multilabel_ attribute is deprecated and will be removed in 0.18 - `sparse_input_` : boolean, + sparse_input_ : boolean, True if the input data to transform is given as a sparse matrix, False otherwise. - `indicator_matrix_` : str + indicator_matrix_ : str 'sparse' when the input data to tansform is a multilable-indicator and is sparse, None otherwise. The indicator_matrix_ attribute is deprecated as of version 0.16 and will be removed in 0.18 @@ -329,6 +330,12 @@ def transform(self, y): Shape will be [n_samples, 1] for binary problems. """ self._check_fitted() + + y_is_multilabel = type_of_target(y).startswith('multilabel') + if y_is_multilabel and not self.y_type_.startswith('multilabel'): + raise ValueError("The object was not fitted with multilabel" + " input.") + return label_binarize(y, self.classes_, pos_label=self.pos_label, neg_label=self.neg_label, @@ -446,7 +453,8 @@ def label_binarize(y, classes, neg_label=0, pos_label=1, allow for fitting to classes independently of the transform operation """ if not isinstance(y, list): - # XXX Workaround that will be removed when list of list format is dropped + # XXX Workaround that will be removed when list of list format is + # dropped y = check_array(y, accept_sparse='csr', ensure_2d=False) if neg_label >= pos_label: raise ValueError("neg_label={0} must be strictly less than " @@ -487,18 +495,21 @@ def label_binarize(y, classes, neg_label=0, pos_label=1, y_type = "multiclass" sorted_class = np.sort(classes) - if (y_type == "multilabel-indicator" and classes.size != y.shape[1] or - not set(classes).issuperset(unique_labels(y))): + if (y_type == "multilabel-indicator" and classes.size != y.shape[1]): raise ValueError("classes {0} missmatch with the labels {1}" "found in the data".format(classes, unique_labels(y))) if y_type in ("binary", "multiclass"): y = column_or_1d(y) - indptr = np.arange(n_samples + 1) - indices = np.searchsorted(sorted_class, y) + + # pick out the known labels from y + y_in_classes = in1d(y, classes) + y_seen = y[y_in_classes] + indices = np.searchsorted(sorted_class, y_seen) + indptr = np.hstack((0, np.cumsum(y_in_classes))) + data = np.empty_like(indices) data.fill(pos_label) - Y = sp.csr_matrix((data, indices, indptr), shape=(n_samples, n_classes)) @@ -657,9 +668,12 @@ class MultiLabelBinarizer(BaseEstimator, TransformerMixin): classes : array-like of shape [n_classes] (optional) Indicates an ordering for the class labels + sparse_output : boolean (default: False), + Set to true if output binary array is desired in CSR sparse format + Attributes ---------- - `classes_` : array of labels + classes_ : array of labels A copy of the `classes` parameter where provided, or otherwise, the sorted set of classes found when fitting. diff --git a/sklearn/preprocessing/tests/test_data.py b/sklearn/preprocessing/tests/test_data.py index 55e85a86dce8c..879b3b20aff85 100644 --- a/sklearn/preprocessing/tests/test_data.py +++ b/sklearn/preprocessing/tests/test_data.py @@ -14,7 +14,7 @@ from sklearn.utils.testing import assert_false from sklearn.utils.testing import assert_warns -from sklearn.utils.sparsefuncs import mean_variance_axis0 +from sklearn.utils.sparsefuncs import mean_variance_axis from sklearn.preprocessing.data import _transform_selected from sklearn.preprocessing.data import Binarizer from sklearn.preprocessing.data import KernelCenterer @@ -283,7 +283,7 @@ def test_scaler_without_centering(): X_scaled.mean(axis=0), [0., -0.01, 2.24, -0.35, -0.78], 2) assert_array_almost_equal(X_scaled.std(axis=0), [0., 1., 1., 1., 1.]) - X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis0(X_csr_scaled) + X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis(X_csr_scaled, 0) assert_array_almost_equal(X_csr_scaled_mean, X_scaled.mean(axis=0)) assert_array_almost_equal(X_csr_scaled_std, X_scaled.std(axis=0)) @@ -349,8 +349,8 @@ def test_scaler_int(): [0., 1.109, 1.856, 21., 1.559], 2) assert_array_almost_equal(X_scaled.std(axis=0), [0., 1., 1., 1., 1.]) - X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis0( - X_csr_scaled.astype(np.float)) + X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis( + X_csr_scaled.astype(np.float), 0) assert_array_almost_equal(X_csr_scaled_mean, X_scaled.mean(axis=0)) assert_array_almost_equal(X_csr_scaled_std, X_scaled.std(axis=0)) @@ -432,7 +432,7 @@ def test_scale_function_without_centering(): # Check that X has not been copied assert_true(X_scaled is not X) - X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis0(X_csr_scaled) + X_csr_scaled_mean, X_csr_scaled_std = mean_variance_axis(X_csr_scaled, 0) assert_array_almost_equal(X_csr_scaled_mean, X_scaled.mean(axis=0)) assert_array_almost_equal(X_csr_scaled_std, X_scaled.std(axis=0)) diff --git a/sklearn/preprocessing/tests/test_label.py b/sklearn/preprocessing/tests/test_label.py index dfdb2d23a2134..f523870ffd2fd 100644 --- a/sklearn/preprocessing/tests/test_label.py +++ b/sklearn/preprocessing/tests/test_label.py @@ -77,6 +77,25 @@ def test_label_binarizer(): assert_array_equal(lb.inverse_transform(got), inp) +def test_label_binarizer_unseen_labels(): + lb = LabelBinarizer() + + expected = np.array([[1, 0, 0], + [0, 1, 0], + [0, 0, 1]]) + got = lb.fit_transform(['b', 'd', 'e']) + assert_array_equal(expected, got) + + expected = np.array([[0, 0, 0], + [1, 0, 0], + [0, 0, 0], + [0, 1, 0], + [0, 0, 1], + [0, 0, 0]]) + got = lb.transform(['a', 'b', 'c', 'd', 'e', 'f']) + assert_array_equal(expected, got) + + @ignore_warnings def test_label_binarizer_column_y(): # first for binary classification vs multi-label with 1 possible class @@ -537,10 +556,8 @@ def test_deprecation_inverse_binarize_thresholding(): def test_invalid_input_label_binarize(): - assert_raises(ValueError, label_binarize, [0.5, 2], classes=[1, 2]) assert_raises(ValueError, label_binarize, [0, 2], classes=[0, 2], pos_label=0, neg_label=1) - assert_raises(ValueError, label_binarize, [1, 2], classes=[0, 2]) def test_inverse_binarize_multiclass(): diff --git a/sklearn/qda.py b/sklearn/qda.py index 0f88094840c7a..3856fb584bdeb 100644 --- a/sklearn/qda.py +++ b/sklearn/qda.py @@ -38,20 +38,20 @@ class QDA(BaseEstimator, ClassifierMixin): Attributes ---------- - `covariances_` : list of array-like, shape = [n_features, n_features] + covariances_ : list of array-like, shape = [n_features, n_features] Covariance matrices of each class. - `means_` : array-like, shape = [n_classes, n_features] + means_ : array-like, shape = [n_classes, n_features] Class means. - `priors_` : array-like, shape = [n_classes] + priors_ : array-like, shape = [n_classes] Class priors (sum to 1). - `rotations_` : list of arrays + rotations_ : list of arrays For each class an array of shape [n_samples, n_samples], the rotation of the Gaussian distribution, i.e. its principal axis. - `scalings_` : array-like, shape = [n_classes, n_features] + scalings_ : array-like, shape = [n_classes, n_features] Contains the scaling of the Gaussian distributions along the principal axes for each class, i.e. the variance in the rotated coordinate system. diff --git a/sklearn/random_projection.py b/sklearn/random_projection.py index e2d592072ea78..608411fefef6b 100644 --- a/sklearn/random_projection.py +++ b/sklearn/random_projection.py @@ -334,7 +334,7 @@ def fit(self, X, y=None): self """ - X = check_array(X) + X = check_array(X, accept_sparse=['csr', 'csc']) n_samples, n_features = X.shape @@ -446,10 +446,10 @@ class GaussianRandomProjection(BaseRandomProjection): Attributes ---------- - ``n_component_`` : int + n_component_ : int Concrete number of components computed when n_components="auto". - ``components_`` : numpy array of shape [n_components, n_features] + components_ : numpy array of shape [n_components, n_features] Random matrix used for the projection. See Also @@ -550,13 +550,13 @@ class SparseRandomProjection(BaseRandomProjection): Attributes ---------- - ``n_component_`` : int + n_component_ : int Concrete number of components computed when n_components="auto". - ``components_`` : CSR matrix with shape [n_components, n_features] + components_ : CSR matrix with shape [n_components, n_features] Random matrix used for the projection. - ``density_`` : float in range 0.0 - 1.0 + density_ : float in range 0.0 - 1.0 Concrete density computed from when density = "auto". See Also diff --git a/sklearn/semi_supervised/label_propagation.py b/sklearn/semi_supervised/label_propagation.py index 25fc2d6d9eac3..46973f4f74b29 100644 --- a/sklearn/semi_supervised/label_propagation.py +++ b/sklearn/semi_supervised/label_propagation.py @@ -282,19 +282,19 @@ class LabelPropagation(BaseLabelPropagation): Attributes ---------- - `X_` : array, shape = [n_samples, n_features] + X_ : array, shape = [n_samples, n_features] Input array. - `classes_` : array, shape = [n_classes] + classes_ : array, shape = [n_classes] The distinct labels used in classifying instances. - `label_distributions_` : array, shape = [n_samples, n_classes] + label_distributions_ : array, shape = [n_samples, n_classes] Categorical distribution for each item. - `transduction_` : array, shape = [n_samples] + transduction_ : array, shape = [n_samples] Label assigned to each item via the transduction. - `n_iter_` : int + n_iter_ : int Number of iterations run. Examples @@ -364,19 +364,19 @@ class LabelSpreading(BaseLabelPropagation): Attributes ---------- - `X_` : array, shape = [n_samples, n_features] + X_ : array, shape = [n_samples, n_features] Input array. - `classes_` : array, shape = [n_classes] + classes_ : array, shape = [n_classes] The distinct labels used in classifying instances. - `label_distributions_` : array, shape = [n_samples, n_classes] + label_distributions_ : array, shape = [n_samples, n_classes] Categorical distribution for each item. - `transduction_` : array, shape = [n_samples] + transduction_ : array, shape = [n_samples] Label assigned to each item via the transduction. - `n_iter_` : int + n_iter_ : int Number of iterations run. Examples diff --git a/sklearn/setup.py b/sklearn/setup.py index 82a40024e5be1..111d9680287e6 100644 --- a/sklearn/setup.py +++ b/sklearn/setup.py @@ -22,8 +22,6 @@ def configuration(parent_package='', top_path=None): config.add_subpackage('feature_extraction/tests') config.add_subpackage('cluster') config.add_subpackage('cluster/tests') - config.add_subpackage('cluster/bicluster') - config.add_subpackage('cluster/bicluster/tests') config.add_subpackage('covariance') config.add_subpackage('covariance/tests') config.add_subpackage('cross_decomposition') diff --git a/sklearn/svm/base.py b/sklearn/svm/base.py index 8a92fe62c31bf..d8be425aec79e 100644 --- a/sklearn/svm/base.py +++ b/sklearn/svm/base.py @@ -308,8 +308,7 @@ def _dense_predict(self, X): cache_size=self.cache_size) def _sparse_predict(self, X): - X = sp.csr_matrix(X, dtype=np.float64) - + # Precondition: X is a csr_matrix of dtype np.float64. kernel = self.kernel if callable(kernel): kernel = 'precomputed' @@ -382,6 +381,9 @@ def decision_function(self, X): return dec_func def _validate_for_predict(self, X): + if not hasattr(self, "support_"): + raise ValueError("this %s has not been fitted yet" + % type(self).__name__) X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C") if self._sparse and not sp.isspmatrix(X): X = sp.csr_matrix(X) @@ -583,9 +585,18 @@ def _sparse_predict_proba(self, X): self.probability, self.n_support_, self.probA_, self.probB_) +def _get_liblinear_solver_type(multi_class, penalty, loss, dual): + """Find the liblinear magic number for the solver. + + This number depends on the values of the following attributes: + - multi_class + - penalty + - loss + - dual -class BaseLibLinear(six.with_metaclass(ABCMeta, BaseEstimator)): - """Base for classes binding liblinear (dense and sparse versions)""" + The same number is internally by LibLinear to determine which + solver to use. + """ _solver_type_dict = { 'PL2_LLR_D0': 0, # L2 penalty, logistic regression @@ -598,192 +609,153 @@ class BaseLibLinear(six.with_metaclass(ABCMeta, BaseEstimator)): 'PL2_LLR_D1': 7, # L2 penalty, logistic regression, dual form } - @abstractmethod - def __init__(self, penalty='l2', loss='l2', dual=True, tol=1e-4, C=1.0, - multi_class='ovr', fit_intercept=True, intercept_scaling=1, - class_weight=None, verbose=0, random_state=None, max_iter=100, - solver='liblinear'): - - self.penalty = penalty - self.loss = loss - self.dual = dual - self.tol = tol - self.C = C - self.fit_intercept = fit_intercept - self.intercept_scaling = intercept_scaling - self.multi_class = multi_class - self.class_weight = class_weight - self.verbose = verbose - self.random_state = random_state - self.solver = solver - self.max_iter = max_iter - - # Check that the arguments given are valid: - self._get_solver_type() - - def _get_solver_type(self): - """Find the liblinear magic number for the solver. - - This number depends on the values of the following attributes: - - multi_class - - penalty - - loss - - dual - """ - if self.multi_class == 'crammer_singer': - solver_type = 'MC_SVC' - elif self.multi_class == 'ovr': - solver_type = "P%s_L%s_D%d" % ( - self.penalty.upper(), self.loss.upper(), int(self.dual)) - else: - raise ValueError("`multi_class` must be one of `ovr`, " - "`crammer_singer`, got %r" % self.multi_class) - if not solver_type in self._solver_type_dict: - if self.penalty.upper() == 'L1' and self.loss.upper() == 'L1': - error_string = ("The combination of penalty='l1' " - "and loss='l1' is not supported.") - elif self.penalty.upper() == 'L2' and self.loss.upper() == 'L1': - # this has to be in primal - error_string = ("penalty='l2' and loss='l1' is " - "only supported when dual='true'.") - else: - # only PL1 in dual remains - error_string = ("penalty='l1' is only supported " - "when dual='false'.") - raise ValueError('Unsupported set of arguments: %s, ' - 'Parameters: penalty=%r, loss=%r, dual=%r' - % (error_string, self.penalty, - self.loss, self.dual)) - return self._solver_type_dict[solver_type] - - def fit(self, X, y): - """Fit the model according to the given training data. - - Parameters - ---------- - X : {array-like, sparse matrix}, shape = [n_samples, n_features] - Training vector, where n_samples in the number of samples and - n_features is the number of features. - - y : array-like, shape = [n_samples] - Target vector relative to X - - Returns - ------- - self : object - Returns self. - """ - - # Circular import, logistic_regression_path depends on LogisticRegression - # and hence BaseLibLinear. - from ..linear_model import logistic_regression_path - - if self.solver != 'liblinear': - if self.penalty != 'l2': - raise ValueError("newton-cg and lbfgs solvers support only " - "l2 penalties.") - if self.dual: - raise ValueError("newton-cg and lbfgs solvers support only " - "the primal form.") - - self._enc = LabelEncoder() - y_ind = self._enc.fit_transform(y) - if len(self.classes_) < 2: - raise ValueError("The number of classes has to be greater than" - " one.") - - X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C") - - # Used in the liblinear solver. - self.class_weight_ = compute_class_weight(self.class_weight, - self.classes_, y) - - if X.shape[0] != y_ind.shape[0]: - raise ValueError("X and y have incompatible shapes.\n" - "X has %s samples, but y has %s." % - (X.shape[0], y_ind.shape[0])) - - if self.solver not in ['liblinear', 'newton-cg', 'lbfgs']: - raise ValueError("Logistic Regression supports only liblinear," - " newton-cg and lbfgs solvers.") - - if self.solver == 'liblinear': - liblinear.set_verbosity_wrap(self.verbose) - - rnd = check_random_state(self.random_state) - if self.verbose: - print('[LibLinear]', end='') - - # LibLinear wants targets as doubles, even for classification - y_ind = np.asarray(y_ind, dtype=np.float64).ravel() - raw_coef_ = liblinear.train_wrap(X, y_ind, - sp.isspmatrix(X), - self._get_solver_type(), - self.tol, self._get_bias(), - self.C, self.class_weight_, - rnd.randint(np.iinfo('i').max)) - # Regarding rnd.randint(..) in the above signature: - # seed for srand in range [0..INT_MAX); due to limitations in Numpy - # on 32-bit platforms, we can't get to the UINT_MAX limit that - # srand supports - - if self.fit_intercept: - self.coef_ = raw_coef_[:, :-1] - self.intercept_ = self.intercept_scaling * raw_coef_[:, -1] - else: - self.coef_ = raw_coef_ - self.intercept_ = 0. - + if multi_class == 'crammer_singer': + solver_type = 'MC_SVC' + elif multi_class == 'ovr': + solver_type = "P%s_L%s_D%d" % ( + penalty.upper(), loss.upper(), int(dual)) + else: + raise ValueError("`multi_class` must be one of `ovr`, " + "`crammer_singer`, got %r" % multi_class) + if not solver_type in _solver_type_dict: + if penalty.upper() == 'L1' and loss.upper() == 'L1': + error_string = ("The combination of penalty='l1' " + "and loss='l1' is not supported.") + elif penalty.upper() == 'L2' and loss.upper() == 'L1': + # this has to be in primal + error_string = ("penalty='l2' and loss='l1' is " + "only supported when dual='true'.") else: - if self.penalty != 'l2': - raise ValueError("newton-cg and lbfgs solvers support only " - "l2 penalties.") - - n_tasks = len(self.classes_) - classes_ = self.classes_ - - if len(self.classes_) == 2: - n_tasks = 1 - classes_ = classes_[1:] - - self.coef_ = np.empty((n_tasks, X.shape[1])) - self.intercept_ = np.zeros(n_tasks) - - for ind, class_ in enumerate(classes_): - coef_, _ = logistic_regression_path( - X, y, pos_class=class_, Cs=[self.C], - fit_intercept=self.fit_intercept, - tol=self.tol, verbose=self.verbose, - solver=self.solver, copy=True, - max_iter=self.max_iter, class_weight=self.class_weight) - - coef_ = coef_[0] - if self.fit_intercept: - self.coef_[ind] = coef_[:-1] - self.intercept_[ind] = coef_[-1] - - else: - self.coef_[ind] = coef_ - - if self.multi_class == "crammer_singer" and len(self.classes_) == 2: - self.coef_ = (self.coef_[1] - self.coef_[0]).reshape(1, -1) - if self.fit_intercept: - intercept = self.intercept_[1] - self.intercept_[0] - self.intercept_ = np.array([intercept]) - - return self - - @property - def classes_(self): - return self._enc.classes_ - - def _get_bias(self): - if self.fit_intercept: - return self.intercept_scaling - else: - return -1.0 - - -libsvm.set_verbosity_wrap(0) -libsvm_sparse.set_verbosity_wrap(0) -liblinear.set_verbosity_wrap(0) + # only PL1 in dual remains + error_string = ("penalty='l1' is only supported " + "when dual='false'.") + raise ValueError('Unsupported set of arguments: %s, ' + 'Parameters: penalty=%r, loss=%r, dual=%r' + % (error_string, penalty, loss, dual)) + return _solver_type_dict[solver_type] + + +def _fit_liblinear(X, y, C, fit_intercept, intercept_scaling, class_weight, + penalty, dual, verbose, max_iter, tol, + random_state=None, multi_class='ovr', loss='lr'): + """Used by Logistic Regression (and CV) and LinearSVC. + + Preprocessing is done in this function before supplying it to liblinear. + + Parameters + ---------- + X : {array-like, sparse matrix}, shape = [n_samples, n_features] + Training vector, where n_samples in the number of samples and + n_features is the number of features. + + y : array-like, shape = [n_samples] + Target vector relative to X + + C : float + Inverse of cross-validation parameter. Lower the C, the more + the penalization. + + fit_intercept : bool + Whether or not to fit the intercept, that is to add a intercept + term to the decision function. + + intercept_scaling : float + LibLinear internally penalizes the intercept and this term is subject + to regularization just like the other terms of the feature vector. + In order to avoid this, one should increase the intercept_scaling. + such that the feature vector becomes [x, intercept_scaling]. + + class_weight : {dict, 'auto'}, optional + Weight assigned to each class. If class_weight provided is 'auto', + then the weights provided are inverses of the frequency in the + target vector. + + penalty : str, {'l1', 'l2'} + The norm of the penalty used in regularization. + + dual : bool + Dual or primal formulation, + + verbose : int + Set verbose to any positive number for verbosity. + + max_iter : int + Number of iterations. + + tol : float + Stopping condition. + + random_state : int seed, RandomState instance, or None (default) + The seed of the pseudo random number generator to use when + shuffling the data. + + multi_class : str, {'ovr', 'crammer_singer'} + `ovr` trains n_classes one-vs-rest classifiers, while `crammer_singer` + optimizes a joint objective over all classes. + While `crammer_singer` is interesting from an theoretical perspective + as it is consistent it is seldom used in practice and rarely leads to + better accuracy and is more expensive to compute. + If `crammer_singer` is chosen, the options loss, penalty and dual will + be ignored. + + loss : str, {'lr', 'l1', 'l2'} + The loss function. 'l1' is the hinge loss while 'l2' is the squared + hinge loss and 'lr' is the Logistic loss. + + Returns + ------- + coef_ : ndarray, shape (n_features, n_features + 1) + The coefficent vector got by minimizing the objective function. + + intercept_ : float + The intercept term added to the vector. + + n_iter_ : int + Maximum number of iterations run across all classes. + """ + enc = LabelEncoder() + y_ind = enc.fit_transform(y) + classes_ = enc.classes_ + if len(classes_) < 2: + raise ValueError("This solver needs samples of at least 2 classes" + " in the data, but the data contains only one" + " class: %r" % classes_[0]) + + class_weight_ = compute_class_weight(class_weight, classes_, y) + liblinear.set_verbosity_wrap(verbose) + rnd = check_random_state(random_state) + if verbose: + print('[LibLinear]', end='') + + bias = -1.0 + if fit_intercept: + bias = intercept_scaling + + libsvm.set_verbosity_wrap(verbose) + libsvm_sparse.set_verbosity_wrap(verbose) + liblinear.set_verbosity_wrap(verbose) + + # LibLinear wants targets as doubles, even for classification + y_ind = np.asarray(y_ind, dtype=np.float64).ravel() + solver_type = _get_liblinear_solver_type(multi_class, penalty, loss, dual) + raw_coef_, n_iter_ = liblinear.train_wrap( + X, y_ind, sp.isspmatrix(X), solver_type, tol, bias, C, + class_weight_, max_iter, rnd.randint(np.iinfo('i').max) + ) + # Regarding rnd.randint(..) in the above signature: + # seed for srand in range [0..INT_MAX); due to limitations in Numpy + # on 32-bit platforms, we can't get to the UINT_MAX limit that + # srand supports + n_iter_ = max(n_iter_) + if n_iter_ >= max_iter and verbose > 0: + warnings.warn("Liblinear failed to converge, increase " + "the number of iterations.", ConvergenceWarning) + + if fit_intercept: + coef_ = raw_coef_[:, :-1] + intercept_ = intercept_scaling * raw_coef_[:, -1] + else: + coef_ = raw_coef_ + intercept_ = 0. + + return coef_, intercept_, n_iter_ diff --git a/sklearn/svm/bounds.py b/sklearn/svm/bounds.py index d98d034b027c8..788a90b33671d 100644 --- a/sklearn/svm/bounds.py +++ b/sklearn/svm/bounds.py @@ -1,6 +1,13 @@ -import operator +"""Determination of parameter bounds""" +# Author: Paolo Losi +# License: BSD 3 clause + import numpy as np +from ..preprocessing import LabelBinarizer +from ..utils.validation import check_consistent_length, check_array +from ..utils.extmath import safe_sparse_dot + def l1_min_c(X, y, loss='l2', fit_intercept=True, intercept_scaling=1.0): """ @@ -41,44 +48,23 @@ def l1_min_c(X, y, loss='l2', fit_intercept=True, intercept_scaling=1.0): l1_min_c: float minimum value for C """ - import scipy.sparse as sp if loss not in ('l2', 'log'): raise ValueError('loss type not in ("l2", "log")') - y = np.asarray(y) - - if sp.issparse(X): - X = sp.csc_matrix(X) - hstack = sp.hstack - dot = operator.mul - else: - X = np.asarray(X) - hstack = np.hstack - dot = np.dot + X = check_array(X, accept_sparse='csc') + check_consistent_length(X, y) + Y = LabelBinarizer(neg_label=-1).fit_transform(y).T + # maximum absolute value over classes and features + den = np.max(np.abs(safe_sparse_dot(Y, X))) if fit_intercept: bias = intercept_scaling * np.ones((np.size(y), 1)) - X = hstack((X, bias)) - - classes = np.unique(y) - n_classes = np.size(classes) - if n_classes <= 2: - c = classes[0] - y = y.reshape((1, -1)) - _y = np.empty(y.shape) - _y[y == c] = 1 - _y[y != c] = -1 - else: - _y = np.empty((n_classes, np.size(y))) - for i, c in enumerate(classes): - _y[i, y == c] = 1 - _y[i, y != c] = -1 - - den = np.max(np.abs(dot(_y, X))) + den = max(den, abs(np.dot(Y, bias)).max()) if den == 0.0: - raise ValueError('Ill-posed l1_min_c calculation') + raise ValueError('Ill-posed l1_min_c calculation: l1 will always ' + 'select zero coefficients for this data') if loss == 'l2': return 0.5 / den else: # loss == 'log': diff --git a/sklearn/svm/classes.py b/sklearn/svm/classes.py index 23329a940b0cf..77fc3c6c4f1ed 100644 --- a/sklearn/svm/classes.py +++ b/sklearn/svm/classes.py @@ -1,11 +1,14 @@ -from .base import BaseLibLinear, BaseSVC, BaseLibSVM -from ..base import RegressorMixin +import numpy as np + +from .base import _fit_liblinear, BaseSVC, BaseLibSVM +from ..base import BaseEstimator, RegressorMixin from ..linear_model.base import LinearClassifierMixin, SparseCoefMixin from ..feature_selection.from_model import _LearntSelectorMixin +from ..utils import check_array, check_X_y -class LinearSVC(BaseLibLinear, LinearClassifierMixin, _LearntSelectorMixin, - SparseCoefMixin): +class LinearSVC(BaseEstimator, LinearClassifierMixin, + _LearntSelectorMixin, SparseCoefMixin): """Linear Support Vector Classification. Similar to SVC with parameter kernel='linear', but implemented in terms of @@ -80,10 +83,12 @@ class frequencies. The seed of the pseudo random number generator to use when shuffling the data. + max_iter : int, default 1000 + The maximum number of iterations to be run. Attributes ---------- - `coef_` : array, shape = [n_features] if n_classes == 2 \ + coef_ : array, shape = [n_features] if n_classes == 2 \ else [n_classes, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. @@ -91,7 +96,7 @@ class frequencies. `coef_` is readonly property derived from `raw_coef_` that \ follows the internal memory layout of liblinear. - `intercept_` : array, shape = [1] if n_classes == 2 else [n_classes] + intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. Notes @@ -104,6 +109,10 @@ class frequencies. The underlying implementation (liblinear) uses a sparse internal representation for the data that will incur a memory copy. + Predict output may not match that of standalone liblinear in certain + cases. See :ref:`differences from liblinear ` + in the narrative documentation. + **References:** `LIBLINEAR: A Library for Large Linear Classification `__ @@ -133,13 +142,57 @@ class frequencies. def __init__(self, penalty='l2', loss='l2', dual=True, tol=1e-4, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, - class_weight=None, verbose=0, random_state=None): - super(LinearSVC, self).__init__( - penalty=penalty, loss=loss, dual=dual, tol=tol, C=C, - multi_class=multi_class, fit_intercept=fit_intercept, - intercept_scaling=intercept_scaling, - class_weight=class_weight, verbose=verbose, - random_state=random_state) + class_weight=None, verbose=0, random_state=None, max_iter=1000): + self.penalty = penalty + self.loss = loss + self.dual = dual + self.tol = tol + self.C = C + self.multi_class = multi_class + self.fit_intercept = fit_intercept + self.intercept_scaling = intercept_scaling + self.class_weight = class_weight + self.verbose = verbose + self.random_state = random_state + self.max_iter = max_iter + + def fit(self, X, y): + """Fit the model according to the given training data. + + Parameters + ---------- + X : {array-like, sparse matrix}, shape = [n_samples, n_features] + Training vector, where n_samples in the number of samples and + n_features is the number of features. + + y : array-like, shape = [n_samples] + Target vector relative to X + + Returns + ------- + self : object + Returns self. + """ + if self.C < 0: + raise ValueError("Penalty term must be positive; got (C=%r)" + % self.C) + + X, y = check_X_y(X, y, accept_sparse='csr', dtype=np.float64, order="C") + self.classes_ = np.unique(y) + self.coef_, self.intercept_, self.n_iter_ = _fit_liblinear( + X, y, self.C, self.fit_intercept, self.intercept_scaling, + self.class_weight, self.penalty, self.dual, self.verbose, + self.max_iter, self.tol, self.random_state, self.multi_class, + self.loss + ) + + if self.multi_class == "crammer_singer" and len(self.classes_) == 2: + self.coef_ = (self.coef_[1] - self.coef_[0]).reshape(1, -1) + if self.fit_intercept: + intercept = self.intercept_[1] - self.intercept_[0] + self.intercept_ = np.array([intercept]) + + return self class SVC(BaseSVC): @@ -216,30 +269,30 @@ class frequencies. Attributes ---------- - `support_` : array-like, shape = [n_SV] + support_ : array-like, shape = [n_SV] Index of support vectors. - `support_vectors_` : array-like, shape = [n_SV, n_features] + support_vectors_ : array-like, shape = [n_SV, n_features] Support vectors. - `n_support_` : array-like, dtype=int32, shape = [n_class] + n_support_ : array-like, dtype=int32, shape = [n_class] number of support vector for each class. - `dual_coef_` : array, shape = [n_class-1, n_SV] + dual_coef_ : array, shape = [n_class-1, n_SV] Coefficients of the support vector in the decision function. \ For multiclass, coefficient for all 1-vs-1 classifiers. \ The layout of the coefficients in the multiclass case is somewhat \ non-trivial. See the section about multi-class classification in the \ SVM section of the User Guide for details. - `coef_` : array, shape = [n_class-1, n_features] + coef_ : array, shape = [n_class-1, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. `coef_` is readonly property derived from `dual_coef_` and `support_vectors_` - `intercept_` : array, shape = [n_class * (n_class-1) / 2] + intercept_ : array, shape = [n_class * (n_class-1) / 2] Constants in decision function. Examples @@ -340,30 +393,30 @@ class NuSVC(BaseSVC): Attributes ---------- - `support_` : array-like, shape = [n_SV] + support_ : array-like, shape = [n_SV] Index of support vectors. - `support_vectors_` : array-like, shape = [n_SV, n_features] + support_vectors_ : array-like, shape = [n_SV, n_features] Support vectors. - `n_support_` : array-like, dtype=int32, shape = [n_class] + n_support_ : array-like, dtype=int32, shape = [n_class] number of support vector for each class. - `dual_coef_` : array, shape = [n_class-1, n_SV] + dual_coef_ : array, shape = [n_class-1, n_SV] Coefficients of the support vector in the decision function. \ For multiclass, coefficient for all 1-vs-1 classifiers. \ The layout of the coefficients in the multiclass case is somewhat \ non-trivial. See the section about multi-class classification in \ the SVM section of the User Guide for details. - `coef_` : array, shape = [n_class-1, n_features] + coef_ : array, shape = [n_class-1, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. `coef_` is readonly property derived from `dual_coef_` and `support_vectors_` - `intercept_` : array, shape = [n_class * (n_class-1) / 2] + intercept_ : array, shape = [n_class * (n_class-1) / 2] Constants in decision function. Examples @@ -464,23 +517,23 @@ class SVR(BaseLibSVM, RegressorMixin): Attributes ---------- - `support_` : array-like, shape = [n_SV] + support_ : array-like, shape = [n_SV] Index of support vectors. - `support_vectors_` : array-like, shape = [nSV, n_features] + support_vectors_ : array-like, shape = [nSV, n_features] Support vectors. - `dual_coef_` : array, shape = [n_classes-1, n_SV] + dual_coef_ : array, shape = [n_classes-1, n_SV] Coefficients of the support vector in the decision function. - `coef_` : array, shape = [n_classes-1, n_features] + coef_ : array, shape = [n_classes-1, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. `coef_` is readonly property derived from `dual_coef_` and `support_vectors_` - `intercept_` : array, shape = [n_class * (n_class-1) / 2] + intercept_ : array, shape = [n_class * (n_class-1) / 2] Constants in decision function. Examples @@ -580,23 +633,23 @@ class NuSVR(BaseLibSVM, RegressorMixin): Attributes ---------- - `support_` : array-like, shape = [n_SV] + support_ : array-like, shape = [n_SV] Index of support vectors. - `support_vectors_` : array-like, shape = [nSV, n_features] + support_vectors_ : array-like, shape = [nSV, n_features] Support vectors. - `dual_coef_` : array, shape = [n_classes-1, n_SV] + dual_coef_ : array, shape = [n_classes-1, n_SV] Coefficients of the support vector in the decision function. - `coef_` : array, shape = [n_classes-1, n_features] + coef_ : array, shape = [n_classes-1, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. `coef_` is readonly property derived from `dual_coef_` and `support_vectors_` - `intercept_` : array, shape = [n_class * (n_class-1) / 2] + intercept_ : array, shape = [n_class * (n_class-1) / 2] Constants in decision function. Examples @@ -690,23 +743,23 @@ class OneClassSVM(BaseLibSVM): Attributes ---------- - `support_` : array-like, shape = [n_SV] + support_ : array-like, shape = [n_SV] Index of support vectors. - `support_vectors_` : array-like, shape = [nSV, n_features] + support_vectors_ : array-like, shape = [nSV, n_features] Support vectors. - `dual_coef_` : array, shape = [n_classes-1, n_SV] + dual_coef_ : array, shape = [n_classes-1, n_SV] Coefficient of the support vector in the decision function. - `coef_` : array, shape = [n_classes-1, n_features] + coef_ : array, shape = [n_classes-1, n_features] Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel. `coef_` is readonly property derived from `dual_coef_` and `support_vectors_` - `intercept_` : array, shape = [n_classes-1] + intercept_ : array, shape = [n_classes-1] Constants in decision function. """ diff --git a/sklearn/svm/liblinear.c b/sklearn/svm/liblinear.c index b166a40dc5c17..c232aea07890d 100644 --- a/sklearn/svm/liblinear.c +++ b/sklearn/svm/liblinear.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.19 on Thu Aug 1 22:04:14 2013 */ +/* Generated by Cython 0.20.1post0 (Debian 0.20.1+git90-g0e6e38e-1ubuntu2) on Fri Aug 1 00:56:43 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -19,6 +19,7 @@ #elif PY_VERSION_HEX < 0x02040000 #error Cython requires Python 2.4+. #else +#define CYTHON_ABI "0_20_1post0" #include /* For offsetof */ #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) @@ -53,6 +54,9 @@ #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif +#if CYTHON_COMPILING_IN_PYPY +#define Py_OptimizeFlag 0 +#endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX @@ -60,7 +64,7 @@ #define PY_FORMAT_SIZE_T "" #define CYTHON_FORMAT_SSIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) + #define PyInt_AsSsize_t(o) __Pyx_PyInt_As_int(o) #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ (PyErr_Format(PyExc_TypeError, \ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ @@ -112,13 +116,15 @@ #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type #endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 +#if PY_VERSION_HEX < 0x02060000 #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") #endif #if PY_MAJOR_VERSION >= 3 @@ -131,19 +137,44 @@ #if PY_VERSION_HEX < 0x02060000 #define Py_TPFLAGS_HAVE_VERSION_TAG 0 #endif +#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT) + #define Py_TPFLAGS_IS_ABSTRACT 0 +#endif +#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE) + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type @@ -176,7 +207,7 @@ #else #define __Pyx_PyBaseString_Check(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj) || \ PyString_Check(obj) || PyUnicode_Check(obj)) - #define __Pyx_PyBaseString_CheckExact(obj) (Py_TYPE(obj) == &PyBaseString_Type) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) @@ -201,11 +232,12 @@ #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif -#if PY_VERSION_HEX < 0x03020000 +#if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong @@ -261,6 +293,17 @@ #define CYTHON_INLINE #endif #endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif #ifdef NAN #define __PYX_NAN() ((float) NAN) #else @@ -273,6 +316,12 @@ static CYTHON_INLINE float __PYX_NAN() { return value; } #endif +#ifdef __cplusplus +template +void __Pyx_call_destructor(T* x) { + x->~T(); +} +#endif #if PY_MAJOR_VERSION >= 3 @@ -333,11 +382,23 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) ( \ + (sizeof(type) < sizeof(Py_ssize_t)) || \ + (sizeof(type) > sizeof(Py_ssize_t) && \ + likely(v < (type)PY_SSIZE_T_MAX || \ + v == (type)PY_SSIZE_T_MAX) && \ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN || \ + v == (type)PY_SSIZE_T_MIN))) || \ + (sizeof(type) == sizeof(Py_ssize_t) && \ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX || \ + v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize @@ -345,11 +406,13 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif +#define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) -#define __Pyx_PyObject_FromUString(s) __Pyx_PyObject_FromString((char*)s) -#define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((char*)s) -#define __Pyx_PyStr_FromUString(s) __Pyx_PyStr_FromString((char*)s) -#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((char*)s) +#define __Pyx_PyObject_FromUString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromUString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromUString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((const char*)s) #if PY_MAJOR_VERSION < 3 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { @@ -369,7 +432,6 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #if CYTHON_COMPILING_IN_CPYTHON #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else @@ -378,7 +440,7 @@ static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; -static int __Pyx_init_sys_getdefaultencoding_params() { +static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys = NULL; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; @@ -403,7 +465,7 @@ static int __Pyx_init_sys_getdefaultencoding_params() { if (ascii_chars_b == NULL || strncmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, - "This module compiled with c_string_encoding=ascii, but default encoding '%s' is not a superset of ascii.", + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } @@ -427,7 +489,7 @@ static int __Pyx_init_sys_getdefaultencoding_params() { #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; -static int __Pyx_init_sys_getdefaultencoding_params() { +static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys = NULL; PyObject* default_encoding = NULL; char* default_encoding_c; @@ -450,16 +512,11 @@ static int __Pyx_init_sys_getdefaultencoding_params() { #endif -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ @@ -498,7 +555,7 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "liblinear.pyx", - "numpy.pxd", + "__init__.pxd", "type.pxd", }; #define IS_UNSIGNED(type) (((type) -1) > 0) @@ -537,7 +594,7 @@ typedef struct { } __Pyx_BufFmt_Context; -/* "numpy.pxd":723 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":723 * # in Cython to enable them only on the right systems. * * ctypedef npy_int8 int8_t # <<<<<<<<<<<<<< @@ -546,7 +603,7 @@ typedef struct { */ typedef npy_int8 __pyx_t_5numpy_int8_t; -/* "numpy.pxd":724 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":724 * * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t # <<<<<<<<<<<<<< @@ -555,7 +612,7 @@ typedef npy_int8 __pyx_t_5numpy_int8_t; */ typedef npy_int16 __pyx_t_5numpy_int16_t; -/* "numpy.pxd":725 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":725 * ctypedef npy_int8 int8_t * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t # <<<<<<<<<<<<<< @@ -564,7 +621,7 @@ typedef npy_int16 __pyx_t_5numpy_int16_t; */ typedef npy_int32 __pyx_t_5numpy_int32_t; -/* "numpy.pxd":726 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":726 * ctypedef npy_int16 int16_t * ctypedef npy_int32 int32_t * ctypedef npy_int64 int64_t # <<<<<<<<<<<<<< @@ -573,7 +630,7 @@ typedef npy_int32 __pyx_t_5numpy_int32_t; */ typedef npy_int64 __pyx_t_5numpy_int64_t; -/* "numpy.pxd":730 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":730 * #ctypedef npy_int128 int128_t * * ctypedef npy_uint8 uint8_t # <<<<<<<<<<<<<< @@ -582,7 +639,7 @@ typedef npy_int64 __pyx_t_5numpy_int64_t; */ typedef npy_uint8 __pyx_t_5numpy_uint8_t; -/* "numpy.pxd":731 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":731 * * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t # <<<<<<<<<<<<<< @@ -591,7 +648,7 @@ typedef npy_uint8 __pyx_t_5numpy_uint8_t; */ typedef npy_uint16 __pyx_t_5numpy_uint16_t; -/* "numpy.pxd":732 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":732 * ctypedef npy_uint8 uint8_t * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t # <<<<<<<<<<<<<< @@ -600,7 +657,7 @@ typedef npy_uint16 __pyx_t_5numpy_uint16_t; */ typedef npy_uint32 __pyx_t_5numpy_uint32_t; -/* "numpy.pxd":733 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":733 * ctypedef npy_uint16 uint16_t * ctypedef npy_uint32 uint32_t * ctypedef npy_uint64 uint64_t # <<<<<<<<<<<<<< @@ -609,7 +666,7 @@ typedef npy_uint32 __pyx_t_5numpy_uint32_t; */ typedef npy_uint64 __pyx_t_5numpy_uint64_t; -/* "numpy.pxd":737 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":737 * #ctypedef npy_uint128 uint128_t * * ctypedef npy_float32 float32_t # <<<<<<<<<<<<<< @@ -618,7 +675,7 @@ typedef npy_uint64 __pyx_t_5numpy_uint64_t; */ typedef npy_float32 __pyx_t_5numpy_float32_t; -/* "numpy.pxd":738 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":738 * * ctypedef npy_float32 float32_t * ctypedef npy_float64 float64_t # <<<<<<<<<<<<<< @@ -627,7 +684,7 @@ typedef npy_float32 __pyx_t_5numpy_float32_t; */ typedef npy_float64 __pyx_t_5numpy_float64_t; -/* "numpy.pxd":747 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":747 * # The int types are mapped a bit surprising -- * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t # <<<<<<<<<<<<<< @@ -636,7 +693,7 @@ typedef npy_float64 __pyx_t_5numpy_float64_t; */ typedef npy_long __pyx_t_5numpy_int_t; -/* "numpy.pxd":748 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":748 * # numpy.int corresponds to 'l' and numpy.long to 'q' * ctypedef npy_long int_t * ctypedef npy_longlong long_t # <<<<<<<<<<<<<< @@ -645,7 +702,7 @@ typedef npy_long __pyx_t_5numpy_int_t; */ typedef npy_longlong __pyx_t_5numpy_long_t; -/* "numpy.pxd":749 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":749 * ctypedef npy_long int_t * ctypedef npy_longlong long_t * ctypedef npy_longlong longlong_t # <<<<<<<<<<<<<< @@ -654,7 +711,7 @@ typedef npy_longlong __pyx_t_5numpy_long_t; */ typedef npy_longlong __pyx_t_5numpy_longlong_t; -/* "numpy.pxd":751 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":751 * ctypedef npy_longlong longlong_t * * ctypedef npy_ulong uint_t # <<<<<<<<<<<<<< @@ -663,7 +720,7 @@ typedef npy_longlong __pyx_t_5numpy_longlong_t; */ typedef npy_ulong __pyx_t_5numpy_uint_t; -/* "numpy.pxd":752 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":752 * * ctypedef npy_ulong uint_t * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< @@ -672,7 +729,7 @@ typedef npy_ulong __pyx_t_5numpy_uint_t; */ typedef npy_ulonglong __pyx_t_5numpy_ulong_t; -/* "numpy.pxd":753 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":753 * ctypedef npy_ulong uint_t * ctypedef npy_ulonglong ulong_t * ctypedef npy_ulonglong ulonglong_t # <<<<<<<<<<<<<< @@ -681,7 +738,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulong_t; */ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; -/* "numpy.pxd":755 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":755 * ctypedef npy_ulonglong ulonglong_t * * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< @@ -690,7 +747,7 @@ typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; */ typedef npy_intp __pyx_t_5numpy_intp_t; -/* "numpy.pxd":756 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":756 * * ctypedef npy_intp intp_t * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< @@ -699,7 +756,7 @@ typedef npy_intp __pyx_t_5numpy_intp_t; */ typedef npy_uintp __pyx_t_5numpy_uintp_t; -/* "numpy.pxd":758 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":758 * ctypedef npy_uintp uintp_t * * ctypedef npy_double float_t # <<<<<<<<<<<<<< @@ -708,7 +765,7 @@ typedef npy_uintp __pyx_t_5numpy_uintp_t; */ typedef npy_double __pyx_t_5numpy_float_t; -/* "numpy.pxd":759 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":759 * * ctypedef npy_double float_t * ctypedef npy_double double_t # <<<<<<<<<<<<<< @@ -717,7 +774,7 @@ typedef npy_double __pyx_t_5numpy_float_t; */ typedef npy_double __pyx_t_5numpy_double_t; -/* "numpy.pxd":760 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":760 * ctypedef npy_double float_t * ctypedef npy_double double_t * ctypedef npy_longdouble longdouble_t # <<<<<<<<<<<<<< @@ -748,7 +805,7 @@ typedef npy_longdouble __pyx_t_5numpy_longdouble_t; /*--- Type declarations ---*/ -/* "numpy.pxd":762 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":762 * ctypedef npy_longdouble longdouble_t * * ctypedef npy_cfloat cfloat_t # <<<<<<<<<<<<<< @@ -757,7 +814,7 @@ typedef npy_longdouble __pyx_t_5numpy_longdouble_t; */ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; -/* "numpy.pxd":763 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":763 * * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< @@ -766,7 +823,7 @@ typedef npy_cfloat __pyx_t_5numpy_cfloat_t; */ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; -/* "numpy.pxd":764 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":764 * ctypedef npy_cfloat cfloat_t * ctypedef npy_cdouble cdouble_t * ctypedef npy_clongdouble clongdouble_t # <<<<<<<<<<<<<< @@ -775,7 +832,7 @@ typedef npy_cdouble __pyx_t_5numpy_cdouble_t; */ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; -/* "numpy.pxd":766 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":766 * ctypedef npy_clongdouble clongdouble_t * * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< @@ -834,6 +891,14 @@ typedef npy_cdouble __pyx_t_5numpy_complex_t; #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif /* CYTHON_REFNANNY */ +#define __Pyx_XDECREF_SET(r, v) do { \ + PyObject *tmp = (PyObject *) r; \ + r = v; __Pyx_XDECREF(tmp); \ + } while (0) +#define __Pyx_DECREF_SET(r, v) do { \ + PyObject *tmp = (PyObject *) r; \ + r = v; __Pyx_DECREF(tmp); \ + } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) @@ -863,27 +928,28 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); -#define __Pyx_GetItemInt(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i, is_list, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -#define __Pyx_GetItemInt_List(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func, is_list, wraparound, boundscheck) \ - (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i, wraparound, boundscheck) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); @@ -892,6 +958,12 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/ +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ @@ -907,10 +979,6 @@ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); -static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ - typedef struct { Py_ssize_t shape, strides, suboffsets; } __Pyx_Buf_DimInfo; @@ -938,14 +1006,22 @@ static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1}; static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /*proto*/ -static CYTHON_INLINE npy_int32 __Pyx_PyInt_from_py_npy_int32(PyObject *); +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t); +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *); + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +static CYTHON_INLINE npy_int32 __Pyx_PyInt_As_npy_int32(PyObject *); + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value); #ifndef __PYX_FORCE_INIT_THREADS #define __PYX_FORCE_INIT_THREADS 0 #endif +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + #if CYTHON_CCOMPLEX #ifdef __cplusplus #define __Pyx_CREAL(z) ((z).real()) @@ -958,7 +1034,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t); #define __Pyx_CREAL(z) ((z).real) #define __Pyx_CIMAG(z) ((z).imag) #endif -#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX +#if (defined(_WIN32) || defined(__clang__)) && defined(__cplusplus) && CYTHON_CCOMPLEX #define __Pyx_SET_CREAL(z,x) ((z).real(x)) #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) #else @@ -1044,37 +1120,7 @@ static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(do #endif #endif -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); static int __Pyx_check_binary_version(void); @@ -1147,138 +1193,153 @@ int __pyx_module_is_main_sklearn__svm__liblinear = 0; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_Y, int __pyx_v_is_sparse, int __pyx_v_solver_type, double __pyx_v_eps, double __pyx_v_bias, double __pyx_v_C, PyArrayObject *__pyx_v_class_weight, unsigned int __pyx_v_random_seed); /* proto */ +static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_Y, int __pyx_v_is_sparse, int __pyx_v_solver_type, double __pyx_v_eps, double __pyx_v_bias, double __pyx_v_C, PyArrayObject *__pyx_v_class_weight, int __pyx_v_max_iter, unsigned int __pyx_v_random_seed); /* proto */ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_2set_verbosity_wrap(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_verbosity); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ -static char __pyx_k_1[] = "ndarray is not C contiguous"; -static char __pyx_k_3[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_5[] = "Non-native byte order not supported"; -static char __pyx_k_7[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_8[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_11[] = "Format string allocated too short."; -static char __pyx_k_13[] = "\nWrapper for liblinear\n\nAuthor: fabian.pedregosa@inria.fr\n"; -static char __pyx_k_16[] = "/Users/mblondel/Desktop/projects/scikit-learn/sklearn/svm/liblinear.pyx"; -static char __pyx_k_17[] = "sklearn.svm.liblinear"; -static char __pyx_k__B[] = "B"; -static char __pyx_k__C[] = "C"; -static char __pyx_k__F[] = "F"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__X[] = "X"; -static char __pyx_k__Y[] = "Y"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__w[] = "w"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__eps[] = "eps"; -static char __pyx_k__bias[] = "bias"; -static char __pyx_k__data[] = "data"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__empty[] = "empty"; -static char __pyx_k__int32[] = "int32"; -static char __pyx_k__len_w[] = "len_w"; -static char __pyx_k__model[] = "model"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__order[] = "order"; -static char __pyx_k__param[] = "param"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__arange[] = "arange"; -static char __pyx_k__indptr[] = "indptr"; -static char __pyx_k__indices[] = "indices"; -static char __pyx_k__problem[] = "problem"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__nr_class[] = "nr_class"; -static char __pyx_k__error_msg[] = "error_msg"; -static char __pyx_k__is_sparse[] = "is_sparse"; -static char __pyx_k__verbosity[] = "verbosity"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k____import__[] = "__import__"; -static char __pyx_k__nr_feature[] = "nr_feature"; -static char __pyx_k__train_wrap[] = "train_wrap"; -static char __pyx_k__random_seed[] = "random_seed"; -static char __pyx_k__solver_type[] = "solver_type"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__class_weight[] = "class_weight"; -static char __pyx_k____pyx_getbuffer[] = "__pyx_getbuffer"; -static char __pyx_k__class_weight_label[] = "class_weight_label"; -static char __pyx_k__set_verbosity_wrap[] = "set_verbosity_wrap"; -static char __pyx_k____pyx_releasebuffer[] = "__pyx_releasebuffer"; -static PyObject *__pyx_kp_u_1; -static PyObject *__pyx_kp_u_11; -static PyObject *__pyx_kp_s_16; -static PyObject *__pyx_n_s_17; -static PyObject *__pyx_kp_u_3; -static PyObject *__pyx_kp_u_5; -static PyObject *__pyx_kp_u_7; -static PyObject *__pyx_kp_u_8; -static PyObject *__pyx_n_s__C; -static PyObject *__pyx_n_s__F; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s__X; -static PyObject *__pyx_n_s__Y; -static PyObject *__pyx_n_s____import__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____pyx_getbuffer; -static PyObject *__pyx_n_s____pyx_releasebuffer; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__arange; -static PyObject *__pyx_n_s__bias; -static PyObject *__pyx_n_s__class_weight; -static PyObject *__pyx_n_s__class_weight_label; -static PyObject *__pyx_n_s__data; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__empty; -static PyObject *__pyx_n_s__eps; -static PyObject *__pyx_n_s__error_msg; -static PyObject *__pyx_n_s__indices; -static PyObject *__pyx_n_s__indptr; -static PyObject *__pyx_n_s__int32; -static PyObject *__pyx_n_s__is_sparse; -static PyObject *__pyx_n_s__len_w; -static PyObject *__pyx_n_s__model; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__nr_class; -static PyObject *__pyx_n_s__nr_feature; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__order; -static PyObject *__pyx_n_s__param; -static PyObject *__pyx_n_s__problem; -static PyObject *__pyx_n_s__random_seed; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__set_verbosity_wrap; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__solver_type; -static PyObject *__pyx_n_s__train_wrap; -static PyObject *__pyx_n_s__verbosity; -static PyObject *__pyx_n_s__w; +static char __pyx_k_B[] = "B"; +static char __pyx_k_C[] = "C"; +static char __pyx_k_F[] = "F"; +static char __pyx_k_H[] = "H"; +static char __pyx_k_I[] = "I"; +static char __pyx_k_L[] = "L"; +static char __pyx_k_O[] = "O"; +static char __pyx_k_Q[] = "Q"; +static char __pyx_k_X[] = "X"; +static char __pyx_k_Y[] = "Y"; +static char __pyx_k_b[] = "b"; +static char __pyx_k_d[] = "d"; +static char __pyx_k_f[] = "f"; +static char __pyx_k_g[] = "g"; +static char __pyx_k_h[] = "h"; +static char __pyx_k_i[] = "i"; +static char __pyx_k_l[] = "l"; +static char __pyx_k_q[] = "q"; +static char __pyx_k_w[] = "w"; +static char __pyx_k_Zd[] = "Zd"; +static char __pyx_k_Zf[] = "Zf"; +static char __pyx_k_Zg[] = "Zg"; +static char __pyx_k_np[] = "np"; +static char __pyx_k_eps[] = "eps"; +static char __pyx_k_bias[] = "bias"; +static char __pyx_k_data[] = "data"; +static char __pyx_k_intc[] = "intc"; +static char __pyx_k_main[] = "__main__"; +static char __pyx_k_test[] = "__test__"; +static char __pyx_k_dtype[] = "dtype"; +static char __pyx_k_empty[] = "empty"; +static char __pyx_k_len_w[] = "len_w"; +static char __pyx_k_model[] = "model"; +static char __pyx_k_numpy[] = "numpy"; +static char __pyx_k_order[] = "order"; +static char __pyx_k_param[] = "param"; +static char __pyx_k_range[] = "range"; +static char __pyx_k_shape[] = "shape"; +static char __pyx_k_zeros[] = "zeros"; +static char __pyx_k_arange[] = "arange"; +static char __pyx_k_import[] = "__import__"; +static char __pyx_k_indptr[] = "indptr"; +static char __pyx_k_labels[] = "labels_"; +static char __pyx_k_n_iter[] = "n_iter"; +static char __pyx_k_indices[] = "indices"; +static char __pyx_k_problem[] = "problem"; +static char __pyx_k_max_iter[] = "max_iter"; +static char __pyx_k_nr_class[] = "nr_class"; +static char __pyx_k_error_msg[] = "error_msg"; +static char __pyx_k_is_sparse[] = "is_sparse"; +static char __pyx_k_verbosity[] = "verbosity"; +static char __pyx_k_ValueError[] = "ValueError"; +static char __pyx_k_nr_feature[] = "nr_feature"; +static char __pyx_k_train_wrap[] = "train_wrap"; +static char __pyx_k_random_seed[] = "random_seed"; +static char __pyx_k_solver_type[] = "solver_type"; +static char __pyx_k_RuntimeError[] = "RuntimeError"; +static char __pyx_k_class_weight[] = "class_weight"; +static char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; +static char __pyx_k_pyx_releasebuffer[] = "__pyx_releasebuffer"; +static char __pyx_k_class_weight_label[] = "class_weight_label"; +static char __pyx_k_set_verbosity_wrap[] = "set_verbosity_wrap"; +static char __pyx_k_sklearn_svm_liblinear[] = "sklearn.svm.liblinear"; +static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous"; +static char __pyx_k_Wrapper_for_liblinear_Author_fa[] = "\nWrapper for liblinear\n\nAuthor: fabian.pedregosa@inria.fr\n"; +static char __pyx_k_home_manoj_scikit_learn_sklearn[] = "/home/manoj/scikit-learn/sklearn/svm/liblinear.pyx"; +static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)"; +static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd"; +static char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported"; +static char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous"; +static char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short."; +static PyObject *__pyx_n_s_C; +static PyObject *__pyx_n_s_F; +static PyObject *__pyx_kp_u_Format_string_allocated_too_shor; +static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2; +static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor; +static PyObject *__pyx_n_s_RuntimeError; +static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_n_s_X; +static PyObject *__pyx_n_s_Y; +static PyObject *__pyx_n_s_arange; +static PyObject *__pyx_n_s_bias; +static PyObject *__pyx_n_s_class_weight; +static PyObject *__pyx_n_s_class_weight_label; +static PyObject *__pyx_n_s_data; +static PyObject *__pyx_n_s_dtype; +static PyObject *__pyx_n_s_empty; +static PyObject *__pyx_n_s_eps; +static PyObject *__pyx_n_s_error_msg; +static PyObject *__pyx_kp_s_home_manoj_scikit_learn_sklearn; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_indices; +static PyObject *__pyx_n_s_indptr; +static PyObject *__pyx_n_s_intc; +static PyObject *__pyx_n_s_is_sparse; +static PyObject *__pyx_n_s_labels; +static PyObject *__pyx_n_s_len_w; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_max_iter; +static PyObject *__pyx_n_s_model; +static PyObject *__pyx_n_s_n_iter; +static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous; +static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou; +static PyObject *__pyx_n_s_np; +static PyObject *__pyx_n_s_nr_class; +static PyObject *__pyx_n_s_nr_feature; +static PyObject *__pyx_n_s_numpy; +static PyObject *__pyx_n_s_order; +static PyObject *__pyx_n_s_param; +static PyObject *__pyx_n_s_problem; +static PyObject *__pyx_n_s_pyx_getbuffer; +static PyObject *__pyx_n_s_pyx_releasebuffer; +static PyObject *__pyx_n_s_random_seed; +static PyObject *__pyx_n_s_range; +static PyObject *__pyx_n_s_set_verbosity_wrap; +static PyObject *__pyx_n_s_shape; +static PyObject *__pyx_n_s_sklearn_svm_liblinear; +static PyObject *__pyx_n_s_solver_type; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_train_wrap; +static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd; +static PyObject *__pyx_n_s_verbosity; +static PyObject *__pyx_n_s_w; +static PyObject *__pyx_n_s_zeros; static PyObject *__pyx_int_1; -static PyObject *__pyx_int_15; -static PyObject *__pyx_k_tuple_2; -static PyObject *__pyx_k_tuple_4; -static PyObject *__pyx_k_tuple_6; -static PyObject *__pyx_k_tuple_9; -static PyObject *__pyx_k_tuple_10; -static PyObject *__pyx_k_tuple_12; -static PyObject *__pyx_k_tuple_14; -static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_codeobj_15; -static PyObject *__pyx_k_codeobj_19; +static PyObject *__pyx_tuple_; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_tuple__7; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_codeobj__8; +static PyObject *__pyx_codeobj__10; + +/* "sklearn/svm/liblinear.pyx":14 + * + * + * def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, # <<<<<<<<<<<<<< + * bint is_sparse, int solver_type, double eps, double bias, + * double C, np.ndarray[np.float64_t, ndim=1] class_weight, + */ /* Python wrapper */ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ @@ -1292,6 +1353,7 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s double __pyx_v_bias; double __pyx_v_C; PyArrayObject *__pyx_v_class_weight = 0; + int __pyx_v_max_iter; unsigned int __pyx_v_random_seed; int __pyx_lineno = 0; const char *__pyx_filename = NULL; @@ -1300,12 +1362,13 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("train_wrap (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__Y,&__pyx_n_s__is_sparse,&__pyx_n_s__solver_type,&__pyx_n_s__eps,&__pyx_n_s__bias,&__pyx_n_s__C,&__pyx_n_s__class_weight,&__pyx_n_s__random_seed,0}; - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_Y,&__pyx_n_s_is_sparse,&__pyx_n_s_solver_type,&__pyx_n_s_eps,&__pyx_n_s_bias,&__pyx_n_s_C,&__pyx_n_s_class_weight,&__pyx_n_s_max_iter,&__pyx_n_s_random_seed,0}; + PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); @@ -1321,53 +1384,58 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__X)) != 0)) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: - if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__Y)) != 0)) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_Y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: - if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__is_sparse)) != 0)) kw_args--; + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_is_sparse)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: - if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__solver_type)) != 0)) kw_args--; + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_solver_type)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: - if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__eps)) != 0)) kw_args--; + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_eps)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: - if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bias)) != 0)) kw_args--; + if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_bias)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 6: - if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__C)) != 0)) kw_args--; + if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_C)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 7: - if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__class_weight)) != 0)) kw_args--; + if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_class_weight)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 8: - if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__random_seed)) != 0)) kw_args--; + if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_iter)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 9: + if (likely((values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_random_seed)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "train_wrap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - } else if (PyTuple_GET_SIZE(__pyx_args) != 9) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 10) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -1379,20 +1447,22 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + values[9] = PyTuple_GET_ITEM(__pyx_args, 9); } __pyx_v_X = values[0]; __pyx_v_Y = ((PyArrayObject *)values[1]); __pyx_v_is_sparse = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_is_sparse == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_solver_type = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_solver_type == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_solver_type = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_solver_type == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_eps = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_eps == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_bias = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_bias == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_C = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_C == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_class_weight = ((PyArrayObject *)values[7]); - __pyx_v_random_seed = __Pyx_PyInt_AsUnsignedInt(values[8]); if (unlikely((__pyx_v_random_seed == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_max_iter = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_max_iter == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_random_seed = __Pyx_PyInt_As_unsigned_int(values[9]); if (unlikely((__pyx_v_random_seed == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 9, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("train_wrap", 1, 10, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("sklearn.svm.liblinear.train_wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1400,7 +1470,9 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_Y), __pyx_ptype_5numpy_ndarray, 1, "Y", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_class_weight), __pyx_ptype_5numpy_ndarray, 1, "class_weight", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_7sklearn_3svm_9liblinear_train_wrap(__pyx_self, __pyx_v_X, __pyx_v_Y, __pyx_v_is_sparse, __pyx_v_solver_type, __pyx_v_eps, __pyx_v_bias, __pyx_v_C, __pyx_v_class_weight, __pyx_v_random_seed); + __pyx_r = __pyx_pf_7sklearn_3svm_9liblinear_train_wrap(__pyx_self, __pyx_v_X, __pyx_v_Y, __pyx_v_is_sparse, __pyx_v_solver_type, __pyx_v_eps, __pyx_v_bias, __pyx_v_C, __pyx_v_class_weight, __pyx_v_max_iter, __pyx_v_random_seed); + + /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -1409,15 +1481,7 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_1train_wrap(PyObject *__pyx_s return __pyx_r; } -/* "sklearn/svm/liblinear.pyx":14 - * - * - * def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, # <<<<<<<<<<<<<< - * bint is_sparse, int solver_type, double eps, double bias, - * double C, np.ndarray[np.float64_t, ndim=1] class_weight, - */ - -static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_Y, int __pyx_v_is_sparse, int __pyx_v_solver_type, double __pyx_v_eps, double __pyx_v_bias, double __pyx_v_C, PyArrayObject *__pyx_v_class_weight, unsigned int __pyx_v_random_seed) { +static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyArrayObject *__pyx_v_Y, int __pyx_v_is_sparse, int __pyx_v_solver_type, double __pyx_v_eps, double __pyx_v_bias, double __pyx_v_C, PyArrayObject *__pyx_v_class_weight, int __pyx_v_max_iter, unsigned int __pyx_v_random_seed) { struct parameter *__pyx_v_param; struct problem *__pyx_v_problem; struct model *__pyx_v_model; @@ -1426,6 +1490,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb PyArrayObject *__pyx_v_class_weight_label = 0; PyArrayObject *__pyx_v_w = 0; int __pyx_v_nr_class; + int __pyx_v_labels_; + PyArrayObject *__pyx_v_n_iter = 0; int __pyx_v_nr_feature; __Pyx_LocalBuf_ND __pyx_pybuffernd_Y; __Pyx_Buffer __pyx_pybuffer_Y; @@ -1433,27 +1499,30 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb __Pyx_Buffer __pyx_pybuffer_class_weight; __Pyx_LocalBuf_ND __pyx_pybuffernd_class_weight_label; __Pyx_Buffer __pyx_pybuffer_class_weight_label; + __Pyx_LocalBuf_ND __pyx_pybuffernd_n_iter; + __Pyx_Buffer __pyx_pybuffer_n_iter; __Pyx_LocalBuf_ND __pyx_pybuffernd_w; __Pyx_Buffer __pyx_pybuffer_w; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; - __pyx_t_5numpy_int32_t __pyx_t_8; - PyArrayObject *__pyx_t_9 = NULL; - int __pyx_t_10; - int __pyx_t_11; + PyObject *__pyx_t_8 = NULL; + __pyx_t_5numpy_int32_t __pyx_t_9; + PyArrayObject *__pyx_t_10 = NULL; + PyArrayObject *__pyx_t_11 = NULL; int __pyx_t_12; - PyArrayObject *__pyx_t_13 = NULL; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; + int __pyx_t_13; + PyArrayObject *__pyx_t_14 = NULL; + int __pyx_t_15; PyObject *__pyx_t_16 = NULL; PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -1466,6 +1535,10 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb __pyx_pybuffer_w.refcount = 0; __pyx_pybuffernd_w.data = NULL; __pyx_pybuffernd_w.rcbuffer = &__pyx_pybuffer_w; + __pyx_pybuffer_n_iter.pybuffer.buf = NULL; + __pyx_pybuffer_n_iter.refcount = 0; + __pyx_pybuffernd_n_iter.data = NULL; + __pyx_pybuffernd_n_iter.rcbuffer = &__pyx_pybuffer_n_iter; __pyx_pybuffer_Y.pybuffer.buf = NULL; __pyx_pybuffer_Y.refcount = 0; __pyx_pybuffernd_Y.data = NULL; @@ -1492,7 +1565,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * problem = csr_set_problem( * (X.data).data, */ - if (__pyx_v_is_sparse) { + __pyx_t_1 = (__pyx_v_is_sparse != 0); + if (__pyx_t_1) { /* "sklearn/svm/liblinear.pyx":26 * if is_sparse: @@ -1501,8 +1575,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * (X.indices).shape, * (X.indices).data, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); /* "sklearn/svm/liblinear.pyx":27 * problem = csr_set_problem( @@ -1511,8 +1585,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * (X.indices).data, * (X.indptr).shape, */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indices); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); /* "sklearn/svm/liblinear.pyx":28 * (X.data).data, @@ -1521,8 +1595,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * (X.indptr).shape, * (X.indptr).data, */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indices); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); /* "sklearn/svm/liblinear.pyx":29 * (X.indices).shape, @@ -1531,8 +1605,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * (X.indptr).data, * Y.data, (X.shape[1]), bias) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indptr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); /* "sklearn/svm/liblinear.pyx":30 * (X.indices).data, @@ -1541,8 +1615,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * Y.data, (X.shape[1]), bias) * else: */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__indptr); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); /* "sklearn/svm/liblinear.pyx":31 * (X.indptr).shape, @@ -1551,29 +1625,37 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * else: * problem = set_problem( */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s__shape); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_6, 1, sizeof(long), PyInt_FromLong, 0, 0, 1); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = __Pyx_PyInt_from_py_npy_int32(__pyx_t_7); if (unlikely((__pyx_t_8 == (npy_int32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_7, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_problem = csr_set_problem(((PyArrayObject *)__pyx_t_1)->data, ((PyArrayObject *)__pyx_t_2)->dimensions, ((PyArrayObject *)__pyx_t_3)->data, ((PyArrayObject *)__pyx_t_4)->dimensions, ((PyArrayObject *)__pyx_t_5)->data, __pyx_v_Y->data, ((__pyx_t_5numpy_int32_t)__pyx_t_8), __pyx_v_bias); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = __Pyx_PyInt_As_npy_int32(__pyx_t_8); if (unlikely((__pyx_t_9 == (npy_int32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "sklearn/svm/liblinear.pyx":25 + * + * if is_sparse: + * problem = csr_set_problem( # <<<<<<<<<<<<<< + * (X.data).data, + * (X.indices).shape, + */ + __pyx_v_problem = csr_set_problem(((PyArrayObject *)__pyx_t_2)->data, ((PyArrayObject *)__pyx_t_3)->dimensions, ((PyArrayObject *)__pyx_t_4)->data, ((PyArrayObject *)__pyx_t_5)->dimensions, ((PyArrayObject *)__pyx_t_6)->data, __pyx_v_Y->data, ((__pyx_t_5numpy_int32_t)__pyx_t_9), __pyx_v_bias); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L3; } /*else*/ { - /* "sklearn/svm/liblinear.pyx":37 + /* "sklearn/svm/liblinear.pyx":33 + * Y.data, (X.shape[1]), bias) + * else: + * problem = set_problem( # <<<<<<<<<<<<<< + * (X).data, * Y.data, - * (X).shape, - * bias) # <<<<<<<<<<<<<< - * - * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] \ */ __pyx_v_problem = set_problem(((PyArrayObject *)__pyx_v_X)->data, __pyx_v_Y->data, ((PyArrayObject *)__pyx_v_X)->dimensions, __pyx_v_bias); } @@ -1582,61 +1664,61 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb /* "sklearn/svm/liblinear.pyx":40 * * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] \ - * class_weight_label = np.arange(class_weight.shape[0], dtype=np.int32) # <<<<<<<<<<<<<< + * class_weight_label = np.arange(class_weight.shape[0], dtype=np.intc) # <<<<<<<<<<<<<< * param = set_parameter(solver_type, eps, C, class_weight.shape[0], * class_weight_label.data, class_weight.data, */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_arange); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__arange); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_Py_intptr_t((__pyx_v_class_weight->dimensions[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_class_weight->dimensions[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_intc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__int32); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = ((PyArrayObject *)__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) { + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) { __pyx_v_class_weight_label = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_class_weight_label.diminfo[0].strides = __pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_class_weight_label.diminfo[0].shape = __pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer.shape[0]; } } - __pyx_t_9 = 0; - __pyx_v_class_weight_label = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_10 = 0; + __pyx_v_class_weight_label = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; - /* "sklearn/svm/liblinear.pyx":43 - * param = set_parameter(solver_type, eps, C, class_weight.shape[0], + /* "sklearn/svm/liblinear.pyx":41 + * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] \ + * class_weight_label = np.arange(class_weight.shape[0], dtype=np.intc) + * param = set_parameter(solver_type, eps, C, class_weight.shape[0], # <<<<<<<<<<<<<< * class_weight_label.data, class_weight.data, - * random_seed) # <<<<<<<<<<<<<< - * - * error_msg = check_parameter(problem, param) + * max_iter, random_seed) */ - __pyx_v_param = set_parameter(__pyx_v_solver_type, __pyx_v_eps, __pyx_v_C, (__pyx_v_class_weight->dimensions[0]), __pyx_v_class_weight_label->data, __pyx_v_class_weight->data, __pyx_v_random_seed); + __pyx_v_param = set_parameter(__pyx_v_solver_type, __pyx_v_eps, __pyx_v_C, (__pyx_v_class_weight->dimensions[0]), __pyx_v_class_weight_label->data, __pyx_v_class_weight->data, __pyx_v_max_iter, __pyx_v_random_seed); /* "sklearn/svm/liblinear.pyx":45 - * random_seed) + * max_iter, random_seed) * * error_msg = check_parameter(problem, param) # <<<<<<<<<<<<<< * if error_msg: @@ -1651,8 +1733,8 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * free_problem(problem) * free_parameter(param) */ - __pyx_t_10 = (__pyx_v_error_msg != 0); - if (__pyx_t_10) { + __pyx_t_1 = (__pyx_v_error_msg != 0); + if (__pyx_t_1) { /* "sklearn/svm/liblinear.pyx":47 * error_msg = check_parameter(problem, param) @@ -1679,22 +1761,20 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * * # early return */ - __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_error_msg); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_error_msg); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; } - __pyx_L4:; /* "sklearn/svm/liblinear.pyx":52 * @@ -1728,9 +1808,13 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * */ /*finally:*/ { - #ifdef WITH_THREAD - Py_BLOCK_THREADS - #endif + /*normal exit:*/{ + #ifdef WITH_THREAD + Py_BLOCK_THREADS + #endif + goto __pyx_L7; + } + __pyx_L7:; } } @@ -1738,120 +1822,207 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb * # coef matrix holder created as fortran since that's what's used in liblinear * cdef np.ndarray[np.float64_t, ndim=2, mode='fortran'] w * cdef int nr_class = get_nr_class(model) # <<<<<<<<<<<<<< - * cdef int nr_feature = get_nr_feature(model) - * if bias > 0: nr_feature = nr_feature + 1 + * + * cdef int labels_ = nr_class */ __pyx_v_nr_class = get_nr_class(__pyx_v_model); - /* "sklearn/svm/liblinear.pyx":58 - * cdef np.ndarray[np.float64_t, ndim=2, mode='fortran'] w + /* "sklearn/svm/liblinear.pyx":59 * cdef int nr_class = get_nr_class(model) + * + * cdef int labels_ = nr_class # <<<<<<<<<<<<<< + * if nr_class == 2: + * labels_ = 1 + */ + __pyx_v_labels_ = __pyx_v_nr_class; + + /* "sklearn/svm/liblinear.pyx":60 + * + * cdef int labels_ = nr_class + * if nr_class == 2: # <<<<<<<<<<<<<< + * labels_ = 1 + * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] n_iter = np.zeros(labels_, dtype=np.intc) + */ + __pyx_t_1 = ((__pyx_v_nr_class == 2) != 0); + if (__pyx_t_1) { + + /* "sklearn/svm/liblinear.pyx":61 + * cdef int labels_ = nr_class + * if nr_class == 2: + * labels_ = 1 # <<<<<<<<<<<<<< + * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] n_iter = np.zeros(labels_, dtype=np.intc) + * get_n_iter(model, n_iter.data) + */ + __pyx_v_labels_ = 1; + goto __pyx_L8; + } + __pyx_L8:; + + /* "sklearn/svm/liblinear.pyx":62 + * if nr_class == 2: + * labels_ = 1 + * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] n_iter = np.zeros(labels_, dtype=np.intc) # <<<<<<<<<<<<<< + * get_n_iter(model, n_iter.data) + * + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_labels_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_intc); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_n_iter.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) { + __pyx_v_n_iter = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_n_iter.rcbuffer->pybuffer.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_pybuffernd_n_iter.diminfo[0].strides = __pyx_pybuffernd_n_iter.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_n_iter.diminfo[0].shape = __pyx_pybuffernd_n_iter.rcbuffer->pybuffer.shape[0]; + } + } + __pyx_t_11 = 0; + __pyx_v_n_iter = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "sklearn/svm/liblinear.pyx":63 + * labels_ = 1 + * cdef np.ndarray[np.int32_t, ndim=1, mode='c'] n_iter = np.zeros(labels_, dtype=np.intc) + * get_n_iter(model, n_iter.data) # <<<<<<<<<<<<<< + * + * cdef int nr_feature = get_nr_feature(model) + */ + get_n_iter(__pyx_v_model, ((int *)__pyx_v_n_iter->data)); + + /* "sklearn/svm/liblinear.pyx":65 + * get_n_iter(model, n_iter.data) + * * cdef int nr_feature = get_nr_feature(model) # <<<<<<<<<<<<<< * if bias > 0: nr_feature = nr_feature + 1 - * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer + * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer */ __pyx_v_nr_feature = get_nr_feature(__pyx_v_model); - /* "sklearn/svm/liblinear.pyx":59 - * cdef int nr_class = get_nr_class(model) + /* "sklearn/svm/liblinear.pyx":66 + * * cdef int nr_feature = get_nr_feature(model) * if bias > 0: nr_feature = nr_feature + 1 # <<<<<<<<<<<<<< - * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer + * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer * w = np.empty((1, nr_feature),order='F') */ - __pyx_t_10 = (__pyx_v_bias > 0.0); - if (__pyx_t_10) { + __pyx_t_1 = ((__pyx_v_bias > 0.0) != 0); + if (__pyx_t_1) { __pyx_v_nr_feature = (__pyx_v_nr_feature + 1); - goto __pyx_L8; + goto __pyx_L9; } - __pyx_L8:; + __pyx_L9:; - /* "sklearn/svm/liblinear.pyx":60 + /* "sklearn/svm/liblinear.pyx":67 * cdef int nr_feature = get_nr_feature(model) * if bias > 0: nr_feature = nr_feature + 1 - * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer # <<<<<<<<<<<<<< + * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer # <<<<<<<<<<<<<< * w = np.empty((1, nr_feature),order='F') * copy_w(w.data, model, nr_feature) */ - __pyx_t_10 = (__pyx_v_nr_class == 2); - if (__pyx_t_10) { - __pyx_t_11 = (__pyx_v_solver_type != 4); - __pyx_t_12 = __pyx_t_11; + __pyx_t_1 = ((__pyx_v_nr_class == 2) != 0); + if (__pyx_t_1) { + __pyx_t_12 = ((__pyx_v_solver_type != 4) != 0); + __pyx_t_13 = __pyx_t_12; } else { - __pyx_t_12 = __pyx_t_10; + __pyx_t_13 = __pyx_t_1; } - if (__pyx_t_12) { + if (__pyx_t_13) { - /* "sklearn/svm/liblinear.pyx":61 + /* "sklearn/svm/liblinear.pyx":68 * if bias > 0: nr_feature = nr_feature + 1 - * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer + * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer * w = np.empty((1, nr_feature),order='F') # <<<<<<<<<<<<<< * copy_w(w.data, model, nr_feature) * else: */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_nr_feature); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_nr_feature); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_order, __pyx_n_s_F) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer); - __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_14 < 0)) { - PyErr_Fetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_15 < 0)) { + PyErr_Fetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_15); Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17); + Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); __Pyx_RaiseBufferFallbackError(); } else { - PyErr_Restore(__pyx_t_15, __pyx_t_16, __pyx_t_17); + PyErr_Restore(__pyx_t_16, __pyx_t_17, __pyx_t_18); } } __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_w.diminfo[1].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_w.diminfo[1].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_13 = 0; - __pyx_v_w = ((PyArrayObject *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_14 = 0; + __pyx_v_w = ((PyArrayObject *)__pyx_t_6); + __pyx_t_6 = 0; - /* "sklearn/svm/liblinear.pyx":62 - * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer + /* "sklearn/svm/liblinear.pyx":69 + * if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer * w = np.empty((1, nr_feature),order='F') * copy_w(w.data, model, nr_feature) # <<<<<<<<<<<<<< * else: * len_w = (nr_class) * nr_feature */ copy_w(__pyx_v_w->data, __pyx_v_model, __pyx_v_nr_feature); - goto __pyx_L9; + goto __pyx_L10; } /*else*/ { - /* "sklearn/svm/liblinear.pyx":64 + /* "sklearn/svm/liblinear.pyx":71 * copy_w(w.data, model, nr_feature) * else: * len_w = (nr_class) * nr_feature # <<<<<<<<<<<<<< @@ -1860,66 +2031,66 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb */ __pyx_v_len_w = (__pyx_v_nr_class * __pyx_v_nr_feature); - /* "sklearn/svm/liblinear.pyx":65 + /* "sklearn/svm/liblinear.pyx":72 * else: * len_w = (nr_class) * nr_feature * w = np.empty((nr_class, nr_feature),order='F') # <<<<<<<<<<<<<< * copy_w(w.data, model, len_w) * */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_nr_class); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_nr_feature); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_6 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_order, __pyx_n_s_F) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromLong(__pyx_v_nr_class); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyInt_FromLong(__pyx_v_nr_feature); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_4 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = ((PyArrayObject *)__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = ((PyArrayObject *)__pyx_t_6); { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer); - __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_14 < 0)) { - PyErr_Fetch(&__pyx_t_17, &__pyx_t_16, &__pyx_t_15); + __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack); + if (unlikely(__pyx_t_15 < 0)) { + PyErr_Fetch(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_w.rcbuffer->pybuffer, (PyObject*)__pyx_v_w, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_F_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_15); + Py_XDECREF(__pyx_t_18); Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_16); __Pyx_RaiseBufferFallbackError(); } else { - PyErr_Restore(__pyx_t_17, __pyx_t_16, __pyx_t_15); + PyErr_Restore(__pyx_t_18, __pyx_t_17, __pyx_t_16); } } __pyx_pybuffernd_w.diminfo[0].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_w.diminfo[0].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_w.diminfo[1].strides = __pyx_pybuffernd_w.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_w.diminfo[1].shape = __pyx_pybuffernd_w.rcbuffer->pybuffer.shape[1]; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_13 = 0; - __pyx_v_w = ((PyArrayObject *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_14 = 0; + __pyx_v_w = ((PyArrayObject *)__pyx_t_6); + __pyx_t_6 = 0; - /* "sklearn/svm/liblinear.pyx":66 + /* "sklearn/svm/liblinear.pyx":73 * len_w = (nr_class) * nr_feature * w = np.empty((nr_class, nr_feature),order='F') * copy_w(w.data, model, len_w) # <<<<<<<<<<<<<< @@ -1928,9 +2099,9 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb */ copy_w(__pyx_v_w->data, __pyx_v_model, __pyx_v_len_w); } - __pyx_L9:; + __pyx_L10:; - /* "sklearn/svm/liblinear.pyx":69 + /* "sklearn/svm/liblinear.pyx":76 * * ### FREE * free_and_destroy_model(&model) # <<<<<<<<<<<<<< @@ -1939,7 +2110,7 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb */ free_and_destroy_model((&__pyx_v_model)); - /* "sklearn/svm/liblinear.pyx":70 + /* "sklearn/svm/liblinear.pyx":77 * ### FREE * free_and_destroy_model(&model) * free_problem(problem) # <<<<<<<<<<<<<< @@ -1948,7 +2119,7 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb */ free_problem(__pyx_v_problem); - /* "sklearn/svm/liblinear.pyx":71 + /* "sklearn/svm/liblinear.pyx":78 * free_and_destroy_model(&model) * free_problem(problem) * free_parameter(param) # <<<<<<<<<<<<<< @@ -1957,33 +2128,49 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb */ free_parameter(__pyx_v_param); - /* "sklearn/svm/liblinear.pyx":74 + /* "sklearn/svm/liblinear.pyx":81 * # destroy_param(param) don't call this or it will destroy class_weight_label and class_weight * - * return w # <<<<<<<<<<<<<< + * return w, n_iter # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(((PyObject *)__pyx_v_w)); - __pyx_r = ((PyObject *)__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_w)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_w)); + __Pyx_INCREF(((PyObject *)__pyx_v_n_iter)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_n_iter)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_n_iter)); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "sklearn/svm/liblinear.pyx":14 + * + * + * def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, # <<<<<<<<<<<<<< + * bint is_sparse, int solver_type, double eps, double bias, + * double C, np.ndarray[np.float64_t, ndim=1] class_weight, + */ + + /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Y.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_class_weight.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_n_iter.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("sklearn.svm.liblinear.train_wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -1993,15 +2180,25 @@ static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_train_wrap(CYTHON_UNUSED PyOb __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_Y.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_class_weight.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_class_weight_label.rcbuffer->pybuffer); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_n_iter.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_w.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_class_weight_label); __Pyx_XDECREF((PyObject *)__pyx_v_w); + __Pyx_XDECREF((PyObject *)__pyx_v_n_iter); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "sklearn/svm/liblinear.pyx":84 + * + * + * def set_verbosity_wrap(int verbosity): # <<<<<<<<<<<<<< + * """ + * Control verbosity of libsvm library + */ + /* Python wrapper */ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_3set_verbosity_wrap(PyObject *__pyx_self, PyObject *__pyx_arg_verbosity); /*proto*/ static char __pyx_doc_7sklearn_3svm_9liblinear_2set_verbosity_wrap[] = "\n Control verbosity of libsvm library\n "; @@ -2015,7 +2212,7 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_3set_verbosity_wrap(PyObject __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_verbosity_wrap (wrapper)", 0); assert(__pyx_arg_verbosity); { - __pyx_v_verbosity = __Pyx_PyInt_AsInt(__pyx_arg_verbosity); if (unlikely((__pyx_v_verbosity == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_verbosity = __Pyx_PyInt_As_int(__pyx_arg_verbosity); if (unlikely((__pyx_v_verbosity == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2024,36 +2221,47 @@ static PyObject *__pyx_pw_7sklearn_3svm_9liblinear_3set_verbosity_wrap(PyObject return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_7sklearn_3svm_9liblinear_2set_verbosity_wrap(__pyx_self, ((int)__pyx_v_verbosity)); + + /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/svm/liblinear.pyx":77 - * - * - * def set_verbosity_wrap(int verbosity): # <<<<<<<<<<<<<< - * """ - * Control verbosity of libsvm library - */ - static PyObject *__pyx_pf_7sklearn_3svm_9liblinear_2set_verbosity_wrap(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_verbosity) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_verbosity_wrap", 0); - /* "sklearn/svm/liblinear.pyx":81 + /* "sklearn/svm/liblinear.pyx":88 * Control verbosity of libsvm library * """ * set_verbosity(verbosity) # <<<<<<<<<<<<<< */ set_verbosity(__pyx_v_verbosity); + /* "sklearn/svm/liblinear.pyx":84 + * + * + * def set_verbosity_wrap(int verbosity): # <<<<<<<<<<<<<< + * """ + * Control verbosity of libsvm library + */ + + /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":194 + * # experimental exception made for __getbuffer__ and __releasebuffer__ + * # -- the details of this may change. + * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fullfill the PEP. + */ + /* Python wrapper */ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { @@ -2061,18 +2269,12 @@ static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "numpy.pxd":194 - * # experimental exception made for __getbuffer__ and __releasebuffer__ - * # -- the details of this may change. - * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fullfill the PEP. - */ - static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { int __pyx_v_copy_shape; int __pyx_v_i; @@ -2104,22 +2306,20 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __Pyx_GIVEREF(__pyx_v_info->obj); } - /* "numpy.pxd":200 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":200 * # of flags * * if info == NULL: return # <<<<<<<<<<<<<< * * cdef int copy_shape, i, ndim */ - __pyx_t_1 = (__pyx_v_info == NULL); + __pyx_t_1 = ((__pyx_v_info == NULL) != 0); if (__pyx_t_1) { __pyx_r = 0; goto __pyx_L0; - goto __pyx_L3; } - __pyx_L3:; - /* "numpy.pxd":203 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":203 * * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -2128,7 +2328,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_endian_detector = 1; - /* "numpy.pxd":204 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":204 * cdef int copy_shape, i, ndim * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -2137,7 +2337,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "numpy.pxd":206 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":206 * cdef bint little_endian = ((&endian_detector)[0] != 0) * * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< @@ -2146,17 +2346,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_ndim = PyArray_NDIM(__pyx_v_self); - /* "numpy.pxd":208 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":208 * ndim = PyArray_NDIM(self) * * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< * copy_shape = 1 * else: */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); + __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0); if (__pyx_t_1) { - /* "numpy.pxd":209 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":209 * * if sizeof(npy_intp) != sizeof(Py_ssize_t): * copy_shape = 1 # <<<<<<<<<<<<<< @@ -2168,7 +2368,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":211 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":211 * copy_shape = 1 * else: * copy_shape = 0 # <<<<<<<<<<<<<< @@ -2179,87 +2379,83 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L4:; - /* "numpy.pxd":213 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":213 * copy_shape = 0 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * raise ValueError(u"ndarray is not C contiguous") */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS); + __pyx_t_1 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0); if (__pyx_t_1) { - /* "numpy.pxd":214 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":214 * * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< * raise ValueError(u"ndarray is not C contiguous") * */ - __pyx_t_2 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS)); + __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS) != 0)) != 0); __pyx_t_3 = __pyx_t_2; } else { __pyx_t_3 = __pyx_t_1; } if (__pyx_t_3) { - /* "numpy.pxd":215 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":215 * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; } - __pyx_L5:; - /* "numpy.pxd":217 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":217 * raise ValueError(u"ndarray is not C contiguous") * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): * raise ValueError(u"ndarray is not Fortran contiguous") */ - __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS); + __pyx_t_3 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0); if (__pyx_t_3) { - /* "numpy.pxd":218 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":218 * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< * raise ValueError(u"ndarray is not Fortran contiguous") * */ - __pyx_t_1 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS)); + __pyx_t_1 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS) != 0)) != 0); __pyx_t_2 = __pyx_t_1; } else { __pyx_t_2 = __pyx_t_3; } if (__pyx_t_2) { - /* "numpy.pxd":219 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":219 * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< * * info.buf = PyArray_DATA(self) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; } - __pyx_L6:; - /* "numpy.pxd":221 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":221 * raise ValueError(u"ndarray is not Fortran contiguous") * * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< @@ -2268,7 +2464,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->buf = PyArray_DATA(__pyx_v_self); - /* "numpy.pxd":222 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":222 * * info.buf = PyArray_DATA(self) * info.ndim = ndim # <<<<<<<<<<<<<< @@ -2277,16 +2473,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->ndim = __pyx_v_ndim; - /* "numpy.pxd":223 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":223 * info.buf = PyArray_DATA(self) * info.ndim = ndim * if copy_shape: # <<<<<<<<<<<<<< * # Allocate new buffer for strides and shape info. * # This is allocated as one block, strides first. */ - if (__pyx_v_copy_shape) { + __pyx_t_2 = (__pyx_v_copy_shape != 0); + if (__pyx_t_2) { - /* "numpy.pxd":226 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":226 * # Allocate new buffer for strides and shape info. * # This is allocated as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< @@ -2295,7 +2492,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2))); - /* "numpy.pxd":227 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":227 * # This is allocated as one block, strides first. * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim # <<<<<<<<<<<<<< @@ -2304,7 +2501,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); - /* "numpy.pxd":228 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":228 * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) * info.shape = info.strides + ndim * for i in range(ndim): # <<<<<<<<<<<<<< @@ -2315,7 +2512,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "numpy.pxd":229 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":229 * info.shape = info.strides + ndim * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< @@ -2324,7 +2521,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]); - /* "numpy.pxd":230 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":230 * for i in range(ndim): * info.strides[i] = PyArray_STRIDES(self)[i] * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< @@ -2337,7 +2534,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":232 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":232 * info.shape[i] = PyArray_DIMS(self)[i] * else: * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< @@ -2346,7 +2543,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self)); - /* "numpy.pxd":233 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":233 * else: * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< @@ -2357,7 +2554,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L7:; - /* "numpy.pxd":234 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":234 * info.strides = PyArray_STRIDES(self) * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL # <<<<<<<<<<<<<< @@ -2366,7 +2563,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->suboffsets = NULL; - /* "numpy.pxd":235 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":235 * info.shape = PyArray_DIMS(self) * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< @@ -2375,16 +2572,16 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self); - /* "numpy.pxd":236 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":236 * info.suboffsets = NULL * info.itemsize = PyArray_ITEMSIZE(self) * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< * * cdef int t */ - __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(__pyx_v_self)); + __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0)); - /* "numpy.pxd":239 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":239 * * cdef int t * cdef char* f = NULL # <<<<<<<<<<<<<< @@ -2393,7 +2590,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_f = NULL; - /* "numpy.pxd":240 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":240 * cdef int t * cdef char* f = NULL * cdef dtype descr = self.descr # <<<<<<<<<<<<<< @@ -2405,7 +2602,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_v_descr = ((PyArray_Descr *)__pyx_t_4); __pyx_t_4 = 0; - /* "numpy.pxd":244 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":244 * cdef int offset * * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< @@ -2414,23 +2611,23 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); - /* "numpy.pxd":246 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":246 * cdef bint hasfields = PyDataType_HASFIELDS(descr) * * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< * # do not call releasebuffer * info.obj = None */ - __pyx_t_2 = (!__pyx_v_hasfields); + __pyx_t_2 = ((!(__pyx_v_hasfields != 0)) != 0); if (__pyx_t_2) { - __pyx_t_3 = (!__pyx_v_copy_shape); + __pyx_t_3 = ((!(__pyx_v_copy_shape != 0)) != 0); __pyx_t_1 = __pyx_t_3; } else { __pyx_t_1 = __pyx_t_2; } if (__pyx_t_1) { - /* "numpy.pxd":248 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":248 * if not hasfields and not copy_shape: * # do not call releasebuffer * info.obj = None # <<<<<<<<<<<<<< @@ -2446,7 +2643,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } /*else*/ { - /* "numpy.pxd":251 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":251 * else: * # need to call releasebuffer * info.obj = self # <<<<<<<<<<<<<< @@ -2461,17 +2658,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } __pyx_L10:; - /* "numpy.pxd":253 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":253 * info.obj = self * * if not hasfields: # <<<<<<<<<<<<<< * t = descr.type_num * if ((descr.byteorder == c'>' and little_endian) or */ - __pyx_t_1 = (!__pyx_v_hasfields); + __pyx_t_1 = ((!(__pyx_v_hasfields != 0)) != 0); if (__pyx_t_1) { - /* "numpy.pxd":254 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":254 * * if not hasfields: * t = descr.type_num # <<<<<<<<<<<<<< @@ -2481,31 +2678,31 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P __pyx_t_5 = __pyx_v_descr->type_num; __pyx_v_t = __pyx_t_5; - /* "numpy.pxd":255 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":255 * if not hasfields: * t = descr.type_num * if ((descr.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '>'); + __pyx_t_1 = ((__pyx_v_descr->byteorder == '>') != 0); if (__pyx_t_1) { - __pyx_t_2 = __pyx_v_little_endian; + __pyx_t_2 = (__pyx_v_little_endian != 0); } else { __pyx_t_2 = __pyx_t_1; } if (!__pyx_t_2) { - /* "numpy.pxd":256 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":256 * t = descr.type_num * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< * raise ValueError(u"Non-native byte order not supported") * if t == NPY_BYTE: f = "b" */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '<'); + __pyx_t_1 = ((__pyx_v_descr->byteorder == '<') != 0); if (__pyx_t_1) { - __pyx_t_3 = (!__pyx_v_little_endian); + __pyx_t_3 = ((!(__pyx_v_little_endian != 0)) != 0); __pyx_t_7 = __pyx_t_3; } else { __pyx_t_7 = __pyx_t_1; @@ -2516,23 +2713,21 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P } if (__pyx_t_1) { - /* "numpy.pxd":257 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":257 * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; } - __pyx_L12:; - /* "numpy.pxd":274 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":274 * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< @@ -2541,7 +2736,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ switch (__pyx_v_t) { - /* "numpy.pxd":258 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":258 * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< @@ -2549,10 +2744,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_SHORT: f = "h" */ case NPY_BYTE: - __pyx_v_f = __pyx_k__b; + __pyx_v_f = __pyx_k_b; break; - /* "numpy.pxd":259 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":259 * raise ValueError(u"Non-native byte order not supported") * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< @@ -2560,10 +2755,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_USHORT: f = "H" */ case NPY_UBYTE: - __pyx_v_f = __pyx_k__B; + __pyx_v_f = __pyx_k_B; break; - /* "numpy.pxd":260 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":260 * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< @@ -2571,10 +2766,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_INT: f = "i" */ case NPY_SHORT: - __pyx_v_f = __pyx_k__h; + __pyx_v_f = __pyx_k_h; break; - /* "numpy.pxd":261 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":261 * elif t == NPY_UBYTE: f = "B" * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< @@ -2582,10 +2777,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_UINT: f = "I" */ case NPY_USHORT: - __pyx_v_f = __pyx_k__H; + __pyx_v_f = __pyx_k_H; break; - /* "numpy.pxd":262 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":262 * elif t == NPY_SHORT: f = "h" * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< @@ -2593,10 +2788,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONG: f = "l" */ case NPY_INT: - __pyx_v_f = __pyx_k__i; + __pyx_v_f = __pyx_k_i; break; - /* "numpy.pxd":263 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":263 * elif t == NPY_USHORT: f = "H" * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< @@ -2604,10 +2799,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_ULONG: f = "L" */ case NPY_UINT: - __pyx_v_f = __pyx_k__I; + __pyx_v_f = __pyx_k_I; break; - /* "numpy.pxd":264 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":264 * elif t == NPY_INT: f = "i" * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< @@ -2615,10 +2810,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONGLONG: f = "q" */ case NPY_LONG: - __pyx_v_f = __pyx_k__l; + __pyx_v_f = __pyx_k_l; break; - /* "numpy.pxd":265 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":265 * elif t == NPY_UINT: f = "I" * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< @@ -2626,10 +2821,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_ULONGLONG: f = "Q" */ case NPY_ULONG: - __pyx_v_f = __pyx_k__L; + __pyx_v_f = __pyx_k_L; break; - /* "numpy.pxd":266 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":266 * elif t == NPY_LONG: f = "l" * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< @@ -2637,10 +2832,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_FLOAT: f = "f" */ case NPY_LONGLONG: - __pyx_v_f = __pyx_k__q; + __pyx_v_f = __pyx_k_q; break; - /* "numpy.pxd":267 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":267 * elif t == NPY_ULONG: f = "L" * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< @@ -2648,10 +2843,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_DOUBLE: f = "d" */ case NPY_ULONGLONG: - __pyx_v_f = __pyx_k__Q; + __pyx_v_f = __pyx_k_Q; break; - /* "numpy.pxd":268 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":268 * elif t == NPY_LONGLONG: f = "q" * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< @@ -2659,10 +2854,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_LONGDOUBLE: f = "g" */ case NPY_FLOAT: - __pyx_v_f = __pyx_k__f; + __pyx_v_f = __pyx_k_f; break; - /* "numpy.pxd":269 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":269 * elif t == NPY_ULONGLONG: f = "Q" * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< @@ -2670,10 +2865,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CFLOAT: f = "Zf" */ case NPY_DOUBLE: - __pyx_v_f = __pyx_k__d; + __pyx_v_f = __pyx_k_d; break; - /* "numpy.pxd":270 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":270 * elif t == NPY_FLOAT: f = "f" * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< @@ -2681,10 +2876,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CDOUBLE: f = "Zd" */ case NPY_LONGDOUBLE: - __pyx_v_f = __pyx_k__g; + __pyx_v_f = __pyx_k_g; break; - /* "numpy.pxd":271 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":271 * elif t == NPY_DOUBLE: f = "d" * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< @@ -2692,10 +2887,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_CLONGDOUBLE: f = "Zg" */ case NPY_CFLOAT: - __pyx_v_f = __pyx_k__Zf; + __pyx_v_f = __pyx_k_Zf; break; - /* "numpy.pxd":272 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":272 * elif t == NPY_LONGDOUBLE: f = "g" * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< @@ -2703,10 +2898,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * elif t == NPY_OBJECT: f = "O" */ case NPY_CDOUBLE: - __pyx_v_f = __pyx_k__Zd; + __pyx_v_f = __pyx_k_Zd; break; - /* "numpy.pxd":273 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":273 * elif t == NPY_CFLOAT: f = "Zf" * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< @@ -2714,10 +2909,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * else: */ case NPY_CLONGDOUBLE: - __pyx_v_f = __pyx_k__Zg; + __pyx_v_f = __pyx_k_Zg; break; - /* "numpy.pxd":274 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":274 * elif t == NPY_CDOUBLE: f = "Zd" * elif t == NPY_CLONGDOUBLE: f = "Zg" * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< @@ -2725,37 +2920,37 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) */ case NPY_OBJECT: - __pyx_v_f = __pyx_k__O; + __pyx_v_f = __pyx_k_O; break; default: - /* "numpy.pxd":276 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":276 * elif t == NPY_OBJECT: f = "O" * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * info.format = f * return */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_7), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __pyx_t_8 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_8)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } - /* "numpy.pxd":277 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":277 * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * info.format = f # <<<<<<<<<<<<<< @@ -2764,7 +2959,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->format = __pyx_v_f; - /* "numpy.pxd":278 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":278 * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * info.format = f * return # <<<<<<<<<<<<<< @@ -2773,11 +2968,10 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_r = 0; goto __pyx_L0; - goto __pyx_L11; } /*else*/ { - /* "numpy.pxd":280 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":280 * return * else: * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< @@ -2786,7 +2980,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_info->format = ((char *)malloc(255)); - /* "numpy.pxd":281 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":281 * else: * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = c'^' # Native data types, manual alignment # <<<<<<<<<<<<<< @@ -2795,7 +2989,7 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_info->format[0]) = '^'; - /* "numpy.pxd":282 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":282 * info.format = stdlib.malloc(_buffer_format_string_len) * info.format[0] = c'^' # Native data types, manual alignment * offset = 0 # <<<<<<<<<<<<<< @@ -2804,17 +2998,17 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ __pyx_v_offset = 0; - /* "numpy.pxd":285 - * f = _util_dtypestring(descr, info.format + 1, + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":283 + * info.format[0] = c'^' # Native data types, manual alignment + * offset = 0 + * f = _util_dtypestring(descr, info.format + 1, # <<<<<<<<<<<<<< * info.format + _buffer_format_string_len, - * &offset) # <<<<<<<<<<<<<< - * f[0] = c'\0' # Terminate format string - * + * &offset) */ __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_f = __pyx_t_9; - /* "numpy.pxd":286 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":286 * info.format + _buffer_format_string_len, * &offset) * f[0] = c'\0' # Terminate format string # <<<<<<<<<<<<<< @@ -2823,8 +3017,16 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P */ (__pyx_v_f[0]) = '\x00'; } - __pyx_L11:; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":194 + * # experimental exception made for __getbuffer__ and __releasebuffer__ + * # -- the details of this may change. + * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fullfill the PEP. + */ + + /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; @@ -2848,39 +3050,41 @@ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, P return __pyx_r; } +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":288 + * f[0] = c'\0' # Terminate format string + * + * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + */ + /* Python wrapper */ static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); + + /* function exit code */ __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":288 - * f[0] = c'\0' # Terminate format string - * - * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - */ - static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__releasebuffer__", 0); - /* "numpy.pxd":289 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":289 * * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): */ - __pyx_t_1 = PyArray_HASFIELDS(__pyx_v_self); + __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0); if (__pyx_t_1) { - /* "numpy.pxd":290 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":290 * def __releasebuffer__(ndarray self, Py_buffer* info): * if PyArray_HASFIELDS(self): * stdlib.free(info.format) # <<<<<<<<<<<<<< @@ -2892,17 +3096,17 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s } __pyx_L3:; - /* "numpy.pxd":291 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":291 * if PyArray_HASFIELDS(self): * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< * stdlib.free(info.strides) * # info.shape was stored after info.strides in the same block */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); + __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0); if (__pyx_t_1) { - /* "numpy.pxd":292 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":292 * stdlib.free(info.format) * if sizeof(npy_intp) != sizeof(Py_ssize_t): * stdlib.free(info.strides) # <<<<<<<<<<<<<< @@ -2914,10 +3118,19 @@ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_s } __pyx_L4:; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":288 + * f[0] = c'\0' # Terminate format string + * + * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + */ + + /* function exit code */ __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":768 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":768 * ctypedef npy_cdouble complex_t * * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< @@ -2934,7 +3147,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); - /* "numpy.pxd":769 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":769 * * cdef inline object PyArray_MultiIterNew1(a): * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< @@ -2948,8 +3161,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":768 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, a) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -2960,7 +3180,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__ return __pyx_r; } -/* "numpy.pxd":771 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":771 * return PyArray_MultiIterNew(1, a) * * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< @@ -2977,7 +3197,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); - /* "numpy.pxd":772 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":772 * * cdef inline object PyArray_MultiIterNew2(a, b): * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< @@ -2991,8 +3211,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":771 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, b) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -3003,7 +3230,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__ return __pyx_r; } -/* "numpy.pxd":774 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":774 * return PyArray_MultiIterNew(2, a, b) * * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< @@ -3020,7 +3247,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); - /* "numpy.pxd":775 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":775 * * cdef inline object PyArray_MultiIterNew3(a, b, c): * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< @@ -3034,8 +3261,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":774 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, c) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -3046,7 +3280,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__ return __pyx_r; } -/* "numpy.pxd":777 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":777 * return PyArray_MultiIterNew(3, a, b, c) * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< @@ -3063,7 +3297,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); - /* "numpy.pxd":778 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":778 * * cdef inline object PyArray_MultiIterNew4(a, b, c, d): * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< @@ -3077,8 +3311,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":777 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, d) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -3089,7 +3330,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__ return __pyx_r; } -/* "numpy.pxd":780 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":780 * return PyArray_MultiIterNew(4, a, b, c, d) * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< @@ -3106,7 +3347,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); - /* "numpy.pxd":781 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":781 * * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< @@ -3120,8 +3361,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ __pyx_t_1 = 0; goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":780 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -3132,7 +3380,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__ return __pyx_r; } -/* "numpy.pxd":783 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":783 * return PyArray_MultiIterNew(5, a, b, c, d, e) * * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< @@ -3154,20 +3402,19 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx Py_ssize_t __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_5; + int __pyx_t_6; int __pyx_t_7; int __pyx_t_8; int __pyx_t_9; - int __pyx_t_10; - long __pyx_t_11; - char *__pyx_t_12; + long __pyx_t_10; + char *__pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_util_dtypestring", 0); - /* "numpy.pxd":790 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":790 * cdef int delta_offset * cdef tuple i * cdef int endian_detector = 1 # <<<<<<<<<<<<<< @@ -3176,7 +3423,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_endian_detector = 1; - /* "numpy.pxd":791 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":791 * cdef tuple i * cdef int endian_detector = 1 * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< @@ -3185,18 +3432,18 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - /* "numpy.pxd":794 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":794 * cdef tuple fields * * for childname in descr.names: # <<<<<<<<<<<<<< * fields = descr.fields[childname] * child, new_offset = fields */ - if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) { + if (unlikely(__pyx_v_descr->names == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; for (;;) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON @@ -3204,33 +3451,31 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx #else __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif - __Pyx_XDECREF(__pyx_v_childname); - __pyx_v_childname = __pyx_t_3; + __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3); __pyx_t_3 = 0; - /* "numpy.pxd":795 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":795 * * for childname in descr.names: * fields = descr.fields[childname] # <<<<<<<<<<<<<< * child, new_offset = fields * */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_3); - if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_fields)); - __pyx_v_fields = ((PyObject*)__pyx_t_3); + if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; - /* "numpy.pxd":796 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":796 * for childname in descr.names: * fields = descr.fields[childname] * child, new_offset = fields # <<<<<<<<<<<<<< * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: */ - if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) { - PyObject* sequence = ((PyObject *)__pyx_v_fields); + if (likely(__pyx_v_fields != Py_None)) { + PyObject* sequence = __pyx_v_fields; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else @@ -3252,129 +3497,96 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); #endif - } else if (1) { + } else { __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else - { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_fields)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; } if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_child)); - __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_new_offset); - __pyx_v_new_offset = __pyx_t_4; + __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4); __pyx_t_4 = 0; - /* "numpy.pxd":798 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":798 * child, new_offset = fields * - * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< + * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") * */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":799 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":799 * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< * * if ((child.byteorder == c'>' and little_endian) or */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; } - __pyx_L7:; - /* "numpy.pxd":801 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":801 * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") * * if ((child.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") */ - __pyx_t_7 = (__pyx_v_child->byteorder == '>'); - if (__pyx_t_7) { - __pyx_t_8 = __pyx_v_little_endian; + __pyx_t_6 = ((__pyx_v_child->byteorder == '>') != 0); + if (__pyx_t_6) { + __pyx_t_7 = (__pyx_v_little_endian != 0); } else { - __pyx_t_8 = __pyx_t_7; + __pyx_t_7 = __pyx_t_6; } - if (!__pyx_t_8) { + if (!__pyx_t_7) { - /* "numpy.pxd":802 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":802 * * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< * raise ValueError(u"Non-native byte order not supported") * # One could encode it in the format string and have Cython */ - __pyx_t_7 = (__pyx_v_child->byteorder == '<'); - if (__pyx_t_7) { - __pyx_t_9 = (!__pyx_v_little_endian); - __pyx_t_10 = __pyx_t_9; + __pyx_t_6 = ((__pyx_v_child->byteorder == '<') != 0); + if (__pyx_t_6) { + __pyx_t_8 = ((!(__pyx_v_little_endian != 0)) != 0); + __pyx_t_9 = __pyx_t_8; } else { - __pyx_t_10 = __pyx_t_7; + __pyx_t_9 = __pyx_t_6; } - __pyx_t_7 = __pyx_t_10; + __pyx_t_6 = __pyx_t_9; } else { - __pyx_t_7 = __pyx_t_8; + __pyx_t_6 = __pyx_t_7; } - if (__pyx_t_7) { + if (__pyx_t_6) { - /* "numpy.pxd":803 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":803 * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * # One could encode it in the format string and have Cython * # complain instead, BUT: < and > in format strings also imply */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; } - __pyx_L8:; - /* "numpy.pxd":813 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":813 * * # Output padding bytes * while offset[0] < new_offset: # <<<<<<<<<<<<<< @@ -3382,15 +3594,15 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx * f += 1 */ while (1) { - __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_7) break; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_6) break; - /* "numpy.pxd":814 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":814 * # Output padding bytes * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< @@ -3399,7 +3611,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ (__pyx_v_f[0]) = 120; - /* "numpy.pxd":815 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":815 * while offset[0] < new_offset: * f[0] = 120 # "x"; pad byte * f += 1 # <<<<<<<<<<<<<< @@ -3408,413 +3620,410 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx */ __pyx_v_f = (__pyx_v_f + 1); - /* "numpy.pxd":816 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":816 * f[0] = 120 # "x"; pad byte * f += 1 * offset[0] += 1 # <<<<<<<<<<<<<< * * offset[0] += child.itemsize */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + 1); + __pyx_t_10 = 0; + (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + 1); } - /* "numpy.pxd":818 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":818 * offset[0] += 1 * * offset[0] += child.itemsize # <<<<<<<<<<<<<< * * if not PyDataType_HASFIELDS(child): */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + __pyx_v_child->elsize); + __pyx_t_10 = 0; + (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + __pyx_v_child->elsize); - /* "numpy.pxd":820 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":820 * offset[0] += child.itemsize * * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< * t = child.type_num * if end - f < 5: */ - __pyx_t_7 = (!PyDataType_HASFIELDS(__pyx_v_child)); - if (__pyx_t_7) { + __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":821 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":821 * * if not PyDataType_HASFIELDS(child): * t = child.type_num # <<<<<<<<<<<<<< * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_t); - __pyx_v_t = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4); + __pyx_t_4 = 0; - /* "numpy.pxd":822 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":822 * if not PyDataType_HASFIELDS(child): * t = child.type_num * if end - f < 5: # <<<<<<<<<<<<<< * raise RuntimeError(u"Format string allocated too short.") * */ - __pyx_t_7 = ((__pyx_v_end - __pyx_v_f) < 5); - if (__pyx_t_7) { + __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0); + if (__pyx_t_6) { - /* "numpy.pxd":823 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":823 * t = child.type_num * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< * * # Until ticket #99 is fixed, use integers to avoid warnings */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; } - __pyx_L12:; - /* "numpy.pxd":826 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":826 * * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" */ - __pyx_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 98; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":827 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":827 * # Until ticket #99 is fixed, use integers to avoid warnings * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" */ - __pyx_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 66; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":828 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":828 * if t == NPY_BYTE: f[0] = 98 #"b" * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" */ - __pyx_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 104; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":829 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":829 * elif t == NPY_UBYTE: f[0] = 66 #"B" * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" */ - __pyx_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 72; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":830 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":830 * elif t == NPY_SHORT: f[0] = 104 #"h" * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" */ - __pyx_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 105; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":831 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":831 * elif t == NPY_USHORT: f[0] = 72 #"H" * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" */ - __pyx_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 73; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":832 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":832 * elif t == NPY_INT: f[0] = 105 #"i" * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" */ - __pyx_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 108; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":833 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":833 * elif t == NPY_UINT: f[0] = 73 #"I" * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 76; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":834 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":834 * elif t == NPY_LONG: f[0] = 108 #"l" * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 113; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":835 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":835 * elif t == NPY_ULONG: f[0] = 76 #"L" * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 81; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":836 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":836 * elif t == NPY_LONGLONG: f[0] = 113 #"q" * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" */ - __pyx_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 102; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":837 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":837 * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf */ - __pyx_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 100; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":838 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":838 * elif t == NPY_FLOAT: f[0] = 102 #"f" * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 103; - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":839 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":839 * elif t == NPY_DOUBLE: f[0] = 100 #"d" * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg */ - __pyx_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 102; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":840 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":840 * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" */ - __pyx_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 100; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":841 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":841 * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: */ - __pyx_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_6) { (__pyx_v_f[0]) = 90; (__pyx_v_f[1]) = 103; __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; + goto __pyx_L11; } - /* "numpy.pxd":842 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":842 * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) */ - __pyx_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { + if (__pyx_t_6) { (__pyx_v_f[0]) = 79; - goto __pyx_L13; + goto __pyx_L11; } /*else*/ { - /* "numpy.pxd":844 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":844 * elif t == NPY_OBJECT: f[0] = 79 #"O" * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< * f += 1 * else: */ - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_7), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L13:; + __pyx_L11:; - /* "numpy.pxd":845 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":845 * else: * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) * f += 1 # <<<<<<<<<<<<<< @@ -3822,25 +4031,25 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx * # Cython ignores struct boundary information ("T{...}"), */ __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L11; + goto __pyx_L9; } /*else*/ { - /* "numpy.pxd":849 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":849 * # Cython ignores struct boundary information ("T{...}"), * # so don't output it * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< * return f * */ - __pyx_t_12 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_12; + __pyx_t_11 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_11; } - __pyx_L11:; + __pyx_L9:; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "numpy.pxd":850 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":850 * # so don't output it * f = _util_dtypestring(child, f, end, offset) * return f # <<<<<<<<<<<<<< @@ -3850,13 +4059,19 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx __pyx_r = __pyx_v_f; goto __pyx_L0; - __pyx_r = 0; - goto __pyx_L0; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":783 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< + * # Recursive utility function used in __getbuffer__ to get format + * # string. The new location in the format string is returned. + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -3869,7 +4084,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx return __pyx_r; } -/* "numpy.pxd":965 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":966 * * * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< @@ -3881,9 +4096,10 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a PyObject *__pyx_v_baseptr; __Pyx_RefNannyDeclarations int __pyx_t_1; + int __pyx_t_2; __Pyx_RefNannySetupContext("set_array_base", 0); - /* "numpy.pxd":967 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":968 * cdef inline void set_array_base(ndarray arr, object base): * cdef PyObject* baseptr * if base is None: # <<<<<<<<<<<<<< @@ -3891,9 +4107,10 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a * else: */ __pyx_t_1 = (__pyx_v_base == Py_None); - if (__pyx_t_1) { + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "numpy.pxd":968 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":969 * cdef PyObject* baseptr * if base is None: * baseptr = NULL # <<<<<<<<<<<<<< @@ -3905,7 +4122,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a } /*else*/ { - /* "numpy.pxd":970 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":971 * baseptr = NULL * else: * Py_INCREF(base) # important to do this before decref below! # <<<<<<<<<<<<<< @@ -3914,7 +4131,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_INCREF(__pyx_v_base); - /* "numpy.pxd":971 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":972 * else: * Py_INCREF(base) # important to do this before decref below! * baseptr = base # <<<<<<<<<<<<<< @@ -3925,7 +4142,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a } __pyx_L3:; - /* "numpy.pxd":972 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":973 * Py_INCREF(base) # important to do this before decref below! * baseptr = base * Py_XDECREF(arr.base) # <<<<<<<<<<<<<< @@ -3934,7 +4151,7 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ Py_XDECREF(__pyx_v_arr->base); - /* "numpy.pxd":973 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":974 * baseptr = base * Py_XDECREF(arr.base) * arr.base = baseptr # <<<<<<<<<<<<<< @@ -3943,10 +4160,19 @@ static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_a */ __pyx_v_arr->base = __pyx_v_baseptr; + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":966 + * + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * cdef PyObject* baseptr + * if base is None: + */ + + /* function exit code */ __Pyx_RefNannyFinishContext(); } -/* "numpy.pxd":975 +/* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976 * arr.base = baseptr * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -3960,17 +4186,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py int __pyx_t_1; __Pyx_RefNannySetupContext("get_array_base", 0); - /* "numpy.pxd":976 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":977 * * cdef inline object get_array_base(ndarray arr): * if arr.base is NULL: # <<<<<<<<<<<<<< * return None * else: */ - __pyx_t_1 = (__pyx_v_arr->base == NULL); + __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0); if (__pyx_t_1) { - /* "numpy.pxd":977 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":978 * cdef inline object get_array_base(ndarray arr): * if arr.base is NULL: * return None # <<<<<<<<<<<<<< @@ -3981,11 +4207,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __Pyx_INCREF(Py_None); __pyx_r = Py_None; goto __pyx_L0; - goto __pyx_L3; } /*else*/ { - /* "numpy.pxd":979 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":980 * return None * else: * return arr.base # <<<<<<<<<<<<<< @@ -3995,9 +4220,16 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py __pyx_r = ((PyObject *)__pyx_v_arr->base); goto __pyx_L0; } - __pyx_L3:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976 + * arr.base = baseptr + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * if arr.base is NULL: + * return None + */ + + /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -4016,7 +4248,7 @@ static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, #endif __Pyx_NAMESTR("liblinear"), - __Pyx_DOCSTR(__pyx_k_13), /* m_doc */ + __Pyx_DOCSTR(__pyx_k_Wrapper_for_liblinear_Author_fa), /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ @@ -4027,61 +4259,65 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0}, - {&__pyx_kp_u_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 1, 0, 0}, - {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0}, - {&__pyx_n_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 1}, - {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0}, - {&__pyx_kp_u_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 1, 0, 0}, - {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0}, - {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0}, - {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1}, - {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1}, - {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s__X, __pyx_k__X, sizeof(__pyx_k__X), 0, 0, 1, 1}, - {&__pyx_n_s__Y, __pyx_k__Y, sizeof(__pyx_k__Y), 0, 0, 1, 1}, - {&__pyx_n_s____import__, __pyx_k____import__, sizeof(__pyx_k____import__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____pyx_getbuffer, __pyx_k____pyx_getbuffer, sizeof(__pyx_k____pyx_getbuffer), 0, 0, 1, 1}, - {&__pyx_n_s____pyx_releasebuffer, __pyx_k____pyx_releasebuffer, sizeof(__pyx_k____pyx_releasebuffer), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__arange, __pyx_k__arange, sizeof(__pyx_k__arange), 0, 0, 1, 1}, - {&__pyx_n_s__bias, __pyx_k__bias, sizeof(__pyx_k__bias), 0, 0, 1, 1}, - {&__pyx_n_s__class_weight, __pyx_k__class_weight, sizeof(__pyx_k__class_weight), 0, 0, 1, 1}, - {&__pyx_n_s__class_weight_label, __pyx_k__class_weight_label, sizeof(__pyx_k__class_weight_label), 0, 0, 1, 1}, - {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1}, - {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, - {&__pyx_n_s__empty, __pyx_k__empty, sizeof(__pyx_k__empty), 0, 0, 1, 1}, - {&__pyx_n_s__eps, __pyx_k__eps, sizeof(__pyx_k__eps), 0, 0, 1, 1}, - {&__pyx_n_s__error_msg, __pyx_k__error_msg, sizeof(__pyx_k__error_msg), 0, 0, 1, 1}, - {&__pyx_n_s__indices, __pyx_k__indices, sizeof(__pyx_k__indices), 0, 0, 1, 1}, - {&__pyx_n_s__indptr, __pyx_k__indptr, sizeof(__pyx_k__indptr), 0, 0, 1, 1}, - {&__pyx_n_s__int32, __pyx_k__int32, sizeof(__pyx_k__int32), 0, 0, 1, 1}, - {&__pyx_n_s__is_sparse, __pyx_k__is_sparse, sizeof(__pyx_k__is_sparse), 0, 0, 1, 1}, - {&__pyx_n_s__len_w, __pyx_k__len_w, sizeof(__pyx_k__len_w), 0, 0, 1, 1}, - {&__pyx_n_s__model, __pyx_k__model, sizeof(__pyx_k__model), 0, 0, 1, 1}, - {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, - {&__pyx_n_s__nr_class, __pyx_k__nr_class, sizeof(__pyx_k__nr_class), 0, 0, 1, 1}, - {&__pyx_n_s__nr_feature, __pyx_k__nr_feature, sizeof(__pyx_k__nr_feature), 0, 0, 1, 1}, - {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, - {&__pyx_n_s__order, __pyx_k__order, sizeof(__pyx_k__order), 0, 0, 1, 1}, - {&__pyx_n_s__param, __pyx_k__param, sizeof(__pyx_k__param), 0, 0, 1, 1}, - {&__pyx_n_s__problem, __pyx_k__problem, sizeof(__pyx_k__problem), 0, 0, 1, 1}, - {&__pyx_n_s__random_seed, __pyx_k__random_seed, sizeof(__pyx_k__random_seed), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__set_verbosity_wrap, __pyx_k__set_verbosity_wrap, sizeof(__pyx_k__set_verbosity_wrap), 0, 0, 1, 1}, - {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, - {&__pyx_n_s__solver_type, __pyx_k__solver_type, sizeof(__pyx_k__solver_type), 0, 0, 1, 1}, - {&__pyx_n_s__train_wrap, __pyx_k__train_wrap, sizeof(__pyx_k__train_wrap), 0, 0, 1, 1}, - {&__pyx_n_s__verbosity, __pyx_k__verbosity, sizeof(__pyx_k__verbosity), 0, 0, 1, 1}, - {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1}, + {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1}, + {&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1}, + {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0}, + {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0}, + {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, + {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1}, + {&__pyx_n_s_Y, __pyx_k_Y, sizeof(__pyx_k_Y), 0, 0, 1, 1}, + {&__pyx_n_s_arange, __pyx_k_arange, sizeof(__pyx_k_arange), 0, 0, 1, 1}, + {&__pyx_n_s_bias, __pyx_k_bias, sizeof(__pyx_k_bias), 0, 0, 1, 1}, + {&__pyx_n_s_class_weight, __pyx_k_class_weight, sizeof(__pyx_k_class_weight), 0, 0, 1, 1}, + {&__pyx_n_s_class_weight_label, __pyx_k_class_weight_label, sizeof(__pyx_k_class_weight_label), 0, 0, 1, 1}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, + {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1}, + {&__pyx_n_s_eps, __pyx_k_eps, sizeof(__pyx_k_eps), 0, 0, 1, 1}, + {&__pyx_n_s_error_msg, __pyx_k_error_msg, sizeof(__pyx_k_error_msg), 0, 0, 1, 1}, + {&__pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_k_home_manoj_scikit_learn_sklearn, sizeof(__pyx_k_home_manoj_scikit_learn_sklearn), 0, 0, 1, 0}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1}, + {&__pyx_n_s_indptr, __pyx_k_indptr, sizeof(__pyx_k_indptr), 0, 0, 1, 1}, + {&__pyx_n_s_intc, __pyx_k_intc, sizeof(__pyx_k_intc), 0, 0, 1, 1}, + {&__pyx_n_s_is_sparse, __pyx_k_is_sparse, sizeof(__pyx_k_is_sparse), 0, 0, 1, 1}, + {&__pyx_n_s_labels, __pyx_k_labels, sizeof(__pyx_k_labels), 0, 0, 1, 1}, + {&__pyx_n_s_len_w, __pyx_k_len_w, sizeof(__pyx_k_len_w), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_max_iter, __pyx_k_max_iter, sizeof(__pyx_k_max_iter), 0, 0, 1, 1}, + {&__pyx_n_s_model, __pyx_k_model, sizeof(__pyx_k_model), 0, 0, 1, 1}, + {&__pyx_n_s_n_iter, __pyx_k_n_iter, sizeof(__pyx_k_n_iter), 0, 0, 1, 1}, + {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0}, + {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0}, + {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, + {&__pyx_n_s_nr_class, __pyx_k_nr_class, sizeof(__pyx_k_nr_class), 0, 0, 1, 1}, + {&__pyx_n_s_nr_feature, __pyx_k_nr_feature, sizeof(__pyx_k_nr_feature), 0, 0, 1, 1}, + {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_n_s_order, __pyx_k_order, sizeof(__pyx_k_order), 0, 0, 1, 1}, + {&__pyx_n_s_param, __pyx_k_param, sizeof(__pyx_k_param), 0, 0, 1, 1}, + {&__pyx_n_s_problem, __pyx_k_problem, sizeof(__pyx_k_problem), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_releasebuffer, __pyx_k_pyx_releasebuffer, sizeof(__pyx_k_pyx_releasebuffer), 0, 0, 1, 1}, + {&__pyx_n_s_random_seed, __pyx_k_random_seed, sizeof(__pyx_k_random_seed), 0, 0, 1, 1}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_set_verbosity_wrap, __pyx_k_set_verbosity_wrap, sizeof(__pyx_k_set_verbosity_wrap), 0, 0, 1, 1}, + {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, + {&__pyx_n_s_sklearn_svm_liblinear, __pyx_k_sklearn_svm_liblinear, sizeof(__pyx_k_sklearn_svm_liblinear), 0, 0, 1, 1}, + {&__pyx_n_s_solver_type, __pyx_k_solver_type, sizeof(__pyx_k_solver_type), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_train_wrap, __pyx_k_train_wrap, sizeof(__pyx_k_train_wrap), 0, 0, 1, 1}, + {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0}, + {&__pyx_n_s_verbosity, __pyx_k_verbosity, sizeof(__pyx_k_verbosity), 0, 0, 1, 1}, + {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, + {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -4091,71 +4327,71 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "numpy.pxd":215 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":215 * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< * * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) */ - __pyx_k_tuple_2 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_1)); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); - /* "numpy.pxd":219 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":219 * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< * * info.buf = PyArray_DATA(self) */ - __pyx_k_tuple_4 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_3)); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); - /* "numpy.pxd":257 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":257 * if ((descr.byteorder == c'>' and little_endian) or * (descr.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * if t == NPY_BYTE: f = "b" * elif t == NPY_UBYTE: f = "B" */ - __pyx_k_tuple_6 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_5)); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_6); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); - /* "numpy.pxd":799 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":799 * - * if (end - f) - (new_offset - offset[0]) < 15: + * if (end - f) - (new_offset - offset[0]) < 15: * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< * * if ((child.byteorder == c'>' and little_endian) or */ - __pyx_k_tuple_9 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_8)); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_9); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); - /* "numpy.pxd":803 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":803 * if ((child.byteorder == c'>' and little_endian) or * (child.byteorder == c'<' and not little_endian)): * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< * # One could encode it in the format string and have Cython * # complain instead, BUT: < and > in format strings also imply */ - __pyx_k_tuple_10 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_5)); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_10); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); - /* "numpy.pxd":823 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":823 * t = child.type_num * if end - f < 5: * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< * * # Until ticket #99 is fixed, use integers to avoid warnings */ - __pyx_k_tuple_12 = PyTuple_Pack(1, ((PyObject *)__pyx_kp_u_11)); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_12); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); /* "sklearn/svm/liblinear.pyx":14 * @@ -4164,22 +4400,22 @@ static int __Pyx_InitCachedConstants(void) { * bint is_sparse, int solver_type, double eps, double bias, * double C, np.ndarray[np.float64_t, ndim=1] class_weight, */ - __pyx_k_tuple_14 = PyTuple_Pack(18, ((PyObject *)__pyx_n_s__X), ((PyObject *)__pyx_n_s__Y), ((PyObject *)__pyx_n_s__is_sparse), ((PyObject *)__pyx_n_s__solver_type), ((PyObject *)__pyx_n_s__eps), ((PyObject *)__pyx_n_s__bias), ((PyObject *)__pyx_n_s__C), ((PyObject *)__pyx_n_s__class_weight), ((PyObject *)__pyx_n_s__random_seed), ((PyObject *)__pyx_n_s__param), ((PyObject *)__pyx_n_s__problem), ((PyObject *)__pyx_n_s__model), ((PyObject *)__pyx_n_s__error_msg), ((PyObject *)__pyx_n_s__len_w), ((PyObject *)__pyx_n_s__class_weight_label), ((PyObject *)__pyx_n_s__w), ((PyObject *)__pyx_n_s__nr_class), ((PyObject *)__pyx_n_s__nr_feature)); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_14); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14)); - __pyx_k_codeobj_15 = (PyObject*)__Pyx_PyCode_New(9, 0, 18, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_16, __pyx_n_s__train_wrap, 14, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__7 = PyTuple_Pack(21, __pyx_n_s_X, __pyx_n_s_Y, __pyx_n_s_is_sparse, __pyx_n_s_solver_type, __pyx_n_s_eps, __pyx_n_s_bias, __pyx_n_s_C, __pyx_n_s_class_weight, __pyx_n_s_max_iter, __pyx_n_s_random_seed, __pyx_n_s_param, __pyx_n_s_problem, __pyx_n_s_model, __pyx_n_s_error_msg, __pyx_n_s_len_w, __pyx_n_s_class_weight_label, __pyx_n_s_w, __pyx_n_s_nr_class, __pyx_n_s_labels, __pyx_n_s_n_iter, __pyx_n_s_nr_feature); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(10, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_train_wrap, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "sklearn/svm/liblinear.pyx":77 + /* "sklearn/svm/liblinear.pyx":84 * * * def set_verbosity_wrap(int verbosity): # <<<<<<<<<<<<<< * """ * Control verbosity of libsvm library */ - __pyx_k_tuple_18 = PyTuple_Pack(2, ((PyObject *)__pyx_n_s__verbosity), ((PyObject *)__pyx_n_s__verbosity)); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_18); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); - __pyx_k_codeobj_19 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_16, __pyx_n_s__set_verbosity_wrap, 77, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_verbosity, __pyx_n_s_verbosity); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_manoj_scikit_learn_sklearn, __pyx_n_s_set_verbosity_wrap, 84, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -4189,8 +4425,7 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -4240,21 +4475,13 @@ PyMODINIT_FUNC PyInit_liblinear(void) #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("liblinear"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_13), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("liblinear"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_Wrapper_for_liblinear_Author_fa), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_INCREF(__pyx_d); - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "sklearn.svm.liblinear")) { - if (unlikely(PyDict_SetItemString(modules, "sklearn.svm.liblinear", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); @@ -4266,8 +4493,16 @@ PyMODINIT_FUNC PyInit_liblinear(void) if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif if (__pyx_module_is_main_sklearn__svm__liblinear) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!PyDict_GetItemString(modules, "sklearn.svm.liblinear")) { + if (unlikely(PyDict_SetItemString(modules, "sklearn.svm.liblinear", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } } + #endif /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ @@ -4300,9 +4535,9 @@ PyMODINIT_FUNC PyInit_liblinear(void) * cimport numpy as np * cimport liblinear */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "sklearn/svm/liblinear.pyx":11 @@ -4321,21 +4556,21 @@ PyMODINIT_FUNC PyInit_liblinear(void) * bint is_sparse, int solver_type, double eps, double bias, * double C, np.ndarray[np.float64_t, ndim=1] class_weight, */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_3svm_9liblinear_1train_wrap, NULL, __pyx_n_s_17); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_3svm_9liblinear_1train_wrap, NULL, __pyx_n_s_sklearn_svm_liblinear); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__train_wrap, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_train_wrap, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/svm/liblinear.pyx":77 + /* "sklearn/svm/liblinear.pyx":84 * * * def set_verbosity_wrap(int verbosity): # <<<<<<<<<<<<<< * """ * Control verbosity of libsvm library */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_3svm_9liblinear_3set_verbosity_wrap, NULL, __pyx_n_s_17); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_3svm_9liblinear_3set_verbosity_wrap, NULL, __pyx_n_s_sklearn_svm_liblinear); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__set_verbosity_wrap, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_verbosity_wrap, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "sklearn/svm/liblinear.pyx":1 @@ -4344,11 +4579,11 @@ PyMODINIT_FUNC PyInit_liblinear(void) * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_d, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "numpy.pxd":975 + /* "/usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976 * arr.base = baseptr * * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< @@ -4397,7 +4632,7 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else - "name '%s' is not defined", PyString_AS_STRING(name)); + "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; @@ -4423,7 +4658,7 @@ static void __Pyx_RaiseArgtupleInvalid( more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } @@ -4527,12 +4762,12 @@ static int __Pyx_ParseOptionalKeywords( goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); + "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", + "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", @@ -4542,23 +4777,29 @@ static int __Pyx_ParseOptionalKeywords( return -1; } -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, +static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); +} +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { - if (!type) { - PyErr_Format(PyExc_SystemError, "Missing type object"); + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); return 0; } if (none_allowed && obj == Py_None) return 1; else if (exact) { - if (Py_TYPE(obj) == type) return 1; + if (likely(Py_TYPE(obj) == type)) return 1; + #if PY_MAJOR_VERSION == 2 + else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif } else { - if (PyObject_TypeCheck(obj, type)) return 1; + if (likely(PyObject_TypeCheck(obj, type))) return 1; } - PyErr_Format(PyExc_TypeError, - "Argument '%s' has incorrect type (expected %s, got %s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); + __Pyx_RaiseArgumentTypeInvalid(name, obj, type); return 0; } @@ -4902,8 +5143,10 @@ __pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) } if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; while (*ts && *ts != ')') { - if (isspace(*ts)) - continue; + switch (*ts) { + case ' ': case '\f': case '\r': case '\n': case '\t': case '\v': continue; + default: break; /* not a 'break' in the loop */ + } number = __Pyx_BufFmt_ExpectNumber(&ts); if (number == -1) return NULL; if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) @@ -4943,10 +5186,10 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha __Pyx_BufFmt_RaiseExpected(ctx); return NULL; } - return ts; + return ts; case ' ': - case 10: - case 13: + case '\r': + case '\n': ++ts; break; case '<': @@ -5022,21 +5265,25 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha if (*ts != 'f' && *ts != 'd' && *ts != 'g') { __Pyx_BufFmt_RaiseUnexpectedChar('Z'); return NULL; - } /* fall through */ + } case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': case 'l': case 'L': case 'q': case 'Q': case 'f': case 'd': case 'g': - case 'O': case 's': case 'p': + case 'O': case 'p': if (ctx->enc_type == *ts && got_Z == ctx->is_complex && ctx->enc_packmode == ctx->new_packmode) { ctx->enc_count += ctx->new_count; - } else { - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_count = ctx->new_count; - ctx->enc_packmode = ctx->new_packmode; - ctx->enc_type = *ts; - ctx->is_complex = got_Z; + ctx->new_count = 1; + got_Z = 0; + ++ts; + break; } + case 's': + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->enc_count = ctx->new_count; + ctx->enc_packmode = ctx->new_packmode; + ctx->enc_type = *ts; + ctx->is_complex = got_Z; ++ts; ctx->new_count = 1; got_Z = 0; @@ -5200,9 +5447,32 @@ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { return result; } +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); +#if PY_VERSION_HEX >= 0x02060000 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; +#endif + result = (*call)(func, arg, kw); +#if PY_VERSION_HEX >= 0x02060000 + Py_LeaveRecursiveCall(); +#endif + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); + PyErr_SetString(PyExc_SystemError, "Missing type object"); return 0; } if (likely(PyObject_TypeCheck(obj, type))) @@ -5329,27 +5599,40 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + if (PyObject_IsSubclass(instance_class, type)) { + type = instance_class; + } else { + instance_class = NULL; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } } } else { PyErr_SetString(PyExc_TypeError, @@ -5396,7 +5679,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject #endif static void __Pyx_RaiseBufferFallbackError(void) { - PyErr_Format(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); } @@ -5407,7 +5690,7 @@ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, - "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack", + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", index, (index == 1) ? "" : "s"); } @@ -5415,73 +5698,28 @@ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); } -static CYTHON_INLINE int __Pyx_IterFinish(void) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - PyObject* exc_type = tstate->curexc_type; - if (unlikely(exc_type)) { - if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { - PyObject *exc_value, *exc_tb; - exc_value = tstate->curexc_value; - exc_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - Py_DECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_tb); - return 0; +#if PY_MAJOR_VERSION < 3 +static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { + #if PY_VERSION_HEX >= 0x02060000 + if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); + #endif + if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags); + #if PY_VERSION_HEX < 0x02060000 + if (obj->ob_type->tp_dict) { + PyObject *getbuffer_cobj = PyObject_GetItem( + obj->ob_type->tp_dict, __pyx_n_s_pyx_getbuffer); + if (getbuffer_cobj) { + getbufferproc func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); + Py_DECREF(getbuffer_cobj); + if (!func) + goto fail; + return func(obj, view, flags); } else { - return -1; - } - } - return 0; -#else - if (unlikely(PyErr_Occurred())) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { PyErr_Clear(); - return 0; - } else { - return -1; } } - return 0; -#endif -} - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } else { - return __Pyx_IterFinish(); - } - return 0; -} - -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - #if PY_VERSION_HEX >= 0x02060000 - if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); #endif - if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags); - #if PY_VERSION_HEX < 0x02060000 - if (obj->ob_type->tp_dict) { - PyObject *getbuffer_cobj = PyObject_GetItem( - obj->ob_type->tp_dict, __pyx_n_s____pyx_getbuffer); - if (getbuffer_cobj) { - getbufferproc func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); - Py_DECREF(getbuffer_cobj); - if (!func) - goto fail; - return func(obj, view, flags); - } else { - PyErr_Clear(); - } - } - #endif - PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); + PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name); #if PY_VERSION_HEX < 0x02060000 fail: #endif @@ -5500,7 +5738,7 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { #if PY_VERSION_HEX < 0x02060000 if (obj->ob_type->tp_dict) { PyObject *releasebuffer_cobj = PyObject_GetItem( - obj->ob_type->tp_dict, __pyx_n_s____pyx_releasebuffer); + obj->ob_type->tp_dict, __pyx_n_s_pyx_releasebuffer); if (releasebuffer_cobj) { releasebufferproc func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); Py_DECREF(releasebuffer_cobj); @@ -5533,7 +5771,7 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { PyObject *list; #if PY_VERSION_HEX < 0x03030000 PyObject *py_import; - py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s____import__); + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif @@ -5607,88 +5845,400 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { return module; } -static CYTHON_INLINE npy_int32 __Pyx_PyInt_from_py_npy_int32(PyObject* x) { - const npy_int32 neg_one = (npy_int32)-1, const_zero = (npy_int32)0; - const int is_unsigned = const_zero < neg_one; - if (sizeof(npy_int32) == sizeof(char)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedChar(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedChar(x); - } else if (sizeof(npy_int32) == sizeof(short)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedShort(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedShort(x); - } else if (sizeof(npy_int32) == sizeof(int)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedInt(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedInt(x); - } else if (sizeof(npy_int32) == sizeof(long)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedLong(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedLong(x); - } else if (sizeof(npy_int32) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedLongLong(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedLongLong(x); - } else { - #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); - #else - npy_int32 val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func) \ + { \ + func_type value = func(x); \ + if (sizeof(target_type) < sizeof(func_type)) { \ + if (unlikely(value != (func_type) (target_type) value)) { \ + func_type zero = 0; \ + PyErr_SetString(PyExc_OverflowError, \ + (is_unsigned && unlikely(value < zero)) ? \ + "can't convert negative value to " #target_type : \ + "value too large to convert to " #target_type); \ + return (target_type) -1; \ + } \ + } \ + return (target_type) value; \ + } + +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; + } + return (int) val; } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; + } + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(int) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(int) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong) + } else if (sizeof(int) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong) + } } - #endif - return (npy_int32)-1; + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; } } -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t val) { - const Py_intptr_t neg_one = (Py_intptr_t)-1, const_zero = (Py_intptr_t)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(Py_intptr_t) == sizeof(char)) || - (sizeof(Py_intptr_t) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(Py_intptr_t) == sizeof(int)) || - (sizeof(Py_intptr_t) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(Py_intptr_t) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { + const unsigned int neg_one = (unsigned int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(unsigned int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; + } + return (unsigned int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(unsigned int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (unsigned int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; + } + if (sizeof(unsigned int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(unsigned int)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(unsigned int) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(unsigned int) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(unsigned int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyLong_AsLong) + } else if (sizeof(unsigned int) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long long, PyLong_AsLongLong) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + unsigned int val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (unsigned int) -1; + } + } else { + unsigned int val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned int) -1; + val = __Pyx_PyInt_As_unsigned_int(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(long) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE npy_int32 __Pyx_PyInt_As_npy_int32(PyObject *x) { + const npy_int32 neg_one = (npy_int32) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(npy_int32) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(npy_int32, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to npy_int32"); + return (npy_int32) -1; + } + return (npy_int32) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(npy_int32)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (npy_int32) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to npy_int32"); + return (npy_int32) -1; + } + if (sizeof(npy_int32) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(npy_int32, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(npy_int32) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(npy_int32, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(npy_int32)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(npy_int32) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(npy_int32) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(npy_int32) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(npy_int32, long, PyLong_AsLong) + } else if (sizeof(npy_int32) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(npy_int32, long long, PyLong_AsLongLong) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + npy_int32 val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (npy_int32) -1; + } + } else { + npy_int32 val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (npy_int32) -1; + val = __Pyx_PyInt_As_npy_int32(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_Py_intptr_t(Py_intptr_t value) { + const Py_intptr_t neg_one = (Py_intptr_t) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(Py_intptr_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(Py_intptr_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(Py_intptr_t) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(Py_intptr_t), little, !is_unsigned); } } +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(int) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + #if CYTHON_CCOMPLEX #ifdef __cplusplus static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { @@ -5929,358 +6479,54 @@ static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t val) { #endif #endif -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif #endif -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned long) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG) } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned long) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned long) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } + "can't convert negative value to long"); + return (long) -1; } -#endif -#endif - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; + return (long) val; } - return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS + #if CYTHON_USE_PYLONG_INTERNALS if (sizeof(digit) <= sizeof(long)) { switch (Py_SIZE(x)) { case 0: return 0; case 1: return (long) ((PyLongObject*)x)->ob_digit[0]; } } -#endif + #endif #endif if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); - return (long)-1; + return (long) -1; + } + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(long) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong) } - return (long)PyLong_AsUnsignedLong(x); } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS + #if CYTHON_USE_PYLONG_INTERNALS if (sizeof(digit) <= sizeof(long)) { switch (Py_SIZE(x)) { case 0: return 0; @@ -6288,198 +6534,46 @@ static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { case -1: return -(long) ((PyLongObject*)x)->ob_digit[0]; } } + #endif #endif -#endif - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong) + } else if (sizeof(long) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong) } -#endif -#endif - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (signed long) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(signed long) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(signed long) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS -#include "longintrepr.h" -#endif -#endif -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } - } -#endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -#if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(signed PY_LONG_LONG)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(signed PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0]; - } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; } #endif -#endif - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); + return (long) -1; } } else { - signed PY_LONG_LONG val; + long val; PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } @@ -6549,7 +6643,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", + "%.200s.%.200s is not a type object", module_name, class_name); goto bad; } @@ -6577,7 +6671,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class } else if ((size_t)basicsize != size) { PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", + "%.200s.%.200s has the wrong size, try recompiling", module_name, class_name); goto bad; } @@ -6781,7 +6875,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { return 0; } -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) { +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, strlen(c_str)); } static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { @@ -6818,7 +6912,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_ if (PyUnicode_READY(o) == -1) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (PyUnicode_IS_ASCII(o)) { - *length = PyUnicode_GET_DATA_SIZE(o); + *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); @@ -6830,10 +6924,18 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_ #endif /* PY_VERSION_HEX < 0x03030000 */ } else #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ +#if !CYTHON_COMPILING_IN_PYPY +#if PY_VERSION_HEX >= 0x02060000 + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif +#endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); - if (r < 0) { + if (unlikely(r < 0)) { return NULL; } else { return result; @@ -6878,7 +6980,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", + "__%.4s__ returned non-%.4s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; @@ -6890,9 +6992,35 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { } return res; } +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) + return PyInt_AS_LONG(b); +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + switch (Py_SIZE(b)) { + case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0]; + case 0: return 0; + case 1: return ((PyLongObject*)b)->ob_digit[0]; + } + #endif + #endif + #if PY_VERSION_HEX < 0x02060000 + return PyInt_AsSsize_t(b); + #else + return PyLong_AsSsize_t(b); + #endif + } + x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); @@ -6911,16 +7039,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); #endif } -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - if ((val != (unsigned PY_LONG_LONG)-1) || !PyErr_Occurred()) - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} #endif /* Py_PYTHON_H */ diff --git a/sklearn/svm/liblinear.pxd b/sklearn/svm/liblinear.pxd index d06e5192b4a17..878323762a1bb 100644 --- a/sklearn/svm/liblinear.pxd +++ b/sklearn/svm/liblinear.pxd @@ -13,12 +13,13 @@ cdef extern from "src/liblinear/linear.h": model *train(problem_const_ptr prob, parameter_const_ptr param) nogil int get_nr_feature (model *model) int get_nr_class (model *model) + void get_n_iter (model *model, int *n_iter) void free_and_destroy_model (model **) void destroy_param (parameter *) cdef extern from "src/liblinear/liblinear_helper.c": void copy_w(void *, model *, int) - parameter *set_parameter(int, double, double, int, char *, char *, int) + parameter *set_parameter(int, double, double, int, char *, char *, int, int) problem *set_problem (char *, char *, np.npy_intp *, double) problem *csr_set_problem (char *values, np.npy_intp *n_indices, char *indices, np.npy_intp *n_indptr, char *indptr, char *Y, diff --git a/sklearn/svm/liblinear.pyx b/sklearn/svm/liblinear.pyx index 379d31886f688..dad92959a987b 100644 --- a/sklearn/svm/liblinear.pyx +++ b/sklearn/svm/liblinear.pyx @@ -14,7 +14,7 @@ np.import_array() def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, bint is_sparse, int solver_type, double eps, double bias, double C, np.ndarray[np.float64_t, ndim=1] class_weight, - unsigned random_seed): + int max_iter, unsigned random_seed): cdef parameter *param cdef problem *problem cdef model *model @@ -37,10 +37,10 @@ def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, bias) cdef np.ndarray[np.int32_t, ndim=1, mode='c'] \ - class_weight_label = np.arange(class_weight.shape[0], dtype=np.int32) + class_weight_label = np.arange(class_weight.shape[0], dtype=np.intc) param = set_parameter(solver_type, eps, C, class_weight.shape[0], class_weight_label.data, class_weight.data, - random_seed) + max_iter, random_seed) error_msg = check_parameter(problem, param) if error_msg: @@ -55,6 +55,13 @@ def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, # coef matrix holder created as fortran since that's what's used in liblinear cdef np.ndarray[np.float64_t, ndim=2, mode='fortran'] w cdef int nr_class = get_nr_class(model) + + cdef int labels_ = nr_class + if nr_class == 2: + labels_ = 1 + cdef np.ndarray[np.int32_t, ndim=1, mode='c'] n_iter = np.zeros(labels_, dtype=np.intc) + get_n_iter(model, n_iter.data) + cdef int nr_feature = get_nr_feature(model) if bias > 0: nr_feature = nr_feature + 1 if nr_class == 2 and solver_type != 4: # solver is not Crammer-Singer @@ -71,7 +78,7 @@ def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y, free_parameter(param) # destroy_param(param) don't call this or it will destroy class_weight_label and class_weight - return w + return w, n_iter def set_verbosity_wrap(int verbosity): diff --git a/sklearn/svm/src/liblinear/liblinear_helper.c b/sklearn/svm/src/liblinear/liblinear_helper.c index c04aa0faaedb1..96d1e8ca301d0 100644 --- a/sklearn/svm/src/liblinear/liblinear_helper.c +++ b/sklearn/svm/src/liblinear/liblinear_helper.c @@ -181,7 +181,7 @@ struct problem * csr_set_problem (char *values, npy_intp *n_indices, /* Create a paramater struct with and return it */ struct parameter *set_parameter(int solver_type, double eps, double C, npy_intp nr_weight, char *weight_label, - char *weight, unsigned seed) + char *weight, int max_iter, unsigned seed) { struct parameter *param = malloc(sizeof(struct parameter)); if (param == NULL) @@ -195,6 +195,7 @@ struct parameter *set_parameter(int solver_type, double eps, double C, param->nr_weight = (int) nr_weight; param->weight_label = (int *) weight_label; param->weight = (double *) weight; + param->max_iter = max_iter; return param; } diff --git a/sklearn/svm/src/liblinear/linear.cpp b/sklearn/svm/src/liblinear/linear.cpp index 9e396632ece6b..13d540ab25f83 100644 --- a/sklearn/svm/src/liblinear/linear.cpp +++ b/sklearn/svm/src/liblinear/linear.cpp @@ -9,6 +9,15 @@ See issue 546: https://github.com/scikit-learn/scikit-learn/pull/546 - Also changed roles for pairwise class weights, Andreas Mueller See issue 1491: https://github.com/scikit-learn/scikit-learn/pull/1491 + + Modified 2014: + + - Remove the hard-coded value of max_iter (1000), that allows max_iter + to be passed as a parameter from the classes LogisticRegression and + LinearSVC, Manoj Kumar + - Added function get_n_iter that exposes the number of iterations. + See issue 3499: https://github.com/scikit-learn/scikit-learn/issues/3499 + See pull 3501: https://github.com/scikit-learn/scikit-learn/pull/3501 */ @@ -472,7 +481,7 @@ class Solver_MCSVM_CS public: Solver_MCSVM_CS(const problem *prob, int nr_class, double *C, double eps=0.1, int max_iter=100000); ~Solver_MCSVM_CS(); - void Solve(double *w); + int Solve(double *w); private: void solve_sub_problem(double A_i, int yi, double C_yi, int active_i, double *alpha_new); bool be_shrunk(int i, int m, int yi, double alpha_i, double minG); @@ -547,7 +556,7 @@ bool Solver_MCSVM_CS::be_shrunk(int i, int m, int yi, double alpha_i, double min return false; } -void Solver_MCSVM_CS::Solve(double *w) +int Solver_MCSVM_CS::Solve(double *w) { int i, m, s; int iter = 0; @@ -757,6 +766,7 @@ void Solver_MCSVM_CS::Solve(double *w) delete [] alpha_index; delete [] y_index; delete [] active_size_i; + return iter; } // A coordinate descent algorithm for @@ -789,16 +799,15 @@ void Solver_MCSVM_CS::Solve(double *w) #define GETI(i) (y[i]+1) // To support weights for instances, use GETI(i) (i) -static void solve_l2r_l1l2_svc( +static int solve_l2r_l1l2_svc( const problem *prob, double *w, double eps, - double Cp, double Cn, int solver_type) + double Cp, double Cn, int solver_type, int max_iter) { int l = prob->l; int w_size = prob->n; int i, s, iter = 0; double C, d, G; double *QD = new double[l]; - int max_iter = 1000; int *index = new int[l]; double *alpha = new double[l]; schar *y = new schar[l]; @@ -976,6 +985,7 @@ static void solve_l2r_l1l2_svc( delete [] alpha; delete [] y; delete [] index; + return iter; } @@ -1007,9 +1017,9 @@ static void solve_l2r_l1l2_svc( #define GETI(i) (0) // To support weights for instances, use GETI(i) (i) -static void solve_l2r_l1l2_svr( +static int solve_l2r_l1l2_svr( const problem *prob, double *w, const parameter *param, - int solver_type) + int solver_type, int max_iter) { int l = prob->l; double C = param->C; @@ -1017,7 +1027,6 @@ static void solve_l2r_l1l2_svr( int w_size = prob->n; double eps = param->eps; int i, s, iter = 0; - int max_iter = 1000; int active_size = l; int *index = new int[l]; @@ -1209,6 +1218,7 @@ static void solve_l2r_l1l2_svr( delete [] beta; delete [] QD; delete [] index; + return iter; } @@ -1234,13 +1244,13 @@ static void solve_l2r_l1l2_svr( #define GETI(i) (y[i]+1) // To support weights for instances, use GETI(i) (i) -void solve_l2r_lr_dual(const problem *prob, double *w, double eps, double Cp, double Cn) +int solve_l2r_lr_dual(const problem *prob, double *w, double eps, double Cp, double Cn, + int max_iter) { int l = prob->l; int w_size = prob->n; int i, s, iter = 0; double *xTx = new double[l]; - int max_iter = 1000; int *index = new int[l]; double *alpha = new double[2*l]; // store alpha and C - alpha schar *y = new schar[l]; @@ -1389,6 +1399,7 @@ void solve_l2r_lr_dual(const problem *prob, double *w, double eps, double Cp, do delete [] alpha; delete [] y; delete [] index; + return iter; } // A coordinate descent algorithm for @@ -1408,14 +1419,13 @@ void solve_l2r_lr_dual(const problem *prob, double *w, double eps, double Cp, do #define GETI(i) (y[i]+1) // To support weights for instances, use GETI(i) (i) -static void solve_l1r_l2_svc( +static int solve_l1r_l2_svc( problem *prob_col, double *w, double eps, - double Cp, double Cn) + double Cp, double Cn, int max_iter) { int l = prob_col->l; int w_size = prob_col->n; int j, s, iter = 0; - int max_iter = 1000; int active_size = w_size; int max_num_linesearch = 20; @@ -1676,6 +1686,7 @@ static void solve_l1r_l2_svc( delete [] y; delete [] b; delete [] xj_sq; + return iter; } // A coordinate descent algorithm for @@ -1695,14 +1706,13 @@ static void solve_l1r_l2_svc( #define GETI(i) (y[i]+1) // To support weights for instances, use GETI(i) (i) -static void solve_l1r_lr( +static int solve_l1r_lr( const problem *prob_col, double *w, double eps, - double Cp, double Cn) + double Cp, double Cn, int max_newton_iter) { int l = prob_col->l; int w_size = prob_col->n; int j, s, newton_iter=0, iter=0; - int max_newton_iter = 100; int max_iter = 1000; int max_num_linesearch = 20; int active_size; @@ -2057,6 +2067,7 @@ static void solve_l1r_lr( delete [] exp_wTx_new; delete [] tau; delete [] D; + return newton_iter; } // transpose matrix X from row format to column format @@ -2207,11 +2218,13 @@ static void group_classes(const problem *prob, int *nr_class_ret, int **label_re free(data_label); } -static void train_one(const problem *prob, const parameter *param, double *w, double Cp, double Cn) +static int train_one(const problem *prob, const parameter *param, double *w, double Cp, double Cn) { double eps=param->eps; + int max_iter=param->max_iter; int pos = 0; int neg = 0; + int n_iter; for(int i=0;il;i++) if(prob->y[i] > 0) pos++; @@ -2233,9 +2246,9 @@ static void train_one(const problem *prob, const parameter *param, double *w, do C[i] = Cn; } fun_obj=new l2r_lr_fun(prob, C); - TRON tron_obj(fun_obj, primal_solver_tol); + TRON tron_obj(fun_obj, primal_solver_tol, max_iter); tron_obj.set_print_string(liblinear_print_string); - tron_obj.tron(w); + n_iter=tron_obj.tron(w); delete fun_obj; delete [] C; break; @@ -2251,25 +2264,25 @@ static void train_one(const problem *prob, const parameter *param, double *w, do C[i] = Cn; } fun_obj=new l2r_l2_svc_fun(prob, C); - TRON tron_obj(fun_obj, primal_solver_tol); + TRON tron_obj(fun_obj, primal_solver_tol, max_iter); tron_obj.set_print_string(liblinear_print_string); - tron_obj.tron(w); + n_iter=tron_obj.tron(w); delete fun_obj; delete [] C; break; } case L2R_L2LOSS_SVC_DUAL: - solve_l2r_l1l2_svc(prob, w, eps, Cp, Cn, L2R_L2LOSS_SVC_DUAL); + n_iter=solve_l2r_l1l2_svc(prob, w, eps, Cp, Cn, L2R_L2LOSS_SVC_DUAL, max_iter); break; case L2R_L1LOSS_SVC_DUAL: - solve_l2r_l1l2_svc(prob, w, eps, Cp, Cn, L2R_L1LOSS_SVC_DUAL); + n_iter=solve_l2r_l1l2_svc(prob, w, eps, Cp, Cn, L2R_L1LOSS_SVC_DUAL, max_iter); break; case L1R_L2LOSS_SVC: { problem prob_col; feature_node *x_space = NULL; transpose(prob, &x_space ,&prob_col); - solve_l1r_l2_svc(&prob_col, w, primal_solver_tol, Cp, Cn); + n_iter=solve_l1r_l2_svc(&prob_col, w, primal_solver_tol, Cp, Cn, max_iter); delete [] prob_col.y; delete [] prob_col.x; delete [] x_space; @@ -2280,14 +2293,14 @@ static void train_one(const problem *prob, const parameter *param, double *w, do problem prob_col; feature_node *x_space = NULL; transpose(prob, &x_space ,&prob_col); - solve_l1r_lr(&prob_col, w, primal_solver_tol, Cp, Cn); + n_iter=solve_l1r_lr(&prob_col, w, primal_solver_tol, Cp, Cn, max_iter); delete [] prob_col.y; delete [] prob_col.x; delete [] x_space; break; } case L2R_LR_DUAL: - solve_l2r_lr_dual(prob, w, eps, Cp, Cn); + n_iter=solve_l2r_lr_dual(prob, w, eps, Cp, Cn, max_iter); break; case L2R_L2LOSS_SVR: { @@ -2296,24 +2309,25 @@ static void train_one(const problem *prob, const parameter *param, double *w, do C[i] = param->C; fun_obj=new l2r_l2_svr_fun(prob, C, param->p); - TRON tron_obj(fun_obj, param->eps); + TRON tron_obj(fun_obj, param->eps, max_iter); tron_obj.set_print_string(liblinear_print_string); - tron_obj.tron(w); + n_iter=tron_obj.tron(w); delete fun_obj; delete [] C; break; } case L2R_L1LOSS_SVR_DUAL: - solve_l2r_l1l2_svr(prob, w, param, L2R_L1LOSS_SVR_DUAL); + n_iter=solve_l2r_l1l2_svr(prob, w, param, L2R_L1LOSS_SVR_DUAL, max_iter); break; case L2R_L2LOSS_SVR_DUAL: - solve_l2r_l1l2_svr(prob, w, param, L2R_L2LOSS_SVR_DUAL); + n_iter=solve_l2r_l1l2_svr(prob, w, param, L2R_L2LOSS_SVR_DUAL, max_iter); break; default: fprintf(stderr, "ERROR: unknown solver_type\n"); break; } + return n_iter; } // @@ -2325,6 +2339,7 @@ model* train(const problem *prob, const parameter *param) int l = prob->l; int n = prob->n; int w_size = prob->n; + int n_iter; model *model_ = Malloc(model,1); if(prob->bias>=0) @@ -2339,9 +2354,10 @@ model* train(const problem *prob, const parameter *param) param->solver_type == L2R_L2LOSS_SVR_DUAL) { model_->w = Malloc(double, w_size); + model_->n_iter = Malloc(int, 1); model_->nr_class = 2; model_->label = NULL; - train_one(prob, param, &model_->w[0], 0, 0); + model_->n_iter[0] =train_one(prob, param, &model_->w[0], 0, 0); } else { @@ -2393,18 +2409,19 @@ model* train(const problem *prob, const parameter *param) if(param->solver_type == MCSVM_CS) { model_->w=Malloc(double, n*nr_class); + model_->n_iter=Malloc(int, 1); for(i=0;ieps); - Solver.Solve(model_->w); + model_->n_iter[0]=Solver.Solve(model_->w); } else { if(nr_class == 2) { model_->w=Malloc(double, w_size); - + model_->n_iter=Malloc(int, 1); int e0 = start[0]+count[0]; k=0; for(; kw[0], weighted_C[1], weighted_C[0]); + model_->n_iter[0]=train_one(&sub_prob, param, &model_->w[0], weighted_C[1], weighted_C[0]); } else { model_->w=Malloc(double, w_size*nr_class); double *w=Malloc(double, w_size); + model_->n_iter=Malloc(int, nr_class); for(i=0;iC); + model_->n_iter[i]=train_one(&sub_prob, param, w, weighted_C[i], param->C); for(int j=0;jw[j*nr_class+i] = w[j]; @@ -2790,6 +2808,18 @@ void get_labels(const model *model_, int* label) label[i] = model_->label[i]; } +void get_n_iter(const model *model_, int* n_iter) +{ + int labels; + labels = model_->nr_class; + if (labels == 2) + labels = 1; + + if (model_->n_iter != NULL) + for(int i=0;in_iter[i]; +} + void free_model_content(struct model *model_ptr) { if(model_ptr->w != NULL) diff --git a/sklearn/svm/src/liblinear/linear.h b/sklearn/svm/src/liblinear/linear.h index 22a356743a790..489cce25ce822 100644 --- a/sklearn/svm/src/liblinear/linear.h +++ b/sklearn/svm/src/liblinear/linear.h @@ -31,6 +31,7 @@ struct parameter int nr_weight; int *weight_label; double* weight; + int max_iter; double p; }; @@ -42,6 +43,7 @@ struct model double *w; int *label; /* label of each class */ double bias; + int *n_iter; /* no. of iterations of each class */ }; struct model* train(const struct problem *prob, const struct parameter *param); @@ -57,6 +59,7 @@ struct model *load_model(const char *model_file_name); int get_nr_feature(const struct model *model_); int get_nr_class(const struct model *model_); void get_labels(const struct model *model_, int* label); +void get_n_iter(const struct model *model_, int* n_iter); void free_model_content(struct model *model_ptr); void free_and_destroy_model(struct model **model_ptr_ptr); diff --git a/sklearn/svm/src/liblinear/tron.cpp b/sklearn/svm/src/liblinear/tron.cpp index a35c1023d7bc8..38dd921bc8e38 100644 --- a/sklearn/svm/src/liblinear/tron.cpp +++ b/sklearn/svm/src/liblinear/tron.cpp @@ -44,7 +44,7 @@ TRON::~TRON() { } -void TRON::tron(double *w) +int TRON::tron(double *w) { // Parameters for updating the iterates. double eta0 = 1e-4, eta1 = 0.25, eta2 = 0.75; @@ -146,6 +146,7 @@ void TRON::tron(double *w) delete[] r; delete[] w_new; delete[] s; + return --iter; } int TRON::trcg(double delta, double *g, double *s, double *r) diff --git a/sklearn/svm/src/liblinear/tron.h b/sklearn/svm/src/liblinear/tron.h index 3045c2e83a133..3349b83f6418a 100644 --- a/sklearn/svm/src/liblinear/tron.h +++ b/sklearn/svm/src/liblinear/tron.h @@ -18,7 +18,7 @@ class TRON TRON(const function *fun_obj, double eps = 0.1, int max_iter = 1000); ~TRON(); - void tron(double *w); + int tron(double *w); void set_print_string(void (*i_print) (const char *buf)); private: diff --git a/sklearn/svm/tests/test_svm.py b/sklearn/svm/tests/test_svm.py index e6a06024d8b65..a65b8967dbbc7 100644 --- a/sklearn/svm/tests/test_svm.py +++ b/sklearn/svm/tests/test_svm.py @@ -16,7 +16,7 @@ from sklearn.utils import check_random_state from sklearn.utils import ConvergenceWarning from sklearn.utils.testing import assert_greater, assert_in, assert_less -from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import assert_raises_regexp, assert_warns # toy sample @@ -435,18 +435,16 @@ def test_linearsvc_parameters(): params = [(dual, loss, penalty) for dual in [True, False] for loss in ['l1', 'l2', 'lr'] for penalty in ['l1', 'l2']] + X, y = make_classification(n_samples=5, n_features=5) + for dual, loss, penalty in params: - if loss == 'l1' and penalty == 'l1': - assert_raises(ValueError, svm.LinearSVC, penalty=penalty, - loss=loss, dual=dual) - elif loss == 'l1' and penalty == 'l2' and not dual: - assert_raises(ValueError, svm.LinearSVC, penalty=penalty, - loss=loss, dual=dual) - elif penalty == 'l1' and dual: - assert_raises(ValueError, svm.LinearSVC, penalty=penalty, - loss=loss, dual=dual) + clf = svm.LinearSVC(penalty=penalty, loss=loss, dual=dual) + if (loss == 'l1' and penalty == 'l1') or ( + loss == 'l1' and penalty == 'l2' and not dual) or ( + penalty == 'l1' and dual): + assert_raises(ValueError, clf.fit, X, y) else: - svm.LinearSVC(penalty=penalty, loss=loss, dual=dual) + clf.fit(X, y) def test_linearsvc(): @@ -666,6 +664,18 @@ def test_timeout(): assert_warns(ConvergenceWarning, a.fit, X, Y) +def test_unfitted(): + X = "foo!" # input validation not required when SVM not fitted + + clf = svm.SVC() + assert_raises_regexp(Exception, r".*\bSVC\b.*\bnot\b.*\bfitted\b", + clf.predict, X) + + clf = svm.NuSVR() + assert_raises_regexp(Exception, r".*\bNuSVR\b.*\bnot\b.*\bfitted\b", + clf.predict, X) + + def test_consistent_proba(): a = svm.SVC(probability=True, max_iter=1, random_state=0) proba_1 = a.fit(X, Y).predict_proba(X) @@ -674,6 +684,14 @@ def test_consistent_proba(): assert_array_almost_equal(proba_1, proba_2) +def test_linear_svc_convergence_warnings(): + """Test that warnings are raised if model does not converge""" + + lsvc = svm.LinearSVC(max_iter=2, verbose=1) + assert_warns(ConvergenceWarning, lsvc.fit, X, Y) + assert_equal(lsvc.n_iter_, 2) + + if __name__ == '__main__': import nose nose.runmodule() diff --git a/sklearn/tests/test_common.py b/sklearn/tests/test_common.py index 920aab6bba2be..7244b85778a81 100644 --- a/sklearn/tests/test_common.py +++ b/sklearn/tests/test_common.py @@ -17,7 +17,9 @@ from sklearn.utils.testing import assert_false from sklearn.utils.testing import all_estimators from sklearn.utils.testing import assert_greater +from sklearn.utils.testing import assert_in from sklearn.utils.testing import SkipTest +from sklearn.utils.testing import ignore_warnings import sklearn from sklearn.base import (ClassifierMixin, RegressorMixin, @@ -26,6 +28,7 @@ from sklearn.datasets import make_classification from sklearn.cross_validation import train_test_split +from sklearn.linear_model.base import LinearClassifierMixin from sklearn.utils.estimator_checks import ( check_parameters_default_constructible, check_regressors_classifiers_sparse_data, @@ -44,6 +47,7 @@ check_classifiers_pickle, check_class_weight_classifiers, check_class_weight_auto_classifiers, + check_class_weight_auto_linear_classifier, check_estimators_overwrite_params, check_cluster_overwrite_params, check_sparsify_binary_classifier, @@ -187,7 +191,8 @@ def test_configure(): # Blas/Atlas development headers warnings.simplefilter('ignore', UserWarning) if PY3: - exec(open('setup.py').read(), dict(__name__='__main__')) + with open('setup.py') as f: + exec(f.read(), dict(__name__='__main__')) else: execfile('setup.py', dict(__name__='__main__')) finally: @@ -214,7 +219,7 @@ def test_class_weight_classifiers(): yield check_class_weight_classifiers, name, Classifier -def test_class_weight_auto_classifies(): +def test_class_weight_auto_classifiers(): """Test that class_weight="auto" improves f1-score""" # This test is broken; its success depends on: @@ -251,6 +256,26 @@ def test_class_weight_auto_classifies(): X_train, y_train, X_test, y_test, weights) +def test_class_weight_auto_linear_classifiers(): + classifiers = all_estimators(type_filter='classifier') + + with warnings.catch_warnings(record=True): + linear_classifiers = [ + (name, clazz) + for name, clazz in classifiers + if 'class_weight' in clazz().get_params().keys() + and issubclass(clazz, LinearClassifierMixin)] + + for name, Classifier in linear_classifiers: + if name == "LogisticRegressionCV": + # Contrary to RidgeClassifierCV, LogisticRegressionCV use actual + # CV folds and fit a model for each CV iteration before averaging + # the coef. Therefore it is expected to not behave exactly as the + # other linear model. + continue + yield check_class_weight_auto_linear_classifier, name, Classifier + + def test_estimators_overwrite_params(): # test whether any classifier overwrites his init parameters during fit for est_type in ["classifier", "regressor", "transformer"]: @@ -263,12 +288,14 @@ def test_estimators_overwrite_params(): yield check_estimators_overwrite_params, name, Estimator +@ignore_warnings def test_import_all_consistency(): # Smoke test to check that any name in a __all__ list is actually defined # in the namespace of the module or package. pkgs = pkgutil.walk_packages(path=sklearn.__path__, prefix='sklearn.', onerror=lambda _: None) - for importer, modname, ispkg in pkgs: + submods = [modname for _, modname, _ in pkgs] + for modname in submods + ['sklearn']: if ".tests." in modname: continue package = __import__(modname, fromlist="dummy") @@ -279,6 +306,15 @@ def test_import_all_consistency(): modname, name)) +def test_root_import_all_completeness(): + EXCEPTIONS = ('utils', 'tests', 'base', 'setup') + for _, modname, _ in pkgutil.walk_packages(path=sklearn.__path__, + onerror=lambda _: None): + if '.' in modname or modname.startswith('_') or modname in EXCEPTIONS: + continue + assert_in(modname, sklearn.__all__) + + def test_sparsify_estimators(): #Test if predict with sparsified estimators works. #Tests regression, binary classification, and multi-class classification. @@ -320,12 +356,13 @@ def test_non_transformer_estimators_n_iter(): # libsvm and accessing the iter parameter is non-trivial. if name in (['Ridge', 'SVR', 'NuSVR', 'NuSVC', 'RidgeClassifier', 'SVC', 'RandomizedLasso', - 'LogisticRegressionCV', 'LogisticRegression', - 'LinearSVC']): + 'LogisticRegressionCV']): continue # Tested in test_transformer_n_iter below - elif name in CROSS_DECOMPOSITION: + elif name in CROSS_DECOMPOSITION or ( + name in ['LinearSVC', 'LogisticRegression'] + ): continue else: @@ -342,7 +379,7 @@ def test_transformer_n_iter(): # Dependent on external solvers and hence accessing the iter # param is non-trivial. external_solver = ['Isomap', 'KernelPCA', 'LocallyLinearEmbedding', - 'RandomizedLasso', 'LogisticRegression', - 'LogisticRegressionCV', 'LinearSVC'] + 'RandomizedLasso', 'LogisticRegressionCV'] + if hasattr(estimator, "max_iter") and name not in external_solver: yield check_transformer_n_iter, name, estimator diff --git a/sklearn/tests/test_cross_validation.py b/sklearn/tests/test_cross_validation.py index eba0a93301b63..e3af30a1b2bae 100644 --- a/sklearn/tests/test_cross_validation.py +++ b/sklearn/tests/test_cross_validation.py @@ -16,6 +16,7 @@ from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import assert_warns_message from sklearn.utils.testing import ignore_warnings from sklearn.utils.mocking import CheckingClassifier, MockDataFrame @@ -27,14 +28,16 @@ from sklearn.metrics import accuracy_score from sklearn.metrics import explained_variance_score from sklearn.metrics import make_scorer +from sklearn.metrics import precision_score from sklearn.externals import six from sklearn.externals.six.moves import zip from sklearn.linear_model import Ridge +from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVC -from sklearn.preprocessing import Imputer +from sklearn.preprocessing import Imputer, LabelBinarizer from sklearn.pipeline import Pipeline @@ -117,22 +120,15 @@ def test_kfold_valueerrors(): # Check that a warning is raised if the least populated class has too few # members. - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - y = [3, 3, -1, -1, 2] - cv = cval.StratifiedKFold(y, 3) - # checking there was only one warning. - assert_equal(len(w), 1) - # checking it has the right type - assert_equal(w[0].category, Warning) - # checking it's the right warning. This might be a bad test since it's - # a characteristic of the code and not a behavior - assert_true("The least populated class" in str(w[0])) - - # Check that despite the warning the folds are still computed even - # though all the classes are not necessarily represented at on each - # side of the split at each split - check_cv_coverage(cv, expected_n_iter=3, n_samples=len(y)) + y = [3, 3, -1, -1, 2] + + cv = assert_warns_message(Warning, "The least populated class", + cval.StratifiedKFold, y, 3) + + # Check that despite the warning the folds are still computed even + # though all the classes are not necessarily represented at on each + # side of the split at each split + check_cv_coverage(cv, expected_n_iter=3, n_samples=len(y)) # Error when number of folds is <= 1 assert_raises(ValueError, cval.KFold, 2, 0) @@ -957,3 +953,48 @@ def test_permutation_test_score_allow_nans(): ('classifier', MockClassifier()), ]) cval.permutation_test_score(p, X, y, cv=5) + + +def test_check_cv_return_types(): + X = np.ones((9, 2)) + cv = cval._check_cv(3, X, classifier=False) + assert_true(isinstance(cv, cval.KFold)) + + y_binary = np.array([0, 1, 0, 1, 0, 0, 1, 1, 1]) + cv = cval._check_cv(3, X, y_binary, classifier=True) + assert_true(isinstance(cv, cval.StratifiedKFold)) + + y_multiclass = np.array([0, 1, 0, 1, 2, 1, 2, 0, 2]) + cv = cval._check_cv(3, X, y_multiclass, classifier=True) + assert_true(isinstance(cv, cval.StratifiedKFold)) + + X = np.ones((5, 2)) + y_seq_of_seqs = [[], [1, 2], [3], [0, 1, 3], [2]] + cv = cval._check_cv(3, X, y_seq_of_seqs, classifier=True) + assert_true(isinstance(cv, cval.KFold)) + + y_indicator_matrix = LabelBinarizer().fit_transform(y_seq_of_seqs) + cv = cval._check_cv(3, X, y_indicator_matrix, classifier=True) + assert_true(isinstance(cv, cval.KFold)) + + y_multioutput = np.array([[1, 2], [0, 3], [0, 0], [3, 1], [2, 0]]) + cv = cval._check_cv(3, X, y_multioutput, classifier=True) + assert_true(isinstance(cv, cval.KFold)) + + +def test_cross_val_score_multilabel(): + X = np.array([[-3, 4], [2, 4], [3, 3], [0, 2], [-3, 1], + [-2, 1], [0, 0], [-2, -1], [-1, -2], [1, -2]]) + y = np.array([[1, 1], [0, 1], [0, 1], [0, 1], [1, 1], + [0, 1], [1, 0], [1, 1], [1, 0], [0, 0]]) + clf = KNeighborsClassifier(n_neighbors=1) + scoring_micro = make_scorer(precision_score, average='micro') + scoring_macro = make_scorer(precision_score, average='macro') + scoring_samples = make_scorer(precision_score, average='samples') + score_micro = cval.cross_val_score(clf, X, y, scoring=scoring_micro, cv=5) + score_macro = cval.cross_val_score(clf, X, y, scoring=scoring_macro, cv=5) + score_samples = cval.cross_val_score(clf, X, y, + scoring=scoring_samples, cv=5) + assert_almost_equal(score_micro, [1, 1/2, 3/4, 1/2, 1/3]) + assert_almost_equal(score_macro, [1, 1/2, 3/4, 1/2, 1/4]) + assert_almost_equal(score_samples, [1, 1/2, 3/4, 1/2, 1/4]) diff --git a/sklearn/tests/test_dummy.py b/sklearn/tests/test_dummy.py index c536baf1d1c37..2fe56cb72424c 100644 --- a/sklearn/tests/test_dummy.py +++ b/sklearn/tests/test_dummy.py @@ -1,5 +1,7 @@ +from __future__ import division import warnings import numpy as np +import scipy.sparse as sp from sklearn.base import clone from sklearn.utils.testing import assert_array_equal @@ -7,6 +9,8 @@ from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_raises +from sklearn.utils.testing import assert_true +from sklearn.utils.testing import assert_warns_message from sklearn.dummy import DummyClassifier, DummyRegressor @@ -397,3 +401,90 @@ def test_classification_sample_weight(): clf = DummyClassifier().fit(X, y, sample_weight) assert_array_almost_equal(clf.class_prior_, [0.2 / 1.2, 1. / 1.2]) + + +def test_constant_strategy_sparse_target(): + X = [[0]] * 5 # ignored + y = sp.csc_matrix(np.array([[0, 1], + [4, 0], + [1, 1], + [1, 4], + [1, 1]])) + + n_samples = len(X) + + clf = DummyClassifier(strategy="constant", random_state=0, constant=[1, 0]) + clf.fit(X, y) + y_pred = clf.predict(X) + assert_true(sp.issparse(y_pred)) + assert_array_equal(y_pred.toarray(), np.hstack([np.ones((n_samples, 1)), + np.zeros((n_samples, 1))])) + + +def test_uniform_strategy_sparse_target_warning(): + X = [[0]] * 5 # ignored + y = sp.csc_matrix(np.array([[2, 1], + [2, 2], + [1, 4], + [4, 2], + [1, 1]])) + + clf = DummyClassifier(strategy="uniform", random_state=0) + assert_warns_message(UserWarning, + "the uniform strategy would not save memory", + clf.fit, X, y) + + X = [[0]] * 500 + y_pred = clf.predict(X) + + for k in range(y.shape[1]): + p = np.bincount(y_pred[:, k]) / float(len(X)) + assert_almost_equal(p[1], 1/3, decimal=1) + assert_almost_equal(p[2], 1/3, decimal=1) + assert_almost_equal(p[4], 1/3, decimal=1) + + +def test_stratified_strategy_sparse_target(): + X = [[0]] * 5 # ignored + y = sp.csc_matrix(np.array([[4, 1], + [0, 0], + [1, 1], + [1, 4], + [1, 1]])) + + clf = DummyClassifier(strategy="stratified", random_state=0) + clf.fit(X, y) + + X = [[0]] * 500 + y_pred = clf.predict(X) + assert_true(sp.issparse(y_pred)) + y_pred = y_pred.toarray() + + for k in range(y.shape[1]): + p = np.bincount(y_pred[:, k]) / float(len(X)) + assert_almost_equal(p[1], 3. / 5, decimal=1) + assert_almost_equal(p[0], 1. / 5, decimal=1) + assert_almost_equal(p[4], 1. / 5, decimal=1) + + +def test_most_frequent_strategy_sparse_target(): + X = [[0]] * 5 # ignored + y = sp.csc_matrix(np.array([[1, 0], + [1, 3], + [4, 0], + [0, 1], + [1, 0]])) + + n_samples = len(X) + clf = DummyClassifier(strategy="most_frequent", random_state=0) + clf.fit(X, y) + + y_pred = clf.predict(X) + assert_true(sp.issparse(y_pred)) + assert_array_equal(y_pred.toarray(), np.hstack([np.ones((n_samples, 1)), + np.zeros((n_samples, 1))])) + + +if __name__ == '__main__': + import nose + nose.runmodule() diff --git a/sklearn/tests/test_grid_search.py b/sklearn/tests/test_grid_search.py index 02183d18cd2fc..7791993a44901 100644 --- a/sklearn/tests/test_grid_search.py +++ b/sklearn/tests/test_grid_search.py @@ -15,12 +15,16 @@ import scipy.sparse as sp from sklearn.utils.testing import assert_equal +from sklearn.utils.testing import assert_not_equal from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_raise_message from sklearn.utils.testing import assert_false, assert_true from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_array_almost_equal +from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import assert_no_warnings +from sklearn.utils.testing import ignore_warnings from sklearn.utils.mocking import CheckingClassifier, MockDataFrame from scipy.stats import distributions @@ -31,7 +35,8 @@ from sklearn.datasets import make_blobs from sklearn.datasets import make_multilabel_classification from sklearn.grid_search import (GridSearchCV, RandomizedSearchCV, - ParameterGrid, ParameterSampler) + ParameterGrid, ParameterSampler, + ChangedBehaviorWarning) from sklearn.svm import LinearSVC, SVC from sklearn.tree import DecisionTreeRegressor from sklearn.tree import DecisionTreeClassifier @@ -143,13 +148,14 @@ def test_grid_search(): assert_raises(ValueError, grid_search.fit, X, y) +@ignore_warnings def test_grid_search_no_score(): # Test grid-search on classifier that has no score function. clf = LinearSVC(random_state=0) X, y = make_blobs(random_state=0, centers=2) Cs = [.1, 1, 10] clf_no_score = LinearSVCNoScore(random_state=0) - grid_search = GridSearchCV(clf, {'C': Cs}) + grid_search = GridSearchCV(clf, {'C': Cs}, scoring='accuracy') grid_search.fit(X, y) grid_search_no_score = GridSearchCV(clf_no_score, {'C': Cs}, @@ -168,6 +174,36 @@ def test_grid_search_no_score(): [[1]]) +def test_grid_search_score_method(): + X, y = make_classification(n_samples=100, n_classes=2, flip_y=.2, + random_state=0) + clf = LinearSVC(random_state=0) + grid = {'C': [.1]} + + search_no_scoring = GridSearchCV(clf, grid, scoring=None).fit(X, y) + search_accuracy = GridSearchCV(clf, grid, scoring='accuracy').fit(X, y) + search_no_score_method_auc = GridSearchCV(LinearSVCNoScore(), grid, + scoring='roc_auc').fit(X, y) + search_auc = GridSearchCV(clf, grid, scoring='roc_auc').fit(X, y) + + # Check warning only occurs in situation where behavior changed: + # estimator requires score method to compete with scoring parameter + score_no_scoring = assert_no_warnings(search_no_scoring.score, X, y) + score_accuracy = assert_warns(ChangedBehaviorWarning, + search_accuracy.score, X, y) + score_no_score_auc = assert_no_warnings(search_no_score_method_auc.score, + X, y) + score_auc = assert_warns(ChangedBehaviorWarning, + search_auc.score, X, y) + # ensure the test is sane + assert_true(score_auc < 1.0) + assert_true(score_accuracy < 1.0) + assert_not_equal(score_auc, score_accuracy) + + assert_almost_equal(score_accuracy, score_no_scoring) + assert_almost_equal(score_auc, score_no_score_auc) + + def test_trivial_grid_scores(): """Test search over a "grid" with only one point. diff --git a/sklearn/tests/test_lda.py b/sklearn/tests/test_lda.py index 220f95c6f6cb8..452f9df5aea71 100644 --- a/sklearn/tests/test_lda.py +++ b/sklearn/tests/test_lda.py @@ -3,9 +3,10 @@ from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_equal +from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_true -from .. import lda +from sklearn import lda # Data is just 6 separable points in the plane X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]) @@ -49,3 +50,36 @@ def test_lda_transform(): clf = lda.LDA() X_transformed = clf.fit(X, y).transform(X) assert_equal(X_transformed.shape[1], 1) + + +def test_lda_orthogonality(): + # arrange four classes with their means in a kite-shaped pattern + # the longer distance should be transformed to the first component, and + # the shorter distance to the second component. + means = np.array([[0, 0, -1], [0, 2, 0], [0, -2, 0], [0, 0, 5]]) + + # We construct perfectly symmetric distributions, so the LDA can estimate + # precise means. + scatter = np.array([[0.1, 0, 0], [-0.1, 0, 0], [0, 0.1, 0], [0, -0.1, 0], + [0, 0, 0.1], [0, 0, -0.1]]) + + X = (means[:, np.newaxis, :] + scatter[np.newaxis, :, :]).reshape((-1, 3)) + y = np.repeat(np.arange(means.shape[0]), scatter.shape[0]) + + # Fit LDA and transform the means + clf = lda.LDA().fit(X, y) + means_transformed = clf.transform(means) + + d1 = means_transformed[3] - means_transformed[0] + d2 = means_transformed[2] - means_transformed[1] + d1 /= np.sqrt(np.sum(d1**2)) + d2 /= np.sqrt(np.sum(d2**2)) + + # the transformed within-class covariance should be the identity matrix + assert_almost_equal(np.cov(clf.transform(scatter).T), np.eye(2)) + + # the means of classes 0 and 3 should lie on the first component + assert_almost_equal(np.abs(np.dot(d1[:2], [1, 0])), 1.0) + + # the means of classes 1 and 2 should lie on the second component + assert_almost_equal(np.abs(np.dot(d2[:2], [0, 1])), 1.0) diff --git a/sklearn/tests/test_random_projection.py b/sklearn/tests/test_random_projection.py index 1bc91917ec0cf..719e41b2bfba4 100644 --- a/sklearn/tests/test_random_projection.py +++ b/sklearn/tests/test_random_projection.py @@ -1,27 +1,25 @@ from __future__ import division -import warnings import numpy as np import scipy.sparse as sp from sklearn.metrics import euclidean_distances -from sklearn.random_projection import ( - johnson_lindenstrauss_min_dim, - gaussian_random_matrix, - sparse_random_matrix, - SparseRandomProjection, - GaussianRandomProjection) - -from sklearn.utils.testing import ( - assert_less, - assert_raises, - assert_raise_message, - assert_array_equal, - assert_equal, - assert_almost_equal, - assert_in, - assert_array_almost_equal) +from sklearn.random_projection import johnson_lindenstrauss_min_dim +from sklearn.random_projection import gaussian_random_matrix +from sklearn.random_projection import sparse_random_matrix +from sklearn.random_projection import SparseRandomProjection +from sklearn.random_projection import GaussianRandomProjection + +from sklearn.utils.testing import assert_less +from sklearn.utils.testing import assert_raises +from sklearn.utils.testing import assert_raise_message +from sklearn.utils.testing import assert_array_equal +from sklearn.utils.testing import assert_equal +from sklearn.utils.testing import assert_almost_equal +from sklearn.utils.testing import assert_in +from sklearn.utils.testing import assert_array_almost_equal +from sklearn.utils.testing import assert_warns all_sparse_random_matrix = [sparse_random_matrix] all_dense_random_matrix = [gaussian_random_matrix] @@ -338,8 +336,18 @@ def test_warning_n_components_greater_than_n_features(): data, _ = make_sparse_random_data(5, n_features, int(n_features / 4)) for RandomProjection in all_RandomProjection: - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - RandomProjection(n_components=n_features + 1).fit(data) - assert_equal(len(w), 1) - assert issubclass(w[-1].category, UserWarning) + assert_warns(UserWarning, + RandomProjection(n_components=n_features + 1).fit, data) + + +def test_works_with_sparse_data(): + n_features = 20 + data, _ = make_sparse_random_data(5, n_features, int(n_features / 4)) + + for RandomProjection in all_RandomProjection: + rp_dense = RandomProjection(n_components=3, + random_state=1).fit(data) + rp_sparse = RandomProjection(n_components=3, + random_state=1).fit(sp.csr_matrix(data)) + assert_array_almost_equal(densify(rp_dense.components_), + densify(rp_sparse.components_)) diff --git a/sklearn/tree/_tree.pyx b/sklearn/tree/_tree.pyx index e18eca2826c49..fae59a7f13bce 100644 --- a/sklearn/tree/_tree.pyx +++ b/sklearn/tree/_tree.pyx @@ -2202,7 +2202,7 @@ cdef class Tree: threshold : array of double, shape [node_count] threshold[i] holds the threshold for the internal node i. - value : array of double, shape [node_count, n_outputs, ] + value : array of double, shape [node_count, n_outputs, max_n_classes] Contains the constant prediction value of each node. impurity : array of double, shape [node_count] diff --git a/sklearn/tree/tree.py b/sklearn/tree/tree.py index 8064f1f1b951e..a60f1a6ccca25 100644 --- a/sklearn/tree/tree.py +++ b/sklearn/tree/tree.py @@ -414,22 +414,22 @@ class DecisionTreeClassifier(BaseDecisionTree, ClassifierMixin): Attributes ---------- - `tree_` : Tree object + tree_ : Tree object The underlying Tree object. - `max_features_` : int, + max_features_ : int, The infered value of max_features. - `classes_` : array of shape = [n_classes] or a list of such arrays + classes_ : array of shape = [n_classes] or a list of such arrays The classes labels (single output problem), or a list of arrays of class labels (multi-output problem). - `n_classes_` : int or list + n_classes_ : int or list The number of classes (for single output problems), or a list containing the number of classes for each output (for multi-output problems). - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also @@ -624,13 +624,13 @@ class DecisionTreeRegressor(BaseDecisionTree, RegressorMixin): Attributes ---------- - `tree_` : Tree object + tree_ : Tree object The underlying Tree object. - `max_features_` : int, + max_features_ : int, The infered value of max_features. - `feature_importances_` : array of shape = [n_features] + feature_importances_ : array of shape = [n_features] The feature importances. The higher, the more important the feature. The importance of a feature is computed as the diff --git a/sklearn/utils/__init__.py b/sklearn/utils/__init__.py index 38e87bc14d275..e2f6a2f5ec211 100644 --- a/sklearn/utils/__init__.py +++ b/sklearn/utils/__init__.py @@ -13,7 +13,6 @@ check_random_state, column_or_1d, check_array, check_consistent_length, check_X_y, indexable) from .class_weight import compute_class_weight -from sklearn.utils.sparsetools import minimum_spanning_tree __all__ = ["murmurhash3_32", "as_float_array", @@ -21,7 +20,6 @@ "warn_if_not_float", "check_random_state", "compute_class_weight", - "minimum_spanning_tree", "column_or_1d", "safe_indexing", "check_consistent_length", "check_X_y", 'indexable'] @@ -150,7 +148,12 @@ def safe_indexing(X, indices): # Pandas Dataframes and Series return X.iloc[indices] elif hasattr(X, "shape"): - return X[indices] + if hasattr(X, 'take') and (hasattr(indices, 'dtype') and + indices.dtype.kind == 'i'): + # This is often substantially faster than X[indices] + return X.take(indices, axis=0) + else: + return X[indices] else: return [X[idx] for idx in indices] @@ -239,7 +242,8 @@ def resample(*arrays, **options): max_n_samples, n_samples)) check_consistent_length(*arrays) - arrays = [check_array(x, accept_sparse='csr', ensure_2d=False) for x in arrays] + arrays = [check_array(x, accept_sparse='csr', ensure_2d=False) + for x in arrays] if replace: indices = random_state.randint(0, n_samples, size=(max_n_samples,)) diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py index c114d45887794..701a0a5efd27a 100644 --- a/sklearn/utils/estimator_checks.py +++ b/sklearn/utils/estimator_checks.py @@ -527,7 +527,7 @@ def check_classifiers_input_shapes(name, Classifier): def check_classifiers_classes(name, Classifier): - X, y = make_blobs(n_samples=30, random_state=0) + X, y = make_blobs(n_samples=30, random_state=0, cluster_std=0.1) X, y = shuffle(X, y, random_state=7) X = StandardScaler().fit_transform(X) # We need to make sure that we have non negative data, for things @@ -725,6 +725,36 @@ def check_class_weight_auto_classifiers(name, Classifier, X_train, y_train, f1_score(y_test, y_pred)) +def check_class_weight_auto_linear_classifier(name, Classifier): + """Test class weights with non-contiguous class labels.""" + X = np.array([[-1.0, -1.0], [-1.0, 0], [-.8, -1.0], + [1.0, 1.0], [1.0, 0.0]]) + y = [1, 1, 1, -1, -1] + + with warnings.catch_warnings(record=True): + classifier = Classifier() + if hasattr(classifier, "n_iter"): + # This is a very small dataset, default n_iter are likely to prevent + # convergence + classifier.set_params(n_iter=1000) + set_random_state(classifier) + + # Let the model compute the class frequencies + classifier.set_params(class_weight='auto') + coef_auto = classifier.fit(X, y).coef_.copy() + + # Count each label occurrence to reweight manually + mean_weight = (1. / 3 + 1. / 2) / 2 + class_weight = { + 1: 1. / 3 / mean_weight, + -1: 1. / 2 / mean_weight, + } + classifier.set_params(class_weight=class_weight) + coef_manual = classifier.fit(X, y).coef_.copy() + + assert_array_almost_equal(coef_auto, coef_manual) + + def check_estimators_overwrite_params(name, Estimator): X, y = make_blobs(random_state=0, n_samples=9) y = multioutput_estimator_convert_y_2d(name, y) @@ -921,6 +951,7 @@ def check_non_transformer_estimators_n_iter(name, estimator, multi_output=False) if multi_output: y_ = y_[:, np.newaxis] + set_random_state(estimator, 0) if name == 'AffinityPropagation': estimator.fit(X) else: @@ -932,12 +963,13 @@ def check_transformer_n_iter(name, estimator): if name in CROSS_DECOMPOSITION: # Check using default data X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]] - y_ = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]] + y_ = [[0.1, -0.2], [0.9, 1.1], [0.1, -0.5], [0.3, -0.2]] else: X, y_ = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]], random_state=0, n_features=2, cluster_std=0.1) X -= X.min() - 0.1 + set_random_state(estimator, 0) estimator.fit(X, y_) # These return a n_iter per component. diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index c5dff97121540..e9eb901256467 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -6,6 +6,7 @@ # Alexandre T. Passos # Olivier Grisel # Lars Buitinck +# Stefan van der Walt # License: BSD 3 clause from functools import partial @@ -54,8 +55,8 @@ def squared_norm(x): def row_norms(X, squared=False): """Row-wise (squared) Euclidean norm of X. - Equivalent to (X * X).sum(axis=1), but also supports CSR sparse matrices - and does not create an X.shape-sized temporary. + Equivalent to np.sqrt((X * X).sum(axis=1)), but also supports CSR sparse + matrices and does not create an X.shape-sized temporary. Performs no input validation. """ @@ -501,24 +502,20 @@ def cartesian(arrays, out=None): [3, 5, 6], [3, 5, 7]]) - References - ---------- - http://stackoverflow.com/q/1208118 - """ - arrays = [np.asarray(x).ravel() for x in arrays] + arrays = [np.asarray(x) for x in arrays] + shape = (len(x) for x in arrays) dtype = arrays[0].dtype - n = np.prod([x.size for x in arrays]) + ix = np.indices(shape) + ix = ix.reshape(len(arrays), -1).T + if out is None: - out = np.empty([n, len(arrays)], dtype=dtype) - - m = n // arrays[0].size - out[:, 0] = np.repeat(arrays[0], m) - if arrays[1:]: - cartesian(arrays[1:], out=out[0:m, 1:]) - for j in xrange(1, arrays[0].size): - out[j * m:(j + 1) * m, 1:] = out[0:m, 1:] + out = np.empty_like(ix, dtype=dtype) + + for n, arr in enumerate(arrays): + out[:, n] = arrays[n][ix[:, n]] + return out diff --git a/sklearn/utils/fixes.py b/sklearn/utils/fixes.py index 5c8ca290268d8..fa6d89e650bf1 100644 --- a/sklearn/utils/fixes.py +++ b/sklearn/utils/fixes.py @@ -11,11 +11,11 @@ # License: BSD 3 clause import inspect +import warnings import numpy as np import scipy.sparse as sp - np_version = [] for x in np.__version__.split('.'): try: @@ -102,7 +102,11 @@ def astype(array, dtype, copy=True): try: - sp.csr_matrix([1.0, 2.0, 3.0]).max(axis=0) + with warnings.catch_warnings(record=True): + # Don't raise the numpy deprecation warnings that appear in + # 1.9, but avoid Python bug due to simplefilter('ignore') + warnings.simplefilter('always') + sp.csr_matrix([1.0, 2.0, 3.0]).max(axis=0) except (TypeError, AttributeError): # in scipy < 14.0, sparse matrix min/max doesn't accept an `axis` argument # the following code is taken from the scipy 0.14 codebase @@ -240,3 +244,47 @@ def within_tol(x, y, atol, rtol): # Make NaN == NaN cond[np.isnan(x) & np.isnan(y)] = True return cond + +if np_version < (1, 8): + def in1d(ar1, ar2, assume_unique=False, invert=False): + # Backport of numpy function in1d 1.8.1 to support numpy 1.6.2 + # Ravel both arrays, behavior for the first array could be different + ar1 = np.asarray(ar1).ravel() + ar2 = np.asarray(ar2).ravel() + + # This code is significantly faster when the condition is satisfied. + if len(ar2) < 10 * len(ar1) ** 0.145: + if invert: + mask = np.ones(len(ar1), dtype=np.bool) + for a in ar2: + mask &= (ar1 != a) + else: + mask = np.zeros(len(ar1), dtype=np.bool) + for a in ar2: + mask |= (ar1 == a) + return mask + + # Otherwise use sorting + if not assume_unique: + ar1, rev_idx = np.unique(ar1, return_inverse=True) + ar2 = np.unique(ar2) + + ar = np.concatenate((ar1, ar2)) + # We need this to be a stable sort, so always use 'mergesort' + # here. The values from the first array should always come before + # the values from the second array. + order = ar.argsort(kind='mergesort') + sar = ar[order] + if invert: + bool_ar = (sar[1:] != sar[:-1]) + else: + bool_ar = (sar[1:] == sar[:-1]) + flag = np.concatenate((bool_ar, [invert])) + indx = order.argsort(kind='mergesort')[:len(ar1)] + + if assume_unique: + return flag[indx] + else: + return flag[indx][rev_idx] +else: + from numpy import in1d diff --git a/sklearn/utils/multiclass.py b/sklearn/utils/multiclass.py index 255f348a54d8d..7dc83de27ca0e 100644 --- a/sklearn/utils/multiclass.py +++ b/sklearn/utils/multiclass.py @@ -6,6 +6,7 @@ ========================================== """ +from __future__ import division from collections import Sequence from itertools import chain import warnings @@ -347,3 +348,77 @@ def _check_partial_fit_first_call(clf, classes=None): # classes is None and clf.classes_ has already previously been set: # nothing to do return False + + +def class_distribution(y, sample_weight=None): + """Compute class priors from multioutput-multiclass target data + + Parameters + ---------- + y : array like or sparse matrix of size (n_samples, n_outputs) + The labels for each example. + + sample_weight : array-like of shape = (n_samples,), optional + Sample weights. + + Return + ------ + classes : list of size n_outputs of arrays of size (n_classes,) + List of classes for each column. + + n_classes : list of integrs of size n_outputs + Number of classes in each column + + class_prior : list of size n_outputs of arrays of size (n_classes,) + Class distribution of each column. + + """ + classes = [] + n_classes = [] + class_prior = [] + + n_samples, n_outputs = y.shape + + if issparse(y): + y = y.tocsc() + y_nnz = np.diff(y.indptr) + + for k in range(n_outputs): + col_nonzero = y.indices[y.indptr[k]:y.indptr[k + 1]] + # separate sample weights for zero and non-zero elements + if sample_weight is not None: + nz_samp_weight = np.asarray(sample_weight)[col_nonzero] + zeros_samp_weight_sum = (np.sum(sample_weight) - + np.sum(nz_samp_weight)) + else: + nz_samp_weight = None + zeros_samp_weight_sum = y.shape[0] - y_nnz[k] + + classes_k, y_k = np.unique(y.data[y.indptr[k]:y.indptr[k + 1]], + return_inverse=True) + class_prior_k = np.bincount(y_k, weights=nz_samp_weight) + + # An explicit zero was found, combine its wieght with the wieght + # of the implicit zeros + if 0 in classes_k: + class_prior_k[classes_k == 0] += zeros_samp_weight_sum + + # If an there is an implict zero and it is not in classes and + # class_prior, make an entry for it + if 0 not in classes_k and y_nnz[k] < y.shape[0]: + classes_k = np.insert(classes_k, 0, 0) + class_prior_k = np.insert(class_prior_k, 0, + zeros_samp_weight_sum) + + classes.append(classes_k) + n_classes.append(classes_k.shape[0]) + class_prior.append(class_prior_k / class_prior_k.sum()) + else: + for k in range(n_outputs): + classes_k, y_k = np.unique(y[:, k], return_inverse=True) + classes.append(classes_k) + n_classes.append(classes_k.shape[0]) + class_prior_k = np.bincount(y_k, weights=sample_weight) + class_prior.append(class_prior_k / class_prior_k.sum()) + + return (classes, n_classes, class_prior) diff --git a/sklearn/utils/random.py b/sklearn/utils/random.py index 7912f45b48d52..fbbcefa20c858 100644 --- a/sklearn/utils/random.py +++ b/sklearn/utils/random.py @@ -1,8 +1,11 @@ -# This file contains a backport of np.random.choice from numpy 1.7 -# The function can be removed when we bump the requirements to >=1.7 - +# Author: Hamzeh Alsalhi +# +# License: BSD 3 clause +from __future__ import division import numpy as np +import scipy.sparse as sp import operator +import array from sklearn.utils import check_random_state @@ -11,6 +14,8 @@ __all__ = ['sample_without_replacement', 'choice'] +# This is a backport of np.random.choice from numpy 1.7 +# The function can be removed when we bump the requirements to >=1.7 def choice(a, size=None, replace=True, p=None, random_state=None): """ choice(a, size=None, replace=True, p=None) @@ -180,7 +185,7 @@ def choice(a, size=None, replace=True, p=None, random_state=None): # In most cases a scalar will have been made an array idx = idx.item(0) - #Use samples as indices for a if a is array-like + # Use samples as indices for a if a is array-like if a.ndim == 0: return idx @@ -195,3 +200,88 @@ def choice(a, size=None, replace=True, p=None, random_state=None): return res return a[idx] + + +def random_choice_csc(n_samples, classes, class_probability=None, + random_state=None): + """Generate a sparse random matrix given column class distributions + + Parameters + ---------- + n_samples : int, + Number of samples to draw in each column. + + classes : list of size n_outputs of arrays of size (n_classes,) + List of classes for each column. + + class_probability : list of size n_outputs of arrays of size (n_classes,) + Optional (default=None). Class distribution of each column. If None the + uniform distribution is assumed. + + random_state : int, RandomState instance or None, optional (default=None) + If int, random_state is the seed used by the random number generator; + If RandomState instance, random_state is the random number generator; + If None, the random number generator is the RandomState instance used + by `np.random`. + + Return + ------ + random_matrix : sparse csc matrix of size (n_samples, n_outputs) + + """ + data = array.array('i') + indices = array.array('i') + indptr = array.array('i', [0]) + + for j in range(len(classes)): + classes[j] = np.asarray(classes[j]) + if classes[j].dtype.kind != 'i': + raise ValueError("class dtype %s is not supported" % + classes[j].dtype) + classes[j] = classes[j].astype(int) + + # use uniform distribution if no class_probability is given + if class_probability is None: + class_prob_j = np.empty(shape=classes[j].shape[0]) + class_prob_j.fill(1 / classes[j].shape[0]) + else: + class_prob_j = np.asarray(class_probability[j]) + + if np.sum(class_prob_j) != 1.0: + raise ValueError("Probability array at index {0} does not sum to " + "one".format(j)) + + if class_prob_j.shape[0] != classes[j].shape[0]: + raise ValueError("classes[{0}] (length {1}) and " + "class_probability[{0}] (length {2}) have " + "different length.".format(j, + classes[j].shape[0], + class_prob_j.shape[0])) + + # If 0 is not present in the classes insert it with a probability 0.0 + if 0 not in classes[j]: + classes[j] = np.insert(classes[j], 0, 0) + class_prob_j = np.insert(class_prob_j, 0, 0.0) + + # If there are nonzero classes choose randomly using class_probability + if classes[j].shape[0] > 1: + p_nonzero = 1 - class_prob_j[classes[j] == 0] + nnz = int(n_samples * p_nonzero) + ind_sample = sample_without_replacement(n_population=n_samples, + n_samples=nnz, + random_state=random_state) + indices.extend(ind_sample) + + # Normalize probabilites for the nonzero elements + classes_j_nonzero = classes[j] != 0 + class_probability_nz = class_prob_j[classes_j_nonzero] + class_probability_nz_norm = (class_probability_nz / + np.sum(class_probability_nz)) + classes_ind = np.searchsorted(class_probability_nz_norm.cumsum(), + np.random.rand(nnz)) + data.extend(classes[j][classes_j_nonzero][classes_ind]) + indptr.append(len(indices)) + + return sp.csc_matrix((data, indices, indptr), + (n_samples, len(classes)), + dtype=int) diff --git a/sklearn/utils/sparsefuncs.py b/sklearn/utils/sparsefuncs.py index 04fd52a082ec7..e17cf95b6a535 100644 --- a/sklearn/utils/sparsefuncs.py +++ b/sklearn/utils/sparsefuncs.py @@ -6,8 +6,8 @@ import numpy as np from .fixes import sparse_min_max -from .sparsefuncs_fast import (csr_mean_variance_axis0, - csc_mean_variance_axis0) +from .sparsefuncs_fast import csr_mean_variance_axis0 as _csr_mean_var_axis0 +from .sparsefuncs_fast import csc_mean_variance_axis0 as _csc_mean_var_axis0 def _raise_typeerror(X): @@ -53,7 +53,7 @@ def inplace_csr_row_scale(X, scale): X.data *= np.repeat(scale, np.diff(X.indptr)) -def mean_variance_axis0(X): +def mean_variance_axis(X, axis): """Compute mean and variance along axis 0 on a CSR or CSC matrix Parameters @@ -61,6 +61,9 @@ def mean_variance_axis0(X): X: CSR or CSC sparse matrix, shape (n_samples, n_features) Input data. + axis: int (either 0 or 1) + Axis along which the axis should be computed. + Returns ------- @@ -71,10 +74,20 @@ def mean_variance_axis0(X): Feature-wise variances """ + if axis not in (0, 1): + raise ValueError( + "Unknown axis value: %d. Use 0 for rows, or 1 for columns" % axis) + if isinstance(X, sp.csr_matrix): - return csr_mean_variance_axis0(X) + if axis == 0: + return _csr_mean_var_axis0(X) + else: + return _csc_mean_var_axis0(X.T) elif isinstance(X, sp.csc_matrix): - return csc_mean_variance_axis0(X) + if axis == 0: + return _csc_mean_var_axis0(X) + else: + return _csr_mean_var_axis0(X.T) else: _raise_typeerror(X) @@ -258,13 +271,16 @@ def inplace_swap_column(X, m, n): def min_max_axis(X, axis): - """Compute minimum and maximum along axis 0 on a CSR or CSC matrix + """Compute minimum and maximum along an axis on a CSR or CSC matrix Parameters ---------- - X: CSR or CSC sparse matrix, shape (n_samples, n_features) + X : CSR or CSC sparse matrix, shape (n_samples, n_features) Input data. + axis: int (either 0 or 1) + Axis along which the axis should be computed. + Returns ------- @@ -278,3 +294,51 @@ def min_max_axis(X, axis): return sparse_min_max(X, axis=axis) else: _raise_typeerror(X) + + +def count_nonzero(X, axis=None, sample_weight=None): + """A variant of X.getnnz() with extension to weighting on axis 0 + + Useful in efficiently calculating multilabel metrics. + + Parameters + ---------- + X : CSR sparse matrix, shape = (n_samples, n_labels) + Input data. + + axis : None, 0 or 1 + The axis on which the data is aggregated. + + sample_weight : array, shape = (n_samples,), optional + Weight for each row of X. + """ + if axis == -1: + axis = 1 + elif axis == -2: + axis = 0 + elif X.format != 'csr': + raise TypeError('Expected CSR sparse format, got {0}'.format(X.format)) + + # We rely here on the fact that np.diff(Y.indptr) for a CSR + # will return the number of nonzero entries in each row. + # A bincount over Y.indices will return the number of nonzeros + # in each column. See ``csr_matrix.getnnz`` in scipy >= 0.14. + if axis is None: + if sample_weight is None: + return X.nnz + else: + return np.dot(np.diff(X.indptr), sample_weight) + elif axis == 1: + out = np.diff(X.indptr) + if sample_weight is None: + return out + return out * sample_weight + elif axis == 0: + if sample_weight is None: + return np.bincount(X.indices, minlength=X.shape[1]) + else: + weights = np.repeat(sample_weight, np.diff(X.indptr)) + return np.bincount(X.indices, minlength=X.shape[1], + weights=weights) + else: + raise ValueError('Unsupported axis: {0}'.format(axis)) diff --git a/sklearn/utils/sparsefuncs_fast.pyx b/sklearn/utils/sparsefuncs_fast.pyx index de8c66905b8b4..b85488f5320e0 100644 --- a/sklearn/utils/sparsefuncs_fast.pyx +++ b/sklearn/utils/sparsefuncs_fast.pyx @@ -275,7 +275,7 @@ def assign_rows_csr(X, out : array, shape=(arbitrary, n_features) """ cdef: - # npy_intp (np.intc in Python) is what np.where returns, + # npy_intp (np.intp in Python) is what np.where returns, # but int is what scipy.sparse uses. int i, ind, j np.npy_intp rX diff --git a/sklearn/utils/sparsetools/README b/sklearn/utils/sparsetools/README index 03d7b62f9eda3..ae03f7de3cf65 100644 --- a/sklearn/utils/sparsetools/README +++ b/sklearn/utils/sparsetools/README @@ -1,6 +1 @@ -Backport of Minimum Spanning Tree - -This code was backported from scipy 0.13, to cover a requirement in new code. -It was backported by Robert Layton on 23rd May, 2013. - -This folder should be removed when the scipy dependency for scikit-learn reaches v0.13 or higher. +Backport of SciPy 0.13 code. diff --git a/sklearn/utils/sparsetools/__init__.py b/sklearn/utils/sparsetools/__init__.py index 13e68955cb80a..3a5c30036a1c2 100644 --- a/sklearn/utils/sparsetools/__init__.py +++ b/sklearn/utils/sparsetools/__init__.py @@ -1,6 +1,5 @@ """sparsetools - a collection of routines for sparse matrix operations""" -from ._min_spanning_tree import minimum_spanning_tree from ._traversal import connected_components -__all__ = ["minimum_spanning_tree", "connected_components"] +__all__ = ["connected_components"] diff --git a/sklearn/utils/sparsetools/_min_spanning_tree.c b/sklearn/utils/sparsetools/_min_spanning_tree.c deleted file mode 100644 index 5b952e4ee9cde..0000000000000 --- a/sklearn/utils/sparsetools/_min_spanning_tree.c +++ /dev/null @@ -1,7003 +0,0 @@ -/* Generated by Cython 0.17.4 on Thu May 23 18:21:44 2013 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ - 0 : _PyUnicode_Ready((PyObject *)(op))) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) - #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_READY(op) (0) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include -#define __PYX_HAVE__sklearn__utils__mst___min_spanning_tree -#define __PYX_HAVE_API__sklearn__utils__mst___min_spanning_tree -#include "stdio.h" -#include "stdlib.h" -#include "numpy/arrayobject.h" -#include "numpy/ufuncobject.h" -#ifdef _OPENMP -#include -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#if CYTHON_COMPILING_IN_CPYTHON -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#else -#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) -#endif -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - -#if !defined(CYTHON_CCOMPLEX) - #if defined(__cplusplus) - #define CYTHON_CCOMPLEX 1 - #elif defined(_Complex_I) - #define CYTHON_CCOMPLEX 1 - #else - #define CYTHON_CCOMPLEX 0 - #endif -#endif -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #include - #else - #include - #endif -#endif -#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__) - #undef _Complex_I - #define _Complex_I 1.0fj -#endif - - -static const char *__pyx_f[] = { - "_min_spanning_tree.pyx", - "numpy.pxd", - "type.pxd", -}; -#define IS_UNSIGNED(type) (((type) -1) > 0) -struct __Pyx_StructField_; -#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0) -typedef struct { - const char* name; /* for error messages only */ - struct __Pyx_StructField_* fields; - size_t size; /* sizeof(type) */ - size_t arraysize[8]; /* length of array in each dimension */ - int ndim; - char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject, c_H_ar */ - char is_unsigned; - int flags; -} __Pyx_TypeInfo; -typedef struct __Pyx_StructField_ { - __Pyx_TypeInfo* type; - const char* name; - size_t offset; -} __Pyx_StructField; -typedef struct { - __Pyx_StructField* field; - size_t parent_offset; -} __Pyx_BufFmt_StackElem; -typedef struct { - __Pyx_StructField root; - __Pyx_BufFmt_StackElem* head; - size_t fmt_offset; - size_t new_count, enc_count; - size_t struct_alignment; - int is_complex; - char enc_type; - char new_packmode; - char enc_packmode; - char is_valid_array; -} __Pyx_BufFmt_Context; - - -/* "numpy.pxd":723 - * # in Cython to enable them only on the right systems. - * - * ctypedef npy_int8 int8_t # <<<<<<<<<<<<<< - * ctypedef npy_int16 int16_t - * ctypedef npy_int32 int32_t - */ -typedef npy_int8 __pyx_t_5numpy_int8_t; - -/* "numpy.pxd":724 - * - * ctypedef npy_int8 int8_t - * ctypedef npy_int16 int16_t # <<<<<<<<<<<<<< - * ctypedef npy_int32 int32_t - * ctypedef npy_int64 int64_t - */ -typedef npy_int16 __pyx_t_5numpy_int16_t; - -/* "numpy.pxd":725 - * ctypedef npy_int8 int8_t - * ctypedef npy_int16 int16_t - * ctypedef npy_int32 int32_t # <<<<<<<<<<<<<< - * ctypedef npy_int64 int64_t - * #ctypedef npy_int96 int96_t - */ -typedef npy_int32 __pyx_t_5numpy_int32_t; - -/* "numpy.pxd":726 - * ctypedef npy_int16 int16_t - * ctypedef npy_int32 int32_t - * ctypedef npy_int64 int64_t # <<<<<<<<<<<<<< - * #ctypedef npy_int96 int96_t - * #ctypedef npy_int128 int128_t - */ -typedef npy_int64 __pyx_t_5numpy_int64_t; - -/* "numpy.pxd":730 - * #ctypedef npy_int128 int128_t - * - * ctypedef npy_uint8 uint8_t # <<<<<<<<<<<<<< - * ctypedef npy_uint16 uint16_t - * ctypedef npy_uint32 uint32_t - */ -typedef npy_uint8 __pyx_t_5numpy_uint8_t; - -/* "numpy.pxd":731 - * - * ctypedef npy_uint8 uint8_t - * ctypedef npy_uint16 uint16_t # <<<<<<<<<<<<<< - * ctypedef npy_uint32 uint32_t - * ctypedef npy_uint64 uint64_t - */ -typedef npy_uint16 __pyx_t_5numpy_uint16_t; - -/* "numpy.pxd":732 - * ctypedef npy_uint8 uint8_t - * ctypedef npy_uint16 uint16_t - * ctypedef npy_uint32 uint32_t # <<<<<<<<<<<<<< - * ctypedef npy_uint64 uint64_t - * #ctypedef npy_uint96 uint96_t - */ -typedef npy_uint32 __pyx_t_5numpy_uint32_t; - -/* "numpy.pxd":733 - * ctypedef npy_uint16 uint16_t - * ctypedef npy_uint32 uint32_t - * ctypedef npy_uint64 uint64_t # <<<<<<<<<<<<<< - * #ctypedef npy_uint96 uint96_t - * #ctypedef npy_uint128 uint128_t - */ -typedef npy_uint64 __pyx_t_5numpy_uint64_t; - -/* "numpy.pxd":737 - * #ctypedef npy_uint128 uint128_t - * - * ctypedef npy_float32 float32_t # <<<<<<<<<<<<<< - * ctypedef npy_float64 float64_t - * #ctypedef npy_float80 float80_t - */ -typedef npy_float32 __pyx_t_5numpy_float32_t; - -/* "numpy.pxd":738 - * - * ctypedef npy_float32 float32_t - * ctypedef npy_float64 float64_t # <<<<<<<<<<<<<< - * #ctypedef npy_float80 float80_t - * #ctypedef npy_float128 float128_t - */ -typedef npy_float64 __pyx_t_5numpy_float64_t; - -/* "numpy.pxd":747 - * # The int types are mapped a bit surprising -- - * # numpy.int corresponds to 'l' and numpy.long to 'q' - * ctypedef npy_long int_t # <<<<<<<<<<<<<< - * ctypedef npy_longlong long_t - * ctypedef npy_longlong longlong_t - */ -typedef npy_long __pyx_t_5numpy_int_t; - -/* "numpy.pxd":748 - * # numpy.int corresponds to 'l' and numpy.long to 'q' - * ctypedef npy_long int_t - * ctypedef npy_longlong long_t # <<<<<<<<<<<<<< - * ctypedef npy_longlong longlong_t - * - */ -typedef npy_longlong __pyx_t_5numpy_long_t; - -/* "numpy.pxd":749 - * ctypedef npy_long int_t - * ctypedef npy_longlong long_t - * ctypedef npy_longlong longlong_t # <<<<<<<<<<<<<< - * - * ctypedef npy_ulong uint_t - */ -typedef npy_longlong __pyx_t_5numpy_longlong_t; - -/* "numpy.pxd":751 - * ctypedef npy_longlong longlong_t - * - * ctypedef npy_ulong uint_t # <<<<<<<<<<<<<< - * ctypedef npy_ulonglong ulong_t - * ctypedef npy_ulonglong ulonglong_t - */ -typedef npy_ulong __pyx_t_5numpy_uint_t; - -/* "numpy.pxd":752 - * - * ctypedef npy_ulong uint_t - * ctypedef npy_ulonglong ulong_t # <<<<<<<<<<<<<< - * ctypedef npy_ulonglong ulonglong_t - * - */ -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -/* "numpy.pxd":753 - * ctypedef npy_ulong uint_t - * ctypedef npy_ulonglong ulong_t - * ctypedef npy_ulonglong ulonglong_t # <<<<<<<<<<<<<< - * - * ctypedef npy_intp intp_t - */ -typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t; - -/* "numpy.pxd":755 - * ctypedef npy_ulonglong ulonglong_t - * - * ctypedef npy_intp intp_t # <<<<<<<<<<<<<< - * ctypedef npy_uintp uintp_t - * - */ -typedef npy_intp __pyx_t_5numpy_intp_t; - -/* "numpy.pxd":756 - * - * ctypedef npy_intp intp_t - * ctypedef npy_uintp uintp_t # <<<<<<<<<<<<<< - * - * ctypedef npy_double float_t - */ -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -/* "numpy.pxd":758 - * ctypedef npy_uintp uintp_t - * - * ctypedef npy_double float_t # <<<<<<<<<<<<<< - * ctypedef npy_double double_t - * ctypedef npy_longdouble longdouble_t - */ -typedef npy_double __pyx_t_5numpy_float_t; - -/* "numpy.pxd":759 - * - * ctypedef npy_double float_t - * ctypedef npy_double double_t # <<<<<<<<<<<<<< - * ctypedef npy_longdouble longdouble_t - * - */ -typedef npy_double __pyx_t_5numpy_double_t; - -/* "numpy.pxd":760 - * ctypedef npy_double float_t - * ctypedef npy_double double_t - * ctypedef npy_longdouble longdouble_t # <<<<<<<<<<<<<< - * - * ctypedef npy_cfloat cfloat_t - */ -typedef npy_longdouble __pyx_t_5numpy_longdouble_t; - -/* "sklearn/utils/mst/_min_spanning_tree.pyx":11 - * - * DTYPE = np.float64 - * ctypedef np.float64_t DTYPE_t # <<<<<<<<<<<<<< - * - * ITYPE = np.int32 - */ -typedef __pyx_t_5numpy_float64_t __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t; - -/* "sklearn/utils/mst/_min_spanning_tree.pyx":14 - * - * ITYPE = np.int32 - * ctypedef np.int32_t ITYPE_t # <<<<<<<<<<<<<< - * - * # EPS is the precision of DTYPE - */ -typedef __pyx_t_5numpy_int32_t __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t; -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< float > __pyx_t_float_complex; - #else - typedef float _Complex __pyx_t_float_complex; - #endif -#else - typedef struct { float real, imag; } __pyx_t_float_complex; -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< double > __pyx_t_double_complex; - #else - typedef double _Complex __pyx_t_double_complex; - #endif -#else - typedef struct { double real, imag; } __pyx_t_double_complex; -#endif - - -/*--- Type declarations ---*/ - -/* "numpy.pxd":762 - * ctypedef npy_longdouble longdouble_t - * - * ctypedef npy_cfloat cfloat_t # <<<<<<<<<<<<<< - * ctypedef npy_cdouble cdouble_t - * ctypedef npy_clongdouble clongdouble_t - */ -typedef npy_cfloat __pyx_t_5numpy_cfloat_t; - -/* "numpy.pxd":763 - * - * ctypedef npy_cfloat cfloat_t - * ctypedef npy_cdouble cdouble_t # <<<<<<<<<<<<<< - * ctypedef npy_clongdouble clongdouble_t - * - */ -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -/* "numpy.pxd":764 - * ctypedef npy_cfloat cfloat_t - * ctypedef npy_cdouble cdouble_t - * ctypedef npy_clongdouble clongdouble_t # <<<<<<<<<<<<<< - * - * ctypedef npy_cdouble complex_t - */ -typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; - -/* "numpy.pxd":766 - * ctypedef npy_clongdouble clongdouble_t - * - * ctypedef npy_cdouble complex_t # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew1(a): - */ -typedef npy_cdouble __pyx_t_5numpy_complex_t; -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ - #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; -#ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { /* inlined PySequence_GetItem() */ - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (unlikely(l < 0)) return NULL; - i += l; - } - return m->sq_item(o, i); - } - } -#else - if (PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ - -static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, - __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); -static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); - -static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ - -#define __Pyx_BufPtrCContig1d(type, buf, i0, s0) ((type)buf + i0) -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ - -typedef struct { - Py_ssize_t shape, strides, suboffsets; -} __Pyx_Buf_DimInfo; -typedef struct { - size_t refcount; - Py_buffer pybuffer; -} __Pyx_Buffer; -typedef struct { - __Pyx_Buffer *rcbuffer; - char *data; - __Pyx_Buf_DimInfo diminfo[8]; -} __Pyx_LocalBuf_ND; - -#if PY_MAJOR_VERSION < 3 - static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); - static void __Pyx_ReleaseBuffer(Py_buffer *view); -#else - #define __Pyx_GetBuffer PyObject_GetBuffer - #define __Pyx_ReleaseBuffer PyBuffer_Release -#endif - - -static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0}; -static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1}; - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ - -static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name); - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #define __Pyx_CREAL(z) ((z).real()) - #define __Pyx_CIMAG(z) ((z).imag()) - #else - #define __Pyx_CREAL(z) (__real__(z)) - #define __Pyx_CIMAG(z) (__imag__(z)) - #endif -#else - #define __Pyx_CREAL(z) ((z).real) - #define __Pyx_CIMAG(z) ((z).imag) -#endif -#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX - #define __Pyx_SET_CREAL(z,x) ((z).real(x)) - #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) -#else - #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x) - #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y) -#endif - -static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eqf(a, b) ((a)==(b)) - #define __Pyx_c_sumf(a, b) ((a)+(b)) - #define __Pyx_c_difff(a, b) ((a)-(b)) - #define __Pyx_c_prodf(a, b) ((a)*(b)) - #define __Pyx_c_quotf(a, b) ((a)/(b)) - #define __Pyx_c_negf(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zerof(z) ((z)==(float)0) - #define __Pyx_c_conjf(z) (::std::conj(z)) - #if 1 - #define __Pyx_c_absf(z) (::std::abs(z)) - #define __Pyx_c_powf(a, b) (::std::pow(a, b)) - #endif - #else - #define __Pyx_c_is_zerof(z) ((z)==0) - #define __Pyx_c_conjf(z) (conjf(z)) - #if 1 - #define __Pyx_c_absf(z) (cabsf(z)) - #define __Pyx_c_powf(a, b) (cpowf(a, b)) - #endif - #endif -#else - static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex); - static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex); - #if 1 - static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex, __pyx_t_float_complex); - #endif -#endif - -static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eq(a, b) ((a)==(b)) - #define __Pyx_c_sum(a, b) ((a)+(b)) - #define __Pyx_c_diff(a, b) ((a)-(b)) - #define __Pyx_c_prod(a, b) ((a)*(b)) - #define __Pyx_c_quot(a, b) ((a)/(b)) - #define __Pyx_c_neg(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zero(z) ((z)==(double)0) - #define __Pyx_c_conj(z) (::std::conj(z)) - #if 1 - #define __Pyx_c_abs(z) (::std::abs(z)) - #define __Pyx_c_pow(a, b) (::std::pow(a, b)) - #endif - #else - #define __Pyx_c_is_zero(z) ((z)==0) - #define __Pyx_c_conj(z) (conj(z)) - #if 1 - #define __Pyx_c_abs(z) (cabs(z)) - #define __Pyx_c_pow(a, b) (cpow(a, b)) - #endif - #endif -#else - static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex); - static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex); - #if 1 - static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex); - #endif -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static int __Pyx_check_binary_version(void); - -#if !defined(__Pyx_PyIdentifier_FromString) -#if PY_MAJOR_VERSION < 3 - #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) -#else - #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) -#endif -#endif - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'cpython.buffer' */ - -/* Module declarations from 'cpython.ref' */ - -/* Module declarations from 'libc.stdio' */ - -/* Module declarations from 'cpython.object' */ - -/* Module declarations from '__builtin__' */ - -/* Module declarations from 'cpython.type' */ -static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; - -/* Module declarations from 'libc.stdlib' */ - -/* Module declarations from 'numpy' */ - -/* Module declarations from 'numpy' */ -static PyTypeObject *__pyx_ptype_5numpy_dtype = 0; -static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0; -static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0; -static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; -static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ - -/* Module declarations from 'sklearn.utils.mst._min_spanning_tree' */ -static __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t __pyx_v_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_EPS; -static __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t __pyx_v_7sklearn_5utils_3mst_18_min_spanning_tree_NULL_IDX; -static PyObject *__pyx_f_7sklearn_5utils_3mst_18_min_spanning_tree__min_spanning_tree(PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *, PyArrayObject *); /*proto*/ -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t = { "DTYPE_t", NULL, sizeof(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t), { 0 }, 0, 'R', 0, 0 }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t = { "ITYPE_t", NULL, sizeof(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t), 0 }; -#define __Pyx_MODULE_NAME "sklearn.utils.mst._min_spanning_tree" -int __pyx_module_is_main_sklearn__utils__mst___min_spanning_tree = 0; - -/* Implementation of 'sklearn.utils.mst._min_spanning_tree' */ -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_pf_7sklearn_5utils_3mst_18_min_spanning_tree_minimum_spanning_tree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_csgraph, PyObject *__pyx_v_overwrite); /* proto */ -static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ -static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ -static char __pyx_k_2[] = "ndarray is not C contiguous"; -static char __pyx_k_4[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_6[] = "Non-native byte order not supported"; -static char __pyx_k_8[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_9[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_12[] = "Format string allocated too short."; -static char __pyx_k_14[] = "scipy.sparse"; -static char __pyx_k_17[] = "minimum_spanning_tree"; -static char __pyx_k_18[] = "/home/bob/Code/scikit-learn/sklearn/utils/mst/_min_spanning_tree.pyx"; -static char __pyx_k_19[] = "sklearn.utils.mst._min_spanning_tree"; -static char __pyx_k_20[] = "minimum_spanning_tree (line 23)"; -static char __pyx_k_21[] = "\n minimum_spanning_tree(csgraph, overwrite=False)\n\n Return a minimum spanning tree of an undirected graph\n\n A minimum spanning tree is a graph consisting of the subset of edges\n which together connect all connected nodes, while minimizing the total\n sum of weights on the edges. This is computed using the Kruskal algorithm.\n\n .. versionadded:: 0.11.0\n\n Parameters\n ----------\n csgraph : array_like or sparse matrix, 2 dimensions\n The N x N matrix representing an undirected graph over N nodes\n (see notes below).\n overwrite : bool, optional\n if true, then parts of the input graph will be overwritten for\n efficiency.\n\n Returns\n -------\n span_tree : csr matrix\n The N x N compressed-sparse representation of the undirected minimum\n spanning tree over the input (see notes below).\n\n Notes\n -----\n This routine uses undirected graphs as input and output. That is, if\n graph[i, j] and graph[j, i] are both zero, then nodes i and j do not\n have an edge connecting them. If either is nonzero, then the two are\n connected by the minimum nonzero value of the two.\n\n Examples\n --------\n The following example shows the computation of a minimum spanning tree\n over a simple four-component graph::\n\n input graph minimum spanning tree\n\n (0) (0)\n / \\ /\n 3 8 3\n / \\ /\n (3)---5---(1) (3)---5---(1)\n \\ / /\n 6 2 2\n \\ / /\n (2) (2)\n\n It is easy to see from inspection that the minimum spanning tree involves\n removing the edges with weights 8 and 6. In compressed sparse\n representation, the solution l""ooks like this:\n\n >>> from scipy.sparse import csr_matrix\n >>> from scipy.sparse.csgraph import minimum_spanning_tree\n >>> X = csr_matrix([[0, 8, 0, 3],\n ... [0, 0, 2, 5],\n ... [0, 0, 0, 6],\n ... [0, 0, 0, 0]])\n >>> Tcsr = minimum_spanning_tree(X)\n >>> Tcsr.toarray().astype(int)\n array([[0, 0, 0, 3],\n [0, 0, 2, 5],\n [0, 0, 0, 0],\n [0, 0, 0, 0]])\n "; -static char __pyx_k__B[] = "B"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__N[] = "N"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__data[] = "data"; -static char __pyx_k__rank[] = "rank"; -static char __pyx_k__DTYPE[] = "DTYPE"; -static char __pyx_k__ITYPE[] = "ITYPE"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__int32[] = "int32"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__zeros[] = "zeros"; -static char __pyx_k__arange[] = "arange"; -static char __pyx_k__astype[] = "astype"; -static char __pyx_k__i_sort[] = "i_sort"; -static char __pyx_k__indptr[] = "indptr"; -static char __pyx_k__argsort[] = "argsort"; -static char __pyx_k__csgraph[] = "csgraph"; -static char __pyx_k__float64[] = "float64"; -static char __pyx_k__indices[] = "indices"; -static char __pyx_k__sp_tree[] = "sp_tree"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__overwrite[] = "overwrite"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__csr_matrix[] = "csr_matrix"; -static char __pyx_k__isspmatrix[] = "isspmatrix"; -static char __pyx_k__row_indices[] = "row_indices"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__dense_output[] = "dense_output"; -static char __pyx_k__predecessors[] = "predecessors"; -static char __pyx_k__copy_if_sparse[] = "copy_if_sparse"; -static char __pyx_k__isspmatrix_csc[] = "isspmatrix_csc"; -static char __pyx_k__validate_graph[] = "validate_graph"; -static char __pyx_k__eliminate_zeros[] = "eliminate_zeros"; -static char __pyx_k___graph_validation[] = "_graph_validation"; -static PyObject *__pyx_kp_u_12; -static PyObject *__pyx_n_s_14; -static PyObject *__pyx_n_s_17; -static PyObject *__pyx_kp_s_18; -static PyObject *__pyx_n_s_19; -static PyObject *__pyx_kp_u_2; -static PyObject *__pyx_kp_u_20; -static PyObject *__pyx_kp_u_21; -static PyObject *__pyx_kp_u_4; -static PyObject *__pyx_kp_u_6; -static PyObject *__pyx_kp_u_8; -static PyObject *__pyx_kp_u_9; -static PyObject *__pyx_n_s__DTYPE; -static PyObject *__pyx_n_s__ITYPE; -static PyObject *__pyx_n_s__N; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s___graph_validation; -static PyObject *__pyx_n_s__arange; -static PyObject *__pyx_n_s__argsort; -static PyObject *__pyx_n_s__astype; -static PyObject *__pyx_n_s__copy_if_sparse; -static PyObject *__pyx_n_s__csgraph; -static PyObject *__pyx_n_s__csr_matrix; -static PyObject *__pyx_n_s__data; -static PyObject *__pyx_n_s__dense_output; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__eliminate_zeros; -static PyObject *__pyx_n_s__float64; -static PyObject *__pyx_n_s__i_sort; -static PyObject *__pyx_n_s__indices; -static PyObject *__pyx_n_s__indptr; -static PyObject *__pyx_n_s__int32; -static PyObject *__pyx_n_s__isspmatrix; -static PyObject *__pyx_n_s__isspmatrix_csc; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__overwrite; -static PyObject *__pyx_n_s__predecessors; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__rank; -static PyObject *__pyx_n_s__row_indices; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__sp_tree; -static PyObject *__pyx_n_s__validate_graph; -static PyObject *__pyx_n_s__zeros; -static PyObject *__pyx_int_15; -static PyObject *__pyx_k_1; -static PyObject *__pyx_k_tuple_3; -static PyObject *__pyx_k_tuple_5; -static PyObject *__pyx_k_tuple_7; -static PyObject *__pyx_k_tuple_10; -static PyObject *__pyx_k_tuple_11; -static PyObject *__pyx_k_tuple_13; -static PyObject *__pyx_k_tuple_15; -static PyObject *__pyx_k_codeobj_16; - -/* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_3mst_18_min_spanning_tree_1minimum_spanning_tree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_3mst_18_min_spanning_tree_minimum_spanning_tree[] = "\n minimum_spanning_tree(csgraph, overwrite=False)\n\n Return a minimum spanning tree of an undirected graph\n\n A minimum spanning tree is a graph consisting of the subset of edges\n which together connect all connected nodes, while minimizing the total\n sum of weights on the edges. This is computed using the Kruskal algorithm.\n\n .. versionadded:: 0.11.0\n\n Parameters\n ----------\n csgraph : array_like or sparse matrix, 2 dimensions\n The N x N matrix representing an undirected graph over N nodes\n (see notes below).\n overwrite : bool, optional\n if true, then parts of the input graph will be overwritten for\n efficiency.\n\n Returns\n -------\n span_tree : csr matrix\n The N x N compressed-sparse representation of the undirected minimum\n spanning tree over the input (see notes below).\n\n Notes\n -----\n This routine uses undirected graphs as input and output. That is, if\n graph[i, j] and graph[j, i] are both zero, then nodes i and j do not\n have an edge connecting them. If either is nonzero, then the two are\n connected by the minimum nonzero value of the two.\n\n Examples\n --------\n The following example shows the computation of a minimum spanning tree\n over a simple four-component graph::\n\n input graph minimum spanning tree\n\n (0) (0)\n / \\ /\n 3 8 3\n / \\ /\n (3)---5---(1) (3)---5---(1)\n \\ / /\n 6 2 2\n \\ / /\n (2) (2)\n\n It is easy to see from inspection that the minimum spanning tree involves\n removing the edges with weights 8 and 6. In compressed sparse\n representation, the solution l""ooks like this:\n\n >>> from scipy.sparse import csr_matrix\n >>> from scipy.sparse.csgraph import minimum_spanning_tree\n >>> X = csr_matrix([[0, 8, 0, 3],\n ... [0, 0, 2, 5],\n ... [0, 0, 0, 6],\n ... [0, 0, 0, 0]])\n >>> Tcsr = minimum_spanning_tree(X)\n >>> Tcsr.toarray().astype(int)\n array([[0, 0, 0, 3],\n [0, 0, 2, 5],\n [0, 0, 0, 0],\n [0, 0, 0, 0]])\n "; -static PyMethodDef __pyx_mdef_7sklearn_5utils_3mst_18_min_spanning_tree_1minimum_spanning_tree = {__Pyx_NAMESTR("minimum_spanning_tree"), (PyCFunction)__pyx_pw_7sklearn_5utils_3mst_18_min_spanning_tree_1minimum_spanning_tree, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_3mst_18_min_spanning_tree_minimum_spanning_tree)}; -static PyObject *__pyx_pw_7sklearn_5utils_3mst_18_min_spanning_tree_1minimum_spanning_tree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_csgraph = 0; - PyObject *__pyx_v_overwrite = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("minimum_spanning_tree (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__csgraph,&__pyx_n_s__overwrite,0}; - PyObject* values[2] = {0,0}; - values[1] = __pyx_k_1; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__csgraph)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__overwrite); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "minimum_spanning_tree") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_csgraph = values[0]; - __pyx_v_overwrite = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("minimum_spanning_tree", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.mst._min_spanning_tree.minimum_spanning_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_3mst_18_min_spanning_tree_minimum_spanning_tree(__pyx_self, __pyx_v_csgraph, __pyx_v_overwrite); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "sklearn/utils/mst/_min_spanning_tree.pyx":23 - * - * - * def minimum_spanning_tree(csgraph, overwrite=False): # <<<<<<<<<<<<<< - * r""" - * minimum_spanning_tree(csgraph, overwrite=False) - */ - -static PyObject *__pyx_pf_7sklearn_5utils_3mst_18_min_spanning_tree_minimum_spanning_tree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_csgraph, PyObject *__pyx_v_overwrite) { - int __pyx_v_N; - PyObject *__pyx_v_data = NULL; - PyObject *__pyx_v_indices = NULL; - PyObject *__pyx_v_indptr = NULL; - PyObject *__pyx_v_rank = NULL; - PyObject *__pyx_v_predecessors = NULL; - PyObject *__pyx_v_i_sort = NULL; - PyObject *__pyx_v_row_indices = NULL; - PyObject *__pyx_v_sp_tree = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - int __pyx_t_6; - Py_ssize_t __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("minimum_spanning_tree", 0); - __Pyx_INCREF(__pyx_v_csgraph); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":93 - * global NULL_IDX - * - * csgraph = validate_graph(csgraph, True, DTYPE, dense_output=False, # <<<<<<<<<<<<<< - * copy_if_sparse=not overwrite) - * cdef int N = csgraph.shape[0] - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__validate_graph); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__DTYPE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_csgraph); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_csgraph); - __Pyx_GIVEREF(__pyx_v_csgraph); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dense_output), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":94 - * - * csgraph = validate_graph(csgraph, True, DTYPE, dense_output=False, - * copy_if_sparse=not overwrite) # <<<<<<<<<<<<<< - * cdef int N = csgraph.shape[0] - * - */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_overwrite); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__copy_if_sparse), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_v_csgraph); - __pyx_v_csgraph = __pyx_t_2; - __pyx_t_2 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":95 - * csgraph = validate_graph(csgraph, True, DTYPE, dense_output=False, - * copy_if_sparse=not overwrite) - * cdef int N = csgraph.shape[0] # <<<<<<<<<<<<<< - * - * data = csgraph.data - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_csgraph, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_N = __pyx_t_6; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":97 - * cdef int N = csgraph.shape[0] - * - * data = csgraph.data # <<<<<<<<<<<<<< - * indices = csgraph.indices - * indptr = csgraph.indptr - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_csgraph, __pyx_n_s__data); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_data = __pyx_t_3; - __pyx_t_3 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":98 - * - * data = csgraph.data - * indices = csgraph.indices # <<<<<<<<<<<<<< - * indptr = csgraph.indptr - * - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_csgraph, __pyx_n_s__indices); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_indices = __pyx_t_3; - __pyx_t_3 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":99 - * data = csgraph.data - * indices = csgraph.indices - * indptr = csgraph.indptr # <<<<<<<<<<<<<< - * - * rank = np.zeros(N, dtype=ITYPE) - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_csgraph, __pyx_n_s__indptr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_indptr = __pyx_t_3; - __pyx_t_3 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":101 - * indptr = csgraph.indptr - * - * rank = np.zeros(N, dtype=ITYPE) # <<<<<<<<<<<<<< - * predecessors = np.arange(N, dtype=ITYPE) - * - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ITYPE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_rank = __pyx_t_1; - __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":102 - * - * rank = np.zeros(N, dtype=ITYPE) - * predecessors = np.arange(N, dtype=ITYPE) # <<<<<<<<<<<<<< - * - * i_sort = np.argsort(data).astype(ITYPE) - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__arange); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__ITYPE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_predecessors = __pyx_t_2; - __pyx_t_2 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":104 - * predecessors = np.arange(N, dtype=ITYPE) - * - * i_sort = np.argsort(data).astype(ITYPE) # <<<<<<<<<<<<<< - * row_indices = np.zeros(len(data), dtype=ITYPE) - * - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__argsort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_data); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data); - __Pyx_GIVEREF(__pyx_v_data); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__astype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__ITYPE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_i_sort = __pyx_t_4; - __pyx_t_4 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":105 - * - * i_sort = np.argsort(data).astype(ITYPE) - * row_indices = np.zeros(len(data), dtype=ITYPE) # <<<<<<<<<<<<<< - * - * _min_spanning_tree(data, indices, indptr, i_sort, - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ITYPE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_v_row_indices = __pyx_t_3; - __pyx_t_3 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":107 - * row_indices = np.zeros(len(data), dtype=ITYPE) - * - * _min_spanning_tree(data, indices, indptr, i_sort, # <<<<<<<<<<<<<< - * row_indices, predecessors, rank) - * - */ - if (!(likely(((__pyx_v_data) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_data, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_v_data; - __Pyx_INCREF(__pyx_t_3); - if (!(likely(((__pyx_v_indices) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_indices, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = __pyx_v_indices; - __Pyx_INCREF(__pyx_t_4); - if (!(likely(((__pyx_v_indptr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_indptr, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __pyx_v_indptr; - __Pyx_INCREF(__pyx_t_2); - if (!(likely(((__pyx_v_i_sort) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_i_sort, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __pyx_v_i_sort; - __Pyx_INCREF(__pyx_t_1); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":108 - * - * _min_spanning_tree(data, indices, indptr, i_sort, - * row_indices, predecessors, rank) # <<<<<<<<<<<<<< - * - * sp_tree = csr_matrix((data, indices, indptr), (N, N)) - */ - if (!(likely(((__pyx_v_row_indices) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_row_indices, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = __pyx_v_row_indices; - __Pyx_INCREF(__pyx_t_8); - if (!(likely(((__pyx_v_predecessors) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_predecessors, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = __pyx_v_predecessors; - __Pyx_INCREF(__pyx_t_9); - if (!(likely(((__pyx_v_rank) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_rank, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = __pyx_v_rank; - __Pyx_INCREF(__pyx_t_10); - __pyx_t_11 = __pyx_f_7sklearn_5utils_3mst_18_min_spanning_tree__min_spanning_tree(((PyArrayObject *)__pyx_t_3), ((PyArrayObject *)__pyx_t_4), ((PyArrayObject *)__pyx_t_2), ((PyArrayObject *)__pyx_t_1), ((PyArrayObject *)__pyx_t_8), ((PyArrayObject *)__pyx_t_9), ((PyArrayObject *)__pyx_t_10)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":110 - * row_indices, predecessors, rank) - * - * sp_tree = csr_matrix((data, indices, indptr), (N, N)) # <<<<<<<<<<<<<< - * sp_tree.eliminate_zeros() - * - */ - __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__csr_matrix); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_data); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_data); - __Pyx_GIVEREF(__pyx_v_data); - __Pyx_INCREF(__pyx_v_indices); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_indices); - __Pyx_GIVEREF(__pyx_v_indices); - __Pyx_INCREF(__pyx_v_indptr); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_indptr); - __Pyx_GIVEREF(__pyx_v_indptr); - __pyx_t_9 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_9 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); - PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_10 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __pyx_v_sp_tree = __pyx_t_1; - __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":111 - * - * sp_tree = csr_matrix((data, indices, indptr), (N, N)) - * sp_tree.eliminate_zeros() # <<<<<<<<<<<<<< - * - * return sp_tree - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sp_tree, __pyx_n_s__eliminate_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":113 - * sp_tree.eliminate_zeros() - * - * return sp_tree # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_sp_tree); - __pyx_r = __pyx_v_sp_tree; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("sklearn.utils.mst._min_spanning_tree.minimum_spanning_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_data); - __Pyx_XDECREF(__pyx_v_indices); - __Pyx_XDECREF(__pyx_v_indptr); - __Pyx_XDECREF(__pyx_v_rank); - __Pyx_XDECREF(__pyx_v_predecessors); - __Pyx_XDECREF(__pyx_v_i_sort); - __Pyx_XDECREF(__pyx_v_row_indices); - __Pyx_XDECREF(__pyx_v_sp_tree); - __Pyx_XDECREF(__pyx_v_csgraph); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "sklearn/utils/mst/_min_spanning_tree.pyx":116 - * - * - * cdef _min_spanning_tree(np.ndarray[DTYPE_t, ndim=1, mode='c'] data, # <<<<<<<<<<<<<< - * np.ndarray[ITYPE_t, ndim=1, mode='c'] col_indices, - * np.ndarray[ITYPE_t, ndim=1, mode='c'] indptr, - */ - -static PyObject *__pyx_f_7sklearn_5utils_3mst_18_min_spanning_tree__min_spanning_tree(PyArrayObject *__pyx_v_data, PyArrayObject *__pyx_v_col_indices, PyArrayObject *__pyx_v_indptr, PyArrayObject *__pyx_v_i_sort, PyArrayObject *__pyx_v_row_indices, PyArrayObject *__pyx_v_predecessors, PyArrayObject *__pyx_v_rank) { - unsigned int __pyx_v_i; - unsigned int __pyx_v_j; - unsigned int __pyx_v_V1; - unsigned int __pyx_v_V2; - unsigned int __pyx_v_R1; - unsigned int __pyx_v_R2; - unsigned int __pyx_v_n_edges_in_mst; - unsigned int __pyx_v_n_verts; - CYTHON_UNUSED __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t __pyx_v_E; - __Pyx_LocalBuf_ND __pyx_pybuffernd_col_indices; - __Pyx_Buffer __pyx_pybuffer_col_indices; - __Pyx_LocalBuf_ND __pyx_pybuffernd_data; - __Pyx_Buffer __pyx_pybuffer_data; - __Pyx_LocalBuf_ND __pyx_pybuffernd_i_sort; - __Pyx_Buffer __pyx_pybuffer_i_sort; - __Pyx_LocalBuf_ND __pyx_pybuffernd_indptr; - __Pyx_Buffer __pyx_pybuffer_indptr; - __Pyx_LocalBuf_ND __pyx_pybuffernd_predecessors; - __Pyx_Buffer __pyx_pybuffer_predecessors; - __Pyx_LocalBuf_ND __pyx_pybuffernd_rank; - __Pyx_Buffer __pyx_pybuffer_rank; - __Pyx_LocalBuf_ND __pyx_pybuffernd_row_indices; - __Pyx_Buffer __pyx_pybuffer_row_indices; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - unsigned int __pyx_t_1; - unsigned int __pyx_t_2; - int __pyx_t_3; - long __pyx_t_4; - __pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t __pyx_t_5; - unsigned int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - unsigned int __pyx_t_10; - unsigned int __pyx_t_11; - unsigned int __pyx_t_12; - unsigned int __pyx_t_13; - unsigned int __pyx_t_14; - unsigned int __pyx_t_15; - unsigned int __pyx_t_16; - unsigned int __pyx_t_17; - unsigned int __pyx_t_18; - unsigned int __pyx_t_19; - unsigned int __pyx_t_20; - unsigned int __pyx_t_21; - unsigned int __pyx_t_22; - unsigned int __pyx_t_23; - unsigned int __pyx_t_24; - unsigned int __pyx_t_25; - unsigned int __pyx_t_26; - unsigned int __pyx_t_27; - unsigned int __pyx_t_28; - unsigned int __pyx_t_29; - unsigned int __pyx_t_30; - unsigned int __pyx_t_31; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_min_spanning_tree", 0); - __pyx_pybuffer_data.pybuffer.buf = NULL; - __pyx_pybuffer_data.refcount = 0; - __pyx_pybuffernd_data.data = NULL; - __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data; - __pyx_pybuffer_col_indices.pybuffer.buf = NULL; - __pyx_pybuffer_col_indices.refcount = 0; - __pyx_pybuffernd_col_indices.data = NULL; - __pyx_pybuffernd_col_indices.rcbuffer = &__pyx_pybuffer_col_indices; - __pyx_pybuffer_indptr.pybuffer.buf = NULL; - __pyx_pybuffer_indptr.refcount = 0; - __pyx_pybuffernd_indptr.data = NULL; - __pyx_pybuffernd_indptr.rcbuffer = &__pyx_pybuffer_indptr; - __pyx_pybuffer_i_sort.pybuffer.buf = NULL; - __pyx_pybuffer_i_sort.refcount = 0; - __pyx_pybuffernd_i_sort.data = NULL; - __pyx_pybuffernd_i_sort.rcbuffer = &__pyx_pybuffer_i_sort; - __pyx_pybuffer_row_indices.pybuffer.buf = NULL; - __pyx_pybuffer_row_indices.refcount = 0; - __pyx_pybuffernd_row_indices.data = NULL; - __pyx_pybuffernd_row_indices.rcbuffer = &__pyx_pybuffer_row_indices; - __pyx_pybuffer_predecessors.pybuffer.buf = NULL; - __pyx_pybuffer_predecessors.refcount = 0; - __pyx_pybuffernd_predecessors.data = NULL; - __pyx_pybuffernd_predecessors.rcbuffer = &__pyx_pybuffer_predecessors; - __pyx_pybuffer_rank.pybuffer.buf = NULL; - __pyx_pybuffer_rank.refcount = 0; - __pyx_pybuffernd_rank.data = NULL; - __pyx_pybuffernd_rank.rcbuffer = &__pyx_pybuffer_rank; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_col_indices.rcbuffer->pybuffer, (PyObject*)__pyx_v_col_indices, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_col_indices.diminfo[0].strides = __pyx_pybuffernd_col_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_col_indices.diminfo[0].shape = __pyx_pybuffernd_col_indices.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_indptr.rcbuffer->pybuffer, (PyObject*)__pyx_v_indptr, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_indptr.diminfo[0].strides = __pyx_pybuffernd_indptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_indptr.diminfo[0].shape = __pyx_pybuffernd_indptr.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_i_sort.rcbuffer->pybuffer, (PyObject*)__pyx_v_i_sort, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_i_sort.diminfo[0].strides = __pyx_pybuffernd_i_sort.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_i_sort.diminfo[0].shape = __pyx_pybuffernd_i_sort.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_indices.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_indices, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_row_indices.diminfo[0].strides = __pyx_pybuffernd_row_indices.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_indices.diminfo[0].shape = __pyx_pybuffernd_row_indices.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_predecessors.rcbuffer->pybuffer, (PyObject*)__pyx_v_predecessors, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_predecessors.diminfo[0].strides = __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_predecessors.diminfo[0].shape = __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_rank.rcbuffer->pybuffer, (PyObject*)__pyx_v_rank, &__Pyx_TypeInfo_nn___pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_pybuffernd_rank.diminfo[0].strides = __pyx_pybuffernd_rank.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_rank.diminfo[0].shape = __pyx_pybuffernd_rank.rcbuffer->pybuffer.shape[0]; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":128 - * cdef unsigned int i, j, V1, V2, R1, R2, n_edges_in_mst, n_verts - * cdef DTYPE_t E - * n_verts = predecessors.shape[0] # <<<<<<<<<<<<<< - * - * # Arrange `row_indices` to contain the row index of each value in `data`. - */ - __pyx_v_n_verts = (__pyx_v_predecessors->dimensions[0]); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":132 - * # Arrange `row_indices` to contain the row index of each value in `data`. - * # Note that the array `col_indices` already contains the column index. - * for i from 0 <= i < n_verts: # <<<<<<<<<<<<<< - * for j from indptr[i] <= j < indptr[i + 1]: - * row_indices[j] = i - */ - __pyx_t_1 = __pyx_v_n_verts; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":133 - * # Note that the array `col_indices` already contains the column index. - * for i from 0 <= i < n_verts: - * for j from indptr[i] <= j < indptr[i + 1]: # <<<<<<<<<<<<<< - * row_indices[j] = i - * - */ - __pyx_t_2 = __pyx_v_i; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_2 >= (size_t)__pyx_pybuffernd_indptr.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = (__pyx_v_i + 1); - __pyx_t_3 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_pybuffernd_indptr.diminfo[0].shape; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_3 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_pybuffernd_indptr.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_indptr.rcbuffer->pybuffer.buf, __pyx_t_4, __pyx_pybuffernd_indptr.diminfo[0].strides)); - for (__pyx_v_j = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_indptr.rcbuffer->pybuffer.buf, __pyx_t_2, __pyx_pybuffernd_indptr.diminfo[0].strides)); __pyx_v_j < __pyx_t_5; __pyx_v_j++) { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":134 - * for i from 0 <= i < n_verts: - * for j from indptr[i] <= j < indptr[i + 1]: - * row_indices[j] = i # <<<<<<<<<<<<<< - * - * # step through the edges from smallest to largest. - */ - __pyx_t_6 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_6 >= (size_t)__pyx_pybuffernd_row_indices.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_row_indices.rcbuffer->pybuffer.buf, __pyx_t_6, __pyx_pybuffernd_row_indices.diminfo[0].strides) = __pyx_v_i; - } - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":138 - * # step through the edges from smallest to largest. - * # V1 and V2 are the vertices, and E is the edge weight connecting them. - * n_edges_in_mst = 0 # <<<<<<<<<<<<<< - * i = 0 - * while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: - */ - __pyx_v_n_edges_in_mst = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":139 - * # V1 and V2 are the vertices, and E is the edge weight connecting them. - * n_edges_in_mst = 0 - * i = 0 # <<<<<<<<<<<<<< - * while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: - * j = i_sort[i] - */ - __pyx_v_i = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":140 - * n_edges_in_mst = 0 - * i = 0 - * while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: # <<<<<<<<<<<<<< - * j = i_sort[i] - * V1 = row_indices[j] - */ - while (1) { - __pyx_t_7 = (__pyx_v_i < (__pyx_v_i_sort->dimensions[0])); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_n_edges_in_mst < (__pyx_v_n_verts - 1)); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":141 - * i = 0 - * while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: - * j = i_sort[i] # <<<<<<<<<<<<<< - * V1 = row_indices[j] - * V2 = col_indices[j] - */ - __pyx_t_1 = __pyx_v_i; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_1 >= (size_t)__pyx_pybuffernd_i_sort.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_j = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_i_sort.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_i_sort.diminfo[0].strides)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":142 - * while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: - * j = i_sort[i] - * V1 = row_indices[j] # <<<<<<<<<<<<<< - * V2 = col_indices[j] - * E = data[j] - */ - __pyx_t_10 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_10 >= (size_t)__pyx_pybuffernd_row_indices.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_V1 = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_row_indices.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_row_indices.diminfo[0].strides)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":143 - * j = i_sort[i] - * V1 = row_indices[j] - * V2 = col_indices[j] # <<<<<<<<<<<<<< - * E = data[j] - * - */ - __pyx_t_11 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_11 >= (size_t)__pyx_pybuffernd_col_indices.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_V2 = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_col_indices.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_col_indices.diminfo[0].strides)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":144 - * V1 = row_indices[j] - * V2 = col_indices[j] - * E = data[j] # <<<<<<<<<<<<<< - * - * # progress upward to the head node of each subtree - */ - __pyx_t_12 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_12 >= (size_t)__pyx_pybuffernd_data.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_E = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_data.diminfo[0].strides)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":147 - * - * # progress upward to the head node of each subtree - * R1 = V1 # <<<<<<<<<<<<<< - * while predecessors[R1] != R1: - * R1 = predecessors[R1] - */ - __pyx_v_R1 = __pyx_v_V1; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":148 - * # progress upward to the head node of each subtree - * R1 = V1 - * while predecessors[R1] != R1: # <<<<<<<<<<<<<< - * R1 = predecessors[R1] - * R2 = V2 - */ - while (1) { - __pyx_t_13 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_13 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_predecessors.diminfo[0].strides)) != __pyx_v_R1); - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":149 - * R1 = V1 - * while predecessors[R1] != R1: - * R1 = predecessors[R1] # <<<<<<<<<<<<<< - * R2 = V2 - * while predecessors[R2] != R2: - */ - __pyx_t_14 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_14 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_R1 = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_predecessors.diminfo[0].strides)); - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":150 - * while predecessors[R1] != R1: - * R1 = predecessors[R1] - * R2 = V2 # <<<<<<<<<<<<<< - * while predecessors[R2] != R2: - * R2 = predecessors[R2] - */ - __pyx_v_R2 = __pyx_v_V2; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":151 - * R1 = predecessors[R1] - * R2 = V2 - * while predecessors[R2] != R2: # <<<<<<<<<<<<<< - * R2 = predecessors[R2] - * - */ - while (1) { - __pyx_t_15 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_15 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_predecessors.diminfo[0].strides)) != __pyx_v_R2); - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":152 - * R2 = V2 - * while predecessors[R2] != R2: - * R2 = predecessors[R2] # <<<<<<<<<<<<<< - * - * # Compress both paths. - */ - __pyx_t_16 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_16 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_R2 = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_predecessors.diminfo[0].strides)); - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":155 - * - * # Compress both paths. - * while predecessors[V1] != R1: # <<<<<<<<<<<<<< - * predecessors[V1] = R1 - * while predecessors[V2] != R2: - */ - while (1) { - __pyx_t_17 = __pyx_v_V1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_17 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_predecessors.diminfo[0].strides)) != __pyx_v_R1); - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":156 - * # Compress both paths. - * while predecessors[V1] != R1: - * predecessors[V1] = R1 # <<<<<<<<<<<<<< - * while predecessors[V2] != R2: - * predecessors[V2] = R2 - */ - __pyx_t_18 = __pyx_v_V1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_18 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_predecessors.diminfo[0].strides) = __pyx_v_R1; - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":157 - * while predecessors[V1] != R1: - * predecessors[V1] = R1 - * while predecessors[V2] != R2: # <<<<<<<<<<<<<< - * predecessors[V2] = R2 - * - */ - while (1) { - __pyx_t_19 = __pyx_v_V2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_19 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_predecessors.diminfo[0].strides)) != __pyx_v_R2); - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":158 - * predecessors[V1] = R1 - * while predecessors[V2] != R2: - * predecessors[V2] = R2 # <<<<<<<<<<<<<< - * - * # if the subtrees are different, then we connect them and keep the - */ - __pyx_t_20 = __pyx_v_V2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_20 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_predecessors.diminfo[0].strides) = __pyx_v_R2; - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":163 - * # edge. Otherwise, we remove the edge: it duplicates one already - * # in the spanning tree. - * if R1 != R2: # <<<<<<<<<<<<<< - * n_edges_in_mst += 1 - * - */ - __pyx_t_9 = (__pyx_v_R1 != __pyx_v_R2); - if (__pyx_t_9) { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":164 - * # in the spanning tree. - * if R1 != R2: - * n_edges_in_mst += 1 # <<<<<<<<<<<<<< - * - * # Use approximate (because of path-compression) rank to try - */ - __pyx_v_n_edges_in_mst = (__pyx_v_n_edges_in_mst + 1); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":168 - * # Use approximate (because of path-compression) rank to try - * # to keep balanced trees. - * if rank[R1] > rank[R2]: # <<<<<<<<<<<<<< - * predecessors[R2] = R1 - * elif rank[R1] < rank[R2]: - */ - __pyx_t_21 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_21 >= (size_t)__pyx_pybuffernd_rank.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_22 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_22 >= (size_t)__pyx_pybuffernd_rank.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_rank.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_rank.diminfo[0].strides)) > (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_rank.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_rank.diminfo[0].strides))); - if (__pyx_t_9) { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":169 - * # to keep balanced trees. - * if rank[R1] > rank[R2]: - * predecessors[R2] = R1 # <<<<<<<<<<<<<< - * elif rank[R1] < rank[R2]: - * predecessors[R1] = R2 - */ - __pyx_t_23 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_23 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_predecessors.diminfo[0].strides) = __pyx_v_R1; - goto __pyx_L18; - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":170 - * if rank[R1] > rank[R2]: - * predecessors[R2] = R1 - * elif rank[R1] < rank[R2]: # <<<<<<<<<<<<<< - * predecessors[R1] = R2 - * else: - */ - __pyx_t_24 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_24 >= (size_t)__pyx_pybuffernd_rank.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_25 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_25 >= (size_t)__pyx_pybuffernd_rank.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = ((*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_rank.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_rank.diminfo[0].strides)) < (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_rank.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_rank.diminfo[0].strides))); - if (__pyx_t_9) { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":171 - * predecessors[R2] = R1 - * elif rank[R1] < rank[R2]: - * predecessors[R1] = R2 # <<<<<<<<<<<<<< - * else: - * predecessors[R2] = R1 - */ - __pyx_t_26 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_26 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_predecessors.diminfo[0].strides) = __pyx_v_R2; - goto __pyx_L18; - } - /*else*/ { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":173 - * predecessors[R1] = R2 - * else: - * predecessors[R2] = R1 # <<<<<<<<<<<<<< - * rank[R1] += 1 - * else: - */ - __pyx_t_27 = __pyx_v_R2; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_27 >= (size_t)__pyx_pybuffernd_predecessors.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_predecessors.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_predecessors.diminfo[0].strides) = __pyx_v_R1; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":174 - * else: - * predecessors[R2] = R1 - * rank[R1] += 1 # <<<<<<<<<<<<<< - * else: - * data[j] = 0 - */ - __pyx_t_28 = __pyx_v_R1; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_28 >= (size_t)__pyx_pybuffernd_rank.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_rank.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_rank.diminfo[0].strides) += 1; - } - __pyx_L18:; - goto __pyx_L17; - } - /*else*/ { - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":176 - * rank[R1] += 1 - * else: - * data[j] = 0 # <<<<<<<<<<<<<< - * - * i += 1 - */ - __pyx_t_29 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_29 >= (size_t)__pyx_pybuffernd_data.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_29, __pyx_pybuffernd_data.diminfo[0].strides) = 0.0; - } - __pyx_L17:; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":178 - * data[j] = 0 - * - * i += 1 # <<<<<<<<<<<<<< - * - * # We may have stopped early if we found a full-sized MST so zero out the rest - */ - __pyx_v_i = (__pyx_v_i + 1); - } - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":181 - * - * # We may have stopped early if we found a full-sized MST so zero out the rest - * while i < i_sort.shape[0]: # <<<<<<<<<<<<<< - * j = i_sort[i] - * data[j] = 0 - */ - while (1) { - __pyx_t_9 = (__pyx_v_i < (__pyx_v_i_sort->dimensions[0])); - if (!__pyx_t_9) break; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":182 - * # We may have stopped early if we found a full-sized MST so zero out the rest - * while i < i_sort.shape[0]: - * j = i_sort[i] # <<<<<<<<<<<<<< - * data[j] = 0 - * i += 1 - */ - __pyx_t_30 = __pyx_v_i; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_30 >= (size_t)__pyx_pybuffernd_i_sort.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_j = (*__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_ITYPE_t *, __pyx_pybuffernd_i_sort.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_i_sort.diminfo[0].strides)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":183 - * while i < i_sort.shape[0]: - * j = i_sort[i] - * data[j] = 0 # <<<<<<<<<<<<<< - * i += 1 - * - */ - __pyx_t_31 = __pyx_v_j; - __pyx_t_3 = -1; - if (unlikely(__pyx_t_31 >= (size_t)__pyx_pybuffernd_data.diminfo[0].shape)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrCContig1d(__pyx_t_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_data.diminfo[0].strides) = 0.0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":184 - * j = i_sort[i] - * data[j] = 0 - * i += 1 # <<<<<<<<<<<<<< - * - */ - __pyx_v_i = (__pyx_v_i + 1); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_col_indices.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_i_sort.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_indptr.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_predecessors.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rank.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_indices.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.utils.mst._min_spanning_tree._min_spanning_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_col_indices.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_i_sort.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_indptr.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_predecessors.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_rank.rcbuffer->pybuffer); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_indices.rcbuffer->pybuffer); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); - __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":194 - * # experimental exception made for __getbuffer__ and __releasebuffer__ - * # -- the details of this may change. - * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fullfill the PEP. - */ - -static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_v_copy_shape; - int __pyx_v_i; - int __pyx_v_ndim; - int __pyx_v_endian_detector; - int __pyx_v_little_endian; - int __pyx_v_t; - char *__pyx_v_f; - PyArray_Descr *__pyx_v_descr = 0; - int __pyx_v_offset; - int __pyx_v_hasfields; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - char *__pyx_t_9; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getbuffer__", 0); - if (__pyx_v_info != NULL) { - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); - } - - /* "numpy.pxd":200 - * # of flags - * - * if info == NULL: return # <<<<<<<<<<<<<< - * - * cdef int copy_shape, i, ndim - */ - __pyx_t_1 = (__pyx_v_info == NULL); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "numpy.pxd":203 - * - * cdef int copy_shape, i, ndim - * cdef int endian_detector = 1 # <<<<<<<<<<<<<< - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * - */ - __pyx_v_endian_detector = 1; - - /* "numpy.pxd":204 - * cdef int copy_shape, i, ndim - * cdef int endian_detector = 1 - * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< - * - * ndim = PyArray_NDIM(self) - */ - __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - - /* "numpy.pxd":206 - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * - * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - */ - __pyx_v_ndim = PyArray_NDIM(__pyx_v_self); - - /* "numpy.pxd":208 - * ndim = PyArray_NDIM(self) - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< - * copy_shape = 1 - * else: - */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); - if (__pyx_t_1) { - - /* "numpy.pxd":209 - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * copy_shape = 1 # <<<<<<<<<<<<<< - * else: - * copy_shape = 0 - */ - __pyx_v_copy_shape = 1; - goto __pyx_L4; - } - /*else*/ { - - /* "numpy.pxd":211 - * copy_shape = 1 - * else: - * copy_shape = 0 # <<<<<<<<<<<<<< - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - */ - __pyx_v_copy_shape = 0; - } - __pyx_L4:; - - /* "numpy.pxd":213 - * copy_shape = 0 - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS); - if (__pyx_t_1) { - - /* "numpy.pxd":214 - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not C contiguous") - * - */ - __pyx_t_2 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS)); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "numpy.pxd":215 - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; - - /* "numpy.pxd":217 - * raise ValueError(u"ndarray is not C contiguous") - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") - */ - __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS); - if (__pyx_t_3) { - - /* "numpy.pxd":218 - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not Fortran contiguous") - * - */ - __pyx_t_1 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS)); - __pyx_t_2 = __pyx_t_1; - } else { - __pyx_t_2 = __pyx_t_3; - } - if (__pyx_t_2) { - - /* "numpy.pxd":219 - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< - * - * info.buf = PyArray_DATA(self) - */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; - } - __pyx_L6:; - - /* "numpy.pxd":221 - * raise ValueError(u"ndarray is not Fortran contiguous") - * - * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< - * info.ndim = ndim - * if copy_shape: - */ - __pyx_v_info->buf = PyArray_DATA(__pyx_v_self); - - /* "numpy.pxd":222 - * - * info.buf = PyArray_DATA(self) - * info.ndim = ndim # <<<<<<<<<<<<<< - * if copy_shape: - * # Allocate new buffer for strides and shape info. - */ - __pyx_v_info->ndim = __pyx_v_ndim; - - /* "numpy.pxd":223 - * info.buf = PyArray_DATA(self) - * info.ndim = ndim - * if copy_shape: # <<<<<<<<<<<<<< - * # Allocate new buffer for strides and shape info. - * # This is allocated as one block, strides first. - */ - if (__pyx_v_copy_shape) { - - /* "numpy.pxd":226 - * # Allocate new buffer for strides and shape info. - * # This is allocated as one block, strides first. - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< - * info.shape = info.strides + ndim - * for i in range(ndim): - */ - __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2))); - - /* "numpy.pxd":227 - * # This is allocated as one block, strides first. - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) - * info.shape = info.strides + ndim # <<<<<<<<<<<<<< - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] - */ - __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); - - /* "numpy.pxd":228 - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) - * info.shape = info.strides + ndim - * for i in range(ndim): # <<<<<<<<<<<<<< - * info.strides[i] = PyArray_STRIDES(self)[i] - * info.shape[i] = PyArray_DIMS(self)[i] - */ - __pyx_t_5 = __pyx_v_ndim; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; - - /* "numpy.pxd":229 - * info.shape = info.strides + ndim - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< - * info.shape[i] = PyArray_DIMS(self)[i] - * else: - */ - (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]); - - /* "numpy.pxd":230 - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] - * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< - * else: - * info.strides = PyArray_STRIDES(self) - */ - (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]); - } - goto __pyx_L7; - } - /*else*/ { - - /* "numpy.pxd":232 - * info.shape[i] = PyArray_DIMS(self)[i] - * else: - * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL - */ - __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self)); - - /* "numpy.pxd":233 - * else: - * info.strides = PyArray_STRIDES(self) - * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) - */ - __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self)); - } - __pyx_L7:; - - /* "numpy.pxd":234 - * info.strides = PyArray_STRIDES(self) - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.itemsize = PyArray_ITEMSIZE(self) - * info.readonly = not PyArray_ISWRITEABLE(self) - */ - __pyx_v_info->suboffsets = NULL; - - /* "numpy.pxd":235 - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< - * info.readonly = not PyArray_ISWRITEABLE(self) - * - */ - __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self); - - /* "numpy.pxd":236 - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) - * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< - * - * cdef int t - */ - __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(__pyx_v_self)); - - /* "numpy.pxd":239 - * - * cdef int t - * cdef char* f = NULL # <<<<<<<<<<<<<< - * cdef dtype descr = self.descr - * cdef list stack - */ - __pyx_v_f = NULL; - - /* "numpy.pxd":240 - * cdef int t - * cdef char* f = NULL - * cdef dtype descr = self.descr # <<<<<<<<<<<<<< - * cdef list stack - * cdef int offset - */ - __pyx_t_4 = ((PyObject *)__pyx_v_self->descr); - __Pyx_INCREF(__pyx_t_4); - __pyx_v_descr = ((PyArray_Descr *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "numpy.pxd":244 - * cdef int offset - * - * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< - * - * if not hasfields and not copy_shape: - */ - __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); - - /* "numpy.pxd":246 - * cdef bint hasfields = PyDataType_HASFIELDS(descr) - * - * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< - * # do not call releasebuffer - * info.obj = None - */ - __pyx_t_2 = (!__pyx_v_hasfields); - if (__pyx_t_2) { - __pyx_t_3 = (!__pyx_v_copy_shape); - __pyx_t_1 = __pyx_t_3; - } else { - __pyx_t_1 = __pyx_t_2; - } - if (__pyx_t_1) { - - /* "numpy.pxd":248 - * if not hasfields and not copy_shape: - * # do not call releasebuffer - * info.obj = None # <<<<<<<<<<<<<< - * else: - * # need to call releasebuffer - */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = Py_None; - goto __pyx_L10; - } - /*else*/ { - - /* "numpy.pxd":251 - * else: - * # need to call releasebuffer - * info.obj = self # <<<<<<<<<<<<<< - * - * if not hasfields: - */ - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = ((PyObject *)__pyx_v_self); - } - __pyx_L10:; - - /* "numpy.pxd":253 - * info.obj = self - * - * if not hasfields: # <<<<<<<<<<<<<< - * t = descr.type_num - * if ((descr.byteorder == c'>' and little_endian) or - */ - __pyx_t_1 = (!__pyx_v_hasfields); - if (__pyx_t_1) { - - /* "numpy.pxd":254 - * - * if not hasfields: - * t = descr.type_num # <<<<<<<<<<<<<< - * if ((descr.byteorder == c'>' and little_endian) or - * (descr.byteorder == c'<' and not little_endian)): - */ - __pyx_t_5 = __pyx_v_descr->type_num; - __pyx_v_t = __pyx_t_5; - - /* "numpy.pxd":255 - * if not hasfields: - * t = descr.type_num - * if ((descr.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< - * (descr.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '>'); - if (__pyx_t_1) { - __pyx_t_2 = __pyx_v_little_endian; - } else { - __pyx_t_2 = __pyx_t_1; - } - if (!__pyx_t_2) { - - /* "numpy.pxd":256 - * t = descr.type_num - * if ((descr.byteorder == c'>' and little_endian) or - * (descr.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" - */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '<'); - if (__pyx_t_1) { - __pyx_t_3 = (!__pyx_v_little_endian); - __pyx_t_7 = __pyx_t_3; - } else { - __pyx_t_7 = __pyx_t_1; - } - __pyx_t_1 = __pyx_t_7; - } else { - __pyx_t_1 = __pyx_t_2; - } - if (__pyx_t_1) { - - /* "numpy.pxd":257 - * if ((descr.byteorder == c'>' and little_endian) or - * (descr.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" - */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; - } - __pyx_L12:; - - /* "numpy.pxd":258 - * (descr.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" - */ - __pyx_t_1 = (__pyx_v_t == NPY_BYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__b; - goto __pyx_L13; - } - - /* "numpy.pxd":259 - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" - */ - __pyx_t_1 = (__pyx_v_t == NPY_UBYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__B; - goto __pyx_L13; - } - - /* "numpy.pxd":260 - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" - */ - __pyx_t_1 = (__pyx_v_t == NPY_SHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__h; - goto __pyx_L13; - } - - /* "numpy.pxd":261 - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" - */ - __pyx_t_1 = (__pyx_v_t == NPY_USHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__H; - goto __pyx_L13; - } - - /* "numpy.pxd":262 - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" - */ - __pyx_t_1 = (__pyx_v_t == NPY_INT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__i; - goto __pyx_L13; - } - - /* "numpy.pxd":263 - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" - */ - __pyx_t_1 = (__pyx_v_t == NPY_UINT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__I; - goto __pyx_L13; - } - - /* "numpy.pxd":264 - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__l; - goto __pyx_L13; - } - - /* "numpy.pxd":265 - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" - */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__L; - goto __pyx_L13; - } - - /* "numpy.pxd":266 - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__q; - goto __pyx_L13; - } - - /* "numpy.pxd":267 - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" - */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Q; - goto __pyx_L13; - } - - /* "numpy.pxd":268 - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" - */ - __pyx_t_1 = (__pyx_v_t == NPY_FLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__f; - goto __pyx_L13; - } - - /* "numpy.pxd":269 - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" - */ - __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__d; - goto __pyx_L13; - } - - /* "numpy.pxd":270 - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__g; - goto __pyx_L13; - } - - /* "numpy.pxd":271 - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" - */ - __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zf; - goto __pyx_L13; - } - - /* "numpy.pxd":272 - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< - * elif t == NPY_CLONGDOUBLE: f = "Zg" - * elif t == NPY_OBJECT: f = "O" - */ - __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zd; - goto __pyx_L13; - } - - /* "numpy.pxd":273 - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< - * elif t == NPY_OBJECT: f = "O" - * else: - */ - __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zg; - goto __pyx_L13; - } - - /* "numpy.pxd":274 - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" - * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - */ - __pyx_t_1 = (__pyx_v_t == NPY_OBJECT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__O; - goto __pyx_L13; - } - /*else*/ { - - /* "numpy.pxd":276 - * elif t == NPY_OBJECT: f = "O" - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< - * info.format = f - * return - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_8), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_8)); - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L13:; - - /* "numpy.pxd":277 - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * info.format = f # <<<<<<<<<<<<<< - * return - * else: - */ - __pyx_v_info->format = __pyx_v_f; - - /* "numpy.pxd":278 - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * info.format = f - * return # <<<<<<<<<<<<<< - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L11; - } - /*else*/ { - - /* "numpy.pxd":280 - * return - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< - * info.format[0] = c'^' # Native data types, manual alignment - * offset = 0 - */ - __pyx_v_info->format = ((char *)malloc(255)); - - /* "numpy.pxd":281 - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) - * info.format[0] = c'^' # Native data types, manual alignment # <<<<<<<<<<<<<< - * offset = 0 - * f = _util_dtypestring(descr, info.format + 1, - */ - (__pyx_v_info->format[0]) = '^'; - - /* "numpy.pxd":282 - * info.format = stdlib.malloc(_buffer_format_string_len) - * info.format[0] = c'^' # Native data types, manual alignment - * offset = 0 # <<<<<<<<<<<<<< - * f = _util_dtypestring(descr, info.format + 1, - * info.format + _buffer_format_string_len, - */ - __pyx_v_offset = 0; - - /* "numpy.pxd":285 - * f = _util_dtypestring(descr, info.format + 1, - * info.format + _buffer_format_string_len, - * &offset) # <<<<<<<<<<<<<< - * f[0] = c'\0' # Terminate format string - * - */ - __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_9; - - /* "numpy.pxd":286 - * info.format + _buffer_format_string_len, - * &offset) - * f[0] = c'\0' # Terminate format string # <<<<<<<<<<<<<< - * - * def __releasebuffer__(ndarray self, Py_buffer* info): - */ - (__pyx_v_f[0]) = '\x00'; - } - __pyx_L11:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL; - } - goto __pyx_L2; - __pyx_L0:; - if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(Py_None); - __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; - } - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_descr); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ -static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); - __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); - __Pyx_RefNannyFinishContext(); -} - -/* "numpy.pxd":288 - * f[0] = c'\0' # Terminate format string - * - * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - */ - -static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__releasebuffer__", 0); - - /* "numpy.pxd":289 - * - * def __releasebuffer__(ndarray self, Py_buffer* info): - * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - */ - __pyx_t_1 = PyArray_HASFIELDS(__pyx_v_self); - if (__pyx_t_1) { - - /* "numpy.pxd":290 - * def __releasebuffer__(ndarray self, Py_buffer* info): - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) # <<<<<<<<<<<<<< - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * stdlib.free(info.strides) - */ - free(__pyx_v_info->format); - goto __pyx_L3; - } - __pyx_L3:; - - /* "numpy.pxd":291 - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< - * stdlib.free(info.strides) - * # info.shape was stored after info.strides in the same block - */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); - if (__pyx_t_1) { - - /* "numpy.pxd":292 - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * stdlib.free(info.strides) # <<<<<<<<<<<<<< - * # info.shape was stored after info.strides in the same block - * - */ - free(__pyx_v_info->strides); - goto __pyx_L4; - } - __pyx_L4:; - - __Pyx_RefNannyFinishContext(); -} - -/* "numpy.pxd":768 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, a) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0); - - /* "numpy.pxd":769 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew2(a, b): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":771 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, b) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0); - - /* "numpy.pxd":772 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":774 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, c) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0); - - /* "numpy.pxd":775 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":777 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, d) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0); - - /* "numpy.pxd":778 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":780 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0); - - /* "numpy.pxd":781 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< - * - * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":783 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< - * # Recursive utility function used in __getbuffer__ to get format - * # string. The new location in the format string is returned. - */ - -static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) { - PyArray_Descr *__pyx_v_child = 0; - int __pyx_v_endian_detector; - int __pyx_v_little_endian; - PyObject *__pyx_v_fields = 0; - PyObject *__pyx_v_childname = NULL; - PyObject *__pyx_v_new_offset = NULL; - PyObject *__pyx_v_t = NULL; - char *__pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *(*__pyx_t_6)(PyObject *); - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - long __pyx_t_11; - char *__pyx_t_12; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_util_dtypestring", 0); - - /* "numpy.pxd":790 - * cdef int delta_offset - * cdef tuple i - * cdef int endian_detector = 1 # <<<<<<<<<<<<<< - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * cdef tuple fields - */ - __pyx_v_endian_detector = 1; - - /* "numpy.pxd":791 - * cdef tuple i - * cdef int endian_detector = 1 - * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< - * cdef tuple fields - * - */ - __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - - /* "numpy.pxd":794 - * cdef tuple fields - * - * for childname in descr.names: # <<<<<<<<<<<<<< - * fields = descr.fields[childname] - * child, new_offset = fields - */ - if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_1 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - for (;;) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - __Pyx_XDECREF(__pyx_v_childname); - __pyx_v_childname = __pyx_t_3; - __pyx_t_3 = 0; - - /* "numpy.pxd":795 - * - * for childname in descr.names: - * fields = descr.fields[childname] # <<<<<<<<<<<<<< - * child, new_offset = fields - * - */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_fields)); - __pyx_v_fields = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "numpy.pxd":796 - * for childname in descr.names: - * fields = descr.fields[childname] - * child, new_offset = fields # <<<<<<<<<<<<<< - * - * if (end - f) - (new_offset - offset[0]) < 15: - */ - if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) { - PyObject* sequence = ((PyObject *)__pyx_v_fields); - #if CYTHON_COMPILING_IN_CPYTHON - Py_ssize_t size = Py_SIZE(sequence); - #else - Py_ssize_t size = PySequence_Size(sequence); - #endif - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - } else if (1) { - __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else - { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_fields)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; - } - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_child)); - __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_new_offset); - __pyx_v_new_offset = __pyx_t_4; - __pyx_t_4 = 0; - - /* "numpy.pxd":798 - * child, new_offset = fields - * - * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") - * - */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - - /* "numpy.pxd":799 - * - * if (end - f) - (new_offset - offset[0]) < 15: - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< - * - * if ((child.byteorder == c'>' and little_endian) or - */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; - } - __pyx_L7:; - - /* "numpy.pxd":801 - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") - * - * if ((child.byteorder == c'>' and little_endian) or # <<<<<<<<<<<<<< - * (child.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - */ - __pyx_t_7 = (__pyx_v_child->byteorder == '>'); - if (__pyx_t_7) { - __pyx_t_8 = __pyx_v_little_endian; - } else { - __pyx_t_8 = __pyx_t_7; - } - if (!__pyx_t_8) { - - /* "numpy.pxd":802 - * - * if ((child.byteorder == c'>' and little_endian) or - * (child.byteorder == c'<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") - * # One could encode it in the format string and have Cython - */ - __pyx_t_7 = (__pyx_v_child->byteorder == '<'); - if (__pyx_t_7) { - __pyx_t_9 = (!__pyx_v_little_endian); - __pyx_t_10 = __pyx_t_9; - } else { - __pyx_t_10 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_10; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - - /* "numpy.pxd":803 - * if ((child.byteorder == c'>' and little_endian) or - * (child.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * # One could encode it in the format string and have Cython - * # complain instead, BUT: < and > in format strings also imply - */ - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; - } - __pyx_L8:; - - /* "numpy.pxd":813 - * - * # Output padding bytes - * while offset[0] < new_offset: # <<<<<<<<<<<<<< - * f[0] = 120 # "x"; pad byte - * f += 1 - */ - while (1) { - __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_7) break; - - /* "numpy.pxd":814 - * # Output padding bytes - * while offset[0] < new_offset: - * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< - * f += 1 - * offset[0] += 1 - */ - (__pyx_v_f[0]) = 120; - - /* "numpy.pxd":815 - * while offset[0] < new_offset: - * f[0] = 120 # "x"; pad byte - * f += 1 # <<<<<<<<<<<<<< - * offset[0] += 1 - * - */ - __pyx_v_f = (__pyx_v_f + 1); - - /* "numpy.pxd":816 - * f[0] = 120 # "x"; pad byte - * f += 1 - * offset[0] += 1 # <<<<<<<<<<<<<< - * - * offset[0] += child.itemsize - */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + 1); - } - - /* "numpy.pxd":818 - * offset[0] += 1 - * - * offset[0] += child.itemsize # <<<<<<<<<<<<<< - * - * if not PyDataType_HASFIELDS(child): - */ - __pyx_t_11 = 0; - (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + __pyx_v_child->elsize); - - /* "numpy.pxd":820 - * offset[0] += child.itemsize - * - * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< - * t = child.type_num - * if end - f < 5: - */ - __pyx_t_7 = (!PyDataType_HASFIELDS(__pyx_v_child)); - if (__pyx_t_7) { - - /* "numpy.pxd":821 - * - * if not PyDataType_HASFIELDS(child): - * t = child.type_num # <<<<<<<<<<<<<< - * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") - */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_t); - __pyx_v_t = __pyx_t_3; - __pyx_t_3 = 0; - - /* "numpy.pxd":822 - * if not PyDataType_HASFIELDS(child): - * t = child.type_num - * if end - f < 5: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short.") - * - */ - __pyx_t_7 = ((__pyx_v_end - __pyx_v_f) < 5); - if (__pyx_t_7) { - - /* "numpy.pxd":823 - * t = child.type_num - * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< - * - * # Until ticket #99 is fixed, use integers to avoid warnings - */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L12; - } - __pyx_L12:; - - /* "numpy.pxd":826 - * - * # Until ticket #99 is fixed, use integers to avoid warnings - * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" - */ - __pyx_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 98; - goto __pyx_L13; - } - - /* "numpy.pxd":827 - * # Until ticket #99 is fixed, use integers to avoid warnings - * if t == NPY_BYTE: f[0] = 98 #"b" - * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" - */ - __pyx_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 66; - goto __pyx_L13; - } - - /* "numpy.pxd":828 - * if t == NPY_BYTE: f[0] = 98 #"b" - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" - */ - __pyx_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 104; - goto __pyx_L13; - } - - /* "numpy.pxd":829 - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" - */ - __pyx_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 72; - goto __pyx_L13; - } - - /* "numpy.pxd":830 - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" - */ - __pyx_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 105; - goto __pyx_L13; - } - - /* "numpy.pxd":831 - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" - */ - __pyx_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 73; - goto __pyx_L13; - } - - /* "numpy.pxd":832 - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - */ - __pyx_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 108; - goto __pyx_L13; - } - - /* "numpy.pxd":833 - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 76; - goto __pyx_L13; - } - - /* "numpy.pxd":834 - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" - */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 113; - goto __pyx_L13; - } - - /* "numpy.pxd":835 - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - */ - __pyx_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 81; - goto __pyx_L13; - } - - /* "numpy.pxd":836 - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - */ - __pyx_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 102; - goto __pyx_L13; - } - - /* "numpy.pxd":837 - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - */ - __pyx_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 100; - goto __pyx_L13; - } - - /* "numpy.pxd":838 - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - */ - __pyx_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 103; - goto __pyx_L13; - } - - /* "numpy.pxd":839 - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - */ - __pyx_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 102; - __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; - } - - /* "numpy.pxd":840 - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - * elif t == NPY_OBJECT: f[0] = 79 #"O" - */ - __pyx_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 100; - __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; - } - - /* "numpy.pxd":841 - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< - * elif t == NPY_OBJECT: f[0] = 79 #"O" - * else: - */ - __pyx_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 103; - __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L13; - } - - /* "numpy.pxd":842 - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - */ - __pyx_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_7) { - (__pyx_v_f[0]) = 79; - goto __pyx_L13; - } - /*else*/ { - - /* "numpy.pxd":844 - * elif t == NPY_OBJECT: f[0] = 79 #"O" - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< - * f += 1 - * else: - */ - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_8), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L13:; - - /* "numpy.pxd":845 - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * f += 1 # <<<<<<<<<<<<<< - * else: - * # Cython ignores struct boundary information ("T{...}"), - */ - __pyx_v_f = (__pyx_v_f + 1); - goto __pyx_L11; - } - /*else*/ { - - /* "numpy.pxd":849 - * # Cython ignores struct boundary information ("T{...}"), - * # so don't output it - * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< - * return f - * - */ - __pyx_t_12 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_12; - } - __pyx_L11:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "numpy.pxd":850 - * # so don't output it - * f = _util_dtypestring(child, f, end, offset) - * return f # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_f; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_child); - __Pyx_XDECREF(__pyx_v_fields); - __Pyx_XDECREF(__pyx_v_childname); - __Pyx_XDECREF(__pyx_v_new_offset); - __Pyx_XDECREF(__pyx_v_t); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "numpy.pxd":965 - * - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * cdef PyObject* baseptr - * if base is None: - */ - -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - PyObject *__pyx_v_baseptr; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("set_array_base", 0); - - /* "numpy.pxd":967 - * cdef inline void set_array_base(ndarray arr, object base): - * cdef PyObject* baseptr - * if base is None: # <<<<<<<<<<<<<< - * baseptr = NULL - * else: - */ - __pyx_t_1 = (__pyx_v_base == Py_None); - if (__pyx_t_1) { - - /* "numpy.pxd":968 - * cdef PyObject* baseptr - * if base is None: - * baseptr = NULL # <<<<<<<<<<<<<< - * else: - * Py_INCREF(base) # important to do this before decref below! - */ - __pyx_v_baseptr = NULL; - goto __pyx_L3; - } - /*else*/ { - - /* "numpy.pxd":970 - * baseptr = NULL - * else: - * Py_INCREF(base) # important to do this before decref below! # <<<<<<<<<<<<<< - * baseptr = base - * Py_XDECREF(arr.base) - */ - Py_INCREF(__pyx_v_base); - - /* "numpy.pxd":971 - * else: - * Py_INCREF(base) # important to do this before decref below! - * baseptr = base # <<<<<<<<<<<<<< - * Py_XDECREF(arr.base) - * arr.base = baseptr - */ - __pyx_v_baseptr = ((PyObject *)__pyx_v_base); - } - __pyx_L3:; - - /* "numpy.pxd":972 - * Py_INCREF(base) # important to do this before decref below! - * baseptr = base - * Py_XDECREF(arr.base) # <<<<<<<<<<<<<< - * arr.base = baseptr - * - */ - Py_XDECREF(__pyx_v_arr->base); - - /* "numpy.pxd":973 - * baseptr = base - * Py_XDECREF(arr.base) - * arr.base = baseptr # <<<<<<<<<<<<<< - * - * cdef inline object get_array_base(ndarray arr): - */ - __pyx_v_arr->base = __pyx_v_baseptr; - - __Pyx_RefNannyFinishContext(); -} - -/* "numpy.pxd":975 - * arr.base = baseptr - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * if arr.base is NULL: - * return None - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_array_base", 0); - - /* "numpy.pxd":976 - * - * cdef inline object get_array_base(ndarray arr): - * if arr.base is NULL: # <<<<<<<<<<<<<< - * return None - * else: - */ - __pyx_t_1 = (__pyx_v_arr->base == NULL); - if (__pyx_t_1) { - - /* "numpy.pxd":977 - * cdef inline object get_array_base(ndarray arr): - * if arr.base is NULL: - * return None # <<<<<<<<<<<<<< - * else: - * return arr.base - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "numpy.pxd":979 - * return None - * else: - * return arr.base # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_arr->base)); - __pyx_r = ((PyObject *)__pyx_v_arr->base); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("_min_spanning_tree"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_u_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 1, 0, 0}, - {&__pyx_n_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 1}, - {&__pyx_n_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 1}, - {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, - {&__pyx_n_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 1}, - {&__pyx_kp_u_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0, 0}, - {&__pyx_kp_u_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 1, 0, 0}, - {&__pyx_kp_u_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 1, 0, 0}, - {&__pyx_kp_u_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 1, 0, 0}, - {&__pyx_kp_u_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0, 0}, - {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0}, - {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0}, - {&__pyx_n_s__DTYPE, __pyx_k__DTYPE, sizeof(__pyx_k__DTYPE), 0, 0, 1, 1}, - {&__pyx_n_s__ITYPE, __pyx_k__ITYPE, sizeof(__pyx_k__ITYPE), 0, 0, 1, 1}, - {&__pyx_n_s__N, __pyx_k__N, sizeof(__pyx_k__N), 0, 0, 1, 1}, - {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s___graph_validation, __pyx_k___graph_validation, sizeof(__pyx_k___graph_validation), 0, 0, 1, 1}, - {&__pyx_n_s__arange, __pyx_k__arange, sizeof(__pyx_k__arange), 0, 0, 1, 1}, - {&__pyx_n_s__argsort, __pyx_k__argsort, sizeof(__pyx_k__argsort), 0, 0, 1, 1}, - {&__pyx_n_s__astype, __pyx_k__astype, sizeof(__pyx_k__astype), 0, 0, 1, 1}, - {&__pyx_n_s__copy_if_sparse, __pyx_k__copy_if_sparse, sizeof(__pyx_k__copy_if_sparse), 0, 0, 1, 1}, - {&__pyx_n_s__csgraph, __pyx_k__csgraph, sizeof(__pyx_k__csgraph), 0, 0, 1, 1}, - {&__pyx_n_s__csr_matrix, __pyx_k__csr_matrix, sizeof(__pyx_k__csr_matrix), 0, 0, 1, 1}, - {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1}, - {&__pyx_n_s__dense_output, __pyx_k__dense_output, sizeof(__pyx_k__dense_output), 0, 0, 1, 1}, - {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, - {&__pyx_n_s__eliminate_zeros, __pyx_k__eliminate_zeros, sizeof(__pyx_k__eliminate_zeros), 0, 0, 1, 1}, - {&__pyx_n_s__float64, __pyx_k__float64, sizeof(__pyx_k__float64), 0, 0, 1, 1}, - {&__pyx_n_s__i_sort, __pyx_k__i_sort, sizeof(__pyx_k__i_sort), 0, 0, 1, 1}, - {&__pyx_n_s__indices, __pyx_k__indices, sizeof(__pyx_k__indices), 0, 0, 1, 1}, - {&__pyx_n_s__indptr, __pyx_k__indptr, sizeof(__pyx_k__indptr), 0, 0, 1, 1}, - {&__pyx_n_s__int32, __pyx_k__int32, sizeof(__pyx_k__int32), 0, 0, 1, 1}, - {&__pyx_n_s__isspmatrix, __pyx_k__isspmatrix, sizeof(__pyx_k__isspmatrix), 0, 0, 1, 1}, - {&__pyx_n_s__isspmatrix_csc, __pyx_k__isspmatrix_csc, sizeof(__pyx_k__isspmatrix_csc), 0, 0, 1, 1}, - {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, - {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, - {&__pyx_n_s__overwrite, __pyx_k__overwrite, sizeof(__pyx_k__overwrite), 0, 0, 1, 1}, - {&__pyx_n_s__predecessors, __pyx_k__predecessors, sizeof(__pyx_k__predecessors), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__rank, __pyx_k__rank, sizeof(__pyx_k__rank), 0, 0, 1, 1}, - {&__pyx_n_s__row_indices, __pyx_k__row_indices, sizeof(__pyx_k__row_indices), 0, 0, 1, 1}, - {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, - {&__pyx_n_s__sp_tree, __pyx_k__sp_tree, sizeof(__pyx_k__sp_tree), 0, 0, 1, 1}, - {&__pyx_n_s__validate_graph, __pyx_k__validate_graph, sizeof(__pyx_k__validate_graph), 0, 0, 1, 1}, - {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "numpy.pxd":215 - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - */ - __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_2)); - PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_u_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3)); - - /* "numpy.pxd":219 - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< - * - * info.buf = PyArray_DATA(self) - */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_4)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_u_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - - /* "numpy.pxd":257 - * if ((descr.byteorder == c'>' and little_endian) or - * (descr.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" - */ - __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_7); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_6)); - PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); - - /* "numpy.pxd":799 - * - * if (end - f) - (new_offset - offset[0]) < 15: - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< - * - * if ((child.byteorder == c'>' and little_endian) or - */ - __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_10); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_9)); - PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_u_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); - - /* "numpy.pxd":803 - * if ((child.byteorder == c'>' and little_endian) or - * (child.byteorder == c'<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * # One could encode it in the format string and have Cython - * # complain instead, BUT: < and > in format strings also imply - */ - __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_11); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_6)); - PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11)); - - /* "numpy.pxd":823 - * t = child.type_num - * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< - * - * # Until ticket #99 is fixed, use integers to avoid warnings - */ - __pyx_k_tuple_13 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_13); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_12)); - PyTuple_SET_ITEM(__pyx_k_tuple_13, 0, ((PyObject *)__pyx_kp_u_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13)); - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":23 - * - * - * def minimum_spanning_tree(csgraph, overwrite=False): # <<<<<<<<<<<<<< - * r""" - * minimum_spanning_tree(csgraph, overwrite=False) - */ - __pyx_k_tuple_15 = PyTuple_New(11); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_15); - __Pyx_INCREF(((PyObject *)__pyx_n_s__csgraph)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_n_s__csgraph)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__csgraph)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__overwrite)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 1, ((PyObject *)__pyx_n_s__overwrite)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__overwrite)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__N)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 2, ((PyObject *)__pyx_n_s__N)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__data)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 3, ((PyObject *)__pyx_n_s__data)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__data)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__indices)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 4, ((PyObject *)__pyx_n_s__indices)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__indices)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__indptr)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 5, ((PyObject *)__pyx_n_s__indptr)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__indptr)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__rank)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 6, ((PyObject *)__pyx_n_s__rank)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rank)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__predecessors)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 7, ((PyObject *)__pyx_n_s__predecessors)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__predecessors)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__i_sort)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 8, ((PyObject *)__pyx_n_s__i_sort)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i_sort)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__row_indices)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 9, ((PyObject *)__pyx_n_s__row_indices)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__row_indices)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__sp_tree)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 10, ((PyObject *)__pyx_n_s__sp_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sp_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); - __pyx_k_codeobj_16 = (PyObject*)__Pyx_PyCode_New(2, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_18, __pyx_n_s_17, 23, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC init_min_spanning_tree(void); /*proto*/ -PyMODINIT_FUNC init_min_spanning_tree(void) -#else -PyMODINIT_FUNC PyInit__min_spanning_tree(void); /*proto*/ -PyMODINIT_FUNC PyInit__min_spanning_tree(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__min_spanning_tree(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_min_spanning_tree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "sklearn.utils.mst._min_spanning_tree")) { - if (unlikely(PyDict_SetItemString(modules, "sklearn.utils.mst._min_spanning_tree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_sklearn__utils__mst___min_spanning_tree) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - /*--- Type import code ---*/ - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", - #if CYTHON_COMPILING_IN_PYPY - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":4 - * # License: BSD, (C) 2011 - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":7 - * cimport numpy as np - * - * from scipy.sparse import csr_matrix, isspmatrix_csc, isspmatrix # <<<<<<<<<<<<<< - * from ._graph_validation import validate_graph - * - */ - __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__csr_matrix)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__csr_matrix)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__csr_matrix)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__isspmatrix_csc)); - PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__isspmatrix_csc)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isspmatrix_csc)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__isspmatrix)); - PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__isspmatrix)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isspmatrix)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_14), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__csr_matrix); - if (__pyx_t_1 == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__csr_matrix); - if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__csr_matrix, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__isspmatrix_csc); - if (__pyx_t_1 == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__isspmatrix_csc); - if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__isspmatrix_csc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__isspmatrix); - if (__pyx_t_1 == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__isspmatrix); - if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__isspmatrix, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":8 - * - * from scipy.sparse import csr_matrix, isspmatrix_csc, isspmatrix - * from ._graph_validation import validate_graph # <<<<<<<<<<<<<< - * - * DTYPE = np.float64 - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_n_s__validate_graph)); - PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__validate_graph)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__validate_graph)); - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s___graph_validation), ((PyObject *)__pyx_t_2), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__validate_graph); - if (__pyx_t_2 == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__validate_graph); - if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_GOTREF(__pyx_t_2); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__validate_graph, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":10 - * from ._graph_validation import validate_graph - * - * DTYPE = np.float64 # <<<<<<<<<<<<<< - * ctypedef np.float64_t DTYPE_t - * - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__float64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DTYPE, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":13 - * ctypedef np.float64_t DTYPE_t - * - * ITYPE = np.int32 # <<<<<<<<<<<<<< - * ctypedef np.int32_t ITYPE_t - * - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__int32); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ITYPE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":17 - * - * # EPS is the precision of DTYPE - * cdef DTYPE_t DTYPE_EPS = 1E-15 # <<<<<<<<<<<<<< - * - * # NULL_IDX is the index used in predecessor matrices to store a non-path - */ - __pyx_v_7sklearn_5utils_3mst_18_min_spanning_tree_DTYPE_EPS = 1E-15; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":20 - * - * # NULL_IDX is the index used in predecessor matrices to store a non-path - * cdef ITYPE_t NULL_IDX = -9999 # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_7sklearn_5utils_3mst_18_min_spanning_tree_NULL_IDX = -9999; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":23 - * - * - * def minimum_spanning_tree(csgraph, overwrite=False): # <<<<<<<<<<<<<< - * r""" - * minimum_spanning_tree(csgraph, overwrite=False) - */ - __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_k_1 = __pyx_t_1; - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7sklearn_5utils_3mst_18_min_spanning_tree_1minimum_spanning_tree, NULL, __pyx_n_s_19); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_17, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "sklearn/utils/mst/_min_spanning_tree.pyx":1 - * # Author: Jake Vanderplas -- # <<<<<<<<<<<<<< - * # License: BSD, (C) 2011 - * - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_20), ((PyObject *)__pyx_kp_u_21)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "numpy.pxd":975 - * arr.base = baseptr - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * if arr.base is NULL: - * return None - */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - __Pyx_AddTraceback("init sklearn.utils.mst._min_spanning_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init sklearn.utils.mst._min_spanning_tree"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AsString(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - continue; - } - name = first_kw_arg; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { - while (*name) { - if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) - && _PyString_Eq(**name, key)) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - if ((**argname == key) || ( - (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) - && _PyString_Eq(**argname, key))) { - goto arg_passed_twice; - } - argname++; - } - } - } else - #endif - if (likely(PyUnicode_Check(key))) { - while (*name) { - int cmp = (**name == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**name, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - int cmp = (**argname == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**argname, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) goto arg_passed_twice; - argname++; - } - } - } else - goto invalid_keyword_type; - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - -static CYTHON_INLINE int __Pyx_IsLittleEndian(void) { - unsigned int n = 1; - return *(unsigned char*)(&n) != 0; -} -static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, - __Pyx_BufFmt_StackElem* stack, - __Pyx_TypeInfo* type) { - stack[0].field = &ctx->root; - stack[0].parent_offset = 0; - ctx->root.type = type; - ctx->root.name = "buffer dtype"; - ctx->root.offset = 0; - ctx->head = stack; - ctx->head->field = &ctx->root; - ctx->fmt_offset = 0; - ctx->head->parent_offset = 0; - ctx->new_packmode = '@'; - ctx->enc_packmode = '@'; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ctx->is_complex = 0; - ctx->is_valid_array = 0; - ctx->struct_alignment = 0; - while (type->typegroup == 'S') { - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = 0; - type = type->fields->type; - } -} -static int __Pyx_BufFmt_ParseNumber(const char** ts) { - int count; - const char* t = *ts; - if (*t < '0' || *t > '9') { - return -1; - } else { - count = *t++ - '0'; - while (*t >= '0' && *t < '9') { - count *= 10; - count += *t++ - '0'; - } - } - *ts = t; - return count; -} -static int __Pyx_BufFmt_ExpectNumber(const char **ts) { - int number = __Pyx_BufFmt_ParseNumber(ts); - if (number == -1) /* First char was not a digit */ - PyErr_Format(PyExc_ValueError,\ - "Does not understand character buffer dtype format string ('%c')", **ts); - return number; -} -static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { - PyErr_Format(PyExc_ValueError, - "Unexpected format string character: '%c'", ch); -} -static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { - switch (ch) { - case 'c': return "'char'"; - case 'b': return "'signed char'"; - case 'B': return "'unsigned char'"; - case 'h': return "'short'"; - case 'H': return "'unsigned short'"; - case 'i': return "'int'"; - case 'I': return "'unsigned int'"; - case 'l': return "'long'"; - case 'L': return "'unsigned long'"; - case 'q': return "'long long'"; - case 'Q': return "'unsigned long long'"; - case 'f': return (is_complex ? "'complex float'" : "'float'"); - case 'd': return (is_complex ? "'complex double'" : "'double'"); - case 'g': return (is_complex ? "'complex long double'" : "'long double'"); - case 'T': return "a struct"; - case 'O': return "Python object"; - case 'P': return "a pointer"; - case 's': case 'p': return "a string"; - case 0: return "end"; - default: return "unparseable format string"; - } -} -static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return 2; - case 'i': case 'I': case 'l': case 'L': return 4; - case 'q': case 'Q': return 8; - case 'f': return (is_complex ? 8 : 4); - case 'd': return (is_complex ? 16 : 8); - case 'g': { - PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); - return 0; - } - case 'O': case 'P': return sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} -static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { - switch (ch) { - case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(short); - case 'i': case 'I': return sizeof(int); - case 'l': case 'L': return sizeof(long); - #ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(PY_LONG_LONG); - #endif - case 'f': return sizeof(float) * (is_complex ? 2 : 1); - case 'd': return sizeof(double) * (is_complex ? 2 : 1); - case 'g': return sizeof(long double) * (is_complex ? 2 : 1); - case 'O': case 'P': return sizeof(void*); - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } - } -} -typedef struct { char c; short x; } __Pyx_st_short; -typedef struct { char c; int x; } __Pyx_st_int; -typedef struct { char c; long x; } __Pyx_st_long; -typedef struct { char c; float x; } __Pyx_st_float; -typedef struct { char c; double x; } __Pyx_st_double; -typedef struct { char c; long double x; } __Pyx_st_longdouble; -typedef struct { char c; void *x; } __Pyx_st_void_p; -#ifdef HAVE_LONG_LONG -typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong; -#endif -static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); - case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); - case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); -#ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG); -#endif - case 'f': return sizeof(__Pyx_st_float) - sizeof(float); - case 'd': return sizeof(__Pyx_st_double) - sizeof(double); - case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); - case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} -/* These are for computing the padding at the end of the struct to align - on the first member of the struct. This will probably the same as above, - but we don't have any guarantees. - */ -typedef struct { short x; char c; } __Pyx_pad_short; -typedef struct { int x; char c; } __Pyx_pad_int; -typedef struct { long x; char c; } __Pyx_pad_long; -typedef struct { float x; char c; } __Pyx_pad_float; -typedef struct { double x; char c; } __Pyx_pad_double; -typedef struct { long double x; char c; } __Pyx_pad_longdouble; -typedef struct { void *x; char c; } __Pyx_pad_void_p; -#ifdef HAVE_LONG_LONG -typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong; -#endif -static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1; - case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short); - case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int); - case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long); -#ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG); -#endif - case 'f': return sizeof(__Pyx_pad_float) - sizeof(float); - case 'd': return sizeof(__Pyx_pad_double) - sizeof(double); - case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double); - case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} -static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { - switch (ch) { - case 'c': - return 'H'; - case 'b': case 'h': case 'i': - case 'l': case 'q': case 's': case 'p': - return 'I'; - case 'B': case 'H': case 'I': case 'L': case 'Q': - return 'U'; - case 'f': case 'd': case 'g': - return (is_complex ? 'C' : 'R'); - case 'O': - return 'O'; - case 'P': - return 'P'; - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } - } -} -static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { - if (ctx->head == NULL || ctx->head->field == &ctx->root) { - const char* expected; - const char* quote; - if (ctx->head == NULL) { - expected = "end"; - quote = ""; - } else { - expected = ctx->head->field->type->name; - quote = "'"; - } - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected %s%s%s but got %s", - quote, expected, quote, - __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); - } else { - __Pyx_StructField* field = ctx->head->field; - __Pyx_StructField* parent = (ctx->head - 1)->field; - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", - field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), - parent->type->name, field->name); - } -} -static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { - char group; - size_t size, offset, arraysize = 1; - if (ctx->enc_type == 0) return 0; - if (ctx->head->field->type->arraysize[0]) { - int i, ndim = 0; - if (ctx->enc_type == 's' || ctx->enc_type == 'p') { - ctx->is_valid_array = ctx->head->field->type->ndim == 1; - ndim = 1; - if (ctx->enc_count != ctx->head->field->type->arraysize[0]) { - PyErr_Format(PyExc_ValueError, - "Expected a dimension of size %zu, got %zu", - ctx->head->field->type->arraysize[0], ctx->enc_count); - return -1; - } - } - if (!ctx->is_valid_array) { - PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d", - ctx->head->field->type->ndim, ndim); - return -1; - } - for (i = 0; i < ctx->head->field->type->ndim; i++) { - arraysize *= ctx->head->field->type->arraysize[i]; - } - ctx->is_valid_array = 0; - ctx->enc_count = 1; - } - group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); - do { - __Pyx_StructField* field = ctx->head->field; - __Pyx_TypeInfo* type = field->type; - if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') { - size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); - } else { - size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); - } - if (ctx->enc_packmode == '@') { - size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); - size_t align_mod_offset; - if (align_at == 0) return -1; - align_mod_offset = ctx->fmt_offset % align_at; - if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; - if (ctx->struct_alignment == 0) - ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type, - ctx->is_complex); - } - if (type->size != size || type->typegroup != group) { - if (type->typegroup == 'C' && type->fields != NULL) { - size_t parent_offset = ctx->head->parent_offset + field->offset; - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = parent_offset; - continue; - } - if ((type->typegroup == 'H' || group == 'H') && type->size == size) { - } else { - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - } - offset = ctx->head->parent_offset + field->offset; - if (ctx->fmt_offset != offset) { - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected", - (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); - return -1; - } - ctx->fmt_offset += size; - if (arraysize) - ctx->fmt_offset += (arraysize - 1) * size; - --ctx->enc_count; /* Consume from buffer string */ - while (1) { - if (field == &ctx->root) { - ctx->head = NULL; - if (ctx->enc_count != 0) { - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - break; /* breaks both loops as ctx->enc_count == 0 */ - } - ctx->head->field = ++field; - if (field->type == NULL) { - --ctx->head; - field = ctx->head->field; - continue; - } else if (field->type->typegroup == 'S') { - size_t parent_offset = ctx->head->parent_offset + field->offset; - if (field->type->fields->type == NULL) continue; /* empty struct */ - field = field->type->fields; - ++ctx->head; - ctx->head->field = field; - ctx->head->parent_offset = parent_offset; - break; - } else { - break; - } - } - } while (ctx->enc_count); - ctx->enc_type = 0; - ctx->is_complex = 0; - return 0; -} -static CYTHON_INLINE PyObject * -__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp) -{ - const char *ts = *tsp; - int i = 0, number; - int ndim = ctx->head->field->type->ndim; -; - ++ts; - if (ctx->new_count != 1) { - PyErr_SetString(PyExc_ValueError, - "Cannot handle repeated arrays in format string"); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - while (*ts && *ts != ')') { - if (isspace(*ts)) - continue; - number = __Pyx_BufFmt_ExpectNumber(&ts); - if (number == -1) return NULL; - if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i]) - return PyErr_Format(PyExc_ValueError, - "Expected a dimension of size %zu, got %d", - ctx->head->field->type->arraysize[i], number); - if (*ts != ',' && *ts != ')') - return PyErr_Format(PyExc_ValueError, - "Expected a comma in format string, got '%c'", *ts); - if (*ts == ',') ts++; - i++; - } - if (i != ndim) - return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d", - ctx->head->field->type->ndim, i); - if (!*ts) { - PyErr_SetString(PyExc_ValueError, - "Unexpected end of format string, expected ')'"); - return NULL; - } - ctx->is_valid_array = 1; - ctx->new_count = 1; - *tsp = ++ts; - return Py_None; -} -static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { - int got_Z = 0; - while (1) { - switch(*ts) { - case 0: - if (ctx->enc_type != 0 && ctx->head == NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - if (ctx->head != NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - return ts; - case ' ': - case 10: - case 13: - ++ts; - break; - case '<': - if (!__Pyx_IsLittleEndian()) { - PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); - return NULL; - } - ctx->new_packmode = '='; - ++ts; - break; - case '>': - case '!': - if (__Pyx_IsLittleEndian()) { - PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); - return NULL; - } - ctx->new_packmode = '='; - ++ts; - break; - case '=': - case '@': - case '^': - ctx->new_packmode = *ts++; - break; - case 'T': /* substruct */ - { - const char* ts_after_sub; - size_t i, struct_count = ctx->new_count; - size_t struct_alignment = ctx->struct_alignment; - ctx->new_count = 1; - ++ts; - if (*ts != '{') { - PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_type = 0; /* Erase processed last struct element */ - ctx->enc_count = 0; - ctx->struct_alignment = 0; - ++ts; - ts_after_sub = ts; - for (i = 0; i != struct_count; ++i) { - ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); - if (!ts_after_sub) return NULL; - } - ts = ts_after_sub; - if (struct_alignment) ctx->struct_alignment = struct_alignment; - } - break; - case '}': /* end of substruct; either repeat or move on */ - { - size_t alignment = ctx->struct_alignment; - ++ts; - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_type = 0; /* Erase processed last struct element */ - if (alignment && ctx->fmt_offset % alignment) { - ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment); - } - } - return ts; - case 'x': - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->fmt_offset += ctx->new_count; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ctx->enc_packmode = ctx->new_packmode; - ++ts; - break; - case 'Z': - got_Z = 1; - ++ts; - if (*ts != 'f' && *ts != 'd' && *ts != 'g') { - __Pyx_BufFmt_RaiseUnexpectedChar('Z'); - return NULL; - } /* fall through */ - case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': - case 'l': case 'L': case 'q': case 'Q': - case 'f': case 'd': case 'g': - case 'O': case 's': case 'p': - if (ctx->enc_type == *ts && got_Z == ctx->is_complex && - ctx->enc_packmode == ctx->new_packmode) { - ctx->enc_count += ctx->new_count; - } else { - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_count = ctx->new_count; - ctx->enc_packmode = ctx->new_packmode; - ctx->enc_type = *ts; - ctx->is_complex = got_Z; - } - ++ts; - ctx->new_count = 1; - got_Z = 0; - break; - case ':': - ++ts; - while(*ts != ':') ++ts; - ++ts; - break; - case '(': - if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL; - break; - default: - { - int number = __Pyx_BufFmt_ExpectNumber(&ts); - if (number == -1) return NULL; - ctx->new_count = (size_t)number; - } - } - } -} -static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { - buf->buf = NULL; - buf->obj = NULL; - buf->strides = __Pyx_zeros; - buf->shape = __Pyx_zeros; - buf->suboffsets = __Pyx_minusones; -} -static CYTHON_INLINE int __Pyx_GetBufferAndValidate( - Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, - int nd, int cast, __Pyx_BufFmt_StackElem* stack) -{ - if (obj == Py_None || obj == NULL) { - __Pyx_ZeroBuffer(buf); - return 0; - } - buf->buf = NULL; - if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail; - if (buf->ndim != nd) { - PyErr_Format(PyExc_ValueError, - "Buffer has wrong number of dimensions (expected %d, got %d)", - nd, buf->ndim); - goto fail; - } - if (!cast) { - __Pyx_BufFmt_Context ctx; - __Pyx_BufFmt_Init(&ctx, stack, dtype); - if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; - } - if ((unsigned)buf->itemsize != dtype->size) { - PyErr_Format(PyExc_ValueError, - "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)", - buf->itemsize, (buf->itemsize > 1) ? "s" : "", - dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); - goto fail; - } - if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; - return 0; -fail:; - __Pyx_ZeroBuffer(buf); - return -1; -} -static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { - if (info->buf == NULL) return; - if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; - __Pyx_ReleaseBuffer(info); -} - -static void __Pyx_RaiseBufferIndexError(int axis) { - PyErr_Format(PyExc_IndexError, - "Out of bounds on buffer access (axis %d)", axis); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - #if PY_VERSION_HEX < 0x02050000 - if (PyClass_Check(type)) { - #else - if (PyType_Check(type)) { - #endif -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } - else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause && cause != Py_None) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); -} - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack", - index, (index == 1) ? "" : "s"); -} - -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - -static CYTHON_INLINE int __Pyx_IterFinish(void) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - PyObject* exc_type = tstate->curexc_type; - if (unlikely(exc_type)) { - if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { - PyObject *exc_value, *exc_tb; - exc_value = tstate->curexc_value; - exc_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - Py_DECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_tb); - return 0; - } else { - return -1; - } - } - return 0; -#else - if (unlikely(PyErr_Occurred())) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; - } else { - return -1; - } - } - return 0; -#endif -} - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } else { - return __Pyx_IterFinish(); - } - return 0; -} - -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - CYTHON_UNUSED PyObject *getbuffer_cobj; - #if PY_VERSION_HEX >= 0x02060000 - if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); - #endif - if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags); - #if PY_VERSION_HEX < 0x02060000 - if (obj->ob_type->tp_dict && - (getbuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, - "__pyx_getbuffer"))) { - getbufferproc func; - #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) - func = (getbufferproc) PyCapsule_GetPointer(getbuffer_cobj, "getbuffer(obj, view, flags)"); - #else - func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); - #endif - Py_DECREF(getbuffer_cobj); - if (!func) - goto fail; - return func(obj, view, flags); - } else { - PyErr_Clear(); - } - #endif - PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); -#if PY_VERSION_HEX < 0x02060000 -fail: -#endif - return -1; -} -static void __Pyx_ReleaseBuffer(Py_buffer *view) { - PyObject *obj = view->obj; - CYTHON_UNUSED PyObject *releasebuffer_cobj; - if (!obj) return; - #if PY_VERSION_HEX >= 0x02060000 - if (PyObject_CheckBuffer(obj)) { - PyBuffer_Release(view); - return; - } - #endif - if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) { __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view); return; } - #if PY_VERSION_HEX < 0x02060000 - if (obj->ob_type->tp_dict && - (releasebuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict, - "__pyx_releasebuffer"))) { - releasebufferproc func; - #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0) - func = (releasebufferproc) PyCapsule_GetPointer(releasebuffer_cobj, "releasebuffer(obj, view)"); - #else - func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); - #endif - Py_DECREF(releasebuffer_cobj); - if (!func) - goto fail; - func(obj, view); - return; - } else { - PyErr_Clear(); - } - #endif - goto nofail; -#if PY_VERSION_HEX < 0x02060000 -fail: -#endif - PyErr_WriteUnraisable(obj); -nofail: - Py_DECREF(obj); - view->obj = NULL; -} -#endif /* PY_MAJOR_VERSION < 3 */ - - - static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - #if PY_VERSION_HEX >= 0x02050000 - { - #if PY_MAJOR_VERSION >= 3 - if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - /* try package relative import first */ - PyObject *py_level = PyInt_FromLong(1); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; /* try absolute import on failure */ - } - #endif - if (!module) { - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - } - } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; - } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name) { -#if PY_MAJOR_VERSION < 3 - PyErr_Format(PyExc_ImportError, "cannot import name %.230s", - PyString_AsString(name)); -#else - PyErr_Format(PyExc_ImportError, "cannot import name %S", name); -#endif -} - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return ::std::complex< float >(x, y); - } - #else - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return x + y*(__pyx_t_float_complex)_Complex_I; - } - #endif -#else - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - __pyx_t_float_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - float denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } - #if 1 - static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) { - #if !defined(HAVE_HYPOT) || defined(_MSC_VER) - return sqrtf(z.real*z.real + z.imag*z.imag); - #else - return hypotf(z.real, z.imag); - #endif - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - float r, lnr, theta, z_r, z_theta; - if (b.imag == 0 && b.real == (int)b.real) { - if (b.real < 0) { - float denom = a.real * a.real + a.imag * a.imag; - a.real = a.real / denom; - a.imag = -a.imag / denom; - b.real = -b.real; - } - switch ((int)b.real) { - case 0: - z.real = 1; - z.imag = 0; - return z; - case 1: - return a; - case 2: - z = __Pyx_c_prodf(a, a); - return __Pyx_c_prodf(a, a); - case 3: - z = __Pyx_c_prodf(a, a); - return __Pyx_c_prodf(z, a); - case 4: - z = __Pyx_c_prodf(a, a); - return __Pyx_c_prodf(z, z); - } - } - if (a.imag == 0) { - if (a.real == 0) { - return a; - } - r = a.real; - theta = 0; - } else { - r = __Pyx_c_absf(a); - theta = atan2f(a.imag, a.real); - } - lnr = logf(r); - z_r = expf(lnr * b.real - theta * b.imag); - z_theta = theta * b.real + lnr * b.imag; - z.real = z_r * cosf(z_theta); - z.imag = z_r * sinf(z_theta); - return z; - } - #endif -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return ::std::complex< double >(x, y); - } - #else - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return x + y*(__pyx_t_double_complex)_Complex_I; - } - #endif -#else - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - __pyx_t_double_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - double denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } - #if 1 - static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { - #if !defined(HAVE_HYPOT) || defined(_MSC_VER) - return sqrt(z.real*z.real + z.imag*z.imag); - #else - return hypot(z.real, z.imag); - #endif - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - double r, lnr, theta, z_r, z_theta; - if (b.imag == 0 && b.real == (int)b.real) { - if (b.real < 0) { - double denom = a.real * a.real + a.imag * a.imag; - a.real = a.real / denom; - a.imag = -a.imag / denom; - b.real = -b.real; - } - switch ((int)b.real) { - case 0: - z.real = 1; - z.imag = 0; - return z; - case 1: - return a; - case 2: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(a, a); - case 3: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(z, a); - case 4: - z = __Pyx_c_prod(a, a); - return __Pyx_c_prod(z, z); - } - } - if (a.imag == 0) { - if (a.real == 0) { - return a; - } - r = a.real; - theta = 0; - } else { - r = __Pyx_c_abs(a); - theta = atan2(a.imag, a.real); - } - lnr = log(r); - z_r = exp(lnr * b.real - theta * b.imag); - z_theta = theta * b.real + lnr * b.imag; - z.real = z_r * cos(z_theta); - z.imag = z_r * sin(z_theta); - return z; - } - #endif -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -#ifndef __PYX_HAVE_RT_ImportModule -#define __PYX_HAVE_RT_ImportModule -static PyObject *__Pyx_ImportModule(const char *name) { - PyObject *py_name = 0; - PyObject *py_module = 0; - py_name = __Pyx_PyIdentifier_FromString(name); - if (!py_name) - goto bad; - py_module = PyImport_Import(py_name); - Py_DECREF(py_name); - return py_module; -bad: - Py_XDECREF(py_name); - return 0; -} -#endif - -#ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, - size_t size, int strict) -{ - PyObject *py_module = 0; - PyObject *result = 0; - PyObject *py_name = 0; - char warning[200]; - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - py_name = __Pyx_PyIdentifier_FromString(class_name); - if (!py_name) - goto bad; - result = PyObject_GetAttr(py_module, py_name); - Py_DECREF(py_name); - py_name = 0; - Py_DECREF(py_module); - py_module = 0; - if (!result) - goto bad; - if (!PyType_Check(result)) { - PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", - module_name, class_name); - goto bad; - } - if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - #if PY_VERSION_HEX < 0x02050000 - if (PyErr_Warn(NULL, warning) < 0) goto bad; - #else - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - #endif - } - else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return NULL; -} -#endif - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */ diff --git a/sklearn/utils/sparsetools/_min_spanning_tree.pyx b/sklearn/utils/sparsetools/_min_spanning_tree.pyx deleted file mode 100644 index c3b2130b0ee3d..0000000000000 --- a/sklearn/utils/sparsetools/_min_spanning_tree.pyx +++ /dev/null @@ -1,185 +0,0 @@ -# Author: Jake Vanderplas -- -# License: BSD, (C) 2011 - -import numpy as np -cimport numpy as np - -from scipy.sparse import csr_matrix, isspmatrix_csc, isspmatrix -from ._graph_validation import validate_graph - -DTYPE = np.float64 -ctypedef np.float64_t DTYPE_t - -ITYPE = np.int32 -ctypedef np.int32_t ITYPE_t - -# EPS is the precision of DTYPE -cdef DTYPE_t DTYPE_EPS = 1E-15 - -# NULL_IDX is the index used in predecessor matrices to store a non-path -cdef ITYPE_t NULL_IDX = -9999 - - -def minimum_spanning_tree(csgraph, overwrite=False): - r""" - minimum_spanning_tree(csgraph, overwrite=False) - - Return a minimum spanning tree of an undirected graph - - A minimum spanning tree is a graph consisting of the subset of edges - which together connect all connected nodes, while minimizing the total - sum of weights on the edges. This is computed using the Kruskal algorithm. - - .. versionadded:: 0.11.0 - - Parameters - ---------- - csgraph : array_like or sparse matrix, 2 dimensions - The N x N matrix representing an undirected graph over N nodes - (see notes below). - overwrite : bool, optional - if true, then parts of the input graph will be overwritten for - efficiency. - - Returns - ------- - span_tree : csr matrix - The N x N compressed-sparse representation of the undirected minimum - spanning tree over the input (see notes below). - - Notes - ----- - This routine uses undirected graphs as input and output. That is, if - graph[i, j] and graph[j, i] are both zero, then nodes i and j do not - have an edge connecting them. If either is nonzero, then the two are - connected by the minimum nonzero value of the two. - - Examples - -------- - The following example shows the computation of a minimum spanning tree - over a simple four-component graph:: - - input graph minimum spanning tree - - (0) (0) - / \ / - 3 8 3 - / \ / - (3)---5---(1) (3)---5---(1) - \ / / - 6 2 2 - \ / / - (2) (2) - - It is easy to see from inspection that the minimum spanning tree involves - removing the edges with weights 8 and 6. In compressed sparse - representation, the solution looks like this: - - >>> from scipy.sparse import csr_matrix - >>> from scipy.sparse.csgraph import minimum_spanning_tree - >>> X = csr_matrix([[0, 8, 0, 3], - ... [0, 0, 2, 5], - ... [0, 0, 0, 6], - ... [0, 0, 0, 0]]) - >>> Tcsr = minimum_spanning_tree(X) - >>> Tcsr.toarray().astype(int) - array([[0, 0, 0, 3], - [0, 0, 2, 5], - [0, 0, 0, 0], - [0, 0, 0, 0]]) - """ - global NULL_IDX - - csgraph = validate_graph(csgraph, True, DTYPE, dense_output=False, - copy_if_sparse=not overwrite) - cdef int N = csgraph.shape[0] - - data = csgraph.data - indices = csgraph.indices - indptr = csgraph.indptr - - rank = np.zeros(N, dtype=ITYPE) - predecessors = np.arange(N, dtype=ITYPE) - - i_sort = np.argsort(data).astype(ITYPE) - row_indices = np.zeros(len(data), dtype=ITYPE) - - _min_spanning_tree(data, indices, indptr, i_sort, - row_indices, predecessors, rank) - - sp_tree = csr_matrix((data, indices, indptr), (N, N)) - sp_tree.eliminate_zeros() - - return sp_tree - - -cdef _min_spanning_tree(np.ndarray[DTYPE_t, ndim=1, mode='c'] data, - np.ndarray[ITYPE_t, ndim=1, mode='c'] col_indices, - np.ndarray[ITYPE_t, ndim=1, mode='c'] indptr, - np.ndarray[ITYPE_t, ndim=1, mode='c'] i_sort, - np.ndarray[ITYPE_t, ndim=1, mode='c'] row_indices, - np.ndarray[ITYPE_t, ndim=1, mode='c'] predecessors, - np.ndarray[ITYPE_t, ndim=1, mode='c'] rank): - # Work-horse routine for computing minimum spanning tree using - # Kruskal's algorithm. By separating this code here, we get more - # efficient indexing. - cdef unsigned int i, j, V1, V2, R1, R2, n_edges_in_mst, n_verts - cdef DTYPE_t E - n_verts = predecessors.shape[0] - - # Arrange `row_indices` to contain the row index of each value in `data`. - # Note that the array `col_indices` already contains the column index. - for i from 0 <= i < n_verts: - for j from indptr[i] <= j < indptr[i + 1]: - row_indices[j] = i - - # step through the edges from smallest to largest. - # V1 and V2 are the vertices, and E is the edge weight connecting them. - n_edges_in_mst = 0 - i = 0 - while i < i_sort.shape[0] and n_edges_in_mst < n_verts - 1: - j = i_sort[i] - V1 = row_indices[j] - V2 = col_indices[j] - E = data[j] - - # progress upward to the head node of each subtree - R1 = V1 - while predecessors[R1] != R1: - R1 = predecessors[R1] - R2 = V2 - while predecessors[R2] != R2: - R2 = predecessors[R2] - - # Compress both paths. - while predecessors[V1] != R1: - predecessors[V1] = R1 - while predecessors[V2] != R2: - predecessors[V2] = R2 - - # if the subtrees are different, then we connect them and keep the - # edge. Otherwise, we remove the edge: it duplicates one already - # in the spanning tree. - if R1 != R2: - n_edges_in_mst += 1 - - # Use approximate (because of path-compression) rank to try - # to keep balanced trees. - if rank[R1] > rank[R2]: - predecessors[R2] = R1 - elif rank[R1] < rank[R2]: - predecessors[R1] = R2 - else: - predecessors[R2] = R1 - rank[R1] += 1 - else: - data[j] = 0 - - i += 1 - - # We may have stopped early if we found a full-sized MST so zero out the rest - while i < i_sort.shape[0]: - j = i_sort[i] - data[j] = 0 - i += 1 - diff --git a/sklearn/utils/sparsetools/setup.py b/sklearn/utils/sparsetools/setup.py index 89cdefbc1ec15..8c23e2c1e51fe 100644 --- a/sklearn/utils/sparsetools/setup.py +++ b/sklearn/utils/sparsetools/setup.py @@ -6,11 +6,6 @@ def configuration(parent_package='', top_path=None): config = Configuration('sparsetools', parent_package, top_path) - config.add_extension('_min_spanning_tree', - sources=['_min_spanning_tree.c'], - include_dirs=[numpy.get_include()], - #libraries=libraries - ) config.add_extension('_traversal', sources=['_traversal.c'], include_dirs=[numpy.get_include()], diff --git a/sklearn/utils/sparsetools/tests/__init__.py b/sklearn/utils/sparsetools/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/sklearn/utils/sparsetools/tests/test_spanning_tree.py b/sklearn/utils/sparsetools/tests/test_spanning_tree.py deleted file mode 100644 index eb4b723059a14..0000000000000 --- a/sklearn/utils/sparsetools/tests/test_spanning_tree.py +++ /dev/null @@ -1,65 +0,0 @@ -"""Test the minimum spanning tree function""" -from __future__ import division, print_function, absolute_import - -import numpy as np -from numpy.testing import assert_ -import numpy.testing as npt -from scipy.sparse import csr_matrix -from sklearn.utils import minimum_spanning_tree - - -def test_minimum_spanning_tree(): - # Create a graph with two connected components. - graph = [[0, 1, 0, 0, 0], - [1, 0, 0, 0, 0], - [0, 0, 0, 8, 5], - [0, 0, 8, 0, 1], - [0, 0, 5, 1, 0]] - graph = np.asarray(graph) - - # Create the expected spanning tree. - expected = [[0, 1, 0, 0, 0], - [0, 0, 0, 0, 0], - [0, 0, 0, 0, 5], - [0, 0, 0, 0, 1], - [0, 0, 0, 0, 0]] - expected = np.asarray(expected) - - # Ensure minimum spanning tree code gives this expected output. - csgraph = csr_matrix(graph) - mintree = minimum_spanning_tree(csgraph) - npt.assert_array_equal(mintree.toarray(), expected, - 'Incorrect spanning tree found.') - - # Ensure that the original graph was not modified. - npt.assert_array_equal(csgraph.toarray(), graph, - 'Original graph was modified.') - - # Now let the algorithm modify the csgraph in place. - mintree = minimum_spanning_tree(csgraph, overwrite=True) - npt.assert_array_equal(mintree.toarray(), expected, - 'Graph was not properly modified to contain MST.') - - np.random.seed(1234) - for N in (5, 10, 15, 20): - # Create a random graph. - graph = 3 + np.random.random((N, N)) - csgraph = csr_matrix(graph) - - # The spanning tree has at most N - 1 edges. - mintree = minimum_spanning_tree(csgraph) - assert_(mintree.nnz < N) - - # Set the sub diagonal to 1 to create a known spanning tree. - idx = np.arange(N - 1) - graph[idx, idx + 1] = 1 - csgraph = csr_matrix(graph) - mintree = minimum_spanning_tree(csgraph) - - # We expect to see this pattern in the spanning tree and otherwise - # have this zero. - expected = np.zeros((N, N)) - expected[idx, idx + 1] = 1 - - npt.assert_array_equal(mintree.toarray(), expected, - 'Incorrect spanning tree found.') diff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py index 37552e48de3dd..615183925332b 100644 --- a/sklearn/utils/testing.py +++ b/sklearn/utils/testing.py @@ -85,7 +85,7 @@ def assert_raises_regexp(expected_exception, expected_regexp, error_message = str(e) if not re.compile(expected_regexp).match(error_message): raise AssertionError("Error message should match pattern " - "'%s'. '%s' does not." % + "%r. %r does not." % (expected_regexp, error_message)) if not_raised: raise AssertionError("Should have raised %r" % @@ -120,7 +120,6 @@ def assert_greater_equal(a, b, msg=None): assert a >= b, message -# To remove when we support numpy 1.7 def assert_warns(warning_class, func, *args, **kw): """Test that a certain warning occurs. @@ -150,6 +149,11 @@ def assert_warns(warning_class, func, *args, **kw): warnings.simplefilter("always") # Trigger a warning. result = func(*args, **kw) + if hasattr(np, 'VisibleDeprecationWarning'): + # Filter out numpy-specific warnings in numpy >= 1.9 + w = [e for e in w + if not e.category is np.VisibleDeprecationWarning] + # Verify some things if not len(w) > 0: raise AssertionError("No warning raised when calling %s" @@ -193,6 +197,9 @@ def assert_warns_message(warning_class, message, func, *args, **kw): with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") + if hasattr(np, 'VisibleDeprecationWarning'): + # Let's not catch the numpy internal DeprecationWarnings + warnings.simplefilter('ignore', np.VisibleDeprecationWarning) # Trigger a warning. result = func(*args, **kw) # Verify some things @@ -231,6 +238,11 @@ def assert_no_warnings(func, *args, **kw): warnings.simplefilter('always') result = func(*args, **kw) + if hasattr(np, 'VisibleDeprecationWarning'): + # Filter out numpy-specific warnings in numpy >= 1.9 + w = [e for e in w + if not e.category is np.VisibleDeprecationWarning] + if len(w) > 0: raise AssertionError("Got warnings when calling %s: %s" % (func.__name__, w)) @@ -470,7 +482,7 @@ def uninstall_mldata_mock(): def all_estimators(include_meta_estimators=False, include_other=False, type_filter=None, include_dont_test=False): - """Get a list of all from sklearn. + """Get a list of all estimators from sklearn. This function crawls the module and gets all classes that inherit from BaseEstimator. Classes that are defined in test-modules are not @@ -485,7 +497,7 @@ def all_estimators(include_meta_estimators=False, include_other=False, BaseEnsemble, OneVsOneClassifier, OutputCodeClassifier, OneVsRestClassifier, RFE, RFECV. - include_others : boolean, default=False + include_other : boolean, default=False Wether to include meta-estimators that are somehow special and can not be default-constructed sensibly. These are currently Pipeline, FeatureUnion and GridSearchCV @@ -605,7 +617,9 @@ def clean_warning_registry(): """Safe way to reset warnings """ warnings.resetwarnings() reg = "__warningregistry__" - for mod in sys.modules.copy().values(): + for mod_name, mod in list(sys.modules.items()): + if 'six.moves' in mod_name: + continue if hasattr(mod, reg): getattr(mod, reg).clear() diff --git a/sklearn/utils/tests/test_multiclass.py b/sklearn/utils/tests/test_multiclass.py index d39681e445850..251b95283317a 100644 --- a/sklearn/utils/tests/test_multiclass.py +++ b/sklearn/utils/tests/test_multiclass.py @@ -1,4 +1,7 @@ +from __future__ import division import numpy as np +import scipy.sparse as sp + from itertools import product from functools import partial from sklearn.externals.six.moves import xrange @@ -12,6 +15,7 @@ from scipy.sparse import lil_matrix from sklearn.utils.testing import assert_array_equal +from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_true from sklearn.utils.testing import assert_false @@ -24,6 +28,8 @@ from sklearn.utils.multiclass import is_multilabel from sklearn.utils.multiclass import is_sequence_of_sequences from sklearn.utils.multiclass import type_of_target +from sklearn.utils.multiclass import class_distribution + class NotAnArray(object): """An object that is convertable to an array. This is useful to @@ -332,6 +338,62 @@ def test_type_of_target(): assert_raises(ValueError, type_of_target, example) +def test_class_distribution(): + y = np.array([[1, 0, 0, 1], + [2, 2, 0, 1], + [1, 3, 0, 1], + [4, 2, 0, 1], + [2, 0, 0, 1], + [1, 3, 0, 1]]) + # Define the sparse matrix with a mix of implicit and explicit zeros + data = np.array([1, 2, 1, 4, 2, 1, 0, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1]) + indices = np.array([0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 5, 0, 1, 2, 3, 4, 5]) + indptr = np.array([0, 6, 11, 11, 17]) + y_sp = sp.csc_matrix((data, indices, indptr), shape=(6, 4)) + + classes, n_classes, class_prior = class_distribution(y) + classes_sp, n_classes_sp, class_prior_sp = class_distribution(y_sp) + classes_expected = [[1, 2, 4], + [0, 2, 3], + [0], + [1]] + n_classes_expected = [3, 3, 1, 1] + class_prior_expected = [[3/6, 2/6, 1/6], + [1/3, 1/3, 1/3], + [1.0], + [1.0]] + + for k in range(y.shape[1]): + assert_array_almost_equal(classes[k], classes_expected[k]) + assert_array_almost_equal(n_classes[k], n_classes_expected[k]) + assert_array_almost_equal(class_prior[k], class_prior_expected[k]) + + assert_array_almost_equal(classes_sp[k], classes_expected[k]) + assert_array_almost_equal(n_classes_sp[k], n_classes_expected[k]) + assert_array_almost_equal(class_prior_sp[k], class_prior_expected[k]) + + # Test again with explicit sample weights + (classes, + n_classes, + class_prior) = class_distribution(y, [1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) + (classes_sp, + n_classes_sp, + class_prior_sp) = class_distribution(y, [1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) + class_prior_expected = [[4/9, 3/9, 2/9], + [2/9, 4/9, 3/9], + [1.0], + [1.0]] + + for k in range(y.shape[1]): + assert_array_almost_equal(classes[k], classes_expected[k]) + assert_array_almost_equal(n_classes[k], n_classes_expected[k]) + assert_array_almost_equal(class_prior[k], class_prior_expected[k]) + + assert_array_almost_equal(classes_sp[k], classes_expected[k]) + assert_array_almost_equal(n_classes_sp[k], n_classes_expected[k]) + assert_array_almost_equal(class_prior_sp[k], class_prior_expected[k]) + + if __name__ == "__main__": import nose nose.runmodule() diff --git a/sklearn/utils/tests/test_random.py b/sklearn/utils/tests/test_random.py index 6d16116d06d3c..7538117d53909 100644 --- a/sklearn/utils/tests/test_random.py +++ b/sklearn/utils/tests/test_random.py @@ -1,9 +1,11 @@ from __future__ import division import numpy as np +import scipy.sparse as sp from scipy.misc import comb as combinations - +from numpy.testing import assert_array_almost_equal from sklearn.utils.random import sample_without_replacement +from sklearn.utils.random import random_choice_csc from sklearn.utils.testing import ( assert_raises, @@ -99,3 +101,87 @@ def check_sample_int_distribution(sample_without_replacement): raise AssertionError( "number of combinations != number of expected (%s != %s)" % (len(output), n_expected)) + + +def test_random_choice_csc(n_samples=10000, random_state=24): + # Explicit class probabilities + classes = [np.array([0, 1]), np.array([0, 1, 2])] + class_probabilites = [np.array([0.5, 0.5]), np.array([0.6, 0.1, 0.3])] + + got = random_choice_csc(n_samples, classes, class_probabilites, + random_state) + assert_true(sp.issparse(got)) + + for k in range(len(classes)): + p = np.bincount(got.getcol(k).toarray().ravel()) / float(n_samples) + assert_array_almost_equal(class_probabilites[k], p, decimal=1) + + # Implicit class probabilities + classes = [[0, 1], [1, 2]] # test for array-like support + class_probabilites = [np.array([0.5, 0.5]), np.array([0, 1/2, 1/2])] + + got = random_choice_csc(n_samples=n_samples, + classes=classes, + random_state=random_state) + assert_true(sp.issparse(got)) + + for k in range(len(classes)): + p = np.bincount(got.getcol(k).toarray().ravel()) / float(n_samples) + assert_array_almost_equal(class_probabilites[k], p, decimal=1) + + # Edge case proabilites 1.0 and 0.0 + classes = [np.array([0, 1]), np.array([0, 1, 2])] + class_probabilites = [np.array([1.0, 0.0]), np.array([0.0, 1.0, 0.0])] + + got = random_choice_csc(n_samples, classes, class_probabilites, + random_state) + assert_true(sp.issparse(got)) + + for k in range(len(classes)): + p = np.bincount(got.getcol(k).toarray().ravel(), + minlength=len(class_probabilites[k])) / n_samples + assert_array_almost_equal(class_probabilites[k], p, decimal=1) + + # One class target data + classes = [[1], [0]] # test for array-like support + class_probabilites = [np.array([0.0, 1.0]), np.array([1.0])] + + got = random_choice_csc(n_samples=n_samples, + classes=classes, + random_state=random_state) + assert_true(sp.issparse(got)) + + for k in range(len(classes)): + p = np.bincount(got.getcol(k).toarray().ravel()) / n_samples + assert_array_almost_equal(class_probabilites[k], p, decimal=1) + + +def test_random_choice_csc_errors(): + # the length of an array in classes and class_probabilites is mismatched + classes = [np.array([0, 1]), np.array([0, 1, 2, 3])] + class_probabilites = [np.array([0.5, 0.5]), np.array([0.6, 0.1, 0.3])] + assert_raises(ValueError, random_choice_csc, 4, classes, + class_probabilites, 1) + + # the class dtype is not supported + classes = [np.array(["a", "1"]), np.array(["z", "1", "2"])] + class_probabilites = [np.array([0.5, 0.5]), np.array([0.6, 0.1, 0.3])] + assert_raises(ValueError, random_choice_csc, 4, classes, + class_probabilites, 1) + + # the class dtype is not supported + classes = [np.array([4.2, 0.1]), np.array([0.1, 0.2, 9.4])] + class_probabilites = [np.array([0.5, 0.5]), np.array([0.6, 0.1, 0.3])] + assert_raises(ValueError, random_choice_csc, 4, classes, + class_probabilites, 1) + + # Given proabilites don't sum to 1 + classes = [np.array([0, 1]), np.array([0, 1, 2])] + class_probabilites = [np.array([0.5, 0.6]), np.array([0.6, 0.1, 0.3])] + assert_raises(ValueError, random_choice_csc, 4, classes, + class_probabilites, 1) + + +if __name__ == '__main__': + import nose + nose.runmodule() diff --git a/sklearn/utils/tests/test_sparsefuncs.py b/sklearn/utils/tests/test_sparsefuncs.py index 686df79aff76d..ff3460fdde4cf 100644 --- a/sklearn/utils/tests/test_sparsefuncs.py +++ b/sklearn/utils/tests/test_sparsefuncs.py @@ -5,11 +5,12 @@ from numpy.testing import assert_array_almost_equal, assert_array_equal from sklearn.datasets import make_classification -from sklearn.utils.sparsefuncs import (mean_variance_axis0, +from sklearn.utils.sparsefuncs import (mean_variance_axis, inplace_column_scale, inplace_row_scale, inplace_swap_row, inplace_swap_column, - min_max_axis) + min_max_axis, + count_nonzero) from sklearn.utils.sparsefuncs_fast import assign_rows_csr from sklearn.utils.testing import assert_raises @@ -25,27 +26,73 @@ def test_mean_variance_axis0(): X[1, 0] = 0 X_csr = sp.csr_matrix(X_lil) - X_means, X_vars = mean_variance_axis0(X_csr) + X_means, X_vars = mean_variance_axis(X_csr, axis=0) assert_array_almost_equal(X_means, np.mean(X, axis=0)) assert_array_almost_equal(X_vars, np.var(X, axis=0)) X_csc = sp.csc_matrix(X_lil) - X_means, X_vars = mean_variance_axis0(X_csc) + X_means, X_vars = mean_variance_axis(X_csc, axis=0) assert_array_almost_equal(X_means, np.mean(X, axis=0)) assert_array_almost_equal(X_vars, np.var(X, axis=0)) - assert_raises(TypeError, mean_variance_axis0, X_lil) + assert_raises(TypeError, mean_variance_axis, X_lil, axis=0) X = X.astype(np.float32) X_csr = X_csr.astype(np.float32) X_csc = X_csr.astype(np.float32) - X_means, X_vars = mean_variance_axis0(X_csr) + X_means, X_vars = mean_variance_axis(X_csr, axis=0) assert_array_almost_equal(X_means, np.mean(X, axis=0)) assert_array_almost_equal(X_vars, np.var(X, axis=0)) - X_means, X_vars = mean_variance_axis0(X_csc) + X_means, X_vars = mean_variance_axis(X_csc, axis=0) assert_array_almost_equal(X_means, np.mean(X, axis=0)) assert_array_almost_equal(X_vars, np.var(X, axis=0)) - assert_raises(TypeError, mean_variance_axis0, X_lil) + assert_raises(TypeError, mean_variance_axis, X_lil, axis=0) + + +def test_mean_variance_illegal_axis(): + X, _ = make_classification(5, 4, random_state=0) + # Sparsify the array a little bit + X[0, 0] = 0 + X[2, 1] = 0 + X[4, 3] = 0 + X_csr = sp.csr_matrix(X) + assert_raises(ValueError, mean_variance_axis, X_csr, axis=-3) + assert_raises(ValueError, mean_variance_axis, X_csr, axis=2) + assert_raises(ValueError, mean_variance_axis, X_csr, axis=-1) + + +def test_mean_variance_axis1(): + X, _ = make_classification(5, 4, random_state=0) + # Sparsify the array a little bit + X[0, 0] = 0 + X[2, 1] = 0 + X[4, 3] = 0 + X_lil = sp.lil_matrix(X) + X_lil[1, 0] = 0 + X[1, 0] = 0 + X_csr = sp.csr_matrix(X_lil) + + X_means, X_vars = mean_variance_axis(X_csr, axis=1) + assert_array_almost_equal(X_means, np.mean(X, axis=1)) + assert_array_almost_equal(X_vars, np.var(X, axis=1)) + + X_csc = sp.csc_matrix(X_lil) + X_means, X_vars = mean_variance_axis(X_csc, axis=1) + + assert_array_almost_equal(X_means, np.mean(X, axis=1)) + assert_array_almost_equal(X_vars, np.var(X, axis=1)) + assert_raises(TypeError, mean_variance_axis, X_lil, axis=1) + + X = X.astype(np.float32) + X_csr = X_csr.astype(np.float32) + X_csc = X_csr.astype(np.float32) + X_means, X_vars = mean_variance_axis(X_csr, axis=1) + assert_array_almost_equal(X_means, np.mean(X, axis=1)) + assert_array_almost_equal(X_vars, np.var(X, axis=1)) + X_means, X_vars = mean_variance_axis(X_csc, axis=1) + assert_array_almost_equal(X_means, np.mean(X, axis=1)) + assert_array_almost_equal(X_vars, np.var(X, axis=1)) + assert_raises(TypeError, mean_variance_axis, X_lil, axis=1) def test_densify_rows(): @@ -289,3 +336,26 @@ def test_min_max_axis_errors(): assert_raises(TypeError, min_max_axis, X_csr.tolil(), axis=0) assert_raises(ValueError, min_max_axis, X_csr, axis=2) assert_raises(ValueError, min_max_axis, X_csc, axis=-3) + + +def test_count_nonzero(): + X = np.array([[0, 3, 0], + [2, -1, 0], + [0, 0, 0], + [9, 8, 7], + [4, 0, 5]], dtype=np.float64) + X_csr = sp.csr_matrix(X) + X_csc = sp.csc_matrix(X) + X_nonzero = X != 0 + sample_weight = [.5, .2, .3, .1, .1] + X_nonzero_weighted = X_nonzero * np.array(sample_weight)[:, None] + + for axis in [0, 1, -1, -2, None]: + assert_array_almost_equal(count_nonzero(X_csr, axis=axis), + X_nonzero.sum(axis=axis)) + assert_array_almost_equal(count_nonzero(X_csr, axis=axis, + sample_weight=sample_weight), + X_nonzero_weighted.sum(axis=axis)) + + assert_raises(TypeError, count_nonzero, X_csc) + assert_raises(ValueError, count_nonzero, X_csr, axis=2) diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py index 33997b9eb8d3a..26aa984b911a5 100644 --- a/sklearn/utils/validation.py +++ b/sklearn/utils/validation.py @@ -156,6 +156,9 @@ def _ensure_sparse_format(spmatrix, accept_sparse, dtype, order, copy, matrix input will raise an error. If the input is sparse but not in the allowed format, it will be converted to the first listed format. + dtype : string, type or None (default=none) + Data type of result. If None, the dtype of the input is preserved. + order : 'F', 'C' or None (default=None) Whether an array will be forced to be fortran or c-style. @@ -218,6 +221,9 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False, If the input is sparse but not in the allowed format, it will be converted to the first listed format. + dtype : string, type or None (default=none) + Data type of result. If None, the dtype of the input is preserved. + order : 'F', 'C' or None (default=None) Whether an array will be forced to be fortran or c-style. @@ -281,6 +287,9 @@ def check_X_y(X, y, accept_sparse=None, dtype=None, order=None, copy=False, If the input is sparse but not in the allowed format, it will be converted to the first listed format. + dtype : string, type or None (default=none) + Data type of result. If None, the dtype of the input is preserved. + order : 'F', 'C' or None (default=None) Whether an array will be forced to be fortran or c-style. @@ -297,6 +306,10 @@ def check_X_y(X, y, accept_sparse=None, dtype=None, order=None, copy=False, allow_nd : boolean (default=False) Whether to allow X.ndim > 2. + multi_output : boolean (default=False) + Whether to allow 2-d y (array or sparse matrix). If false, y will be + validated as a vector. + Returns ------- X_converted : object