Skip to content

Issue in function random(x, a) #7

Closed
@transtrongwind

Description

@transtrongwind

The following function in nda.optimizers.compressor seems incorrect. It does not keep a values; instead it keeps dim-a values.

Random_a compressor, keep a values

def random(x, a):
dim = x.shape[0]
if a == 0:
return 0
if a == dim:
return x
if x.ndim == 2:
for i in range(x.shape[1]):
zero_mask = xp.random.choice(dim, a, replace=False)
x[zero_mask, i] = 0
else:
zero_mask = xp.random.choice(dim, a, replace=False)
x[zero_mask] = 0
return x

To correct the above issue, replace:
xp.random.choice(dim, a, replace=False)
with
xp.random.choice(dim, dim-a, replace=False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions