Getting started
This short guide explains how to get started with EDDL once you have installed it with one of the methods described in the installation section.
First example
Copy this code to a new file and name it main.cpp
:
#include <iostream>
#include <eddl/tensor/tensor.h>
int main(int argc, char* argv[]){
Tensor* t = Tensor::ones({5, 5, 5});
std::cout << "Tensor sum=" << t->sum() << std::endl;
return 0;
}
This example simply sums all the elements of a tensor.
To compile it we are going to use CMake and the find_package(EDDL REQUIRED)
function.
If you are not familiar with CMake, read the next section.
Building with cmake
A better alternative for building programs using EDDL is to use cmake, especially if you are developing for several platforms. Assuming the following folder structure:
first_example/
|- main.cpp
|- CMakeLists.txt
A folder named first_example
with two files inside: a *.cpp
and a CMakeLists.txt
.
Now, you can copy the following lines to the CMakeLists.txt
file so that we can build the first example:
cmake_minimum_required(VERSION 3.9.2)
project(first_example)
add_executable(first_example main.cpp)
find_package(EDDL REQUIRED)
target_link_libraries(first_example PUBLIC EDDL::eddl)
cmake has to know where to find the headers; this is done through the CMAKE_INSTALL_PREFIX
variable. Note that CMAKE_INSTALL_PREFIX
is usually the path to a folder containing the following
subfolders: include
, lib
and bin
, so you don’t have to pass any additional option for linking.
Examples of valid values for CMAKE_INSTALL_PREFIX
on Unix platforms are /usr/local
, /opt
.
The following commands create a directory for building (avoid building in the source folder), builds the first example with cmake and then runs the program:
mkdir build
cd build
cmake ..
make
./first_example
See Build and configuration for more details about the build options.