Skip to content

Commit 118b53d

Browse files
committed
Added pytests for documentation snippets.
1 parent c8b7163 commit 118b53d

File tree

5 files changed

+415
-15
lines changed

5 files changed

+415
-15
lines changed

docs/gettingstarted.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
# [gettingstarted3-snippet]
41-
import arrayFire as af
41+
import arrayfire as af
4242
# Create a six-element array on the host
4343
hA = ([0, 1, 2, 3, 4, 5])
4444

@@ -269,8 +269,6 @@ def main():
269269
result = af.sum(a)
270270
print(f"sum: {result}\n")
271271

272-
if __name__ == "__main__":
273-
main()
274272

275273
# [gettingstarted13-endsnippet]
276274

docs/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
reference = A[:, 2]
9292

93-
a[:, 2] = 3.14
93+
A[:, 2] = 3.14
9494
# [indexing10-endsnippet]
9595

9696

docs/introductiontovectorization.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
# Print the result if needed
5252
print("Convolution result:")
53-
af.af_print(conv)
53+
print(conv)
5454
# [vectorization3-endsnippet]
5555

5656

@@ -64,7 +64,7 @@
6464
NUM_IMAGES = 100
6565

6666
# Generate an array of 100 WIDTH x HEIGHT images of random numbers
67-
imgs = af.randu(WIDTH, HEIGHT, NUM_IMAGES)
67+
imgs = af.randu((NUM_IMAGES, (WIDTH, HEIGHT)))
6868

6969
# Rotate all of the images in a single command (rotate by 45 degrees)
7070
rot_imgs = af.rotate(imgs, 45)
@@ -96,7 +96,7 @@
9696
# [vectorization5-endsnippet]
9797

9898

99-
99+
#NOT WORKING
100100
# [vectorization6-snippet]
101101

102102
import arrayfire as af
@@ -129,7 +129,7 @@
129129

130130
# [vectorization7-endsnippet]
131131

132-
132+
#NOT WORKING
133133
# [vectorization8-snippet]
134134

135135
import arrayfire as af
@@ -161,12 +161,12 @@
161161
import arrayfire as af
162162

163163
# Create the filter and weight vectors
164-
filter = af.randn(1, 5)
165-
weights = af.randu(5, 5)
164+
filter = af.randu((1, 5))
165+
weights = af.randu((5, 5))
166166

167167
# Apply the filter using a for-loop equivalent
168-
filtered_weights = af.constant(0, 5, 5)
169-
for i in range(weights.dims()[1]):
168+
filtered_weights = af.constant(0, (5, 5))
169+
for i in range(weights.shape[1]):
170170
filtered_weights[:, i] = af.matmul(filter, weights[:, i])
171171

172172
# Print the filtered weights array
@@ -180,8 +180,8 @@
180180
import arrayfire as af
181181

182182
# Create the filter and weight vectors
183-
filter = af.randn(1, 5) # Shape: 1x5
184-
weights = af.randu(5, 5) # Shape: 5x5
183+
filter = af.randu((1, 5)) # Shape: 1x5
184+
weights = af.randu((5, 5)) # Shape: 5x5
185185

186186
# Transpose the filter to align dimensions for broadcasting
187187
filter_transposed = af.transpose(filter) # Shape: 5x1
@@ -191,5 +191,5 @@
191191

192192
# Print the filtered weights array
193193
print("Filtered weights:")
194-
af.af_print(filtered_weights)
194+
print(filtered_weights)
195195
# [vectorization10-endsnippet]

tests/test_documentation/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)