Skip to content

Why libtorch tensor value assignment takes so much time? #1534

Open
@tangyipeng100

Description

@tangyipeng100

I just assign 10000 values to a tensor:

clock_t start = clock();
torch::Tensor transform_tensor = torch::zeros({ 10000 });
for (size_t m = 0; m < 10000 m++)
	transform_tensor[m] = int(m);
clock_t finish = clock();

And it takes 0.317s. If I assign 10,000 to an array or a vector, the time cost will be less.
Why tensor takes so much time? Can the time cost be decreased?

Metadata

Metadata

Assignees

No one assigned

    Labels

    TensorsIssues relating to tensors (generic issues/questions or specific tensor tutorials)question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions