Example #1
0
 def treat_variant(self,s,variant) :
     mode = "simd"
     tb_name = s[0]
     fct = Functor(tb_name,'modify','sys')
     for ss in s[1:] :
         ss = re.sub('\b',' ',ss)
         if len(ss) == 0 : continue
         l = ss.split()
         if len(l) == 0 : continue
         fct_name = l[0]
         arity = 1 if len(l) <=1 else int(l[1])
         path = "simd/sse/"+variant
         fct.add_functor(fct_name,arity)
         st = fct.read_functor(fct_name,path)
         src = os.path.join(Recover.Pname,path,fct_name+'.hpp')
         if exist(src) and (os.path.getsize(src) > 1536) :
             print "adding functor %s of arity %d in variant %s (size %s)" % (fct_name, arity, variant,os.path.getsize(src))
             sys.stdout.flush()
             #                print"orig-----------------"
             #show(st)
             d = read(src)
             #                print"src-----------------"
             #show(d)
             v = get_struct(d,"validate")
             c = get_struct(d,"call")
             i = self.get_includes(d,tb_name,mode,fct.get_path_to_nt2())
             st = self.insert_variants(st,v,c,i,
                                       fct.get_tb_style(),
                                       fct.get_tb_name(),
                                       fct_name,
                                       mode)
             #                print"avant-----------------"
             #show(st)
             #                print"apr-Aès-----------------"-b
             fct.write_functor(fct_name,path,st,False)
Example #2
0
 def treat_one_tb(self,s,mode) :
     if mode == 'simd' :
         path = mode+'/common'
     else :
         path = mode
     tb_name = s[0]
     fct = Functor(tb_name,'modify','sys')
     for ss in s[1:] :
         ss = re.sub('\b',' ',ss)
         if len(ss) == 0 : continue
         l = ss.split()
         if len(l) == 0 : continue
         fct_name = l[0]
         arity = 1 if len(l) <=1 else int(l[1])
         fct.add_functor(fct_name,arity)
         st = fct.read_functor(fct_name,path)
         print "in toolbox %s adding functor %s of arity %d" % (tb_name,fct_name, arity) 
         sys.stdout.flush()
         src = os.path.join(Recover.Pname,path,fct_name+'.hpp')
         if exist(src) :
             d = read(src)
             v = get_struct(d,"validate")
             c = get_struct(d,"call")
             i = self.get_includes(d,tb_name,mode,fct.get_path_to_nt2())
             st = self.insert_validate_and_call(st,v,c,i,
                                                fct.get_tb_style(),
                                                fct.get_tb_name(),
                                                fct_name,
                                                mode)
             #            show(st)
             fct.write_functor(fct_name,path,st,False)
Example #3
0
 def add(self,fct_name,acts,subs_dict,action_data,check=True) :
     """add a file"""
     do_it = True
     fname = action_data["file"].replace('$fct_name$',fct_name)
     fct_name_path = os.path.abspath(os.path.join(self.get_tb_abs_path(),acts,fname))
     if acts != "" :
         rel_path = os.path.join(self.get_tb_pathfnt2(),acts)
     else :
         rel_path = 'nt2/include/functions'
         do_it = self.get_tb_style()[0]=='s'
     if do_it :
         tplname = '../tpl/'+action_data["tmpl"]
         # print  "action_data[tmpl] %s" % action_data["tmpl"]
         tpl_name_path = os.path.join(nt2_py_dir(),tplname)
         if "parm" in action_data.keys() :
             s = subs_dict["\$parms_type_and_ranges\$"]
             subs_dict["\$parms_type_and_ranges\$"] =  re.sub('\$parm\$', action_data["parm"], s)
         subs_dict["\$acts\$"] = acts
         inner_text = self.__treat(read(tpl_name_path),subs_dict)
         if "parm" in action_data.keys() :
             subs_dict["\$parms_type_and_ranges\$"] = s
         comment = action_data["cmmt"]
         flag    = action_data["head"]
         h = Headers(rel_path,fct_name,inner=inner_text,comment=comment)
         # print "fct_name_path %s" % fct_name_path
         h.write_header2(fct_name_path,flag=flag,check=check)
