
import uuid

from abc import ABCMeta, abstractmethod


class BaseReader(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        pass

    @abstractmethod
    def _to_raw_pyfrm(self):
        pass

    def to_pyfrm(self):
        mesh = self._to_raw_pyfrm()

        # Add metadata
        mesh['mesh_uuid'] = str(uuid.uuid4())

        return mesh


import re
import uuid
import itertools as it

from abc import ABCMeta, abstractmethod

import numpy as np


class BaseReader(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        pass

    @abstractmethod
    def _to_raw_pyfrm(self):
        pass

    def _optimize(self, mesh):
        # Sort interior interfaces
        for f in it.ifilter(lambda f: re.match('con_p\d+', f), mesh):
            mesh[f] = mesh[f][:,np.argsort(mesh[f][0])]

    def to_pyfrm(self):
        mesh = self._to_raw_pyfrm()

        # Perform some simple optimizations on the mesh
        self._optimize(mesh)

        # Add metadata
        mesh['mesh_uuid'] = str(uuid.uuid4())

        return mesh

Add some simple optimizations into the mesh reader classes.
Add some simple optimizations into the mesh reader classes.

This yields a ~1.5% performance improvement.

  
+ import re
  import uuid
+ import itertools as it
  
  from abc import ABCMeta, abstractmethod
+ 
+ import numpy as np
  
  
  class BaseReader(object):
      __metaclass__ = ABCMeta
  
      @abstractmethod
      def __init__(self):
          pass
  
      @abstractmethod
      def _to_raw_pyfrm(self):
          pass
  
+     def _optimize(self, mesh):
+         # Sort interior interfaces
+         for f in it.ifilter(lambda f: re.match('con_p\d+', f), mesh):
+             mesh[f] = mesh[f][:,np.argsort(mesh[f][0])]
+ 
      def to_pyfrm(self):
          mesh = self._to_raw_pyfrm()
+ 
+         # Perform some simple optimizations on the mesh
+         self._optimize(mesh)
  
          # Add metadata
          mesh['mesh_uuid'] = str(uuid.uuid4())
  
          return mesh
  
Add some simple optimizations into the mesh reader classes.
## Code Before:

import uuid

from abc import ABCMeta, abstractmethod


class BaseReader(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        pass

    @abstractmethod
    def _to_raw_pyfrm(self):
        pass

    def to_pyfrm(self):
        mesh = self._to_raw_pyfrm()

        # Add metadata
        mesh['mesh_uuid'] = str(uuid.uuid4())

        return mesh

## Instruction:
Add some simple optimizations into the mesh reader classes.
## Code After:

import re
import uuid
import itertools as it

from abc import ABCMeta, abstractmethod

import numpy as np


class BaseReader(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        pass

    @abstractmethod
    def _to_raw_pyfrm(self):
        pass

    def _optimize(self, mesh):
        # Sort interior interfaces
        for f in it.ifilter(lambda f: re.match('con_p\d+', f), mesh):
            mesh[f] = mesh[f][:,np.argsort(mesh[f][0])]

    def to_pyfrm(self):
        mesh = self._to_raw_pyfrm()

        # Perform some simple optimizations on the mesh
        self._optimize(mesh)

        # Add metadata
        mesh['mesh_uuid'] = str(uuid.uuid4())

        return mesh
