|
11 | 11 | D2z = get_discrete_Grad(n1,n2,h1,h2,"D_z") |
12 | 12 |
|
13 | 13 | x=zeros(n1,n2) #test on a 'cross' image |
14 | | - x[:,3]=1.0 |
15 | | - x[4,:]=1.0 |
| 14 | + x[:,3].=1.0 |
| 15 | + x[4,:].=1.0 |
16 | 16 |
|
17 | 17 | a1 = D2x*vec(x); a1=reshape(a1,n1-1,n2) |
18 | 18 | a2 = D2z*vec(x); a2=reshape(a2,n1,n2-1) |
|
21 | 21 | a3b = reshape(a3b,n1-1,n2) |
22 | 22 |
|
23 | 23 | #this test depends on the values of h1 and h2, as well as the type of derivative |
24 | | - @test a1==diff(x,1)./h1 |
25 | | - @test a2==diff(x,2)./h2 |
| 24 | + @test a1==diff(x, dims=1)./h1 |
| 25 | + @test a2==diff(x, dims=2)./h2 |
26 | 26 |
|
27 | 27 | #some more general tests: |
28 | | - @test countnz(a1[:,3])==0 |
| 28 | + @test count(!iszero, a1[:,3])==0 |
29 | 29 | for i in [1 2 4 5 6] |
30 | 30 | @test a1[:,1]==a1[:,i] |
31 | 31 | end |
32 | 32 |
|
33 | 33 | #some more general tests: |
34 | | - @test countnz(a2[4,:])==0 |
| 34 | + @test count(!iszero, a2[4,:])==0 |
35 | 35 | for i in [1 2 3 5 6 7 8 9] |
36 | 36 | @test a2[1,:]==a2[i,:] |
37 | 37 | end |
|
52 | 52 | D3z = get_discrete_Grad(n1,n2,n3,h1,h2,h3,"D_z") |
53 | 53 |
|
54 | 54 | x=zeros(n1,n2,n3) #test on a 'cross' image |
55 | | - x[2,:,:]=1.0 |
56 | | - x[:,4,:]=1.0 |
57 | | - x[:,:,3]=1.0 |
| 55 | + x[2,:,:].=1.0 |
| 56 | + x[:,4,:].=1.0 |
| 57 | + x[:,:,3].=1.0 |
58 | 58 |
|
59 | 59 | a1 = D3x*vec(x); a1=reshape(a1,n1-1,n2,n3) |
60 | 60 | a2 = D3y*vec(x); a2=reshape(a2,n1,n2-1,n3) |
61 | 61 | a3 = D3z*vec(x); a3=reshape(a3,n1,n2,n3-1) |
62 | 62 | for i=1:n2 |
63 | | - @test a1[:,i,:]==diff(x[:,i,:],1)./h1 |
| 63 | + @test a1[:,i,:]==diff(x[:,i,:], dims=1)./h1 |
64 | 64 | end |
65 | 65 | for i=1:n3 |
66 | | - @test a1[:,:,i]==diff(x[:,:,i],1)./h1 |
| 66 | + @test a1[:,:,i]==diff(x[:,:,i], dims=1)./h1 |
67 | 67 | end |
68 | 68 |
|
69 | 69 | for i=1:n1 |
70 | | - @test a2[i,:,:]==diff(x[i,:,:],1)./h2 |
| 70 | + @test a2[i,:,:]==diff(x[i,:,:], dims=1)./h2 |
71 | 71 | end |
72 | 72 | for i=1:n3 |
73 | | - @test a2[:,:,i]==diff(x[:,:,i],2)./h2 |
| 73 | + @test a2[:,:,i]==diff(x[:,:,i], dims=2)./h2 |
74 | 74 | end |
75 | 75 |
|
76 | 76 | for i=1:n1 |
77 | | - @test a3[i,:,:]==diff(x[i,:,:],2)./h3 |
| 77 | + @test a3[i,:,:]==diff(x[i,:,:], dims=2)./h3 |
78 | 78 | end |
79 | 79 | for i=1:n2 |
80 | | - @test a3[:,i,:]==diff(x[:,i,:],2)./h3 |
| 80 | + @test a3[:,i,:]==diff(x[:,i,:], dims=2)./h3 |
81 | 81 | end |
82 | 82 |
|
83 | 83 | end |
0 commit comments