Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ s(accum) << v.reduce(op)
```python
A = Matrix.new(dtype, num_rows, num_cols) # new_type
B = A.dup() # dup
A = Matrix.from_values([row_indices], [col_indices], [values]) # build
A = Matrix.from_coo([row_indices], [col_indices], [values]) # build
```
## New from delayed
Delayed objects can be used to create a new object using `.new()` method
Expand All @@ -145,7 +145,7 @@ size = v.size # size
nrows = M.nrows # nrows
ncols = M.ncols # ncols
nvals = M.nvals # nvals
rindices, cindices, vals = M.to_values() # extractTuples
rindices, cindices, vals = M.to_coo() # extractTuples
```
## Initialization
There is a mechanism to initialize `graphblas` with a context prior to use. This allows for setting the backend to
Expand Down Expand Up @@ -174,7 +174,7 @@ def force_odd_func(x):

unary.register_new('force_odd', force_odd_func)

v = Vector.from_values([0, 1, 3], [1, 2, 3])
v = Vector.from_coo([0, 1, 3], [1, 2, 3])
w = v.apply(unary.force_odd).new()
w # indexes=[0, 1, 3], values=[1, 3, 3]
```
Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started/primer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ node 0.

# Create the graph and starting vector
start_node = 0
G = Matrix.from_values(
G = Matrix.from_coo(
[0, 0, 1, 1, 2],
[1, 2, 2, 3, 3],
[2.0, 5.0, 1.5, 4.25, 0.5],
nrows=4, ncols=4)
v = Vector.from_values([start_node], [0.0], size=4)
v = Vector.from_coo([start_node], [0.0], size=4)

# Compute SSSP
while True:
Expand Down
16 changes: 8 additions & 8 deletions docs/user_guide/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A **Matrix** is a 2-dimensional sparse array.

.. code-block:: python

M = gb.Matrix.from_values(
M = gb.Matrix.from_coo(
[3, 0, 3, 5, 6, 0, 6, 1, 6, 2, 4, 1],
[0, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6],
[3, 2, 3, 1, 5, 3, 7, 8, 3, 1, 7, 4],
Expand Down Expand Up @@ -49,7 +49,7 @@ A **Vector** is a 1-dimensional sparse array.

.. code-block:: python

v = gb.Vector.from_values([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8)
v = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8)

Viewing the ``__repr__`` for ``v`` in a notebook will look like the following, although
the name, dtype, and format might be different than what is shown here.
Expand Down Expand Up @@ -142,22 +142,22 @@ The shape and dtype remain unchanged, but the collection will be fully sparse (i
>>> M.nvals
0

to_values
~~~~~~~~~
to_coo
~~~~~~

To go from a collection back to the index and values, ``.to_values()`` can be called. Numpy arrays
To go from a collection back to the index and values, ``.to_coo()`` can be called. Numpy arrays
will be returned in a tuple.

.. code-block:: python

>>> v = gb.Vector.from_values([0, 3, 5], [2.0, 3.1, 4.7])
>>> idx, vals = v.to_values()
>>> v = gb.Vector.from_coo([0, 3, 5], [2.0, 3.1, 4.7])
>>> idx, vals = v.to_coo()
>>> idx
array([0, 3, 5], dtype=uint64)
>>> vals
array([2.0, 3.1, 4.7])

Note that Scalar does not have ``.to_values()``. Instead, the ``.value`` attribute will extract
Note that Scalar does not have ``.to_coo()``. Instead, the ``.value`` attribute will extract
the underlying value or return ``None`` if the Scalar is empty.

Empty Constructors
Expand Down
10 changes: 5 additions & 5 deletions docs/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ From/To Values

Scalar has ``.from_value()`` and ``.value`` to get a Python scalar into and out of python-graphblas.

Matrix and Vector, instead, have a ``.from_values()`` and a ``.to_values()`` method.
Matrix and Vector, instead, have a ``.from_coo()`` and a ``.to_coo()`` method.

``.from_values()`` takes index(es) and values as either:
``.from_coo()`` takes index(es) and values as either:

- Python lists
- Numpy arrays
Expand All @@ -21,12 +21,12 @@ If no dtype is provided, the data type is inferred from the values.
If no size (Vector) or nrows/ncols (Matrix) are provided, the shape is inferred based on the largest
index found for each dimension.

``.to_values()`` returns numpy arrays. Indexes are always returned as ``uint64``, while the values
``.to_coo()`` returns numpy arrays. Indexes are always returned as ``uint64``, while the values
array will match the collection dtype.

.. code-block:: python

v = gb.Vector.from_values([1, 3, 6], [2, 3, 4], float, size=10)
v = gb.Vector.from_coo([1, 3, 6], [2, 3, 4], float, size=10)

.. csv-table::
:header: 0,1,2,3,4,5,6,7,8,9,10
Expand All @@ -35,7 +35,7 @@ array will match the collection dtype.

.. code-block:: python

>>> idx, vals = v.to_values()
>>> idx, vals = v.to_coo()
>>> idx
array([1, 3, 6], dtype=uint64)
>>> vals
Expand Down
98 changes: 49 additions & 49 deletions docs/user_guide/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ a Vector is treated as an nx1 column matrix.

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2], [1, 2, 2, 3, 3],
[2., 5., 1.5, 4.25, 0.5], nrows=4, ncols=4)
B = gb.Matrix.from_values([0, 0, 1, 1, 2, 2, 3, 3], [1, 2, 0, 1, 1, 2, 0, 1],
[3., 2., 9., 6., 3., 1., 0., 5.])
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)
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.])

