From ef47dca509c1c26c5037b9b9024a6a84a3b7fe0b Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Sat, 20 Jun 2015 00:31:15 +0200 Subject: Fix wrong module name in documentation --- python/docSRC/operator.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/docSRC/operator.rst b/python/docSRC/operator.rst index f5369fa..65a5a99 100644 --- a/python/docSRC/operator.rst +++ b/python/docSRC/operator.rst @@ -1,7 +1,7 @@ OpTomo class: the :mod:`operator` module ============================================== -.. automodule:: astra.operator +.. automodule:: astra.optomo :members: :undoc-members: :show-inheritance: -- cgit v1.2.3 From 26198f7e1fbed9d294fc2856f796f408c85b66f3 Mon Sep 17 00:00:00 2001 From: Valerii Sokolov Date: Tue, 9 Jun 2015 11:26:42 +0200 Subject: Don't take address of temporary. --- python/astra/utils.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx index ddb37aa..a8e9e4e 100644 --- a/python/astra/utils.pyx +++ b/python/astra/utils.pyx @@ -95,7 +95,8 @@ cdef void readDict(XMLNode root, _dc): if val.size == 0: break listbase = root.addChildNode(item) - data = np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64)) + contig_data = np.ascontiguousarray(val,dtype=np.float64) + data = np.PyArray_DATA(contig_data) if val.ndim == 2: listbase.setContent(data, val.shape[1], val.shape[0], False) elif val.ndim == 1: @@ -129,7 +130,8 @@ cdef void readOptions(XMLNode node, dc): break listbase = node.addChildNode(six.b('Option')) listbase.addAttribute(< string > six.b('key'), < string > item) - data = np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64)) + contig_data = np.ascontiguousarray(val,dtype=np.float64) + data = np.PyArray_DATA(contig_data) if val.ndim == 2: listbase.setContent(data, val.shape[1], val.shape[0], False) elif val.ndim == 1: -- cgit v1.2.3 From a9ea08c4a11592378b320cac45be8eede8addd6f Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 22 Jun 2015 17:54:23 +0200 Subject: Additional module name fix in documentation --- python/docSRC/operator.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/docSRC/operator.rst b/python/docSRC/operator.rst index 65a5a99..fe500ba 100644 --- a/python/docSRC/operator.rst +++ b/python/docSRC/operator.rst @@ -1,4 +1,4 @@ -OpTomo class: the :mod:`operator` module +OpTomo class: the :mod:`optomo` module ============================================== .. automodule:: astra.optomo -- cgit v1.2.3 From 63d78fbaafa7d247347f9052db86f575d89260b7 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Wed, 24 Jun 2015 20:28:46 +0200 Subject: Fix config to struct/dict translation for array options --- python/astra/utils.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx index a8e9e4e..260c308 100644 --- a/python/astra/utils.pyx +++ b/python/astra/utils.pyx @@ -204,7 +204,10 @@ cdef XMLNode2dict(XMLNode node): while it != nodes.end(): subnode = deref(it) if castString(subnode.getName())=="Option": - opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value')) + if subnode.hasAttribute('value'): + opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value')) + else: + opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getContent()) else: dct[castString(subnode.getName())] = stringToPythonValue(subnode.getContent()) inc(it) -- cgit v1.2.3 From 9e3472ea9041b8755050427d8bdb8a4701019c55 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Thu, 25 Jun 2015 21:52:07 +0200 Subject: Fix memory leak in configuration code --- python/astra/projector3d_c.pyx | 10 ++++++++-- python/astra/projector_c.pyx | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/astra/projector3d_c.pyx b/python/astra/projector3d_c.pyx index 8b978d7..aec9cde 100644 --- a/python/astra/projector3d_c.pyx +++ b/python/astra/projector3d_c.pyx @@ -87,12 +87,18 @@ cdef CProjector3D * getObject(i) except NULL: def projection_geometry(i): cdef CProjector3D * proj = getObject(i) - return utils.configToDict(proj.getProjectionGeometry().getConfiguration()) + cdef Config * cfg = proj.getProjectionGeometry().getConfiguration() + dct = utils.configToDict(cfg) + del cfg + return dct def volume_geometry(i): cdef CProjector3D * proj = getObject(i) - return utils.configToDict(proj.getVolumeGeometry().getConfiguration()) + cdef Config * cfg = proj.getVolumeGeometry().getConfiguration() + dct = utils.configToDict(cfg) + del cfg + return dct def weights_single_ray(i, projection_index, detector_index): diff --git a/python/astra/projector_c.pyx b/python/astra/projector_c.pyx index 9aa868e..77c64a4 100644 --- a/python/astra/projector_c.pyx +++ b/python/astra/projector_c.pyx @@ -91,12 +91,18 @@ cdef CProjector2D * getObject(i) except NULL: def projection_geometry(i): cdef CProjector2D * proj = getObject(i) - return utils.configToDict(proj.getProjectionGeometry().getConfiguration()) + cdef Config * cfg = proj.getProjectionGeometry().getConfiguration() + dct = utils.configToDict(cfg) + del cfg + return dct def volume_geometry(i): cdef CProjector2D * proj = getObject(i) - return utils.configToDict(proj.getVolumeGeometry().getConfiguration()) + cdef Config * cfg = proj.getVolumeGeometry().getConfiguration() + dct = utils.configToDict(cfg) + del cfg + return dct def weights_single_ray(i, projection_index, detector_index): -- cgit v1.2.3 From 4d39c35d6c9124c26de64c9d227a25f612903a2a Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 13:44:59 +0200 Subject: Fix formatting when passing strings to log from high-level code --- python/astra/log_c.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/astra/log_c.pyx b/python/astra/log_c.pyx index f16329f..55c63e6 100644 --- a/python/astra/log_c.pyx +++ b/python/astra/log_c.pyx @@ -53,19 +53,19 @@ cdef extern from "astra/Logging.h" namespace "astra::CLogger": def log_debug(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - debug(cstr[0],sline,cstr[1]) + debug(cstr[0],sline,"%s",cstr[1]) def log_info(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - info(cstr[0],sline,cstr[1]) + info(cstr[0],sline,"%s",cstr[1]) def log_warn(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - warn(cstr[0],sline,cstr[1]) + warn(cstr[0],sline,"%s",cstr[1]) def log_error(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - error(cstr[0],sline,cstr[1]) + error(cstr[0],sline,"%s",cstr[1]) def log_enable(): enable() -- cgit v1.2.3 From 43155c03488ca98c24f8f369e5c8699efa20cca3 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Thu, 30 Jul 2015 15:28:16 +0200 Subject: Fix Python OpTomo for scipy 0.16 scipy 0.16 also uses .T to define a transpose, which conflicts with the old OpTomo implementation. OpTomo now also defines the _transpose() method, which .T will call in scipy 0.16. --- python/astra/optomo.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/astra/optomo.py b/python/astra/optomo.py index 0108674..19b07e3 100644 --- a/python/astra/optomo.py +++ b/python/astra/optomo.py @@ -86,7 +86,15 @@ class OpTomo(scipy.sparse.linalg.LinearOperator): self.proj_id = proj_id - self.T = OpTomoTranspose(self) + self.transposeOpTomo = OpTomoTranspose(self) + try: + self.T = self.transposeOpTomo + except AttributeError: + # Scipy >= 0.16 defines self.T using self._transpose() + pass + + def _transpose(self): + return self.transposeOpTomo def __checkArray(self, arr, shp): if len(arr.shape)==1: -- cgit v1.2.3 From b4bd441549ea71dd6c34a9f2158bbebc39ba4e9e Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Thu, 30 Jul 2015 15:34:10 +0200 Subject: Define a transpose for the OpTomo transpose as well Allows for chaining .T calls. --- python/astra/optomo.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'python') diff --git a/python/astra/optomo.py b/python/astra/optomo.py index 19b07e3..4a64150 100644 --- a/python/astra/optomo.py +++ b/python/astra/optomo.py @@ -197,6 +197,11 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator): self.parent = parent self.dtype = np.float32 self.shape = (parent.shape[1], parent.shape[0]) + try: + self.T = self.parent + except AttributeError: + # Scipy >= 0.16 defines self.T using self._transpose() + pass def _matvec(self, s): return self.parent.rmatvec(s) @@ -204,6 +209,9 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator): def rmatvec(self, v): return self.parent.matvec(v) + def _transpose(self): + return self.parent + def __mul__(self,s): # Catch the case of a backprojection of 2D/3D data if isinstance(s, np.ndarray) and s.shape==self.parent.sshape: -- cgit v1.2.3 From ee790c305942675e94ee66bfd24896d1ef61335a Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 10 Aug 2015 16:22:19 +0200 Subject: Release the gil in algorithm.run --- python/astra/PyIncludes.pxd | 2 +- python/astra/algorithm_c.pyx | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd index 909f58f..35dea5f 100644 --- a/python/astra/PyIncludes.pxd +++ b/python/astra/PyIncludes.pxd @@ -143,7 +143,7 @@ cdef extern from "astra/Float32ProjectionData2D.h" namespace "astra": cdef extern from "astra/Algorithm.h" namespace "astra": cdef cppclass CAlgorithm: bool initialize(Config) - void run(int) + void run(int) nogil bool isInitialized() cdef extern from "astra/ReconstructionAlgorithm2D.h" namespace "astra": diff --git a/python/astra/algorithm_c.pyx b/python/astra/algorithm_c.pyx index 966d3d7..3231c1f 100644 --- a/python/astra/algorithm_c.pyx +++ b/python/astra/algorithm_c.pyx @@ -73,7 +73,9 @@ cdef CAlgorithm * getAlg(i) except NULL: def run(i, iterations=0): cdef CAlgorithm * alg = getAlg(i) - alg.run(iterations) + cdef int its = iterations + with nogil: + alg.run(its) def get_res_norm(i): -- cgit v1.2.3