Skip to content

Commit 9784124

Browse files
anuunchinBaunsgaard
authored andcommitted
[SYSTEMDS-3330] Documentation of builtin functions (main)
This commit adds new automatic generation of separated doc files for all builtin functions, and automatic generation of tests for builtin functions. All based on the original documentation in individual builtin scripts. This change will simplify the development of builtin functions and help new users across both the Python api and internal DML testing. An example of documented code is: .. code-block:: python >>> import numpy as np >>> from systemds.context import SystemDSContext >>> from systemds.operator.algorithm import dist >>> >>> with SystemDSContext() as sds: ... X = sds.from_numpy(np.array([[0], [3], [4]])) ... out = dist(X).compute() ... print(out) [[0. 3. 4.] [3. 0. 1.] [4. 1. 0.]] Closes #2292
1 parent 3e6e321 commit 9784124

File tree

284 files changed

+3600
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+3600
-115
lines changed

scripts/builtin/dist.dml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121

2222
# Returns Euclidean distance matrix (distances between N n-dimensional points)
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import dist
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... X = sds.from_numpy(np.array([[0], [3], [4]]))
32+
# ... out = dist(X).compute()
33+
# ... print(out)
34+
# [[0. 3. 4.]
35+
# [3. 0. 1.]
36+
# [4. 1. 0.]]
37+
#
38+
#
2439
# INPUT:
2540
# --------------------------------------------------------------------------------
2641
# X Matrix to calculate the distance inside

scripts/builtin/img_brightness.dml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@
2121

2222
# The img_brightness-function is an image data augmentation function. It changes the brightness of the image.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_brightness
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 50, 100,
33+
# ... 150, 200 ]], dtype=np.float32)
34+
# ... )
35+
# ... result_img = img_brightness(img, 30.0, 150).compute()
36+
# ... print(result_img.reshape(2, 2))
37+
# [[ 80. 130.]
38+
# [150. 150.]]
39+
#
40+
#
2441
# INPUT:
2542
# -----------------------------------------------------------------------------------------
26-
# img_in Input matrix/image
43+
# img_in Input image as 2D matrix with top left corner at [1, 1]
2744
# value The amount of brightness to be changed for the image
2845
# channel_max Maximum value of the brightness of the image
2946
# -----------------------------------------------------------------------------------------

scripts/builtin/img_brightness_linearized.dml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@
2121

2222
# The img_brightness_linearized-function is an image data augmentation function. It changes the brightness of one or multiple images.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_brightness_linearized
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 50, 100,
33+
# ... 150, 200 ]], dtype=np.float32)
34+
# ... )
35+
# ... result_img = img_brightness_linearized(img, 30.0, 255).compute()
36+
# ... print(result_img.reshape(2, 2))
37+
# [[ 80. 130.]
38+
# [180. 230.]]
39+
#
40+
#
2441
# INPUT:
2542
# -----------------------------------------------------------------------------------------
26-
# img_in Input matrix/image (can represent multiple images every row of the matrix represents a linearized image)
43+
# img_in Input images as linearized 2D matrix with top left corner at [1, 1] (every row represents a linearized matrix/image)
2744
# value The amount of brightness to be changed for the image
2845
# channel_max Maximum value of the brightness of the image
2946
# -----------------------------------------------------------------------------------------

scripts/builtin/img_crop.dml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@
2121

2222
# The img_crop-function is an image data augmentation function. It cuts out a subregion of an image.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_crop
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 50., 100., 150.],
33+
# ... [150., 200., 250.],
34+
# ... [250., 200., 200.]], dtype=np.float32)
35+
# ... )
36+
# ... result_img = img_crop(img, 1, 1, 1, 1).compute()
37+
# ... print(result_img)
38+
# [[200.]]
39+
#
40+
#
2441
# INPUT:
2542
# ----------------------------------------------------------------------------------------
26-
# img_in Input matrix/image
43+
# img_in Input image as 2D matrix with top left corner at [1, 1]
2744
# w The width of the subregion required
2845
# h The height of the subregion required
2946
# x_offset The horizontal coordinate in the image to begin the crop operation

scripts/builtin/img_crop_linearized.dml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,26 @@
2121

2222
# The img_crop_linearized cuts out a rectangular section of multiple linearized images.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_crop_linearized
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 50., 100., 150.,
33+
# ... 150., 200., 250.,
34+
# ... 250., 200., 200. ]], dtype=np.float32)
35+
# ... )
36+
# ... result_img = img_crop_linearized(img, 1, 1, 1, 1, 3, 3).compute()
37+
# ... print(result_img)
38+
# [[200.]]
39+
#
40+
#
2441
# INPUT:
2542
# ----------------------------------------------------------------------------------------
26-
# img_in Linearized input images as 2D matrix
43+
# img_in Input images as linearized 2D matrix with top left corner at [1, 1] (every row represents a linearized matrix/image)
2744
# w The width of the subregion required
2845
# h The height of the subregion required
2946
# x_offset The horizontal offset for the center of the crop region

scripts/builtin/img_cutout.dml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121

