indexing.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright Jim Bosch & Ankit Daftery 2010-2012.
00004 # Distributed under the Boost Software License, Version 1.0.
00005 #    (See accompanying file LICENSE_1_0.txt or copy at
00006 #          http://www.boost.org/LICENSE_1_0.txt)
00007 
00008 import unittest
00009 import numpy
00010 import indexing_mod
00011 
00012 class TestIndexing(unittest.TestCase):
00013 
00014     def testSingle(self):
00015         x = numpy.arange(0,10)
00016         for i in range(0,10):
00017             numpy.testing.assert_equal(indexing_mod.single(x,i), i)
00018         for i in range(-10,0):
00019             numpy.testing.assert_equal(indexing_mod.single(x,i),10+i)
00020 
00021     def testSlice(self):
00022         x = numpy.arange(0,10)
00023         sl = slice(3,8)
00024         b = [3,4,5,6,7]
00025         numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
00026 
00027     def testStepSlice(self):
00028         x = numpy.arange(0,10)
00029         sl = slice(3,8,2)
00030         b = [3,5,7]
00031         numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
00032 
00033     def testIndex(self):
00034         x = numpy.arange(0,10)
00035         chk = numpy.array([3,4,5,6])
00036         numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
00037         chk = numpy.array([[0,1],[2,3]])
00038         numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
00039         x = numpy.arange(9).reshape(3,3)
00040         y = numpy.array([0,1])
00041         z = numpy.array([0,2])
00042         chk = numpy.array([0,5])
00043         numpy.testing.assert_equal(indexing_mod.indexarray(x,y,z),chk)
00044         x = numpy.arange(0,10)
00045         b = x>4
00046         chk = numpy.array([5,6,7,8,9])
00047         numpy.testing.assert_equal(indexing_mod.indexarray(x,b),chk)
00048         x = numpy.arange(9).reshape(3,3)
00049         b = numpy.array([0,2])
00050         sl = slice(0,3)
00051         chk = numpy.array([[0,1,2],[6,7,8]])
00052         numpy.testing.assert_equal(indexing_mod.indexslice(x,b,sl),chk)
00053 
00054 if __name__=="__main__":
00055     unittest.main()


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40