Skip to content

Wrong results when slicing a symmetric sparse tensor in python lib #132

@nickirk

Description

@nickirk

Dear Edgar,

As the title suggests, I provide a minimal example to reproduce it. I am using the latest commit on master: commit c4f89dc

import ctf
import numpy as np
print(ctf.__file__)
vals = [1,2,3,4,5,6]
indices = [0,1,3,4,5,7]

s = ctf.tensor([2,2,2,2], sym=[1,0,1,0], sp=1)
s.write(indices, vals)
d = ctf.tensor([2,2,2,2], sym=[1,0,1,0], sp=0)
d.write(indices, vals)

print(s)
print(d)
assert(np.array_equal(s.to_nparray(),d.to_nparray()))

d_1 = d[:,:,:,:1]
print(d_1)
s_1 = s[:,:,:,:1]
print(s_1)
assert(np.array_equal(s_1.to_nparray(),d_1.to_nparray()))

One can see that d_1 is as intended, while s_1 is wrong. One can also test that as long as we don't use symmetries in the tensor, the slicing works fine for both dense and sparse tensors:

d_ns = ctf.tensor([2,2,2,2], sym=[0,0,0,0], sp=0)
d_ns.write(indices, vals)

d_ns_1 = d_ns[:,:,:,:1]
print(d_ns)
print(d_ns_1)

s_ns = ctf.tensor([2,2,2,2], sym=[0,0,0,0], sp=1)
s_ns.write(indices, vals)

s_ns_1 = s_ns[:,:,:,:1]
print(s_ns)
print(s_ns_1)

I ran the examples on 1 core only.

If you need further information, please let me know.

Thanks in advance,
Ke

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions