Clemapfel / jluna

Julia Wrapper for C++ with Focus on Safety, Elegance, and Ease of Use
https://clemens-cords.com/jluna
MIT License
246 stars 12 forks source link

Array index on a 2D matrix not correct #56

Closed lucwens closed 10 months ago

lucwens commented 12 months ago

While trying out the examples in the excellent manual, I see a discrepancy between what the manual reports and code that I try in Visual Studio 2022.

// create arrays Array<Int64, 1> array_1d = jluna::safe_eval("return Int64[1, 2, 3, 4, 5]"); Array<Int64, 2> array_2d = jluna::safe_eval("return reshape(Int64[i for i in 1:9], 3, 3)");

// print Base["println"]("array_1d: ", array_1d); Base["println"]("array_2d: ", array_2d);

// access elements at index (0-based) Int64 one_d_at_3 = array_1d[2]; Int64 two_d_at_2_2 = array_2d[1, 1];

// print std::cout << one_d_at_3 << std::endl; std::cout << two_d_at_2_2 << std::endl;

This generates [JULIA][LOG] initialization successful (1 thread(s)). array_1d: [1, 2, 3, 4, 5] array_2d: [1 4 7; 2 5 8; 3 6 9] 3 2

For array_2d the element first element of the second row is returned instead of the second, which is 5 as shown in the manual

Clemapfel commented 10 months ago

Sorry for the late reply, I can produce this but only with operator[](...), Array.at works as expected. I will investigate this issue

Clemapfel commented 10 months ago

Fixed by https://github.com/Clemapfel/jluna/commit/d0d32627a01c5b7ca7ad4eeb7f8497289cb0eff4, this fix will go live in version 1.1