From d6dd21d06102bddbde903a65b6bdf215b963bafb Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Mon, 20 Jun 2016 15:04:04 +0200
Subject: [PATCH] Image.axisMapping is memoized (and corresponding bug-fix to
 memoizeMD5).

---
 fsl/data/image.py    | 7 ++++++-
 fsl/utils/memoize.py | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 8387dce2c..2c2ee579c 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -40,6 +40,7 @@ import numpy      as np
 
 import fsl.utils.transform   as transform
 import fsl.utils.notifier    as notifier
+import fsl.utils.memoize     as memoize
 import fsl.utils.path        as fslpath
 import fsl.data.constants    as constants
 import fsl.data.imagewrapper as imagewrapper
@@ -209,7 +210,11 @@ class Nifti1(object):
         
         return int(code)
 
-
+    # TODO Check what has worse performance - hashing
+    #      a 4x4 array (via memoizeMD5), or the call
+    #      to aff2axcodes. I'm guessing the latter,
+    #      but am not 100% sure.
+    @memoize.memoizeMD5
     def axisMapping(self, xform):
         """Returns the (approximate) correspondence of each axis in the source
         coordinate system to the axes in the destination coordinate system,
diff --git a/fsl/utils/memoize.py b/fsl/utils/memoize.py
index 25a7df1de..e7883434d 100644
--- a/fsl/utils/memoize.py
+++ b/fsl/utils/memoize.py
@@ -100,7 +100,7 @@ def memoizeMD5(func):
         hashobj = hashlib.md5()
 
         for arg in args:
-            arg = six.u(arg).encode('utf-8')
+            arg = six.u(str(arg)).encode('utf-8')
             hashobj.update(arg)
 
         digest = hashobj.hexdigest()
-- 
GitLab