Getting Started#

Installation#

To use LibRapid in your CMake project, first clone the project: git clone --recursive https://github.com/LibRapid/libRapid.git

Next, add the following to your CMakeLists.txt

add_subdirectory(librapid)
target_link_libraries(yourTarget PUBLIC librapid)

That’s it! LibRapid will now be compiled and linked with your project!

Your First Program#

 1#include <librapid>
 2namespace lrc = librapid;
 3
 4int main() {
 5    lrc::Array<int> myFirstArray = lrc::fromData({{1, 2, 3, 4},
 6                                                  {5, 6, 7, 8}});
 7
 8    lrc::Array<int> mySecondArray = lrc::fromData({{8, 7, 6, 5},
 9                                                   {4, 3, 2, 1}});
10
11    fmt::print("{}\n\n", myFirstArray);
12    fmt::print("{}\n", mySecondArray);
13
14    fmt::print("Sum of two Arrays:\n{}\n", myFirstArray + mySecondArray);
15    fmt::print("First row of my Array: {}\n", myFirstArray[0]);
16    fmt::print("First row of my Array: {}\n", myFirstArray[0] + mySecondArray[1]);
17
18    return 0;
19}

Your First Program: Explained#

1#include <librapid>
2namespace lrc = librapid;

The first line here allows you to use all of LibRapid’s features in your file. The second line isn’t required, but it makes your code shorter and quicker to type.

5lrc::Array<int> myFirstArray = lrc::fromData({{1, 2, 3, 4},
6                                              {5, 6, 7, 8}});
7
8lrc::Array<int> mySecondArray = lrc::fromData({{8, 7, 6, 5},
9                                               {4, 3, 2, 1}});

These lines create two Array instances from a list of values. Both arrays are 2-dimensional and have 2 rows and 4 columns.

11fmt::print("{}\n\n", myFirstArray);
12fmt::print("{}\n", mySecondArray);

Here, we print out the Arrays we just created. Try changing the numbers to see how the formatting changes!

14fmt::print("Sum of two Arrays:\n{}\n", myFirstArray + mySecondArray);

This line performs a simple arithmetic operation on our Arrays and prints the result.

15fmt::print("First row of my Array: {}\n", myFirstArray[0]);
16fmt::print("First row of my Array: {}\n", myFirstArray[0] + mySecondArray[1]);

As you can see, Array instances can be indexed with the traditional square bracket notation. This means you can easily access sub-arrays of higher-dimensional array objects.