Skip to content

Commit

Permalink
Merge pull request #28 from GraphBLAS/update-vector
Browse files Browse the repository at this point in the history
Update `vector` to be consistent with changes to `matrix`
  • Loading branch information
BenBrock authored Nov 15, 2023
2 parents 2bac6cc + 4f9f0c0 commit 76b9c9e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions markdown/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ graphblas.html: $(TEX_SOURCES) $(MD_SOURCES) Makefile
vector.md \
index.md \
hints.md \
views.md \
functional.md \
plus.md \
multiplies.md \
Expand Down
8 changes: 6 additions & 2 deletions markdown/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ vector(); (1)
vector(const Allocator& alloc); (2)
vector(index_type shape); (3)
vector(index_type shape, const Allocator& alloc); (4)
vector(const vector& other); (5)
vector(vector&& other); (6)
```

Constructs new `grb::vector` data structure.

1) Constructs an empty vector of dimension 0.
2) Constructs an empty vector of dimension `shape`.
1) and 2) Constructs an empty vector of dimension 0.
3) and 4) Constructs an empty vector of dimension `shape`.
5) Copy constructor
6) Move constructor

### Parameters
`shape` - shape of the vector to be constructed
Expand Down
46 changes: 29 additions & 17 deletions markdown/views.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Views

## grb::transpose
## grb::views::transpose

```cpp
namespace views {
inline constexpr /* unspecified */ transpose = /* unspecified */;
}
```
##### Call signature
```cpp
template <MatrixRange M>
grb::transpose_view<M> transpose(M&& matrix);
MatrixRange auto transpose(M&& matrix);
```

### Parameters
Expand All @@ -16,21 +24,25 @@ grb::transpose_view<M> transpose(M&& matrix);
- `M` must meet the requirements of `MatrixRange`

### Return Value
_TODO: Discuss issues with allowing transpose view in output_
Returns a matrix view that is equal to the transpose of `matrix`, satisfying `MatrixRange`.
If `M` meets the requirements of `MutableMatrixRange`, then the return value will also meet the
requirements of `MutableMatrixRange`.

If the value returned by `transpose` outlives the lifetime of `matrix`, then the behavior is undefined.

## grb::transform
## grb::views::transform

```cpp
template <MatrixRange M, typename Fn>
grb::transform_view<M, Fn> transform(M&& matrix, Fn&& fn); (1)
namespace views {
inline constexpr /* unspecified */ transform = /* unspecified */;
}
```
template <VectorRange V, typename Fn>
grb::transform_view<V, Fn> transform(V&& vector, Fn&& fn); (2)
##### Call signature
```cpp
template <MatrixRange M, std::copy_constructible Fn>
MatrixRange auto transform (M&& matrix, Fn&& fn); (1)
template <VectorRange V, std::copy_constructible Fn>
VectorRange auto transform(V&& vector, Fn&& fn); (2)
```

(1) `fn` must accept an argument of type `std::ranges::range_value_t<M>` and return a value of some type. The return type of `fn` will be the scalar type of the transform view.
Expand All @@ -53,9 +65,9 @@ grb::transform_view<V, Fn> transform(V&& vector, Fn&& fn); (2)

### Return Value

(1) Returns a view of the matrix `matrix` in which every stored scalar value has been transformed using the function `fn`.
(1) Returns a view of `matrix` satisfying `MatrixRange`. The stored scalar values will correspond to every stored scalar value in `matrix` transformed using the function `fn`.

(2) Returns a view of the vector `vector` in which every stored scalar value has been transformed using the function `fn`.
(2) Returns a view of `vector` satisfying `VectorRange`. The stored scalar values will correspond to every stored scalar value in `vector` transformed using the function `fn`.

### Example

Expand All @@ -73,11 +85,11 @@ int main(int argc, char** argv) {

// Transform each scalar value based on its
// row and column index.
auto idx_view = grb::transform(a, [](auto&& entry) {
auto&& [idx, v] = entry;
auto&& [i, j] = idx;
return i + j;
});
auto idx_view = grb::views::transform(a, [](auto&& entry) {
auto&& [idx, v] = entry;
auto&& [i, j] = idx;
return i + j;
});

grb::print(idx_view, "index transformed view");

Expand Down

0 comments on commit 76b9c9e

Please sign in to comment.