Skip to content

Commit ac28805

Browse files
committed
major update
1 parent d1f8c3c commit ac28805

23 files changed

+3687
-191
lines changed

CMakeLists.txt

100644100755
+113-28
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,139 @@
22
# Distributed under the GNU General Public License version 3
33
# (http://www.gnu.org/licenses)
44

5-
cmake_minimum_required(VERSION 3.8)
65

7-
# ------- config -------
86

9-
set(PROJECT_NAME mnist_reader)
10-
set(PROJECT_VERSION 1.0)
11-
set(PROJECT_BRIEF "A   C++   library   to   read   the   mnist   dataset.")
7+
# ------------ cmake minimum version ------------
128

13-
#bin or library
14-
set(PROJECT_TYPE library)
9+
cmake_minimum_required(VERSION 3.16.3)
1510

16-
# ------- options -------
1711

18-
option(SHARED_LIBRARY "Type of the output library, shared if set to yes, static if not." OFF)
1912

20-
option(BUILD_DOCS "Build documentation" OFF)
13+
# ------------------ metadatas------------------
2114

22-
option(BUILD_EXAMPLE "Build example" OFF)
15+
set(PROJECT_NAME "mnist_reader")
16+
set(PROJECT_VERSION 1.1)
17+
set(PROJECT_BRIEF "A   simple   c++   lib   to   read   the   mnist   database.")
2318