Example #4
0
    def read_style(self) :
        dirname = self.get_tb_abs_path()
        filename = os.path.join(dirname,'py_data.py')
        if exist(filename) :
            sys.path.insert(0,dirname)
            from py_data import datas
            s = datas['style']
            sys.path.pop(0)
            self.__tb_style = s
            return s

        dirname = self.get_tb_path2mode()
        filename = os.path.join(dirname,self.get_tb_name()+'.hpp')
        if exist(filename) :
            s = read(filename)
            pattern = re.compile("^// This toolbox is of (.*) type")
            for l in s :
                d1 = re.match(pattern,l)
                if d1 :
                    self.__tb_style = d1.groups()
                    return d1
            
      
        self.logger.warning(
            "\nno file allowing to determine the style of " % self.get_tb_name() +
            "longer exists.\nAssuming an usr toolbox.\n" 
            )
        self.__tb_style = 'usr'
        return 'usr'
Example #5
0
 def get_list(self,tb_name) :
     name = os.path.join(Recover.Iname,tb_name+'.hpp')
     txt_name = tb_name+'.txt'
     s = read(name)
     s = create_txt(tb_name,s)
     write(txt_name,s, False)
     return s
Example #6
0
 def get_list(self) :
     l = []
     for tb_name in Find.Toolbox_List :
         name = os.path.join(Recover.Iname,tb_name+'.hpp')
         s = read(name)
         r = self.create_txt(s)
         l.extend(r)
     return l
Example #7
0
 def get_list(self) :
     l = []
     for tb_name in self.tb_list :
         name = os.path.join(self.absolute_path_to_mode(),tb_name,tb_name+'.hpp')
         s = read(name)
         r = self.create_txt(s,tb_name)
         l.extend(r)
     return l
Example #8
0
 def get_functors_rel_path(self) :
     a = os.path.join(self.get_tb_abs_path(),self.get_tb_name()+'.hpp')
     s = read(a)
     r = []
     for l in s :
         m= re.search('\#include <(.*)>',l)
         if m :
             r.append(m.groups()[0])
     return r
Example #9
0
def set_one(fct,fct_name,arity,pname) :
    s = fct.read_functor(fct_name,'scalar')
    print "adding functor %s of arity %d" % (fct_name, arity) 
    src = os.path.join(pname,fct_name+'.hpp')
    d = read(src)
    v = get_validate(d)
    c = get_call(d)
    s = insert_validate_and_call(s,v,c,fct.get_tb_style(),fct.get_tb_name())
    show(s)
    fct.write_functor(fct_name,'scalar',s,False)
Example #10
0
 def update_CMake(self,check) :
     lp = self.__root_abs_path.split('/')
     p = os.path.join('/'.join(lp[:-4]),'CMakeLists.txt')
     s= read(p)
     pattern = "ADD_SUBDIRECTORY\(\${PROJECT_BINARY_DIR}/include/nt2/toolbox/"+self.get_tb_name()+'\)'
     for l in s :
         m = re.match(pattern, l)
         if m : return
     s.append(string.replace(pattern,'\\',''))    
     write(p,s,False)
Example #11
0
 def modify_tpl_defs(self) :
     for k in self.get_dict().keys() :
         if self.get_dict()[k][1] :
            p =  os.path.join(self.get_new_def_path(),k+'.hpp')
            s = read(p)
            pattern = " *NT2_FUNCTION_IMPLEMENTATION.*"
            rep = "  NT2_CRLIBM_FUNCTION_IMPLEMENTATION_TPL("+k+")"
            s = sub_list(pattern,rep,s)
            show(s)
            write(p,s,False)
Example #12
0
 def get_cpp_to_modify(self, tb_name) :
     cpp_list = self.get_unit_test_list(tb_name)
     unit_dir = self.get_unit_dir(tb_name)
     l = []
     for cpp in cpp_list :
         p = os.path.join(unit_dir,cpp+'.cpp')
         s = read(p)
         print len(s)
         if len(s) == self.__datas[self.__sc_si]['length'] :
             l.append(cpp)
     return l
