Getting distance in memory between adjacent elements in Julia – stride() and strides() Method
The stride() is an inbuilt function in julia which is used to return the distance in memory between the specified adjacent elements in specified dimension.
Syntax:
stride(A, k::Integer)Parameters:
- A: Specified array.
- k::Integer: Specified dimension.
Returns: It returns the distance in memory between the specified adjacent elements in specified dimension.
Example:
# Julia program to illustrate # the use of Array stride() method # Getting distance in memory between# adjacent elements of 1D array A = fill(4, 5);println(stride(A, 1)) # Getting distance in memory between# adjacent elements of 2D array B = fill(4, (5, 6));println(stride(B, 2)) # Getting distance in memory between# adjacent elements of 3D array C = fill(4, (5, 6, 7));println(stride(C, 3)) |
Output:
1 5 30
Array strides() method
The strides() is an inbuilt function in julia which is used to return a tuple of the memory strides in each dimension.
Syntax:
strides(A)Parameters:
- A: Specified array.
Returns: It returns a tuple of the memory strides in each dimension.
Example:
# Julia program to illustrate # the use of Array strides() method # Getting a tuple of the memory strides # of 1D array in each dimensionA = fill(4, 5);println(strides(A)) # Getting a tuple of the memory strides # of 2D array in each dimensionB = fill(4, (5, 6));println(strides(B)) # Getting a tuple of the memory strides # of 3D array in each dimensionC = fill(4, (5, 6, 7));println(strides(C)) |
Output:
(1, ) (1, 5) (1, 5, 30)


