From 6bd8af3c5f80c748bdecedff3246263e78dd7150 Mon Sep 17 00:00:00 2001 From: conrad Date: Sat, 6 Mar 2021 13:30:54 +1000 Subject: [PATCH] show explicit initialisation --- examples/example1.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/example1.cpp b/examples/example1.cpp index 7c258611..ad5bba97 100644 --- a/examples/example1.cpp +++ b/examples/example1.cpp @@ -14,9 +14,15 @@ main(int argc, char** argv) { cout << "Armadillo version: " << arma_version::as_string() << endl; - mat A(2,3); // directly specify the matrix size (elements are uninitialised) + // directly specify the matrix size (by default, elements are not initialised) + mat A(2,3); - cout << "A.n_rows: " << A.n_rows << endl; // .n_rows and .n_cols are read only + // explicit element initialisation during initialisation via one of: + // fill::zeros, fill::ones, fill::eye, fill::randu, fill::randn + A = mat(2,3,fill::zeros); + + // .n_rows and .n_cols are read only + cout << "A.n_rows: " << A.n_rows << endl; cout << "A.n_cols: " << A.n_cols << endl; A(1,2) = 456.0; // directly access an element (indexing starts at 0) @@ -27,7 +33,7 @@ main(int argc, char** argv) A.set_size(4,5); // change the size (data is not preserved) - A.fill(5.0); // set all elements to a particular value + A.fill(5.0); // set all elements to a specific value A.print("A:"); A = { { 0.165300, 0.454037, 0.995795, 0.124098, 0.047084 },