Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass by reference #43

Open
vavrines opened this issue Nov 7, 2022 · 0 comments
Open

Pass by reference #43

vavrines opened this issue Nov 7, 2022 · 0 comments

Comments

@vavrines
Copy link

vavrines commented Nov 7, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant