Skip to content

Create output objects in operations.rst examples #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions docs/user_guide/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ a Vector is treated as an nx1 column matrix.
[2., 5., 1.5, 4.25, 0.5], nrows=4, ncols=4)
B = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2, 3, 3], [1, 2, 0, 1, 1, 2, 0, 1],
[3., 2., 9., 6., 3., 1., 0., 5.])
C = gb.Matrix(float, A.nrows, B.ncols)

# These are equivalent
C << A.mxm(B, op='min_plus') # method style
Expand Down Expand Up @@ -69,6 +70,7 @@ a Vector is treated as an nx1 column matrix.
A = gb.Matrix.from_coo([0, 0, 1, 1, 2], [1, 2, 2, 3, 3],
[2., 5., 1.5, 4.25, 0.5], nrows=4, ncols=4)
v = gb.Vector.from_coo([0, 1, 3], [10., 20., 40.])
w = gb.Vector(float, A.nrows)

# These are equivalent
w << A.mxv(v, op='plus_times') # method style
Expand Down Expand Up @@ -102,6 +104,7 @@ a Vector is treated as an nx1 column matrix.
v = gb.Vector.from_coo([0, 1, 3], [10., 20., 40.])
B = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2, 3, 3], [1, 2, 0, 1, 1, 2, 0, 1],
[3., 2., 9., 6., 3., 1., 0., 5.])
u = gb.Vector(float, B.ncols)

# These are equivalent
u << v.vxm(B, op='plus_plus') # method style
Expand Down Expand Up @@ -149,6 +152,7 @@ Example usage:
[2.0, 5.0, 1.5, 4.0, 0.5])
B = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 1, 2],
[3., -2., 0., 6., 3., 1.])
C = gb.Matrix(float, A.nrows, A.ncols)

# These are equivalent
C << A.ewise_mult(B, op='min') # method style
Expand Down Expand Up @@ -221,10 +225,11 @@ should be used with the functional syntax, ``left_default`` and ``right_default`

.. code-block:: python

A = gb.Matrix.from_coo([0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2],
A = gb.Matrix.from_coo([0, 0, 0, 1, 1], [0, 1, 2, 0, 2],
[9.0, 2.0, 5.0, 1.5, 4.0], nrows=3)
B = gb.Matrix.from_coo([0, 0, 0, 2, 2, 2], [0, 1, 2, 0, 1, 2],
[4., 0., -2., 6., 3., 1.])
C = gb.Matrix(float, A.nrows, A.ncols)

# These are equivalent
C << A.ewise_add(B, op='minus') # method style
Expand Down Expand Up @@ -258,10 +263,11 @@ should be used with the functional syntax, ``left_default`` and ``right_default`

.. code-block:: python

A = gb.Matrix.from_coo([0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2],
A = gb.Matrix.from_coo([0, 0, 0, 1, 1], [0, 1, 2, 0, 2],
[9.0, 2.0, 5.0, 1.5, 4.0], nrows=3)
B = gb.Matrix.from_coo([0, 0, 0, 2, 2, 2], [0, 1, 2, 0, 1, 2],
[4., 0., -2., 6., 3., 1.])
C = gb.Matrix(float, A.nrows, A.ncols)

# These are equivalent
C << A.ewise_union(B, op='minus', left_default=0, right_default=0) # method style
Expand Down Expand Up @@ -315,6 +321,7 @@ Vector Slice Example:
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3, 4, 6], [10., 2., 40., -5., 24.])
w = gb.Vector(float, 4)

w << v[:4]

Expand All @@ -336,6 +343,7 @@ Matrix List Example:

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
C = gb.Matrix(float, 2, A.ncols)

C << A[[0, 2], :]

Expand Down Expand Up @@ -473,6 +481,7 @@ function with the collection as the argument.
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3], [10., 20., 40.])
w = gb.Vector(float, v.size)

# These are equivalent
w << v.apply(gb.unary.minv)
Expand All @@ -495,6 +504,7 @@ function with the collection as the argument.
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3], [10., 20., 40.])
w = gb.Vector(int, v.size)

# These are equivalent
w << v.apply(gb.indexunary.index)
Expand All @@ -517,6 +527,7 @@ function with the collection as the argument.
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3], [10., 20., 40.])
w = gb.Vector(float, v.size)

# These are all equivalent
w << v.apply('minus', right=15)
Expand Down Expand Up @@ -548,6 +559,7 @@ Upper Triangle Example:

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 2, 0, 2, 1, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
C = gb.Matrix(float, A.nrows, A.ncols)

# These are equivalent
C << A.select('triu')
Expand All @@ -574,6 +586,7 @@ Select by Value Example:
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3, 4, 6], [10., 2., 40., -5., 24.])
w = gb.Vector(float, v.size)

# These are equivalent
w << v.select('>=', 5)
Expand Down Expand Up @@ -607,6 +620,7 @@ A monoid or aggregator is used to perform the reduction.

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 1],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
w = gb.Vector(float, A.ncols)

w << A.reduce_columnwise('times')

Expand All @@ -630,6 +644,7 @@ A monoid or aggregator is used to perform the reduction.

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 1],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
s = gb.Scalar(float)

s << A.reduce_scalar('max')

Expand All @@ -652,6 +667,7 @@ A monoid or aggregator is used to perform the reduction.
.. code-block:: python

v = gb.Vector.from_coo([0, 1, 3, 4, 6], [10., 2., 40., -5., 24.])
s = gb.Scalar(int)

# These are equivalent
s << v.reduce('argmin')
Expand Down Expand Up @@ -681,6 +697,7 @@ To force the transpose to be computed by itself, use it by itself as the right-h

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
C = gb.Matrix(float, A.ncols, A.nrows)

C << A.T

Expand Down Expand Up @@ -714,6 +731,7 @@ The Kronecker product uses a binary operator.
A = gb.Matrix.from_coo([0, 0, 1], [0, 1, 0], [1., -2., 3.])
B = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
C = gb.Matrix(float, A.nrows * B.nrows, A.ncols * B.ncols)

C << A.kronecker(B, 'times')

Expand Down