from __future__ import print_function, division
import numpy as np
import sys
if sys.version_info < (3,):
    scalarTypes = [float, int, long, np.float64, np.int64, np.int32]
else:
    scalarTypes = [float, int, np.float64, np.int64, np.int32]


def isScalar(f):
    if type(f) in scalarTypes:
        return True
    elif isinstance(f, np.ndarray) and f.size == 1 and type(f[0]) in scalarTypes:
        return True
    return False


def asArray_N_x_Dim(pts, dim):
        if type(pts) == list:
            pts = np.array(pts)
        assert isinstance(pts, np.ndarray), "pts must be a numpy array"

        if dim > 1:
            pts = np.atleast_2d(pts)
        elif len(pts.shape) == 1:
            pts = pts[:, np.newaxis]

        assert pts.shape[1] == dim, "pts must be a column vector of shape (nPts, {0:d}) not ({1:d}, {2:d})".format(*((dim,)+pts.shape))

        return pts


def requires(modules):
    """Decorator to wrap functions with soft dependencies.

    This function was inspired by the `requires` function of pysal,
    which is released under the 'BSD 3-Clause "New" or "Revised" License'.

    https://github.com/pysal/pysal/blob/master/pysal/lib/common.py

    Parameters
    ----------
    modules : dict
        Dictionary containing soft dependencies, e.g.,
        {'matplotlib': matplotlib}.

    Returns
    -------
    decorated_function : function
        Original function if all soft dependencies are met, otherwise
        it returns an empty function which prints why it is not running.

    """

    # Check the required modules, add missing ones in the list `missing`.
    missing = []
    for key, item in modules.items():
        if item is False:
            missing.append(key)

    def decorated_function(function):
        """Wrap function."""
        if not missing:
            return function
        else:
            def passer(*args, **kwargs):
                print(('Missing dependencies: {d}.'.format(d=missing)))
                print(('Not running `{}`.'.format(function.__name__)))
            return passer

    return decorated_function

@@ -109,33 +109,33 @@
   scalarTypes = 
-%5B
+(
 float, int, long
@@ -166,17 +166,17 @@
 np.int32
-%5D
+)
 %0Aelse:%0A 
@@ -192,17 +192,17 @@
 Types = 
-%5B
+(
 float, i
@@ -235,17 +235,17 @@
 np.int32
-%5D
+)
 %0A%0A%0Adef i
@@ -267,18 +267,21 @@
  if 
-type(f) in
+isinstance(f,
  sca
@@ -280,32 +280,33 @@
 e(f, scalarTypes
+)
 :%0A        return

use isinstance to check types in isScalar