Example #13
0
 def get_fctors_dict(self) :
     l = {}
     p0 = self.get_path()
     for name in os.listdir(p0) :
         if name[-4:]=='.hpp' :
             h = name[:-4]
             p = os.path.join(p0,h+'/py_data.py')
             if exist(p) :
                 s = ' '.join(read(p))
                 l[h] ='usr' if s.find('usr') > 0 else 'sys' 
     return l
Example #14
0
 def get_replacmt(self,target) :
     for d in self.get_list_dirs() :
         for h in self.get_list_hpps() :
             f = os.path.join(d,h)
             if exist(f) :
                 s = read(f)
                 st ='\n'.join(s)
                 if re.search(target,st) :
                    s=sub_list(target, Insert.Replacement[target],s)
                    write(f,s,False)
                    print "%s -> %s"%(target,Insert.Replacement[target])
Example #15
0
 def get_matches(self,target) :
     for d in self.get_list_dirs() :
         for h in self.get_list_hpps() :
             f = os.path.join(d,h)
             if exist(f) :
                 s = read(f)
                 st ='\n'.join(s)
                 if re.search(target,st) :
                    rep = Insert.Insertions[target]
                    if not re.search(rep,st) :
                        s.insert(10,rep)
                        write(f,s,False)
                        print "%s -> %s"%(target,h)
Example #16
0
def get_arity(pname) :
    if exist(pname) :
        s = read(pname)
        r = []
        for l in s :
            m = re.search('  NT2_FUNCTION_IMPLEMENTATION',l)
            if m :
                #            print "l = %s " % l
                m = re.search('([0-9]+)\)',l)
                if m :
                    #                print " arity %s "% m.groups()[0]
                    return m.groups()[0]
    return ""
Example #17
0
 def callback( arg, dirname, fnames ):
     for file in fnames:
         if file[-4:] =='.hpp' :
             fname =os.path.join(dirname,file)
             s =read(fname)
             v = gen_proper_guard(dirname[46:],file[:-4])
             if  len(s)>7 and s[8] != "" and s[8] !=v[0] :
                 print "file %s, dir %s " %(file,dirname[46:])
                 print "correct  %s "%v[0]
                 print "existing %s "%s[8]
                 s1 = []
                 s1.extend(banner)
                 s1.extend(v)
                 s1.extend(s[10:])
                 write(fname,s1,False)
Example #18
0
 def get_functors_datas(self) :
     pathes = self.get_functors_abs_path()
     dr = {}
     for p in pathes :
         d= {}
         lp = p.split('/')
         lp[-2]= 'function'
         name = lp[-1][:-4]
         s = read('/'.join(lp))
         r = []
         for l in s :
             m= re.search('([0-9]+)\) *$',l)
             if m : r.append(int(m.groups()[0]))
         d["arity"]=r
         dr[name]=d    
     return dr   
Example #19
0
 def ydm(self,fct_name,acts,subs_dict,action_data,check=True) :
     """modify a file (reverse of mdy): deleting a line"""
     fname = action_data["file"].replace('$root_name$',self.get_tb_name())
     file2modify = os.path.join(self.get_tb_abs_path(),acts,fname)
     text = read(file2modify)
     subs_dict["\$self.tb_pathfnt2\$"]=self.get_tb_pathfnt2()
     subs_dict["\$fct_name\$"]=fct_name
     line2rmv = self.__treat(action_data["l2ad"], subs_dict) 
     test, text = self.__rmv_line(text, line2rmv)
     if test :
         self.logger.info(
             "\nmodifying \n%s\nfor definition of functor %s\n" % (file2modify,fct_name)
             )
         write(file2modify,text,False)
     else :
         self.logger.warning(
             "\nFile %s was not present in file\n%s\n" %  (fct_name,file2modify)
             )
