📜  获取 Julia 中相邻元素之间的内存距离 - stride() 和 strides() 方法

📅  最后修改于: 2022-05-13 01:55:32.640000             🧑  作者: Mango

获取 Julia 中相邻元素之间的内存距离 - stride() 和 strides() 方法

stride()是 julia 中的一个内置函数,用于返回内存中指定维度中指定相邻元素之间的距离。

例子:

# 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))

输出:

1
5
30

数组 strides() 方法

strides()是 julia 中的内置函数,用于返回每个维度中的内存步长元组。

例子:

# Julia program to illustrate 
# the use of Array strides() method
   
# Getting a tuple of the memory strides 
# of 1D array in each dimension
A = fill(4, 5);
println(strides(A))
  
# Getting a tuple of the memory strides 
# of 2D array in each dimension
B = fill(4, (5, 6));
println(strides(B))
  
# Getting a tuple of the memory strides 
# of 3D array in each dimension
C = fill(4, (5, 6, 7));
println(strides(C))

输出:

(1, )
(1, 5)
(1, 5, 30)