def testSelects(self): mask = N.ones((3,2)) mask[1,1] = 0 mask0 = mask.copy() data = N.arange(6).reshape(mask.shape) map_ = DenseArrayMapper(mask) # check if any exception is thrown if we get # out of the outIds self.failUnlessRaises(IndexError, map_.selectOut, [0,1,2,6]) # remove 1,2 map_.selectOut([0,3,4]) self.failUnless((map_.forward(data)==[0, 4, 5]).all()) # remove 1 more map_.selectOut([0,2]) self.failUnless((map_.forward(data)==[0, 5]).all()) # check if original mask wasn't perturbed self.failUnless((mask == mask0).all()) # do the same but using discardOut map_ = DenseArrayMapper(mask) map_.discardOut([1,2]) self.failUnless((map_.forward(data)==[0, 4, 5]).all()) map_.discardOut([1]) self.failUnless((map_.forward(data)==[0, 5]).all()) # check if original mask wasn't perturbed self.failUnless((mask == mask0).all())
def _testSelectReOrder(self): """ Test is desabled for now since if order is incorrect in __debug__ we just spit out a warning - no exception """ mask = N.ones((3,3)) mask[1,1] = 0 data = N.arange(9).reshape(mask.shape) map_ = DenseArrayMapper(mask) oldneighbors = map_.forward(data)[map_.getNeighbors(0, radius=2)] # just do place changes # by default - we don't sort/check order so it would screw things # up map_.selectOut([7, 1, 2, 3, 4, 5, 6, 0]) # we check if an item new outId==7 still has proper neighbors newneighbors = map_.forward(data)[map_.getNeighbors(7, radius=2)] self.failUnless( (oldneighbors != newneighbors ).any())
def testForwardDenseArrayMapper(self): mask = N.ones((3,2)) map_ = DenseArrayMapper(mask) # test shape reports self.failUnless( map_.nfeatures == 6 ) # test 1sample mapping self.failUnless( ( map_.forward( N.arange(6).reshape(3,2) ) \ == [0,1,2,3,4,5]).all() ) # test 4sample mapping foursample = map_.forward( N.arange(24).reshape(4,3,2)) self.failUnless( ( foursample \ == [[0,1,2,3,4,5], [6,7,8,9,10,11], [12,13,14,15,16,17], [18,19,20,21,22,23]]).all() ) # check incomplete masks mask[1,1] = 0 map_ = DenseArrayMapper(mask) self.failUnless( map_.nfeatures == 5 ) self.failUnless( ( map_.forward( N.arange(6).reshape(3,2) ) \ == [0,1,2,4,5]).all() ) # check that it doesn't accept wrong dataspace self.failUnlessRaises( ValueError, map_.forward, N.arange(4).reshape(2,2) ) # check fail if neither mask nor shape self.failUnlessRaises(ValueError, DenseArrayMapper) # check that a full mask is automatically created when providing shape m = DenseArrayMapper(shape=(2, 3, 4)) mp = m.forward(N.arange(24).reshape(2, 3, 4)) self.failUnless((mp == N.arange(24)).all())
def testMapperAliases(self): mm=DenseArrayMapper(N.ones((3,4,2))) # We decided to don't have alias for reverse #self.failUnless((mm(N.arange(24)) == mm.reverse(N.arange(24))).all()) self.failUnless((mm(N.ones((3,4,2))) \ == mm.forward(N.ones((3,4,2)))).all())