# These are equivalent
C << A.mxm(B, op='min_plus') # method style
Expand Down Expand Up @@ -66,9 +66,9 @@ a Vector is treated as an nx1 column matrix.

.. code-block:: python

A = gb.Matrix.from_values([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_values([0, 1, 3], [10., 20., 40.])
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.])

# These are equivalent
w << A.mxv(v, op='plus_times') # method style
Expand Down Expand Up @@ -99,9 +99,9 @@ a Vector is treated as an nx1 column matrix.

.. code-block:: python

v = gb.Vector.from_values([0, 1, 3], [10., 20., 40.])
B = gb.Matrix.from_values([0, 0, 1, 1, 2, 2, 3, 3], [1, 2, 0, 1, 1, 2, 0, 1],
[3., 2., 9., 6., 3., 1., 0., 5.])
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.])

# These are equivalent
u << v.vxm(B, op='plus_plus') # method style
Expand Down Expand Up @@ -145,10 +145,10 @@ Example usage:

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2], [1, 2, 0, 2, 1],
[2.0, 5.0, 1.5, 4.0, 0.5])
B = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 1, 2],
[3., -2., 0., 6., 3., 1.])
A = gb.Matrix.from_coo([0, 0, 1, 1, 2], [1, 2, 0, 2, 1],
[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.])

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

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2],
[9.0, 2.0, 5.0, 1.5, 4.0], nrows=3)
B = gb.Matrix.from_values([0, 0, 0, 2, 2, 2], [0, 1, 2, 0, 1, 2],
[4., 0., -2., 6., 3., 1.])
A = gb.Matrix.from_coo([0, 0, 0, 1, 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.])

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

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 2],
[9.0, 2.0, 5.0, 1.5, 4.0], nrows=3)
B = gb.Matrix.from_values([0, 0, 0, 2, 2, 2], [0, 1, 2, 0, 1, 2],
[4., 0., -2., 6., 3., 1.])
A = gb.Matrix.from_coo([0, 0, 0, 1, 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.])

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

.. code-block:: python

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

w << v[:4]

Expand All @@ -334,8 +334,8 @@ Matrix List Example:

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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 << A[[0, 2], :]

Expand Down Expand Up @@ -374,10 +374,10 @@ Matrix-Matrix Assignment Example:

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
B = gb.Matrix.from_values([0, 0, 1, 1], [0, 1, 0, 1]
[-99., -98., -97., -96.])
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])
B = gb.Matrix.from_coo([0, 0, 1, 1], [0, 1, 0, 1]
[-99., -98., -97., -96.])

A[::2, ::2] << B

Expand Down Expand Up @@ -408,9 +408,9 @@ Matrix-Vector Assignment Example:

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
v = gb.Vector.from_values([2], [-99.])
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])
v = gb.Vector.from_coo([2], [-99.])

A[1, :] << v

Expand Down Expand Up @@ -440,7 +440,7 @@ Vector-Scalar Assignment Example:

.. code-block:: python

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

v[:4] << 99

Expand Down Expand Up @@ -472,7 +472,7 @@ function with the collection as the argument.

.. code-block:: python

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

# These are equivalent
w << v.apply(gb.unary.minv)
Expand All @@ -494,7 +494,7 @@ function with the collection as the argument.

.. code-block:: python

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

# These are equivalent
w << v.apply(gb.indexunary.index)
Expand All @@ -516,7 +516,7 @@ function with the collection as the argument.

.. code-block:: python

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

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

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 2, 1, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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])

# These are equivalent
C << A.select('triu')
Expand All @@ -573,7 +573,7 @@ Select by Value Example:

.. code-block:: python

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

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

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 1],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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 << A.reduce_columnwise('times')

Expand All @@ -628,8 +628,8 @@ A monoid or aggregator is used to perform the reduction.

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 1],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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 << A.reduce_scalar('max')

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

.. code-block:: python

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

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

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 3, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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 << A.T

Expand Down Expand Up @@ -711,9 +711,9 @@ The Kronecker product uses a binary operator.

.. code-block:: python

A = gb.Matrix.from_values([0, 0, 1], [0, 1, 0], [1., -2., 3.])
B = gb.Matrix.from_values([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
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 << A.kronecker(B, 'times')

Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/recorder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Instead, only the calls from the last iteration will be returned.

# Create the graph and starting vector
start_node = 0
G = Matrix.from_values(
G = Matrix.from_coo(
[0, 0, 1, 1, 2],
[1, 2, 2, 3, 3],
[2.0, 5.0, 1.5, 4.25, 0.5],
nrows=4, ncols=4)
v = Vector.from_values([start_node], [0.0], size=4)
v = Vector.from_coo([start_node], [0.0], size=4)

# Compute SSSP
while True:
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/udf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Example user-defined UnaryOp:

UnaryOp.register_new('force_odd', force_odd_func)

v = Vector.from_values([0, 1, 3, 4, 5], [1, 2, 3, 8, 14])
v = Vector.from_coo([0, 1, 3, 4, 5], [1, 2, 3, 8, 14])
w = v.apply(unary.force_odd).new()

.. csv-table:: w
Expand Down
Loading