Skip to content

Speed up by 10-20% by creating full mode array in model.__init__ instead of creating an empty array and appending to it.

Reese Daniel requested to merge model-init-speed into dev

If we create a Model and pass an array of modes (_modes), __init__ currently calls this block:

    self.modes = np.empty([0],dtype=modetype)
    """array containing the modes (n, l, freq, inertia)"""

    if (_modes is not None): self.append_modes(_modes)

self.append_modes simply casts _modes as a modetype array and appends it:

    def append_modes(self,modes):
        ...
        self.modes = np.append(self.modes,np.array(modes,dtype=modetype))

It's simpler to do the work of append_modes in __init__, without appending, which is what this merge request does. It also happens to be 10-20% faster, based on some rough profiling, because AIMS creates Model objects when interpolating and resizing the arrays is slower than simply creating them with the correct size in the first place.

Merge request reports

Loading