Skip to content

Commit

Permalink
Merge branch 'pr/515' into merge-515
Browse files Browse the repository at this point in the history
Conflicts:
	scipy/io/wavfile.py
	scipy/lib/blas/setup.py
	scipy/optimize/tests/test_optimize.py
	scipy/sparse/compressed.py
	scipy/sparse/tests/test_base.py
	scipy/stats/tests/test_fit.py
  • Loading branch information
rgommers committed May 5, 2013
2 parents 009be70 + 2ad7c78 commit de9bdd5
Show file tree
Hide file tree
Showing 381 changed files with 4,745 additions and 2,848 deletions.
2 changes: 1 addition & 1 deletion scipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
majver, minver = [float(i) for i in _num.version.version.split('.')[:2]]
if majver < 1 or (majver == 1 and minver < 5):
import warnings
warnings.warn("Numpy 1.5.0 or above is recommended for this version of " \
warnings.warn("Numpy 1.5.0 or above is recommended for this version of "
"scipy (detected version %s)" % _num.version.version,
UserWarning)

Expand Down
4 changes: 3 additions & 1 deletion scipy/_build_utils/_fortran.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import sys


def _uses_veclib(info):
r_accelerate = re.compile("Accelerate|vecLib")

Expand All @@ -11,6 +12,7 @@ def _uses_veclib(info):

return False


def _uses_mkl(info):
r_mkl = re.compile("mkl_core")

Expand All @@ -21,6 +23,7 @@ def _uses_mkl(info):

return False


def needs_g77_abi_wrapper(info):
"""Returns true if g77 ABI wrapper must be used."""
if _uses_veclib(info):
Expand All @@ -30,4 +33,3 @@ def needs_g77_abi_wrapper(info):
return True
else:
return False

1 change: 1 addition & 0 deletions scipy/cluster/doc/ex1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from scipy import *
from scipy.cluster import vq


def cluster_data(data,cluster_cnt,iter=20,thresh=1e-5):
""" Group data into a number of common clusters
Expand Down
30 changes: 17 additions & 13 deletions scipy/cluster/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def linkage(y, method='single', metric='euclidean'):
[y] = _copy_arrays_if_base_present([y])

Z = np.zeros((d - 1, 4))
_hierarchy_wrap.linkage_wrap(y, Z, int(d), \
_hierarchy_wrap.linkage_wrap(y, Z, int(d),
int(_cpy_non_euclid_methods[method]))
elif len(s) == 2:
X = y
Expand All @@ -642,7 +642,7 @@ def linkage(y, method='single', metric='euclidean'):
if method in _cpy_non_euclid_methods:
dm = distance.pdist(X, metric)
Z = np.zeros((n - 1, 4))
_hierarchy_wrap.linkage_wrap(dm, Z, n, \
_hierarchy_wrap.linkage_wrap(dm, Z, n,
int(_cpy_non_euclid_methods[method]))
elif method in _cpy_euclid_methods:
if metric != 'euclidean':
Expand Down Expand Up @@ -1548,7 +1548,7 @@ def fcluster(Z, t, criterion='inconsistent', depth=2, R=None, monocrit=None):
return T


def fclusterdata(X, t, criterion='inconsistent', \
def fclusterdata(X, t, criterion='inconsistent',
metric='euclidean', depth=2, method='single', R=None):
"""
Cluster observation data using a given metric.
Expand Down Expand Up @@ -1657,6 +1657,7 @@ def leaves_list(Z):
_drotationsortedkeys = list(_drotation.keys())
_drotationsortedkeys.sort()


def _remove_dups(L):
"""
Removes duplicates AND preserves the original order of the elements.
Expand All @@ -1670,16 +1671,19 @@ def _remove_dups(L):
L2.append(i)
return L2


def _get_tick_text_size(p):
for k in _dtextsortedkeys:
if p <= k:
return _dtextsizes[k]


def _get_tick_rotation(p):
for k in _drotationsortedkeys:
if p <= k:
return _drotation[k]


def _plot_dendrogram(icoords, dcoords, ivl, p, n, mh, orientation,
no_labels, color_list, leaf_font_size=None,
leaf_rotation=None, contraction_marks=None):
Expand Down Expand Up @@ -2209,15 +2213,15 @@ def _append_contraction_marks_sub(Z, iv, i, n, contraction_marks):
_append_contraction_marks_sub(Z, iv, Z[i - n, 1], n, contraction_marks)


def _dendrogram_calculate_info(Z, p, truncate_mode, \
color_threshold=np.inf, get_leaves=True, \
orientation='top', labels=None, \
count_sort=False, distance_sort=False, \
show_leaf_counts=False, i=-1, iv=0.0, \
ivl=[], n=0, icoord_list=[], dcoord_list=[], \
lvs=None, mhr=False, \
current_color=[], color_list=[], \
currently_below_threshold=[], \
def _dendrogram_calculate_info(Z, p, truncate_mode,
color_threshold=np.inf, get_leaves=True,
orientation='top', labels=None,
count_sort=False, distance_sort=False,
show_leaf_counts=False, i=-1, iv=0.0,
ivl=[], n=0, icoord_list=[], dcoord_list=[],
lvs=None, mhr=False,
current_color=[], color_list=[],
currently_below_threshold=[],
leaf_label_func=None, level=0,
contraction_marks=None,
link_color_func=None):
Expand Down Expand Up @@ -2683,7 +2687,7 @@ def _leader_identify(tr, T):
right = tr.get_right()
lfid = _leader_identify(left, T)
rfid = _leader_identify(right, T)
print('ndid: %d lid: %d lfid: %d rid: %d rfid: %d' \
print('ndid: %d lid: %d lfid: %d rid: %d rfid: %d'
% (tr.get_id(), left.get_id(), lfid, right.get_id(), rfid))
if lfid != rfid:
if lfid != -1:
Expand Down
19 changes: 10 additions & 9 deletions scipy/cluster/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@
else:
DEFINE_MACROS = []

def configuration(parent_package = '', top_path = None):

def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
config = Configuration('cluster', parent_package, top_path)

config.add_data_dir('tests')

config.add_extension('_vq',
sources=[join('src', 'vq_module.c'), join('src', 'vq.c')],
include_dirs = [get_numpy_include_dirs()],
include_dirs=[get_numpy_include_dirs()],
define_macros=DEFINE_MACROS)

config.add_extension('_hierarchy_wrap',
sources=[join('src', 'hierarchy_wrap.c'), join('src', 'hierarchy.c')],
include_dirs = [get_numpy_include_dirs()],
include_dirs=[get_numpy_include_dirs()],
define_macros=DEFINE_MACROS)

return config

if __name__ == '__main__':
from numpy.distutils.core import setup
setup(maintainer = "SciPy Developers",
author = "Eric Jones",
maintainer_email = "[email protected]",
description = "Clustering Algorithms (Information Theory)",
url = "http://www.scipy.org",
license = "SciPy License (BSD Style)",
setup(maintainer="SciPy Developers",
author="Eric Jones",
maintainer_email="[email protected]",
description="Clustering Algorithms (Information Theory)",
url="http://www.scipy.org",
license="SciPy License (BSD Style)",
**configuration(top_path='').todict()
)
15 changes: 8 additions & 7 deletions scipy/cluster/setupscons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from os.path import join

def configuration(parent_package = '', top_path = None):

def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
config = Configuration('cluster', parent_package, top_path)

Expand All @@ -18,11 +19,11 @@ def configuration(parent_package = '', top_path = None):

if __name__ == '__main__':
from numpy.distutils.core import setup
setup(maintainer = "SciPy Developers",
author = "Eric Jones",
maintainer_email = "[email protected]",
description = "Clustering Algorithms (Information Theory)",
url = "http://www.scipy.org",
license = "SciPy License (BSD Style)",
setup(maintainer="SciPy Developers",
author="Eric Jones",
maintainer_email="[email protected]",
description="Clustering Algorithms (Information Theory)",
url="http://www.scipy.org",
license="SciPy License (BSD Style)",
**configuration(top_path='').todict()
)
5 changes: 3 additions & 2 deletions scipy/cluster/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def test_fcluster_maxclusts_4(self):
T = fcluster(Z, criterion='maxclust', t=4)
self.assertTrue(is_isomorphic(T, expectedT))


class TestLeaders(TestCase):
def test_leaders_single(self):
"Tests leaders using a flat clustering generated by single linkage."
Expand Down Expand Up @@ -828,7 +829,7 @@ def test_is_monotonic_empty(self):

def test_is_monotonic_1x4(self):
"Tests is_monotonic(Z) on 1x4 linkage. Expecting True."
Z = np.asarray([[0, 1, 0.3, 2]], dtype=np.double);
Z = np.asarray([[0, 1, 0.3, 2]], dtype=np.double)
self.assertTrue(is_monotonic(Z) == True)

def test_is_monotonic_2x4_T(self):
Expand Down Expand Up @@ -879,7 +880,7 @@ def test_is_monotonic_tdist_linkage1(self):
def test_is_monotonic_tdist_linkage2(self):
"Tests is_monotonic(Z) on clustering generated by single linkage on tdist data set. Perturbing. Expecting False."
Z = linkage(_ytdist, 'single')
Z[2,2]=0.0
Z[2,2] = 0.0
self.assertTrue(is_monotonic(Z) == False)

def test_is_monotonic_iris_linkage(self):
Expand Down
24 changes: 13 additions & 11 deletions scipy/cluster/tests/test_vq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from scipy.cluster.vq import kmeans, kmeans2, py_vq, py_vq2, vq, ClusterError
try:
from scipy.cluster import _vq
TESTC=True
TESTC = True
except ImportError:
print("== Error while importing _vq, not testing C imp of vq ==")
TESTC=False
TESTC = False

#Optional:
# import modules that are located in the same directory as this file.
Expand All @@ -39,6 +39,7 @@

LABEL1 = np.array([0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1])


class TestVq(TestCase):
def test_py_vq(self):
initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
Expand Down Expand Up @@ -91,6 +92,7 @@ def test__vq_sametype(self):
b = a.astype(float)
assert_raises(ValueError, _vq.vq, a, b)


class TestKMean(TestCase):
def test_large_features(self):
# Generate a data set with large values, and run kmeans on it to
Expand All @@ -111,13 +113,13 @@ def test_large_features(self):
def test_kmeans_simple(self):
initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
code1 = kmeans(X, code, iter = 1)[0]
code1 = kmeans(X, code, iter=1)[0]

assert_array_almost_equal(code1, CODET2)

def test_kmeans_lost_cluster(self):
"""This will cause kmean to have a cluster with no points."""
data = np.fromfile(DATAFILE1, sep = ", ")
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
initk = np.array([[-1.8127404, -0.67128041],
[ 2.04621601, 0.07401111],
Expand All @@ -139,31 +141,31 @@ def test_kmeans2_simple(self):
"""Testing simple call to kmeans2 and its results."""
initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
code1 = kmeans2(X, code, iter = 1)[0]
code2 = kmeans2(X, code, iter = 2)[0]
code1 = kmeans2(X, code, iter=1)[0]
code2 = kmeans2(X, code, iter=2)[0]

assert_array_almost_equal(code1, CODET1)
assert_array_almost_equal(code2, CODET2)

def test_kmeans2_rank1(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep = ", ")
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]
data2 = data[:, 1]

initc = data1[:3]
code = initc.copy()
code1 = kmeans2(data1, code, iter = 1)[0]
code2 = kmeans2(data1, code, iter = 2)[0]
code1 = kmeans2(data1, code, iter=1)[0]
code2 = kmeans2(data1, code, iter=2)[0]

def test_kmeans2_rank1_2(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = np.fromfile(DATAFILE1, sep = ", ")
data = np.fromfile(DATAFILE1, sep=", ")
data = data.reshape((200, 2))
data1 = data[:, 0]

code1 = kmeans2(data1, 2, iter = 1)
code1 = kmeans2(data1, 2, iter=1)

def test_kmeans2_init(self):
"""Testing that kmeans2 init methods work."""
Expand Down
3 changes: 3 additions & 0 deletions scipy/cluster/tests/vq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from scipy.cluster import vq


def python_vq(all_data,code_book):
import time
t1 = time.time()
Expand All @@ -26,6 +27,7 @@ def python_vq(all_data,code_book):

return codes1,dist1


def read_data(name):
f = open(name,'r')
data = []
Expand All @@ -34,6 +36,7 @@ def read_data(name):
f.close()
return array(data)


def main():
np.random.seed((1000,1000))
Ncodes = 40
Expand Down
Loading

0 comments on commit de9bdd5

Please sign in to comment.