24-
# ----------------------
19+
20+
# -------------- type of output -----------------
21+
22+
# ----- (BINARY or LIBRARY) -----
23+
set(PROJECT_TYPE "LIBRARY")
24+
25+
26+
27+
# ------------------- options -------------------
28+
29+
# ----- (DEBUG or RELEASE) ------
30+
set(BUILD_MODE "RELEASE" CACHE STRING "Build mode, possible values are RELEASE and DEBUG.")
31+
32+
if(PROJECT_TYPE STREQUAL "LIBRARY")
33+
# ----- (SHARED or STATIC) ------
34+
set(LIBRARY_TYPE "STATIC" CACHE STRING "Type of the output library, possible values are SHARED and STATIC.")
35+
endif()
36+
37+
# --------- (ON or OFF) ---------
38+
option(BUILD_DOC "Build documentation" OFF)
39+
40+
# --------- (ON or OFF) ---------
41+
option(BUILD_EXAMPLES "Build example" OFF
42+
43+
# --------- (ON or OFF) ---------
44+
option(MNIST_STATIC_CLASS "Use MnistReader as a static class" OFF)
45+
46+
# --------- (ON or OFF) ---------
47+
option(MNIST_SUPER_CLASS "Use MnistReader as a super class" OFF)
48+
49+
# --------- (ON or OFF) ---------
50+
option(C++_STATIC_LIB "Build with the C++ static library" OFF)
51+
52+
# --------------- options feedback --------------
2553

2654
message(${PROJECT_NAME} " building configuration start with the options :" )
27-
if(PROJECT_TYPE STREQUAL "library")
28-
message("SHARED_LIBRARY : " ${SHARED_LIBRARY})
55+
message("PROJECT_TYPE : " ${PROJECT_TYPE})
56+
if(PROJECT_TYPE STREQUAL "LIBRARY")
57+
message("LIBRARY_TYPE : " ${LIBRARY_TYPE})
2958
endif()
30-
message("BUILD_DOCS : " ${BUILD_DOCS})
31-
message("BUILD_EXAMPLE : " ${BUILD_EXAMPLE})
32-
message("You can change this using the -D option of cmake\n")
59+
message("BUILD_MODE : " ${BUILD_MODE})
60+
message("BUILD_DOC : " ${BUILD_DOC})
61+
message("BUILD_EXAMPLES : " ${BUILD_EXAMPLES})
62+
message("MNIST_STATIC_CLASS : " ${MNIST_STATIC_CLASS})
63+
message("MNIST_SUPER_CLASS : " ${MNIST_SUPER_CLASS})
64+
message("C++_STATIC_LIB : " ${C++_STATIC_LIB})
3365

34-
# ----------------------
66+
message("You can change this options using the -D option of cmake\n")
3567

36-
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
3768

38-
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
3969

40-
add_subdirectory(src)
70+
# ------------ project configurations -----------
4171

42-
# ----------------------
72+
# ---- C++ required standart ----
73+
set(CMAKE_CXX_STANDARD 11)
74+
set(CMAKE_CXX_STANDARD_REQUIRED True)
4375

44-
if (BUILD_DOCS)
45-
find_package(Doxygen)
76+
# ----- compilation options -----
77+
ADD_COMPILE_OPTIONS(-O3 -Ofast -Wall -Wextra)
78+
if(BUILD_MODE STREQUAL "DEBUG")
79+
set(DEBUG CMAKE_CXX_FLAGS_DEBUG)
80+
add_compile_options(-g)
81+
else()
82+
set(RELEASE CMAKE_CXX_FLAGS_RELEASE)
83+
endif()
84+
85+
if(C++_STATIC_LIB)
86+
add_compile_options(-static -static-libgcc -static-libstdc++)
87+
endif()
88+
89+
if(MNIST_STATIC_CLASS)
90+
add_compile_options(-D MNIST_READER_STATIC_CLASS)
91+
endif()
92+
93+
if(MNIST_SUPER_CLASS)
94+
add_compile_options(-D MNIST_READER_SUPER_CLASS)
95+
endif()
96+
97+
# --------- project's name --------
98+
set(INSTALL_DIR "${CMAKE_SOURCE_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}")
99+
100+
if(C++_STATIC_LIB)
101+
set(PROJECT_NAME "${PROJECT_NAME}-csl")
102+
endif()
103+
104+
if(MNIST_STATIC_CLASS)
105+
set(PROJECT_NAME "${PROJECT_NAME}-stc")
106+
endif()
107+
108+
if(MNIST_SUPER_CLASS)
109+
set(PROJECT_NAME "${PROJECT_NAME}-suc")
46110
endif()
47111

48-
if (DOXYGEN_FOUND AND BUILD_DOCS)
49-
add_subdirectory(docs)
112+
if(BUILD_MODE STREQUAL "DEBUG")
113+
set(PROJECT_NAME "${PROJECT_NAME}-d")
114+
endif()
115+
116+
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
117+
118+
# -- default installation folder --
119+
set(CMAKE_INSTALL_PREFIX ${INSTALL_DIR})
120+
121+
122+
# ---------------- subdirectories ---------------
123+
124+
# ------ lib or binary config -----
125+
add_subdirectory("src")
126+
127+
# ----------- doc config ----------
128+
if (BUILD_DOC)
129+
find_package(Doxygen)
130+
if (DOXYGEN_FOUND)
131+
add_subdirectory("doc")
132+
endif()
50133
endif()
51134

52-
if (BUILD_EXAMPLE)
53-
add_subdirectory (example)
135+
# -------- examples config --------
136+
if (BUILD_EXAMPLES)
137+
add_subdirectory("examples")
54138
endif()
55139

140+
# -----------------------------------------------

LICENSE

100644100755
File mode changed.

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# mnist_reader
2+
3+
mnist_reader gives a simple and easy way to read and store the mnist database in C++.
4+
5+
Mnist is a database of hand writing numbers used to test and improve image recognition programs.
6+
7+
See : http://yann.lecun.com/exdb/mnist/
8+
9+
## How to use it
10+
11+
#### 1. Download the repository
12+
13+
Download the repository with your browser or with git using :
14+
15+
```
16+
git clone https://github.com/QuentinP-dev/mnist_reader.git
17+
```
18+
19+
#### 2. Build the mnist_reader library
20+
21+
Use the [CMakeLists.txt](/CMakeLists.txt) to create the mnist_reader library :
22+
23+
*(example for a Linux system)*
24+
```
25+
cmake CMakeLists.txt -G Unix\ Makefiles -B conf/
26+
cd conf/
27+
cmake --build .
28+
cmake --install .
29+
```
30+
By default, the library, documentation and examples will be installed in the cmake root folder in a subdirectory named mnist_reader-x.y . *(Where x and y are the major and minor version of the lib).*
31+
32+
You can pass options to the cmake command using -D (see man cmake)
33+
34+
35+
Option | meaning | default value| added suffix
36+
------ | ------- | -------------| ------------
37+
BUILD_DOC | Build the documentation using doxygen | OFF |
38+
BUILD_EXAMPLE | Build a little example | OFF |
39+
C++_STATIC_LIB | Build using the static C++ library | OFF | **ON:** -csl
40+
MNIST_STATIC_CLASS | Use the mnist_reader as a static class | OFF | **ON:** -stc
41+
MNIST_SUPER_CLASS | Use the mnist_reader as a super class | OFF | **ON:** -suc
42+
BUILD_MODE | If DEBUG, add debugging flags to the output library | RELEASE | **ON:** -d
43+
LIBRARY_TYPE | The type of the output library | STATIC | **ON:** .a **OFF:** .so *or* .dll
44+
45+
So if you call cmake with the following line :
46+
```
47+
cmake CMakeLists.txt -B conf/ -D LIBRARY_TYPE=SHARED -D BUILD_MODE=DEBUG -D MNIST_STATIC_CLASS=ON -D C++_STATIC_LIB=ON
48+
```
49+
The name of the output library will be:
50+
**libmnist_reader-csl-stc-d.so**
51+
52+
53+
Include the [mnist_reader.hpp](/include/mnist_reader/mnist_reader.hpp) header in your source code.
54+
55+
Pass the created library to your compiler.
56+
57+
*(example for a g++)*
58+
```
59+
g++ my_source_file.cpp -L path/to/lib/ -lmnist_reader
60+
```
61+
62+
#### 3. In your code
63+
64+
As you can see, mnist_reader comes in differents flavours.
65+
The basic mnist_reader configuration allows you to call :
66+
67+
```c++
68+
MnistReader reader(path_to_training_dataset,path_to_training_labels,path_to_test_dataset,path_to_test_labels,true);
69+
reader.getData(n_data,n_pixel);
70+
```
71+
Where the **MNIST_STATIC_CLASS** option will build the library as a static class:
72+
73+
```c++
74+
MnistReader::setPathToTrainingDataset(path_to_training_dataset);
75+
MnistReader::setPathToTestDataset(path_to_test_dataset);
76+
MnistReader::setPathToTrainingLabels(path_to_training_labels);
77+
MnistReader::setPathToTestLabels(path_to_test_labels);
78+
MnistReader::load();
79+
MnistReader::getData(n_data,n_pixel);
80+
```
81+
82+
To get the *n_pixel* pixel of the n_data data of the database.
83+
84+
the **MNIST_SUPER_CLASS** option will allows you to fully inherit from the MnistReader class.
85+
86+
You can see other examples of use in the [examples](examples/) section.
87+
88+
## Notes
89+
90+
Since the bytes in the Mnist database are writen in big endian, the mnist_reader library use an [endianess.hpp](/include/system/endianess.hpp) file to convert the database in little endian.
91+
92+
## Contact
93+
94+
If you find any bugs or issues using this code, please feel free to send me an email at :
95+
96+
97+
## Licence
98+
99+
GNU GENERAL PUBLIC LICENSE
100+
101+
Version 3, 29 June 2007
102+
103+
This program is free software: you can redistribute it and/or modify
104+
it under the terms of the GNU General Public License as published by
105+
the Free Software Foundation, either version 3 of the License, or
106+
(at your option) any later version.
107+
108+
This program is distributed in the hope that it will be useful,
109+
but WITHOUT ANY WARRANTY; without even the implied warranty of
110+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
111+
See theGNU General Public License for more details.

_config.yml

100644100755
File mode changed.

doc/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (C) 2020 Quentin Putaud
2+
# Distributed under the GNU General Public License version 3
3+
# (http://www.gnu.org/licenses)
4+
5+
6+
# ---- doxygen source files (from CMAKE_ROOT) ---
7+
set(PROJECT_DOXYGEN_FILES
8+
"README.md"
9+
"include/mnist_reader/mnist_reader.hpp"
10+
"include/system/endianess.hpp")
11+
12+
13+
# --------- parsing source files's paths --------
14+
15+
foreach(IT_PATH IN LISTS PROJECT_DOXYGEN_FILES)
16+
set(PROJECT_DOXYGEN_INPUT "${PROJECT_DOXYGEN_INPUT} \\\n\"${CMAKE_SOURCE_DIR}/${IT_PATH}\"")
17+
endforeach()
18+
19+
20+
# -------------- configure .in file -------------
21+
22+
configure_file("Doxyfile.in" "Doxyfile" @ONLY)
23+
24+
25+
# ----------------- adding target ---------------
26+
27+
add_custom_target(
28+
"doc" ALL "${DOXYGEN_EXECUTABLE}"
29+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/doc"
30+
COMMENT "Generating HTML documentation" VERBATIM)
31+
32+
33+
# -------- creating a link to index.html --------
34+
35+
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
36+
execute_process(
37+
COMMAND ln html/index.html index.html -s
38+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
39+
endif()
40+
41+
42+
# ---------------- installing doc ---------------
43+
44+
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" DESTINATION "doc")
45+
46+
47+
# ------------- installing the link -------------
48+
49+
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
50+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/index.html" DESTINATION "doc")
51+
endif()
52+
53+
# -----------------------------------------------

0 commit comments

Comments
 (0)