Permalink
Browse files

Merge pull request #263 from bthirion/fix-type-graph

MRG: Fix type graph

This PR aims at solving issue #256 by casting to float 64 the arrays that need to.
I took this opportunity to clean the tests in nipy.algorithms.graph.
  • Loading branch information...
2 parents 343b8cf + 0523deb commit 9df4e65ffcc691c5defcab26590767779ad4148f @matthew-brett matthew-brett committed May 2, 2013
Showing with 727 additions and 684 deletions.
  1. +14 −10 nipy/algorithms/graph/field.py
  2. +260 −241 nipy/algorithms/graph/tests/test_field.py
  3. +453 −433 nipy/algorithms/graph/tests/test_graph.py
@@ -12,6 +12,7 @@
Author:Bertrand Thirion, 2006--2011
"""
+from warnings import warn
import numpy as np
from .graph import WeightedGraph
@@ -148,18 +149,20 @@ def opening(self, nbiter=1):
self.dilation(nbiter)
def dilation(self, nbiter=1, fast=True):
- """
- Morphological dimlation of the field data. self.field is changed
+ """Morphological dilation of the field data, changed in place
Parameters
----------
nbiter: int, optional, the number of iterations required
- fixme
- -----
- cython
+ Note
+ ----
+ When data dtype is not float64, a slow version of the code is used
"""
nbiter = int(nbiter)
+ if self.field.dtype != np.float64:
+ warn('data type is not float64; a slower version is used')
+ fast = False
if fast:
from ._graph import dilation
if self.E > 0:
@@ -177,16 +180,17 @@ def dilation(self, nbiter=1, fast=True):
self.field = np.array([self.field[row].max(0) for row in rows])
def highest_neighbor(self, refdim=0):
- """ Computes the neighbor with highest field value along refdim
+ """Computes the neighbor with highest field value along refdim
Parameters
----------
- refdim: int optiontal, the dimension to consider
+ refdim: int, optional,
+ the dimension of the field under consideration
Returns
-------
- hneighb: array of shape(self.V), index of the neighbor with highest
- value
+ hneighb: array of shape(self.V),
+ index of the neighbor with highest value
"""
from scipy.sparse import dia_matrix
refdim = int(refdim)
@@ -263,7 +267,7 @@ def local_maxima(self, refdim=0, th=NEGINF):
# create a subfield(thresholding)
sf = self.subfield(self.field.T[refdim] >= th)
initial_field = sf.field.T[refdim]
- sf.field = initial_field.copy()
+ sf.field = initial_field.astype(np.float64)
# compute the depth in the subgraph
ldepth = sf.V * np.ones(sf.V, np.int)
Oops, something went wrong.

0 comments on commit 9df4e65

Please sign in to comment.