Skip to content

Commit

Permalink
Merge pull request #12 from trigeorgis/master
Browse files Browse the repository at this point in the history
Speedup: Use tensordot instead of einsum
  • Loading branch information
jabooth committed Dec 8, 2014
2 parents 6154f9f + 449611f commit 5b6c0cd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion menpofit/transform/modeldriven.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ def d_dp(self, points):

# dW_dl: n_points x (n_dims) x n_centres x n_dims
# dX_dp: (n_points x n_dims) x n_params
dW_dp = np.einsum('ild, lpd -> ipd', self.dW_dl, dX_dp)


# The following is equivalent to
# np.einsum('ild, lpd -> ipd', self.dW_dl, dX_dp)
dW_dp = np.tensordot(self.dW_dl, dX_dp, (1, 0))
dW_dp = dW_dp.diagonal(axis1=3, axis2=1)

# dW_dp: n_points x n_params x n_dims

return dW_dp
Expand Down

0 comments on commit 5b6c0cd

Please sign in to comment.