summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2007-09-30 10:41:27 +0000
committerStefan van der Walt <stefan@sun.ac.za>2007-09-30 10:41:27 +0000
commit325cd587fd8fb15c6b9e69621fa1ae0a54ab8fe5 (patch)
tree0693485c0acbe4107b4bd18086b78419de84e7bc /numpy/lib
parent38cb2ac1c22916d6426055b11e9e870d3f5f7f10 (diff)
downloadnumpy-325cd587fd8fb15c6b9e69621fa1ae0a54ab8fe5.tar.gz
Fix tri when dtype is bool (closes ticket #574).
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_twodim_base.py14
-rw-r--r--numpy/lib/twodim_base.py3
2 files changed, 12 insertions, 5 deletions
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py
index 9e24caa7a..92ddf5b34 100644
--- a/numpy/lib/tests/test_twodim_base.py
+++ b/numpy/lib/tests/test_twodim_base.py
@@ -5,7 +5,7 @@
from numpy.testing import *
set_package_path()
from numpy import arange, rot90, add, fliplr, flipud, zeros, ones, eye, \
- array, diag, histogram2d
+ array, diag, histogram2d, tri
import numpy as np
restore_path()
@@ -160,7 +160,7 @@ class test_histogram2d(NumpyTestCase):
assert_array_equal(H, eye(10,10))
assert_array_equal(xedges, np.linspace(0,9,11))
assert_array_equal(yedges, np.linspace(0,9,11))
-
+
def check_asym(self):
x = array([1, 1, 2, 3, 4, 4, 4, 5])
y = array([1, 3, 2, 0, 1, 2, 3, 4])
@@ -187,6 +187,14 @@ class test_histogram2d(NumpyTestCase):
r = rand(100)+1.
H, xed, yed = histogram2d(r, r, (4, 5), range=([0,1], [0,1]))
assert_array_equal(H, 0)
-
+
+class test_tri(NumpyTestCase):
+ def test_dtype(self):
+ out = array([[1,0,0],
+ [1,1,0],
+ [1,1,1]])
+ assert_array_equal(tri(3),out)
+ assert_array_equal(tri(3,dtype=bool),out.astype(bool))
+
if __name__ == "__main__":
NumpyTest().run()
diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py
index a53790e41..a067139af 100644
--- a/numpy/lib/twodim_base.py
+++ b/numpy/lib/twodim_base.py
@@ -108,8 +108,7 @@ def tri(N, M=None, k=0, dtype=float):
"""
if M is None: M = N
m = greater_equal(subtract.outer(arange(N), arange(M)),-k)
- if m.dtype != dtype:
- return m.astype(dtype)
+ return m.astype(dtype)
def tril(m, k=0):
""" returns the elements on and below the k-th diagonal of m. k=0 is the