Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • xerus xerus
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 41
    • Issues 41
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • xerusxerus
  • xerusxerus
  • Issues
  • #262
Closed
Open
Issue created Feb 04, 2020 by Nando Farchmin@Nando_Farchmin

Slice TTTensor

Would be good to get a subtensor, i.e. slice of the tensor (a subtensor from dimensions (l_1,...,l_n) to dimensions (u_1,...,u_n) where 0 <= l_i <= u_i <= tensor_dim_i, see code below.)

def slice_tt(tt, lower, upper):
    """
    Slice TTTensor in each component from lower to (not including) upper dimension.
    """
    assert len(lower) == len(upper) == len(tt.dimensions)
    assert np.all(np.array(lower) < np.array(upper))
    assert np.all(np.array(upper) <= np.array(tt.dimensions))
    diff = [u-l for l,u in zip(lower,upper)]

    # TODO there should be a more elegant way to slice TTTensors!
    tmp = xe.TTTensor(tt)
    for pos in range(tt.order()):
        tmp.move_core(pos)
        cmp = np.asarray(tmp.get_component(pos))
        cmp[:, :lower[pos], :] = 0
        cmp[:, upper[pos]:, :] = 0
        tmp.set_component(pos, xe.Tensor.from_buffer(cmp))
    tmp.move_core(0)

    tt_slice = xe.TTTensor.random(diff, tmp.ranks())
    for pos in range(tt.order()):
        cmp = np.asarray(tmp.get_component(pos))
        cmp = np.array(cmp[:, lower[pos]:upper[pos], :])
        tt_slice.set_component(pos, xe.Tensor.from_buffer(cmp))

    return tt_slice
Edited Feb 04, 2020 by Nando Farchmin
Assignee
Assign to
Time tracking