def testDenseArrayMapperMetrics(self): """ Test DenseArrayMapperMetric """ mask = N.ones((3,2)) mask[1,1] = 0 # take space with non-square elements neighborFinder = DescreteMetric([0.5, 2]) map_ = DenseArrayMapper(mask, neighborFinder) # test getNeighbors # now it returns list of arrays #target = [N.array([0, 0]), N.array([0, 1]), # N.array([1, 0]), N.array([2, 0])] #result = map_.getNeighborIn([0, 0], 2) #self.failUnless(N.array(map(lambda x,y:(x==y).all(), result, target)).all()) # check by providing outId target = [0,1,2,3] result = map_.getNeighbors(0, 2.1) self.failUnless( result == target ) map__ = DenseArrayMapper(mask, elementsize=[0.5, 2]) self.failUnless( map__.getNeighbors(0, 2.1) == target, msg="DenseArrayMapper must accept elementsize parameter and set" + " DescreteMetric accordingly") self.failUnlessRaises(ValueError, DenseArrayMapper, mask, elementsize=[0.5]*3) """DenseArrayMapper must raise exception when not appropriatly sized
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())