示例#1
0
    def block_test(data, mask, max_blk_edge, rad):

        comm = MPI.COMM_WORLD
        rank = comm.rank

        (dim0, dim1, dim2) = mask.shape

        # Initialize dataset with known pattern
        for subj in data:
            if subj is not None:
                for tr in range(subj.shape[3]):
                    for d1 in range(dim0):
                        for d2 in range(dim1):
                            for d3 in range(dim2):
                                subj[d1, d2, d3, tr] = np.array(
                                    [d1, d2, d3, tr])

        sl = Searchlight(sl_rad=rad, max_blk_edge=max_blk_edge)
        sl.distribute(data, mask)
        sl.broadcast(mask)
        global_outputs = sl.run_block_function(block_test_sfn)

        if rank == 0:
            for d0 in range(rad, global_outputs.shape[0]-rad):
                for d1 in range(rad, global_outputs.shape[1]-rad):
                    for d2 in range(rad, global_outputs.shape[2]-rad):
                        if mask[d0, d1, d2]:
                            assert np.array_equal(
                                np.array(global_outputs[d0, d1, d2]),
                                np.array([d0, d1, d2, 0]))
示例#2
0
 def block_test(data, mask, max_blk_edge, rad):
   
   comm = MPI.COMM_WORLD
   rank = comm.rank
   size = comm.size
   
   nsubj = len(data)
   (dim0, dim1, dim2) = mask.shape
   
   # Initialize dataset with known pattern
   for subj in data:
     if subj is not None:
       for tr in range(subj.shape[3]):
         for d1 in range(dim0):
           for d2 in range(dim1):
             for d3 in range(dim2): 
               subj[d1,d2,d3,tr] = np.array([ d1, d2, d3, tr])
   
   def sfn(l,msk,myrad,bcast_var, extra_params):
     outmat = l[0][:,:,:,0] 
     outmat[~msk] = None
     return outmat[rad:-rad,rad:-rad,rad:-rad] 
   
   sl = Searchlight(sl_rad=rad, max_blk_edge=max_blk_edge)
   sl.distribute(data, mask)
   sl.broadcast(mask)
   global_outputs = sl.run_block_function(sfn)
 
   if rank == 0:
     for d0 in range(rad, global_outputs.shape[0]-rad):
       for d1 in range(rad, global_outputs.shape[1]-rad):
         for d2 in range(rad, global_outputs.shape[2]-rad):
           if mask[d0, d1, d2]:
             assert np.array_equal(np.array(global_outputs[d0,d1,d2]), np.array([d0,d1,d2,0]))
    def block_test(data, mask, max_blk_edge, rad):

        comm = MPI.COMM_WORLD
        rank = comm.rank

        (dim0, dim1, dim2) = mask.shape

        # Initialize dataset with known pattern
        for subj in data:
            if subj is not None:
                for tr in range(subj.shape[3]):
                    for d1 in range(dim0):
                        for d2 in range(dim1):
                            for d3 in range(dim2):
                                subj[d1, d2, d3, tr] = np.array(
                                    [d1, d2, d3, tr])

        sl = Searchlight(sl_rad=rad, max_blk_edge=max_blk_edge)
        sl.distribute(data, mask)
        sl.broadcast(mask)
        global_outputs = sl.run_block_function(block_test_sfn)

        if rank == 0:
            for d0 in range(rad, global_outputs.shape[0]-rad):
                for d1 in range(rad, global_outputs.shape[1]-rad):
                    for d2 in range(rad, global_outputs.shape[2]-rad):
                        if mask[d0, d1, d2]:
                            assert np.array_equal(
                                np.array(global_outputs[d0, d1, d2]),
                                np.array([d0, d1, d2, 0]))
示例#4
0
 def block_test(data, mask, max_blk_edge, rad):
   
   comm = MPI.COMM_WORLD
   rank = comm.rank
   size = comm.size
   
   nsubj = len(data)
   (dim0, dim1, dim2) = mask.shape
   
   # Initialize dataset with known pattern
   for subj in data:
     if subj is not None:
       for tr in range(subj.shape[3]):
         for d1 in range(dim0):
           for d2 in range(dim1):
             for d3 in range(dim2): 
               subj[d1,d2,d3,tr] = np.array([ d1, d2, d3, tr])
   
   def sfn(l,msk,myrad,bcast_var):
     outmat = l[0][:,:,:,0] 
     outmat[~msk] = None
     return outmat[rad:-rad,rad:-rad,rad:-rad] 
   
   sl = Searchlight(sl_rad=rad, max_blk_edge=max_blk_edge)
   sl.distribute(data, mask)
   sl.broadcast(mask)
   global_outputs = sl.run_block_function(sfn)
 
   if rank == 0:
     for d0 in range(rad, global_outputs.shape[0]-rad):
       for d1 in range(rad, global_outputs.shape[1]-rad):
         for d2 in range(rad, global_outputs.shape[2]-rad):
           if mask[d0, d1, d2]:
             assert np.array_equal(np.array(global_outputs[d0,d1,d2]), np.array([d0,d1,d2,0]))