Exemple #1
0
    def test_time_type_check(self):
        """this tests what the best way to do type checking is"""
        g = GRID(4, [0., 0., 0.])
        s = SPOINT(4)
        import time
        import six

        time0 = time.time()
        for i in six.moves.range(5000000):
            if g.type == 'GRID':
                pass
            if s.type == 'GRID':
                pass
        dt_type = time.time() - time0

        time1 = time.time()
        for i in six.moves.range(5000000):
            if isinstance(g, GRID):
                pass
            if isinstance(s, GRID):
                pass
        dt_instance = time.time() - time1
        #print('dt_type=%.4f dt_instance=%.4f' % (dt_type, dt_instance))
        if dt_instance < dt_type:
            msg = ("flip the way you do type checking; card.type == 'GRID' "
                   "is faster than isinstance(card, GRID); dt_instance=%s dt_type=%s" % (dt_instance, dt_type))
            raise ValueError(msg)
Exemple #2
0
    def test_time_type_check(self):
        """this tests what the best way to do type checking is"""
        g = GRID(4, [0., 0., 0.])
        s = SPOINT(4)
        import time

        time0 = time.time()
        for unused_i in range(5000000):
            if g.type == 'GRID':
                pass
            if s.type == 'GRID':
                pass
        dt_type = time.time() - time0

        time1 = time.time()
        for unused_i in range(5000000):
            if isinstance(g, GRID):
                pass
            if isinstance(s, GRID):
                pass
        dt_instance = time.time() - time1
        #print('dt_type=%.4f dt_instance=%.4f' % (dt_type, dt_instance))
        log = SimpleLogger(level='debug', encoding='utf-8', log_func=None)
        msg = (
            "flip the way you do type checking; card.type == 'GRID' "
            "is faster than isinstance(card, GRID); dt_instance=%s dt_type=%s"
            % (dt_instance, dt_type))
        if dt_instance < dt_type:
            log.warning(msg)
Exemple #3
0
 def Node(self, nid, allowEmptyNodes=False):
     if nid == 0 and allowEmptyNodes:
         return None
     elif nid in self.nodes:
         return self.nodes[nid]
     elif self.spoints and nid in self.spoints.spoints:
         return SPOINT(nid)
     else:
         raise RuntimeError('nid=%s is not a GRID or SPOINT' % (nid))
Exemple #4
0
 def _add_spoint_object(self, spoints):
     # type: (Any) -> None
     """adds an SPOINT card"""
     comment = spoints.comment
     for nid in spoints.points:
         if nid in self.spoints:
             continue
         spoint = SPOINT(nid, comment=comment)
         comment = ''
         self.spoints[nid] = spoint
Exemple #5
0
 def Node(self, nid, allowEmptyNodes=False, msg=''):
     if (nid == 0 or nid is None) and allowEmptyNodes:
         return None
     elif nid in self.nodes:
         return self.nodes[nid]
     elif self.spoints and nid in self.spoints.spoints:
         return SPOINT(nid)
     else:
         assert isinstance(nid, int), 'nid should be an integer; not %s' % type(nid)
         raise RuntimeError('nid=%s is not a GRID or SPOINT%s' % (nid, msg))
Exemple #6
0
 def Node(self, nid, allow_empty_nodes=False, msg=''):
     if (nid == 0 or nid is None) and allow_empty_nodes:
         return None
     elif nid in self.nodes:
         return self.nodes[nid]
     elif self.spoints and nid in self.spoints.points:
         return SPOINT(nid)
     elif self.epoints and nid in self.epoints.points:
         return EPOINT(nid)
     else:
         assert isinstance(
             nid,
             integer_types), 'nid should be an integer; not %s' % type(nid)
         nid_list = np.unique(list(self.nodes.keys()))
         raise RuntimeError(
             'nid=%s is not a GRID, SPOINT, or EPOINT%s\n%s' %
             (nid, msg, nid_list))