You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ALP_Tutorial.tex
+32-48Lines changed: 32 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -261,10 +261,14 @@ \subsection{Copying, Masking, and Standard Matrices}
261
261
\subsection{Numerical Linear Algebra}
262
262
263
263
GraphBLAS, as the name implies, provides canonical BLAS-like functionalities on sparse matrices, sparse vectors, and dense vectors. These include \texttt{grb::dot}, \texttt{grb::eWiseAdd}, \texttt{grb::eWiseMul}, \texttt{grb::mxv}, \texttt{grb::vxm}, and \texttt{grb::mxm}. The former three scalar/vector primitives are dubbed \emph{level 1}, the following two matrix--vector primitives \emph{level 2}, and the latter matrix--matrix primitive \emph{level 3}. Their functionalities are summarised as follows:\newline
264
-
264
+
265
265
\textbf{grb::dot} – Compute the dot product of two vectors, $\alpha$\textit{+=}$u^Tv$ or $\alpha$\textit{+=}$\sum_i (u_i \times v_i)$, in essence combining element-wise multiplication with a reduction. The output $\alpha$ is a scalar, usually a primitive type such as \texttt{double}. Unlike the out-of-place \texttt{grb::set}, the \texttt{grb::dot} updates the output scalar in-place.\newline
266
266
267
-
\textbf{grb::eWiseMul, grb::eWiseAdd} - These primitives combine two containers element-by-element, the former using element-wise multiplication, and the latter using element-wise addition. Different from \texttt{grb::set}, these primitives are in-place, meaning the result of the element-wise operations are added to any elements already in the output container; i.e., \texttt{grb::eWiseMul} computes $z$\textit{+=}$x\odot y$, where $\odot$ denotes element-wise multiplication. In case of sparse vectors and an initially-empty output container, the primitives separate themselves in terms of the structure of the output vector, which is composed either of an intersection or union of the input structures.
267
+
\textbf{grb::eWiseMul, grb::eWiseAdd} - These primitives combine two containers element-by-element, the former using element-wise multiplication, and the latter using element-wise addition. Different from \texttt{grb::set},
268
+
these primitives are in-place, meaning the result of the element-wise operations are added to any elements already in the output container; i.e., \texttt{grb::eWiseMul} computes $z$\textit{+=}$x\odot y$, where $\odot$ denotes element-wise multiplication.
269
+
In case of sparse vectors and an initially-empty output container, the primitives separate themselves in terms of the structure of the output vector, which is composed either of an intersection or union of the input structures.
270
+
Since \textbf{grb} primitives are unvaware of conventional multiplication and addition operations, they are provedied
271
+
as correspond monoids from the semiring argument, the multiplicative and additive monoids.
268
272
\begin{itemize}
269
273
\item\textbf{intersection (eWiseMul):} The primitive will compute only an element-wise multiplication for those positions where \emph{both} input containers have entries. This is since any missing entries are assumed to have value zero, and are therefore ignored under multiplication.
270
274
\item\textbf{union (eWiseAdd):} The primitive will compute element-wise addition for those positions where \emph{any} of the input containers have entries. This is again because a missing entry in one of the containers is assumed to have a zero value, meaning the result of the addition simply equals the value of the entry present in the other container.
@@ -289,7 +293,7 @@ \subsection{Numerical Linear Algebra}
289
293
\item use \texttt{grb::set} and \texttt{grb::setElement} to assign values (see below for a suggestion);
290
294
\item perform a matrix--vector multiplication $y = Ax$ (using \texttt{grb::mxv} with the plus-times semiring);
291
295
\item compute a dot product $d = x^Tx$ (using \texttt{grb::dot} with the same semiring);
292
-
\item perform an element-wise multiplication $z = x \odotx$ (using \texttt{grb::eWiseMul} with the same semiring); and
296
+
\item perform an element-wise multiplication $z = x \odoty$ (using \texttt{grb::eWiseMul} with the same semiring); and
293
297
\item print the results.
294
298
\end{enumerate}
295
299
One example $A, x$ could be:
@@ -307,11 +311,11 @@ \subsection{Numerical Linear Algebra}
307
311
Step 1: Constructing a 3x3 sparse matrix A.
308
312
Step 2: Creating vector x = [1, 2, 3]^T.
309
313
Step 3: Computing y = A·x under plus‐times semiring.
310
-
Step 4: Computing z = x ⊙ x (element‐wise multiply).
314
+
Step 4: Computing z = x ⊙ y (element‐wise multiply).
311
315
Step 5: Computing dot_val = xᵀ·x under plus‐times semiring.
312
316
x = [ 1, 2, 3 ]
313
-
y = A·x = [ 7, 18, 17 ]
314
-
z = x ⊙ x = [ 1, 4, 9 ]
317
+
y = A·x = [ 8, 18, 17 ]
318
+
z = x ⊙ y = [ 8, 36, 51 ]
315
319
dot(x,x) = 14
316
320
\end{lstlisting}
317
321
@@ -403,6 +407,22 @@ \section{Solution to Exercise 8}\label{sec:simple_example}
403
407
404
408
using namespace grb;
405
409
410
+
% A =
411
+
% \begin{bmatrix}
412
+
% 0 & 1 & 2 \\
413
+
% 0 & 3 & 4 \\
414
+
% 5 & 6 & 0
415
+
% \end{bmatrix},\quad
416
+
% Step 1: Constructing a 3x3 sparse matrix A.
417
+
% Step 2: Creating vector x = [1, 2, 3]^T.
418
+
% Step 3: Computing y = A·x under plus‐times semiring.
419
+
% Step 4: Computing z = x ⊙ y (element‐wise multiply).
420
+
% Step 5: Computing dot_val = xᵀ·x under plus‐times semiring.
421
+
% x = [ 1, 2, 3 ]
422
+
% y = A·x = [ 8, 18, 17 ]
423
+
% z = x ⊙ y = [ 8, 36, 51 ]
424
+
% dot(x,x) = 14
425
+
406
426
// Indices and values for our sparse 3x3 matrix A:
407
427
//
408
428
// A = [ 1 0 2 ]
@@ -472,16 +492,15 @@ \section{Solution to Exercise 8}\label{sec:simple_example}
472
492
}
473
493
474
494
//------------------------------
475
-
// 6) Compute z = x ⊙ x (element‐wise multiply) via eWiseApply with mul
495
+
// 6) Compute z = x ⊙ y (element‐wise multiply) via eWiseMul with semiring
476
496
//------------------------------
477
-
std::printf("Step 4: Computing z = x ⊙ x (element‐wise multiply).\n");
497
+
std::printf("Step 4: Computing z = x ⊙ y (element‐wise multiply).\n");
@@ -523,48 +542,13 @@ \section{Solution to Exercise 8}\label{sec:simple_example}
523
542
std::printf("\n-- Results --\n");
524
543
printVector(x, "x");
525
544
printVector(y, "y = A·x");
526
-
printVector(z, "z = x ⊙ x");
545
+
printVector(z, "z = x ⊙ y");
527
546
std::printf("dot(x,x) = %g\n\n", dot_val);
528
547
529
548
return EXIT_SUCCESS;
530
549
}
531
550
\end{lstlisting}
532
551
533
-
In this program, we manually set up a $3\times3$ matrix $A$:
534
-
\[
535
-
A = \begin{pmatrix}
536
-
1 & 0 & 2 \\
537
-
0 & 3 & 4 \\
538
-
5 & 6 & 0
539
-
\end{pmatrix},
540
-
\]
541
-
542
-
543
-
and a vector $x = [1,2,3]^T$. The code multiplies $A$ by $x$, producing $y = A \times x$. Given the above $A$ and $x$, the result should be:
544
-
545
-
\[
546
-
y = \begin{pmatrix}
547
-
7 \\
548
-
18 \\
549
-
17
550
-
\end{pmatrix},
551
-
\]
552
-
553
-
because
554
-
$y_0 = 1\cdot1 + 0\cdot2 + 2\cdot3 = 7$,
555
-
$y_1 = 0\cdot1 + 3\cdot2 + 4\cdot3 = 18$,
556
-
$y_2 = 5\cdot1 + 6\cdot2 + 0\cdot3 = 17$.
557
-
558
-
We also compute the dot product $x \cdot x = 1^2 + 2^2 + 3^2 = 14$ and the element-wise product $z = x * x = [1,4,9]^T$. The program then extracts the results with \texttt{grb::extractElement} (to get values from the containers) and prints them. Running this program would produce output similar to:
559
-
560
-
\begin{verbatim}
561
-
y = [7, 18, 17]
562
-
x . x = 14
563
-
z (element-wise product of x with x) = [1, 4, 9]
564
-
\end{verbatim}
565
-
566
-
This confirms that our ALP operations worked as expected. The code demonstrates setting values, performing an \texttt{mxv} multiplication, an element-wise multiply, and a dot product, covering several fundamental ALP/GraphBLAS operations.
567
-
568
552
569
553
\section{Makefile and CMake Instructions}\label{sec:build_instructions}
0 commit comments