Example #20
0
 def get_arity(self,name) :
     p = os.path.join(self.get_tb_path(self.get_tb_name()),'function',name+'.hpp')
     s = read(p)
     for l in s :
         m = re.search('  NT2_FUNCTION_IMPLEMENTATION',l)
         if m :
             #            print "l = %s " % l
             m = re.search('([0-9]+)\)',l)
             if m :
                 #                print " arity %s "% m.groups()[0]
                 return int(m.groups()[0])
         else :
             m = re.search('  NT2_CRLIBM_FUNCTION_IMPLEMENTATION_TPL',l)
             if m :
                 #            print "l = %s " % l
                 m = re.search('([0-9]+)\)',l)
                 if m :
                     #                print " arity %s "% m.groups()[0]
                     return int(m.groups()[0])
                 
     return ""
Example #21
0
 def mdy(self,fct_name,acts,subs_dict,action_data,check=True) :
     """modify a file, inserting a line"""
     fname = action_data["file"].replace('$root_name$',self.get_tb_name())
     file2modify = os.path.join(self.get_tb_abs_path(),acts,fname)
     
     text = read(file2modify)
     subs_dict["\$self.tb_pathfnt2\$"]=self.get_tb_pathfnt2()
     subs_dict["\$fct_name\$"]=fct_name
     line2add = self.__treat(action_data["l2ad"], subs_dict) 
     token = action_data["tokn"]
     test, text = self.__add_line(text, line2add, token)
     if test :
         self.logger.info(
             "\nmodifying \n%s\nfor definition of functor %s\n" % (file2modify,fct_name)
             )
         write(file2modify,text,False)
     else :
         self.logger.warning(
             "\nFile %s was already included\n" % fct_name +
             "in file\n%s\n" %  file2modify
             )
Example #22
0
 def get_arity_and_tplness(self,pname) :
     if exist(pname) :
         s = read(pname)
         r = []
         for l in s :
             m = re.search('  NT2_FUNCTION_IMPLEMENTATION',l)
             if m :
                 #            print "l = %s " % l
                 m = re.search('([0-9]+)\)',l)
                 if m :
                     #                print " arity %s "% m.groups()[0]
                     return (int(m.groups()[0]),False)
             else :
                 m = re.search('  inline NT2_FUNCTION_RETURN_TYPE',l)
                 if m :
                     #            print "l = %s " % l
                     m = re.search('([0-9]+)\)',l)
                     if m :
                         #                print " arity %s "% m.groups()[0]
                         return (int(m.groups()[0]),True)
                 
     return ""
Example #23
0
    def modify_cpp(self,tb_name,cpps) :
        unit_dir = self.get_unit_dir(tb_name)
        d = {}
        if type(cpps) is str :
            d["#fct_name"]= cpps
            d["#tb_name"] = tb_name
            repls = self.update_replacmnt(d)
##            sinserts = self.update_strait_insertions(d)
##            finserts = self.update_final_insertions(d)
            p = os.path.join(unit_dir,cpps+'.cpp')
            s = read(p)
            s,doner = self.mk_replace(s,repls)
##            s,dones = self.mk_inserts(s,sinserts)
##            s,donef = self.mk_insertf(s,finserts)
            if True or doner :#or dones or donef:
                print "%s was modified" % cpps
                #show(s)
                self.update(s,d)
                #                show(s)
                write(p,s,False)

        else :
            for cpp in cpps :
                self.modify_cpp(tb_name,cpp)
Example #24
0
                beg = i-1
        else :
           m1 = re.search("({)",l)
           m2 = re.search("(})",l)
           nbl = len(m1.groups()) if m1 else 0
           nbr = len(m2.groups()) if m2 else 0
           nb += nbl-nbr
           if not nb :
               end = i+1
               return s[beg:end]

           
if __name__ == "__main__" :
    Mylogging.set_level('CRITICAL')
    length = len(sys.argv)
    if length >= 2 :
        fct_name = sys.argv[1]
        pname = os.path.join('/home/jt/DevC++/dev_lasmea/docnt4/nt2-cleanup/nt2/core/numeric/function/details/scalar',fct_name+'.hpp')
        s = read(pname)
        v =get_validate(s)
        show(v)
        print "*********************"
        c = get_call(s)
        show(c)
    else :
        print __doc__
