strides
strides(A)
Returns a tuple of the memory strides in each dimension
Examples
-
Get the memory strides of a 1-dimensional array:
julia> arr = [1, 2, 3, 4, 5]; julia> strides(arr) (1,)
In this example, the
strides
function returns a tuple with a single value(1,)
. This indicates that the arrayarr
has a stride of 1 in the only dimension. -
Get the memory strides of a 2-dimensional array:
julia> matrix = [1 2 3; 4 5 6]; julia> strides(matrix) (3, 1)
The
strides
function returns a tuple(3, 1)
for the 2-dimensional arraymatrix
. This means that the memory stride in the first dimension is 3 and in the second dimension is 1. - Get the memory strides of a multi-dimensional array:
julia> tensor = [1 2 3; 4 5 6; 7 8 9]; julia> strides(tensor) (3, 1)
Here, the
strides
function returns a tuple(3, 1)
for the multi-dimensional arraytensor
. It indicates that the memory stride in the first dimension is 3 and in the second dimension is 1.
Common mistake example:
julia> x = [1 2 3; 4 5 6];
julia> strides(x)
ERROR: MethodError: no method matching strides(::Array{Int64,2})
In this example, the strides
function is used on a 2-dimensional array. However, the function does not accept 2-dimensional arrays as input. It is important to provide the correct input type to the strides
function to avoid this error.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.