2222
# Image Cutout function replaces a rectangular section of an image with a constant value.
2323
#
24+
#
25+
# .. code-block:: python
26+
#
27+
# >>> import numpy as np
28+
# >>> from systemds.context import SystemDSContext
29+
# >>> from systemds.operator.algorithm import img_cutout
30+
# >>>
31+
# >>> with SystemDSContext() as sds:
32+
# ... img = sds.from_numpy(
33+
# ... np.array([[ 50., 100., 150.],
34+
# ... [150., 200., 250.],
35+
# ... [250., 200., 200.]], dtype=np.float32)
36+
# ... )
37+
# ... result_img = img_cutout(img, 2, 2, 1, 1, 49.).compute()
38+
# ... print(result_img)
39+
# [[ 50. 100. 150.]
40+
# [150. 49. 250.]
41+
# [250. 200. 200.]]
42+
#
43+
#
2444
# INPUT:
2545
# ---------------------------------------------------------------------------------------------
2646
# img_in Input image as 2D matrix with top left corner at [1, 1]

scripts/builtin/img_cutout_linearized.dml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,33 @@
2121

2222
# Image Cutout function replaces a rectangular section of an image with a constant value.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_cutout_linearized
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 50., 100., 150.,
33+
# ... 150., 200., 250.,
34+
# ... 250., 200., 200. ]], dtype=np.float32)
35+
# ... )
36+
# ... result_img = img_cutout_linearized(img, 2, 2, 1, 1, 25.0, 3, 3).compute()
37+
# ... print(result_img.reshape(3, 3))
38+
# [[ 50. 100. 150.]
39+
# [150. 25. 250.]
40+
# [250. 200. 200.]]
41+
#
42+
#
2443
# INPUT:
2544
# ---------------------------------------------------------------------------------------------
26-
# img_in Input images as linearized 2D matrix with top left corner at [1, 1]
45+
# img_in Input images as linearized 2D matrix with top left corner at [1, 1] (every row represents a linearized matrix/image)
2746
# x Column index of the top left corner of the rectangle (starting at 1)
2847
# y Row index of the top left corner of the rectangle (starting at 1)
2948
# width Width of the rectangle (must be positive)
3049
# height Height of the rectangle (must be positive)
31-
# fill_value The value to set for the rectangle
50+
# fill_value The value to set for the rectangle
3251
# s_cols Width of a single image
3352
# s_rows Height of a single image
3453
# ---------------------------------------------------------------------------------------------

scripts/builtin/img_invert.dml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@
2121

2222
# This is an image data augmentation function. It inverts an image.
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_invert
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 10., 20., 30.],
33+
# ... [ 40., 50., 60.],
34+
# ... [ 70., 80., 90.]], dtype=np.float32)
35+
# ... )
36+
# ... result_img = img_invert(img, 210.).compute()
37+
# ... print(result_img)
38+
# [[200. 190. 180.]
39+
# [170. 160. 150.]
40+
# [140. 130. 120.]]
41+
#
42+
#
2443
# INPUT:
2544
# ---------------------------------------------------------------------------------------------
26-
# img_in Input image
45+
# img_in Input image as 2D matrix with top left corner at [1, 1]
2746
# max_value The maximum value pixels can have
2847
# ---------------------------------------------------------------------------------------------
2948
#

scripts/builtin/img_invert_linearized.dml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@
2121

2222
# This is an image data augmentation function. It inverts an image.It can handle one or multiple images
2323
#
24+
# .. code-block:: python
25+
#
26+
# >>> import numpy as np
27+
# >>> from systemds.context import SystemDSContext
28+
# >>> from systemds.operator.algorithm import img_invert_linearized
29+
# >>>
30+
# >>> with SystemDSContext() as sds:
31+
# ... img = sds.from_numpy(
32+
# ... np.array([[ 10., 20., 30.,
33+
# ... 40., 50., 60.,
34+
# ... 70., 80., 90. ]], dtype=np.float32)
35+
# ... )
36+
# ... result_img = img_invert_linearized(img, 200.).compute()
37+
# ... print(result_img.reshape(3, 3))
38+
# [[190. 180. 170.]
39+
# [160. 150. 140.]
40+
# [130. 120. 110.]]
41+
#
42+
#
2443
# INPUT:
2544
# ---------------------------------------------------------------------------------------------
26-
# img_in Input matrix/image (every row of the matrix represents a linearized image)
45+
# img_in Input images as linearized 2D matrix with top left corner at [1, 1] (every row represents a linearized matrix/image)
2746
# max_value The maximum value pixels can have
2847
# ---------------------------------------------------------------------------------------------
2948
#

scripts/builtin/img_mirror.dml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,29 @@
2222
# This function is an image data augmentation function.
2323
# It flips an image on the X (horizontal) or Y (vertical) axis.
2424
#
25+
# .. code-block:: python
26+
#
27+
# >>> import numpy as np
28+
# >>> from systemds.context import SystemDSContext
29+
# >>> from systemds.operator.algorithm import img_mirror
30+
# >>>
31+
# >>> with SystemDSContext() as sds:
32+
# ... img = sds.from_numpy(
33+
# ... np.array([[ 10., 20., 30.],
34+
# ... [ 40., 50., 60.],
35+
# ... [ 70., 80., 90.]], dtype=np.float32)
36+
# ... )
37+
# ... result_img = img_mirror(img, False).compute()
38+
# ... print(result_img)
39+
# [[30. 20. 10.]
40+
# [60. 50. 40.]
41+
# [90. 80. 70.]]
42+
#
43+
#
2544
# INPUT:
2645
# ---------------------------------------------------------------------------------------------
27-
# img_in Input matrix/image
28-
# max_value The maximum value pixels can have
46+
# img_in Input image as 2D matrix with top left corner at [1, 1]
47+
# horizontal_axis Flip either in X or Y axis
2948
# ---------------------------------------------------------------------------------------------
3049
#
3150
# OUTPUT:

0 commit comments

Comments
 (0)