sys.path.pop(0)
           
       

Example #25
0
                    input_signal[l:l + i * 4][i * 3 - 1:i * 4 - 1]
                    for l in range(0,
                                   len(input_signal) // MULTI_FACTOR, i * 4)
                ]))
            output_signal.append(abs(positive - negative) * factor % 10)
        else:
            positive = sum(
                chain.from_iterable([
                    input_signal[l:l + i * 4][i - 1:i * 2 - 1]
                    for l in range(0, len(input_signal), i * 4)
                ]))
            negative = sum(
                chain.from_iterable([
                    input_signal[l:l + i * 4][i * 3 - 1:i * 4 - 1]
                    for l in range(0, len(input_signal), i * 4)
                ]))
            output_signal.append(abs(positive - negative) % 10)

    return output_signal


if __name__ == "__main__":
    signal_string = file_utils.read("input16.txt")
    signal = [int(ch) for ch in signal_string] * MULTI_FACTOR
    next_input = signal
    for i in range(0, 100):
        print("Iteration %d" % i)
        next_input = run_phase(next_input, [0, 1, 0, -1])

    print(next_input[:8])
Example #26
0
 def get_Cmake_benches_txt(self) :
     p = os.path.join(self.get_bench_path(),'CMakeLists.txt')
     s = read(p)
     #        show(s)
     return s
Example #27
0
 def get_def(self,fct_name) :
     p = os.path.join(self.get_def_path(),fct_name+'.hpp')
     s = read(p)
     #        show(s)
     return s
    def read_page_from_file(cls):
        from file_utils import read

        cls.page = read(cls.actual_file_name)
Example #29
0
    
def modify_toolbox(tb_name) :
    fct = Functor(tb_name,mode='modify')
    print ("opening toolbox %s" %fct.get_tb_name())+ \
          " with %s mode" % fct.get_tb_mode()
    return fct


if __name__ == "__main__" :
    Mylogging.set_level('CRITICAL')
    length = len(sys.argv)
    if length == 2 :
        # this is old nt2 scalar functors dir
        pname = '/home/jt/DevC++/dev_lasmea/docnt4/nt2-cleanup/nt2/core/numeric/function/details/scalar'
        data_file_name = sys.argv[1][1:] 
        s = read(data_file_name)
        tb_name = s[0]
        fct = modify_toolbox(tb_name)
        for ss in s[1:] :
            ss = re.sub('\b',' ',ss)
            if len(ss) == 0 : continue
            l = ss.split()
            if len(l) == 0 : continue
            fct_name = l[0]
            arity = 1 if len(l) <=1 else int(l[1])
            set_one(fct,fct_name,arity,pname)
    else :
        print __doc__
sys.path.pop(0)
           
       
Example #30
0
 def read_functor(self,fct_name,type) :
     fct_name_path = os.path.join(self.get_tb_abs_path(),'function',type,fct_name+'.hpp')
     r = read(fct_name_path)
     return r
Example #31
0
 def read_similar(self,tb_name,name) :
     name = self.strip(name)
     p = os.path.join(self.get_tb_path(tb_name),'unit/scalar',name+'.cpp')
     return read(p)
Example #32
0
from collections import Counter

import file_utils

if __name__ == "__main__":
    input_data = file_utils.read("input08.txt")
    width = 25
    height = 6
    layer_length = width * height

    layers = [
        input_data[i:i + layer_length]
        for i in range(0, len(input_data), layer_length)
    ]
    min_zero_count = layer_length
    output_value = -1

    for layer in layers:
        c = Counter(layer)
        if c['0'] < min_zero_count:
            min_zero_count = c['0']
            output_value = c['1'] * c['2']

    print(output_value)
Example #33
0
 def get_old_bench_text(self,name) :
     return read(os.path.join(self.get_old_bench_path(),'time_'+name+'.cpp'))