diff --git a/content/learning-paths/cross-platform/matrix/1-foundations.md b/content/learning-paths/cross-platform/matrix/1-foundations.md index 46988b1c90..edf9148289 100644 --- a/content/learning-paths/cross-platform/matrix/1-foundations.md +++ b/content/learning-paths/cross-platform/matrix/1-foundations.md @@ -32,6 +32,16 @@ Emacs](https://www.gnu.org/software/emacs/), or [Sublime Text](https://www.sublimetext.com/), which are also popular and they all support extensions that make C++ development easy. +## Source code + +In case you want to, you can [download the source code](https://gitlab.arm.com/learning-code-examples/code-examples/-/archive/main/code-examples-main.tar.gz?path=learning-paths/cross-platform/matrix) for this learning path. This will download a `.tar.gz` archive that you will need to expand: + +```BASH +tar xfz code-examples-main-learning-paths-cross-platform-matrix.tar.gz +mv code-examples-main-learning-paths-cross-platform-matrix code-examples +``` + +The source code for this learning path will be available in `code-examples/learning-paths/cross-platform/matrix/`. ## What are the differences between configuring the project and building the code? @@ -64,7 +74,7 @@ projects like [LLVM](https://www.llvm.org) or [Qt](https://www.qt.io/). Organizing the files in a project is important because it allows you to: -- Easily navigate the structure and find information. +- Easily navigate the structure and find information. - Organize information for the tools, such as compilers and linkers. - Make a distinction between information that is exported or installed, and what is only relevant for building the project. @@ -117,7 +127,18 @@ There is nothing like creating the canonical `Hello, World!` application! Use your favorite text editor or IDE to create the file `src/howdy.cpp` and add the following content: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-1/src/howdy.cpp" >}} +```CPP +#include +#include + +using namespace std; + +int main(int argc, char *argv[]) { + cout << "Hello, World !\n"; + + return EXIT_SUCCESS; +} +``` ## Setup CMake @@ -226,21 +247,89 @@ library version. Add the `Matrix.h` header file, declaring the `Version` object and the `getVersion` function and save the file as `include/Matrix/Matrix.h`: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-1/include/Matrix/Matrix.h" >}} +```CPP +#pragma once + +namespace MatComp { + +/// The Version struct is used to carry around the major, minor and patch level. +struct Version { + unsigned major; //< The major version level. + unsigned minor; //< The minor version level. + unsigned patch; //< The patch level. +}; + +/// Get the Matrix library version information. +const Version &getVersion(); + +} // namespace MatComp +``` With those declarations in place, create and add the following lines to `lib/Matrix/Matrix.cpp` to provide an implementation to `getVersion`: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-1/lib/Matrix/Matrix.cpp" >}} +```CPP +#include "Matrix/Matrix.h" + +namespace { +const MatComp::Version version = {.major = 0, .minor = 1, .patch = 0}; +} + +namespace MatComp { + +const Version &getVersion() { return version; } + +} // namespace MatComp +``` Now, you can create a program that will make use of the ``getVersion`` function. Use your editor to save the code below as `src/getVersion.cpp`: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-1/src/getVersion.cpp" >}} +```CPP +#include "Matrix/Matrix.h" + +#include +#include + +using namespace std; +using namespace MatComp; + +int main(int argc, char *argv[]) { + const Version &version = getVersion(); + cout << "Using Matrix version: " << version.major << '.' << version.minor + << '.' << version.patch << '\n'; + + return EXIT_SUCCESS; +} +``` Finally, add the instructions below in the top-level `CMakeLists.txt`: -{{< include-code TXT "content/learning-paths/cross-platform/matrix/projects/chapter-1/CMakeLists.txt" >}} +```TXT +# Set the minimum CMake version we require. In our case, it is intentionnally +# very old as we are not making use of recent CMake features. +cmake_minimum_required(VERSION 3.5) + +# Give a name to our project ('Matrix') and inform CMake about the language used. +project(Matrix LANGUAGES CXX) + +# Add 'howdy', a standalone executable with no dependency to any library that +# has to be built from the sources in 'src/howdy.cpp'. +add_executable(howdy src/howdy.cpp) + +# Add our 'Matrix' library, that is built as a static library, from source file +# 'lib/Matrix/Matrix.cpp'. CMake is instruction that C++17 is used, and that +# the library headers can be found in ${CMAKE_SOURCE_DIR}/include. +add_library(Matrix STATIC lib/Matrix/Matrix.cpp) +target_compile_features(Matrix PUBLIC cxx_std_17) +target_include_directories(Matrix + PUBLIC ${CMAKE_SOURCE_DIR}/include) + +# Add 'matrix-getVersion', an executable that depends on the Matrix library, +# that has to be built from source file 'src/getVersion.cpp'. +add_executable(matrix-getVersion src/getVersion.cpp) +target_link_libraries(matrix-getVersion Matrix) +``` The `add_library` instructs CMake how to build the Matrix library. The `target_include_directories` specifies where the Matrix library header is located, and the `target_compile_features` specifies that C++17 is the version @@ -301,3 +390,7 @@ For example, Visual Studio Code can work seamlessly with CMake with plugins, and generate project files for several popular IDEs, such as Xcode, Sublime Text, Eclipse, CodeBlocks, and CodeLite. You can run `cmake --help` to get a list of supported *generators* (in CMake terminology) for your platform. + +You can refer to this chapter source code in +`code-examples/learning-paths/cross-platform/matrix/chapter-1` in the archive that +you have downloaded earlier. \ No newline at end of file diff --git a/content/learning-paths/cross-platform/matrix/2-testing.md b/content/learning-paths/cross-platform/matrix/2-testing.md index 31ed872bab..996d8a31bc 100644 --- a/content/learning-paths/cross-platform/matrix/2-testing.md +++ b/content/learning-paths/cross-platform/matrix/2-testing.md @@ -17,7 +17,7 @@ benefits: - They offer an opportunity to catch regressions. - They demonstrate how to use the library in practice. - They create opportunities for those new to the project to easily check their patches, and verify that the introduction of the new code has not created unintended negative changes. - + You will notice that setting up testing precedes library code development. There are many unit testing frameworks available, and C++ is not short of them. See this [wikipedia @@ -38,7 +38,38 @@ all external dependencies. It will be used by the main `CMakeLists.txt`. Create the file `external/CMakeLists.txt` with the following content: -{{< include-code TXT "content/learning-paths/cross-platform/matrix/projects/chapter-2/external/CMakeLists.txt" >}} +```TXT +cmake_minimum_required(VERSION 3.6) + +project(external LANGUAGES CXX) + +# Get the functionality to configure, build and install external project +# from CMake module 'ExternalProject'. +include(ExternalProject) + +# Use the same compiler, build type and instalation directory than those +# from our caller. +set(EXTERNAL_PROJECT_CMAKE_ARGS + -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}) + +# Add 'googletext' as an external project, that will be cloned with git, +# from the official googletest repository, at version v1.14. +# We ask for a shallow clone, which is a clone with only the revision +# we are interested in rather than googletest's full history --- +# this makes the clone much faster (less data traffic), and uses much +# less disk space ; furthermore, as we are not developping googletest +# but just merely using it, we don't need thre full history. It will be +# built and installed with our build configuration passed with CMAKE_ARGS. +ExternalProject_Add(googletest + PREFIX "external" + GIT_REPOSITORY "https://github.com/google/googletest" + GIT_TAG "v1.14.0" + GIT_SHALLOW TRUE + CMAKE_ARGS ${EXTERNAL_PROJECT_CMAKE_ARGS} +) +``` You might notice a new CMake feature: variables. Variables start with the `$` character and have a name inserted between curly braces. A CMake variable can be set by the CMake itself, or by the user, and they can be modified or used as they are. @@ -235,11 +266,33 @@ several files inside the `tests/` directory. Create the top-level test in `tests/main.cpp` and paste the following code into the file: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/main.cpp" >}} +```CPP +#include "gtest/gtest.h" + +using namespace testing; + +int main(int argc, char **argv) { + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +``` Create `tests/Version.cpp` and add the `getVersion` unit test into the file: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/Version.cpp" >}} +```CPP +#include "Matrix/Matrix.h" + +#include "gtest/gtest.h" + +using namespace MatComp; + +TEST(Matrix, getVersion) { + const Version &version = getVersion(); + EXPECT_EQ(version.major, 0); + EXPECT_EQ(version.minor, 1); + EXPECT_EQ(version.patch, 0); +} +``` This test invokes `getVersion` and checks that the `major`, `minor` and `patch` levels match the expected values. @@ -325,3 +378,7 @@ Matrix/ CMake makes it easy to use GoogleTest as an external project. Adding unit tests as you go is now easy. You have created the unit testing environment for your Matrix library and added a test. The infrastructure is now in place to implement the core of the Matrix processing library. + +You can refer to this chapter source code in +`code-examples/learning-paths/cross-platform/matrix/chapter-2` in the archive that +you have downloaded earlier. \ No newline at end of file diff --git a/content/learning-paths/cross-platform/matrix/3-code-1.md b/content/learning-paths/cross-platform/matrix/3-code-1.md index 0f23f298e4..20bdac8f6a 100644 --- a/content/learning-paths/cross-platform/matrix/3-code-1.md +++ b/content/learning-paths/cross-platform/matrix/3-code-1.md @@ -62,7 +62,28 @@ Open `lib/Matrix/Matrix.cpp` and include at the top of the file: Add `die`'s body as shown below: -{{< include-code CPP "content/learning-paths/cross-platform/matrix/projects/chapter-3/lib/Matrix/Matrix.cpp" >}} +```CPP +#include "Matrix/Matrix.h" + +#include +#include + +namespace { +const MatComp::Version version = {.major = 0, .minor = 1, .patch = 0}; +} + +namespace MatComp { + +const Version &getVersion() { return version; } + +void die(const char *fileName, size_t lineNumber, const char *reason) { + std::cerr << "Fatal: " << reason << " from " << fileName << ':' + << lineNumber << '\n'; + exit(EXIT_FAILURE); +} + +} // namespace MatComp +``` At this stage, the project should still build and compile, try it to confirm: @@ -1045,3 +1066,7 @@ After this rather long exercise, you have a minimalistic, yet fully-functional c Modern C++ enables you to express move and copy semantics, and to use smart pointers to make memory management easy. The compiler also catch a large number of type or misuse errors. With this core functionality in place, you have all you need to implement matrix operations in the next section. + +You can refer to this chapter source code in +`code-examples/learning-paths/cross-platform/matrix/chapter-3` in the archive that +you have downloaded earlier. \ No newline at end of file diff --git a/content/learning-paths/cross-platform/matrix/4-code-2.md b/content/learning-paths/cross-platform/matrix/4-code-2.md index 56828683b7..73812bd3a1 100644 --- a/content/learning-paths/cross-platform/matrix/4-code-2.md +++ b/content/learning-paths/cross-platform/matrix/4-code-2.md @@ -1150,3 +1150,7 @@ built and used. The testing could - and *should* - go much deeper, as a number of corner cases have not been covered. You can continue to add more functions, and more tests. + +You can refer to this chapter source code in +`code-examples/learning-paths/cross-platform/matrix/chapter-4` in the archive that +you have downloaded earlier. \ No newline at end of file diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.clang-format b/content/learning-paths/cross-platform/matrix/projects/chapter-1/.clang-format deleted file mode 100644 index 6107f26f8e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ ---- - -# We use defaults from the LLVM style, but with 4 columns indentation. -BasedOnStyle: LLVM -IndentWidth: 4 diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.gitignore b/content/learning-paths/cross-platform/matrix/projects/chapter-1/.gitignore deleted file mode 100644 index bc9544853e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache/ -build/ diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.vscode/settings.json b/content/learning-paths/cross-platform/matrix/projects/chapter-1/.vscode/settings.json deleted file mode 100644 index f316739241..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "cmake.configureOnOpen": true, - "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true, - "files.trimFinalNewlines": true, - "explorer.excludeGitIgnore": true -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/CMakeLists.txt b/content/learning-paths/cross-platform/matrix/projects/chapter-1/CMakeLists.txt deleted file mode 100644 index 6a55bfdfde..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Set the minimum CMake version we require. In our case, it is intentionnally -# very old as we are not making use of recent CMake features. -cmake_minimum_required(VERSION 3.5) - -# Give a name to our project ('Matrix') and inform CMake about the language used. -project(Matrix LANGUAGES CXX) - -# Add 'howdy', a standalone executable with no dependency to any library that -# has to be built from the sources in 'src/howdy.cpp'. -add_executable(howdy src/howdy.cpp) - -# Add our 'Matrix' library, that is built as a static library, from source file -# 'lib/Matrix/Matrix.cpp'. CMake is instruction that C++17 is used, and that -# the library headers can be found in ${CMAKE_SOURCE_DIR}/include. -add_library(Matrix STATIC lib/Matrix/Matrix.cpp) -target_compile_features(Matrix PUBLIC cxx_std_17) -target_include_directories(Matrix - PUBLIC ${CMAKE_SOURCE_DIR}/include) - -# Add 'matrix-getVersion', an executable that depends on the Matrix library, -# that has to be built from source file 'src/getVersion.cpp'. -add_executable(matrix-getVersion src/getVersion.cpp) -target_link_libraries(matrix-getVersion Matrix) diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/include/Matrix/Matrix.h b/content/learning-paths/cross-platform/matrix/projects/chapter-1/include/Matrix/Matrix.h deleted file mode 100644 index 305479a764..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/include/Matrix/Matrix.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -namespace MatComp { - -/// The Version struct is used to carry around the major, minor and patch level. -struct Version { - unsigned major; //< The major version level. - unsigned minor; //< The minor version level. - unsigned patch; //< The patch level. -}; - -/// Get the Matrix library version information. -const Version &getVersion(); - -} // namespace MatComp diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/lib/Matrix/Matrix.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-1/lib/Matrix/Matrix.cpp deleted file mode 100644 index 075669a5e3..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/lib/Matrix/Matrix.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "Matrix/Matrix.h" - -namespace { -const MatComp::Version version = {.major = 0, .minor = 1, .patch = 0}; -} - -namespace MatComp { - -const Version &getVersion() { return version; } - -} // namespace MatComp diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/getVersion.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/getVersion.cpp deleted file mode 100644 index 16b7e2286b..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/getVersion.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Matrix/Matrix.h" - -#include -#include - -using namespace std; -using namespace MatComp; - -int main(int argc, char *argv[]) { - const Version &version = getVersion(); - cout << "Using Matrix version: " << version.major << '.' << version.minor - << '.' << version.patch << '\n'; - - return EXIT_SUCCESS; -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/howdy.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/howdy.cpp deleted file mode 100644 index 10c08110be..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-1/src/howdy.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -using namespace std; - -int main(int argc, char *argv[]) { - cout << "Hello, World !\n"; - - return EXIT_SUCCESS; -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.clang-format b/content/learning-paths/cross-platform/matrix/projects/chapter-2/.clang-format deleted file mode 100644 index 6107f26f8e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ ---- - -# We use defaults from the LLVM style, but with 4 columns indentation. -BasedOnStyle: LLVM -IndentWidth: 4 diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.gitignore b/content/learning-paths/cross-platform/matrix/projects/chapter-2/.gitignore deleted file mode 100644 index bc9544853e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache/ -build/ diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.vscode/settings.json b/content/learning-paths/cross-platform/matrix/projects/chapter-2/.vscode/settings.json deleted file mode 100644 index f316739241..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "cmake.configureOnOpen": true, - "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true, - "files.trimFinalNewlines": true, - "explorer.excludeGitIgnore": true -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/CMakeLists.txt b/content/learning-paths/cross-platform/matrix/projects/chapter-2/CMakeLists.txt deleted file mode 100644 index 797ff4d37f..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# Set the minimum CMake version we require. In our case, it is intentionnally -# very old as we are not making use of recent CMake features. -cmake_minimum_required(VERSION 3.5) - -# Give a name to our project ('Matrix') and inform CMake about the language used. -project(Matrix LANGUAGES CXX) - -# =================================================================== -# Download, configure, build and install locally our external dependencies. -# This is done once, at configuration time. -# ------------------------------------------------------------------- - -# Build CMake command line so that it will use the same CMake configuration than -# the one we have been invoked with (generator, compiler, build type, build directory) -set(EXTERNAL_PROJECT_CMAKE_ARGS - -G ${CMAKE_GENERATOR} - -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}) - -# Download and configure our external dependencies -execute_process( - COMMAND ${CMAKE_COMMAND} - -S ${CMAKE_SOURCE_DIR}/external - -B ${CMAKE_BINARY_DIR}/external - ${EXTERNAL_PROJECT_CMAKE_ARGS} -) - -# Build our external dependencies. -execute_process( - COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/external -) -# Install our external dependencies. -execute_process( - COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/external -) - -# Import googletest package information (library names, paths, dependencies, ...) -set(GTest_DIR "${CMAKE_BINARY_DIR}/lib/cmake/GTest" - CACHE PATH "Path to the googletest package configuration files") -find_package(GTest REQUIRED - CONFIG - NO_DEFAULT_PATH - NO_PACKAGE_ROOT_PATH - NO_SYSTEM_ENVIRONMENT_PATH -) - -# Add 'howdy', a standalone executable with no dependency to any library that -# has to be built from the sources in 'src/howdy.cpp'. -add_executable(howdy src/howdy.cpp) - -# Add our 'Matrix' library, that is built as a static library, from source file -# 'lib/Matrix/Matrix.cpp'. CMake is instruction that C++17 is used, and that -# the library headers can be found in ${CMAKE_SOURCE_DIR}/include. -add_library(Matrix STATIC lib/Matrix/Matrix.cpp) -target_compile_features(Matrix PUBLIC cxx_std_17) -target_include_directories(Matrix - PUBLIC ${CMAKE_SOURCE_DIR}/include) - -# Add 'matrix-getVersion', an executable that depends on the Matrix library, -# that has to be built from source file 'src/getVersion.cpp'. -add_executable(matrix-getVersion src/getVersion.cpp) -target_link_libraries(matrix-getVersion Matrix) - -# =================================================================== -# Testing -# ------------------------------------------------------------------- -add_executable(matrix-test tests/main.cpp tests/Version.cpp) -target_link_libraries(matrix-test GTest::gtest Matrix) -add_custom_target(check - COMMAND matrix-test --gtest_color=yes --gtest_output=xml:matrix-test.xml -) diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/external/CMakeLists.txt b/content/learning-paths/cross-platform/matrix/projects/chapter-2/external/CMakeLists.txt deleted file mode 100644 index 73c4553f84..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/external/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -project(external LANGUAGES CXX) - -# Get the functionality to configure, build and install external project -# from CMake module 'ExternalProject'. -include(ExternalProject) - -# Use the same compiler, build type and instalation directory than those -# from our caller. -set(EXTERNAL_PROJECT_CMAKE_ARGS - -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}) - -# Add 'googletext' as an external project, that will be cloned with git, -# from the official googletest repository, at version v1.14. -# We ask for a shallow clone, which is a clone with only the revision -# we are interested in rather than googletest's full history --- -# this makes the clone much faster (less data traffic), and uses much -# less disk space ; furthermore, as we are not developping googletest -# but just merely using it, we don't need thre full history. It will be -# built and installed with our build configuration passed with CMAKE_ARGS. -ExternalProject_Add(googletest - PREFIX "external" - GIT_REPOSITORY "https://github.com/google/googletest" - GIT_TAG "v1.14.0" - GIT_SHALLOW TRUE - CMAKE_ARGS ${EXTERNAL_PROJECT_CMAKE_ARGS} -) diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/include/Matrix/Matrix.h b/content/learning-paths/cross-platform/matrix/projects/chapter-2/include/Matrix/Matrix.h deleted file mode 100644 index 305479a764..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/include/Matrix/Matrix.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -namespace MatComp { - -/// The Version struct is used to carry around the major, minor and patch level. -struct Version { - unsigned major; //< The major version level. - unsigned minor; //< The minor version level. - unsigned patch; //< The patch level. -}; - -/// Get the Matrix library version information. -const Version &getVersion(); - -} // namespace MatComp diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/lib/Matrix/Matrix.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-2/lib/Matrix/Matrix.cpp deleted file mode 100644 index 075669a5e3..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/lib/Matrix/Matrix.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "Matrix/Matrix.h" - -namespace { -const MatComp::Version version = {.major = 0, .minor = 1, .patch = 0}; -} - -namespace MatComp { - -const Version &getVersion() { return version; } - -} // namespace MatComp diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/getVersion.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/getVersion.cpp deleted file mode 100644 index 16b7e2286b..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/getVersion.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Matrix/Matrix.h" - -#include -#include - -using namespace std; -using namespace MatComp; - -int main(int argc, char *argv[]) { - const Version &version = getVersion(); - cout << "Using Matrix version: " << version.major << '.' << version.minor - << '.' << version.patch << '\n'; - - return EXIT_SUCCESS; -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/howdy.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/howdy.cpp deleted file mode 100644 index 10c08110be..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/src/howdy.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -using namespace std; - -int main(int argc, char *argv[]) { - cout << "Hello, World !\n"; - - return EXIT_SUCCESS; -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/Version.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/Version.cpp deleted file mode 100644 index 1183b89f1e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/Version.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "Matrix/Matrix.h" - -#include "gtest/gtest.h" - -using namespace MatComp; - -TEST(Matrix, getVersion) { - const Version &version = getVersion(); - EXPECT_EQ(version.major, 0); - EXPECT_EQ(version.minor, 1); - EXPECT_EQ(version.patch, 0); -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/main.cpp b/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/main.cpp deleted file mode 100644 index ef82bbed65..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-2/tests/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gtest/gtest.h" - -using namespace testing; - -int main(int argc, char **argv) { - InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.clang-format b/content/learning-paths/cross-platform/matrix/projects/chapter-3/.clang-format deleted file mode 100644 index 6107f26f8e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.clang-format +++ /dev/null @@ -1,5 +0,0 @@ ---- - -# We use defaults from the LLVM style, but with 4 columns indentation. -BasedOnStyle: LLVM -IndentWidth: 4 diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.gitignore b/content/learning-paths/cross-platform/matrix/projects/chapter-3/.gitignore deleted file mode 100644 index bc9544853e..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache/ -build/ diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.vscode/settings.json b/content/learning-paths/cross-platform/matrix/projects/chapter-3/.vscode/settings.json deleted file mode 100644 index f316739241..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "cmake.configureOnOpen": true, - "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true, - "files.trimFinalNewlines": true, - "explorer.excludeGitIgnore": true -} diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/CMakeLists.txt b/content/learning-paths/cross-platform/matrix/projects/chapter-3/CMakeLists.txt deleted file mode 100644 index 6b0353170a..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/CMakeLists.txt +++ /dev/null @@ -1,74 +0,0 @@ -# Set the minimum CMake version we require. In our case, it is intentionnally -# very old as we are not making use of recent CMake features. -cmake_minimum_required(VERSION 3.5) - -# Give a name to our project ('Matrix') and inform CMake about the language used. -project(Matrix LANGUAGES CXX) - -# =================================================================== -# Download, configure, build and install locally our external dependencies. -# This is done once, at configuration time. -# ------------------------------------------------------------------- - -# Build CMake command line so that it will use the same CMake configuration than -# the one we have been invoked with (generator, compiler, build type, build directory) -set(EXTERNAL_PROJECT_CMAKE_ARGS - -G ${CMAKE_GENERATOR} - -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}) - -# Download and configure our external dependencies -execute_process( - COMMAND ${CMAKE_COMMAND} - -S ${CMAKE_SOURCE_DIR}/external - -B ${CMAKE_BINARY_DIR}/external - ${EXTERNAL_PROJECT_CMAKE_ARGS} -) - -# Build our external dependencies. -execute_process( - COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/external -) -# Install our external dependencies. -execute_process( - COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/external -) - -# Import googletest package information (library names, paths, dependencies, ...) -set(GTest_DIR "${CMAKE_BINARY_DIR}/lib/cmake/GTest" - CACHE PATH "Path to the googletest package configuration files") -find_package(GTest REQUIRED - CONFIG - NO_DEFAULT_PATH - NO_PACKAGE_ROOT_PATH - NO_SYSTEM_ENVIRONMENT_PATH -) - -# Add 'howdy', a standalone executable with no dependency to any library that -# has to be built from the sources in 'src/howdy.cpp'. -add_executable(howdy src/howdy.cpp) - -# Add our 'Matrix' library, that is built as a static library, from source file -# 'lib/Matrix/Matrix.cpp'. CMake is instruction that C++17 is used, and that -# the library headers can be found in ${CMAKE_SOURCE_DIR}/include. -add_library(Matrix STATIC lib/Matrix/Matrix.cpp) -target_compile_features(Matrix PUBLIC cxx_std_17) -target_include_directories(Matrix - PUBLIC ${CMAKE_SOURCE_DIR}/include) - -# Add 'matrix-getVersion', an executable that depends on the Matrix library, -# that has to be built from source file 'src/getVersion.cpp'. -add_executable(matrix-getVersion src/getVersion.cpp) -target_link_libraries(matrix-getVersion Matrix) - -# =================================================================== -# Testing -# ------------------------------------------------------------------- -add_executable(matrix-test tests/main.cpp - tests/Matrix.cpp - tests/Version.cpp) -target_link_libraries(matrix-test GTest::gtest Matrix) -add_custom_target(check - COMMAND matrix-test --gtest_color=yes --gtest_output=xml:matrix-test.xml -) diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/external/CMakeLists.txt b/content/learning-paths/cross-platform/matrix/projects/chapter-3/external/CMakeLists.txt deleted file mode 100644 index 73c4553f84..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/external/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.6) - -project(external LANGUAGES CXX) - -# Get the functionality to configure, build and install external project -# from CMake module 'ExternalProject'. -include(ExternalProject) - -# Use the same compiler, build type and instalation directory than those -# from our caller. -set(EXTERNAL_PROJECT_CMAKE_ARGS - -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}) - -# Add 'googletext' as an external project, that will be cloned with git, -# from the official googletest repository, at version v1.14. -# We ask for a shallow clone, which is a clone with only the revision -# we are interested in rather than googletest's full history --- -# this makes the clone much faster (less data traffic), and uses much -# less disk space ; furthermore, as we are not developping googletest -# but just merely using it, we don't need thre full history. It will be -# built and installed with our build configuration passed with CMAKE_ARGS. -ExternalProject_Add(googletest - PREFIX "external" - GIT_REPOSITORY "https://github.com/google/googletest" - GIT_TAG "v1.14.0" - GIT_SHALLOW TRUE - CMAKE_ARGS ${EXTERNAL_PROJECT_CMAKE_ARGS} -) diff --git a/content/learning-paths/cross-platform/matrix/projects/chapter-3/include/Matrix/Matrix.h b/content/learning-paths/cross-platform/matrix/projects/chapter-3/include/Matrix/Matrix.h deleted file mode 100644 index 17eca879e9..0000000000 --- a/content/learning-paths/cross-platform/matrix/projects/chapter-3/include/Matrix/Matrix.h +++ /dev/null @@ -1,233 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace MatComp { - -/// The Version struct is used to carry around the major, minor and patch level. -struct Version { - unsigned major; //< The major version level. - unsigned minor; //< The minor version level. - unsigned patch; //< The patch level. -}; - -/// Get the Matrix library version information. -const Version &getVersion(); - -/// Immediately terminates the application with \p reason as the error message -/// and the EXIT_FAILURE error code. It will also print the file name (\p -/// fileName) and line number (\p lineNumber) that caused that application to -/// exit. -[[noreturn]] void die(const char *fileName, size_t lineNumber, - const char *reason); - -/// The Matrix class represents N x M matrices for all arithmetic types. -template class Matrix { - - static_assert(std::is_arithmetic::value, - "Matrix only accept arithmetic (i.e. integer or floating " - "point) element types."); - - public: - /// Default construct an invalid Matrix. - constexpr Matrix() : numRows(0), numColumns(0), data(nullptr) {} - - /// Construct a \p numRows x \p numColumns uninitialized Matrix - Matrix(size_t numRows, size_t numColumns) - : numRows(numRows), numColumns(numColumns), data() { - allocate(getNumElements()); - } - - /// Construct a \p numRows x \p numColumns Matrix with all elements - /// initialized to value \p val. - Matrix(size_t numRows, size_t numCols, Ty val) : Matrix(numRows, numCols) { - allocate(getNumElements()); - for (size_t i = 0; i < getNumElements(); i++) - data[i] = val; - } - - /// Construct a \p numRows x \p numColumns Matrix with elements - /// initialized from the values from \p il in row-major order. - Matrix(size_t numRows, size_t numCols, std::initializer_list il) - : Matrix(numRows, numCols) { - if (il.size() != getNumElements()) - die(__FILE__, __LINE__, - "the number of initializers does not match the Matrix number " - "of elements"); - allocate(getNumElements()); - size_t i = 0; - for (const auto &val : il) - data[i++] = val; - } - - /// Get a zero initialized Matrix. - static Matrix zeros(size_t numRows, size_t numColumns) { - return Matrix(numRows, numColumns, Ty(0)); - } - - /// Get a one initialized Matrix. - static Matrix ones(size_t numRows, size_t numColumns) { - return Matrix(numRows, numColumns, Ty(1)); - } - - /// Get the identity Matrix. - static Matrix identity(size_t dimension) { - Matrix id = zeros(dimension, dimension); - for (size_t i = 0; i < dimension; i++) - id.get(i, i) = Ty(1); - return id; - } - - /// Copy-construct from the \p other Matrix. - Matrix(const Matrix &other) - : numRows(other.numRows), numColumns(other.numColumns), data() { - allocate(getNumElements()); - std::memcpy(data.get(), other.data.get(), getSizeInBytes()); - } - - /// Move-construct from the \p other Matrix. - Matrix(Matrix &&other) - : numRows(other.numRows), numColumns(other.numColumns), - data(std::move(other.data)) { - - // Invalidate other. - other.numRows = 0; - other.numColumns = 0; - } - - /// Copy-assign from the \p rhs Matrix. - Matrix &operator=(const Matrix &rhs) { - reallocate(rhs.getNumElements()); - if (getNumElements() != 0) - std::memcpy(data.get(), rhs.data.get(), rhs.getSizeInBytes()); - return *this; - } - - /// Move-assign from the \p rhs Matrix. - Matrix &operator=(Matrix &&rhs) { - numRows = rhs.numRows; - numColumns = rhs.numColums; - data = std::move(rhs.data); - return *this; - } - - /// Assign from the \p il initializer list. - Matrix &operator=(std::initializer_list il) { - if (il.size() != getNumElements()) - die(__FILE__, __LINE__, "number of elements do not match"); - - size_t i = 0; - for (const auto &val : il) - data[i++] = val; - - return *this; - } - - /// Get the number of rows in this matrix. - size_t getNumRows() const { return numRows; } - /// Get the number of columns in this matrix. - size_t getNumColumns() const { return numColumns; } - /// Get the number of elements in this matrix. - size_t getNumElements() const { return numRows * numColumns; } - /// Get the storage size in bytes of the Matrix array. - size_t getSizeInBytes() const { return numRows * numColumns * sizeof(Ty); } - - /// Returns true if this matrix is valid. - operator bool() const { - return numRows != 0 && numColumns != 0; - } - - /// Returns true iff both matrices compare equal. - bool operator==(const Matrix &rhs) const { - // Invalid matrices compare equal. - if (!*this && !rhs) - return true; - // If one is invalid, they can never compare equal. - if (*this ^ rhs) - return false; - // Matrices with different dimensions are not equal. - if (numRows != rhs.numRows || numColumns != rhs.numColumns) - return false; - // Every thing else is equal and sound, compare the elements ! - for (size_t i = 0; i < getNumElements(); i++) - if (data[i] != rhs.data[i]) - return false; - return true; - } - /// Returns true iff matrices do not compare equal. - bool operator!=(const Matrix &rhs) const { return !(*this == rhs); } - - /// Access Matrix element at (\p row, \p col) by reference. - Ty &get(size_t row, size_t col) { - assert(*this && "Invalid Matrix"); - assert(row < numRows && "Out of bounds row access"); - assert(col < numColumns && "Out of bounds column access"); - return data[row * numColumns + col]; - } - /// Access Matrix element at (\p row, \p col) by reference (const version). - const Ty &get(size_t row, size_t col) const { - assert(*this && "Invalid Matrix"); - assert(row < numRows && "Out of bounds row access"); - assert(col < numColumns && "Out of bounds column access"); - return data[row * numColumns + col]; - } - - /// Apply a unary scalar operation to each element. - template