-
Notifications
You must be signed in to change notification settings - Fork 548
Open
Description
If seq_dim is less than 0, it will always be interpreted as seq_dim = 0. This behavior might seem counterintuitive because negative indices typically refer to dimensions counting from the end of the array shape. However, in this specific context, negative values for seq_dim are treated as if they were zero, indicating the first dimension."
Explanation
This clarification helps users understand that:
Negative seq_dim Values: When seq_dim is negative, it does not follow the typical behavior of negative indexing (i.e., counting from the end).
Interpretation as First Dimension: Instead, any negative value is interpreted as referring to the first dimension (dim4[0]), which usually corresponds to the height.
Potential Confusion: This behavior could be confusing if users expect negative indices to behave similarly to how they do in other contexts within ArrayFire or similar libraries.
By explicitly stating that this behavior might be counterintuitive, you help prepare users for this specific handling of negative indices and reduce potential confusion.
#include <arrayfire.h>
#include <iostream>
int main()
{
int h = 3;
int w = 4;
int c = 2;
// Generate range along the first dimension (height)
af::array R_height = af::range(af::dim4(h, w, c), 0, f64);
af::print("R_height", R_height);
// Generate range along the last dimension (channels)
af::array R_channels = af::range(af::dim4(h, w, c), 2, f64);
af::print("R_channels", R_channels); // Correct label here
// Generate range along the last dimension (channels)
af::array R_last_dim = af::range(af::dim4(h, w, c), -1, f64);
af::print("R_last_dim", R_last_dim); // Correct label here
af::array R_last_2_dim = af::range(af::dim4(h, w, c), -2, f64);
af::print("R_last_2_dim", R_last_2_dim); // Correct label here
return 0;
}
R_height
[3 4 2 1]
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
R_channels
[3 4 2 1]
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000
R_last_dim
[3 4 2 1]
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
R_last_2_dim
[3 4 2 1]
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
0.0000 0.0000 0.0000 0.0000
1.0000 1.0000 1.0000 1.0000
2.0000 2.0000 2.0000 2.0000
Metadata
Metadata
Assignees
Labels
No labels