Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(346)

Side by Side Diff: numpy/lib/tests/test_function_base.py

Issue 1105: `piecewise` exposes raw memory (Closed) Base URL: http://svn.scipy.org/svn/numpy/trunk/
Patch Set: Created 15 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« numpy/lib/function_base.py ('K') | « numpy/lib/function_base.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import sys 1 import sys
2 2
3 from numpy.testing import * 3 from numpy.testing import *
4 set_package_path() 4 set_package_path()
5 import numpy.lib;reload(numpy.lib) 5 import numpy.lib;reload(numpy.lib)
6 from numpy.lib import * 6 from numpy.lib import *
7 from numpy.core import * 7 from numpy.core import *
8 8
9 del sys.path[0] 9 del sys.path[0]
10 10
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 class TestUnique(NumpyTestCase): 606 class TestUnique(NumpyTestCase):
607 def check_simple(self): 607 def check_simple(self):
608 x = array([4,3,2,1,1,2,3,4, 0]) 608 x = array([4,3,2,1,1,2,3,4, 0])
609 assert(all(unique(x) == [0,1,2,3,4])) 609 assert(all(unique(x) == [0,1,2,3,4]))
610 assert(unique(array([1,1,1,1,1])) == array([1])) 610 assert(unique(array([1,1,1,1,1])) == array([1]))
611 x = ['widget', 'ham', 'foo', 'bar', 'foo', 'ham'] 611 x = ['widget', 'ham', 'foo', 'bar', 'foo', 'ham']
612 assert(all(unique(x) == ['bar', 'foo', 'ham', 'widget'])) 612 assert(all(unique(x) == ['bar', 'foo', 'ham', 'widget']))
613 x = array([5+6j, 1+1j, 1+10j, 10, 5+6j]) 613 x = array([5+6j, 1+1j, 1+10j, 10, 5+6j])
614 assert(all(unique(x) == [1+1j, 1+10j, 5+6j, 10])) 614 assert(all(unique(x) == [1+1j, 1+10j, 5+6j, 10]))
615 615
616
617 class TestPiecewise(NumpyTestCase):
618 def check_simple(self):
619 # Condition is single bool list
620 x = piecewise([0,0],[True,False],[1])
621 assert_array_equal(x,[1,0])
622
623 # List of conditions: single bool list
624 x = piecewise([0,0],[[True,False]],[1])
625 assert_array_equal(x,[1,0])
626
627 # Conditions is single bool array
628 x = piecewise([0,0],array([True,False]),[1])
629 assert_array_equal(x,[1,0])
630
631 # Condition is single int array
632 x = piecewise([0,0],array([1,0]),[1])
633 assert_array_equal(x,[1,0])
634
635 # List of conditions: int array
636 x = piecewise([0,0],[array([1,0])],[1])
637 assert_array_equal(x,[1,0])
638
639
640 x = piecewise([0,0],[[False,True]],[lambda x: -1])
641 assert_array_equal(x,[0,-1])
642
643 x = piecewise([1,2],[[True,False],[False,True]],[3,4])
644 assert_array_equal(x,[3,4])
645
646 def check_default(self):
647 # No value specified for x[1], should be 0
648 x = piecewise([1,2],[True,False],[2])
649 assert_array_equal(x,[2,0])
650
651 # Should set x[1] to 3
652 x = piecewise([1,2],[True,False],[2,3])
653 assert_array_equal(x,[2,3])
654
ondrej.certik 2008/05/21 09:51:53 This is maybe puristic, but I think the standard i
stefanv 2008/05/21 10:24:26 Done.
655
616 def compare_results(res,desired): 656 def compare_results(res,desired):
617 for i in range(len(desired)): 657 for i in range(len(desired)):
618 assert_array_equal(res[i],desired[i]) 658 assert_array_equal(res[i],desired[i])
619 659
620 if __name__ == "__main__": 660 if __name__ == "__main__":
621 NumpyTest().run() 661 NumpyTest().run()
OLDNEW
« numpy/lib/function_base.py ('K') | « numpy/lib/function_base.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b