镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Pass by reference #43

Open
Open

Description

@vavrines

The assignment operation, i.e.,

xt::jltensor<double, 1> test(xt::jltensor<double, 1> u) {
  xt::jltensor<double, 1> f = u;
  return f;
}

cannot be performed in-place through

void test(xt::jltensor<double, 1> f, xt::jltensor<double, 1> u) {
  f = u;
}

This is understandable since the argument is value instead of the reference.
Is there a workaround for the in-place mutation?

edit: an explicit for-loop can do this

void test1([T](xt::jltensor<double, 1> f, xt::jltensor<double, 1> u) { 
  int nu = u.shape(0);
  for (int i = 0; i < nu; i++) {
    f[i] = u[i];
  }
}

But is there an easier way?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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