Ignore:
Timestamp:
Mar 21, 2006, 10:58:32 AM (18 years ago)
Author:
duncan
Message:

get interpolate tests running in test_all

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/benchmark_least_squares.py

    r2184 r2563  
    2222
    2323from pyvolution.least_squares import Interpolation
     24from fit_interpolate.interpolate import Interpolate
    2425from pmesh.mesh import Mesh
    2526
     
    5758              max_points_per_cell=4,
    5859              is_fit=True,
     60              use_least_squares=True,
    5961              save=False):
    6062        '''
     
    6668        #print "max_points_per_cell", max_points_per_cell
    6769
    68         # make a mesh
     70        mesh_dict = self._build_regular_mesh_dict(maxArea=maxArea,
     71                                                  save=save)
     72        points_dict = self._build_points_dict(num_of_points=num_of_points)
     73           
     74        #Initial time and memory
     75        t0 = time.time()
     76        #m0 = None on windows
     77        m0 = mem_usage()
     78
     79        if use_least_squares is True:
     80            interp = Interpolation(mesh_dict['vertices'],
     81                                   mesh_dict['triangles'],
     82                                   points_dict['points'],
     83                                   expand_search=True,
     84                                   verbose = False,
     85                                   max_points_per_cell = max_points_per_cell)
     86            if is_fit is True:
     87                calc = interp.fit_points(points_dict['point_attributes'])
     88               
     89            else:
     90                # run an interploate problem.
     91                print "Interpolate!"
     92                calc = interp.interpolate(mesh_dict['vertex_attributes'])
     93        else:
     94            # need to change to fit_interpolate code
     95            interp = Interpolate(mesh_dict['vertices'],
     96                                 mesh_dict['triangles'],
     97                                 max_vertices_per_cell = max_points_per_cell)
     98            if is_fit is True:
     99                #calc = interp.fit_points(point_atts)
     100                pass
     101            else:
     102                # run an interploate problem.
     103                print "Interpolate!"
     104                calc = interp.interpolate(mesh_dict['vertex_attributes']
     105                                          ,points_dict['points']
     106                                          ,start_blocking_len = 500000)
     107           
     108        time_taken_sec = (time.time()-t0)
     109        m1 = mem_usage()
     110        if m0 is None or m1 is None:
     111            memory_used = None
     112        else:
     113            memory_used = (m1 - m0)
     114        #print 'That took %.2f seconds' %time_taken_sec
     115        return time_taken_sec, memory_used, len(mesh_dict['triangles'])
     116
     117    def _build_regular_mesh_dict(self,
     118                                 maxArea=1000,
     119                                 save=False):
     120      # make a mesh
    69121        # pretty regular size, with some segments thrown in.
    70122        m = Mesh()
     
    104156            m.export_mesh_file("aaaa.tsh")
    105157        mesh_dict =  m.Mesh2IOTriangulationDict()
    106         #print "mesh_dict",mesh_dict
     158
     159        #Add vert attribute info to the mesh
     160        mesh_dict['vertex_attributes'] = []
     161        # There has to be a better way of doing this..
     162        for vertex in mesh_dict['vertices']:
     163            mesh_dict['vertex_attributes'].append([10.0])
     164
     165        return mesh_dict
     166
     167    def _build_points_dict(self, num_of_points=20000):
     168       
     169        points_dict = {}
    107170        points = []
    108171        point_atts = []
    109         vertex_atts = []
    110172
    111              
    112            
    113173        for point in range(num_of_points):
    114174            points.append([random()*100, random()*100])
    115175            point_atts.append(10.0)
    116176
    117         # There has to be a better way of doing this..
    118         for vertex in mesh_dict['vertices']:
    119             vertex_atts.append(10.0)
    120            
    121         #Initial time and memory
    122         t0 = time.time()
    123         #m0 = None on windows
    124         m0 = mem_usage()
     177        points_dict['points'] = points
     178        points_dict['point_attributes'] = point_atts
     179        return points_dict
    125180
    126         interp = Interpolation(mesh_dict['vertices'],
    127                                mesh_dict['triangles'], points,
    128                                alpha=0.2, expand_search=True,
    129                                verbose = False,
    130                                max_points_per_cell = 4)
    131         if is_fit is True:
    132             calc = interp.fit_points(point_atts)
    133181
    134         else:
    135             # run an interploate problem.
    136             print "Interpolate!"
    137             calc = interp.interpolate(vertex_atts)
    138            
    139         time_taken_sec = (time.time()-t0)
    140         m1 = mem_usage()
    141         if m0 is None or m1 is None:
    142             memory_used = None
    143         else:
    144             memory_used = (m1 - m0)
    145         #print 'That took %.2f seconds' %time_taken_sec
    146         return time_taken_sec, memory_used, len(mesh_dict['triangles'])
     182#-------------------------------------------------------------
     183if __name__ == "__main__":
     184        b = BenchmarkLeastSquares()
     185        b._build_regular_mesh_dict()
     186        b._build_points_dict()
Note: See TracChangeset for help on using the changeset viewer.