00001 """
00002 simple example of how to create a vector and run
00003 commands
00004 """
00005 from slimpy_base.utils.slim_decorators import depends_on
00006
00007 usage = "python simple.py [options]"
00008
00009 from slimpy_base import Execute, vector, fft1,parse_env, env
00010 from slimpy_base.setup import *
00011 from slimpy_base import Scatter
00012
00013 @depends_on( 'blocksize', 'numblocks' )
00014 def scatter_bldr(target,source,env):
00015
00016 parse_env( env )
00017
00018 blocksize = env.get('blocksize',None)
00019 numblocks = env.get('numblocks',None)
00020 assert blocksize is not None or numblocks is not None, "must set blocksize or numblocks"
00021 x = vector( source[0] )
00022
00023 S = Scatter( x.space, blocksize=blocksize, numblocks=numblocks )
00024
00025 r = S *x
00026
00027 r.thr(0.02) * 2
00028
00029 gathered = S.adj() * r
00030
00031 gathered.setName( target[0] )
00032
00033 Execute()
00034
00035 Parameters( 'blocksize', 'numblocks' ,'tgt','src' )
00036 Types( blocksize=eval, numblocks=eval )
00037
00038 if __name__ == '__main__':
00039
00040
00041 check_required( 'blocksize','numblocks' )
00042 check_required( 'tgt' )
00043 check_required( 'src' )
00044
00045
00046 env = parse_args()
00047 target = [ env.pop('tgt') ]
00048 source = [ env.pop('src') ]
00049
00050 scatter_bldr(target, source, env)
00051
00052 else:
00053 __all__ = ['MyScatter']
00054
00055 from slimproj_core.builders.CreateBuilders import add_to_slim_env
00056
00057 MyScatter = add_to_slim_env( "MyScatter", scatter_bldr )
00058
00059