# Path: tt/core/utils.py
# def ind2sub(siz, idx):
#     '''
#     Translates full-format index into tt.vector one's.
#     ----------
#     Parameters:
#         siz - tt.vector modes
#         idx - full-vector index
#     Note: not vectorized.
#     '''
#     n = len(siz)
#     subs = _np.empty((n))
#     k = _np.cumprod(siz[:-1])
#     k = _np.concatenate((_np.ones(1), k))
#     for i in xrange(n - 1, -1, -1):
#         subs[i] = _np.floor(idx / k[i])
#         idx = idx % k[i]
#     return subs.astype(_np.int32)
# 
# Path: tt/core/utils.py
# def gcd(a, b):
#     '''Greatest common divider'''
#     f = _np.frompyfunc(_gcd, 2, 1)
#     return f(a, b)
# 
# Path: tt/core/utils.py
# def my_chop2(sv, eps):  # from ttpy/multifuncr.py
#     if eps <= 0.0:
#         r = len(sv)
#         return r
#     sv0 = _np.cumsum(abs(sv[::-1]) ** 2)[::-1]
#     ff = [i for i in range(len(sv0)) if sv0[i] < eps ** 2]
#     if len(ff) == 0:
#         return len(sv)
#     else:
#         return _np.amin(ff)


import six
import numpy as _np
import math as _math
import copy as _cp
from six.moves import xrange
from . import tt_f90 as _tt_f90
from . import vector as _vector
from . import matrix as _matrix
from .utils import ind2sub as _ind2sub
from .utils import gcd as _gcd
from .utils import my_chop2 as _my_chop2

    if center <= 0 and direction < 0 or center >= N and direction > 0:
        raise ValueError(
            "Heaviside function with specified center and direction gives zero tensor!")
    if direction > 0:
        center = N - center
    cind = []
    for i in xrange(d):
        cind.append(center % n0[i])
        center //= n0[i]

    def gen_notx(currcind, currn):
        return [0.0] * (currn - currcind) + [1.0] * currcind

    def gen_notx_rev(currcind, currn):
        return [1.0] * currcind + [0.0] * (currn - currcind)

    def gen_x(currcind, currn):
        result = [0.0] * currn
        result[currn - currcind - 1] = 1.0
        return result

    def gen_x_rev(currcind, currn):
        result = [0.0] * currn
        result[currcind] = 1.0
        return result

    if direction > 0:
        x = gen_x
        notx = gen_notx

# Path: tt/core/utils.py
# def ind2sub(siz, idx):
#     '''
#     Translates full-format index into tt.vector one's.
#     ----------
#     Parameters:
#         siz - tt.vector modes
#         idx - full-vector index
#     Note: not vectorized.
#     '''
#     n = len(siz)
#     subs = _np.empty((n))
#     k = _np.cumprod(siz[:-1])
#     k = _np.concatenate((_np.ones(1), k))
#     for i in xrange(n - 1, -1, -1):
#         subs[i] = _np.floor(idx / k[i])
#         idx = idx % k[i]
#     return subs.astype(_np.int32)
# 
# Path: tt/core/utils.py
# def gcd(a, b):
#     '''Greatest common divider'''
#     f = _np.frompyfunc(_gcd, 2, 1)
#     return f(a, b)
# 
# Path: tt/core/utils.py
# def my_chop2(sv, eps):  # from ttpy/multifuncr.py
#     if eps <= 0.0:
#         r = len(sv)
#         return r
#     sv0 = _np.cumsum(abs(sv[::-1]) ** 2)[::-1]
#     ff = [i for i in range(len(sv0)) if sv0[i] < eps ** 2]
#     if len(ff) == 0:
#         return len(sv)
#     else:
#         return _np.amin(ff)


# Path: tt/core/tools.py
import six
import numpy as _np
import math as _math
import copy as _cp
from six.moves import xrange
from . import tt_f90 as _tt_f90
from . import vector as _vector
from . import matrix as _matrix
from .utils import ind2sub as _ind2sub
from .utils import gcd as _gcd
from .utils import my_chop2 as _my_chop2


    if center <= 0 and direction < 0 or center >= N and direction > 0:
        raise ValueError(
            "Heaviside function with specified center and direction gives zero tensor!")
    if direction > 0:
        center = N - center
    cind = []
    for i in xrange(d):
        cind.append(center % n0[i])
        center //= n0[i]

    def gen_notx(currcind, currn):
        return [0.0] * (currn - currcind) + [1.0] * currcind

    def gen_notx_rev(currcind, currn):
        return [1.0] * currcind + [0.0] * (currn - currcind)

    def gen_x(currcind, currn):
        result = [0.0] * currn
        result[currn - currcind - 1] = 1.0
        return result

    def gen_x_rev(currcind, currn):
        result = [0.0] * currn
        result[currcind] = 1.0
        return result

    if direction > 0:
        x = gen_x
        notx = gen_notx

    else: