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 xt::xtensor_fixed<...>& to user defined functions #25

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TEST: Added test for passing xt::xtensor_fixed<...>& to functions
  • Loading branch information
czgdp1807 committed Dec 20, 2023
commit ff4525f4df885073da9c72175472f74d8123cf1d
32 changes: 32 additions & 0 deletions integration_tests/array_06.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <xtensor/xfixed.hpp>
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"

double reduce_array(xt::xtensor_fixed<double, xt::xshape<3, 3>>& arr) {
double sum = 0.0;
for( int i = 0; i < arr.shape(0); i++ ) {
for( int j = 0; j < arr.shape(1); j++ ) {
sum += arr(i, j);
}
}
return sum;
}

int main() {

xt::xtensor_fixed<double, xt::xshape<3, 3>> arr1;
double result;

for( int i = 0; i < 3; i++ ) {
for( int j = 0; j < 3; j++ ) {
arr1(i, j) = i*3 + j;
}
}

std::cout << arr1 << std::endl;
result = reduce_array(arr1);
std::cout << result << std::endl;

return 0;
}