### Setup ProtoTest Example Executable Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Sets up the 'prototest' executable for the ProtoTest example. This includes defining the executable, linking it with common test libraries, and configuring compiler and linker properties for optimized builds. ```cmake set(src_executable_prototest prototest) add_executable(${src_executable_prototest} examples/prototest.cpp) target_link_libraries(${src_executable_prototest} ${src_common_test_exe_libs}) set_target_properties(${src_executable_prototest} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_prototest} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") ``` -------------------------------- ### Setup HelloSP_TP Example Executable Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures the build for the HelloSP_TP example application. It defines the executable name, links necessary libraries, and sets compiler and linker flags for optimized builds. ```cmake set(src_executable_hellosptp hello_sp_tp) add_executable(${src_executable_hellosptp} examples/algorithms/HelloSP_TP.cpp) target_link_libraries(${src_executable_hellosptp} ${src_common_test_exe_libs}) set_target_properties(${src_executable_hellosptp} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_hellosptp} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") ``` -------------------------------- ### Setup HelloRegions Example Executable Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures the 'helloregion' executable for the HelloRegions example. It specifies the source file, links necessary libraries, and applies compiler and linker flags for optimized performance. ```cmake set(src_executable_helloregion helloregion) add_executable(${src_executable_helloregion} examples/regions/HelloRegions.cpp) target_link_libraries(${src_executable_helloregion} ${src_common_test_exe_libs}) set_target_properties(${src_executable_helloregion} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_helloregion} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") ``` -------------------------------- ### Install NuPIC Core Source: https://github.com/numenta/nupic.core/blob/master/README.md Run the make install command to install the built NuPIC Core components. ```bash # While still in $NUPIC_CORE/build/scripts make install ``` -------------------------------- ### Simple Source Installation Source: https://github.com/numenta/nupic.core/blob/master/README.md Installs nupic.core from source using the setup.py script. This method does not support incremental builds. Use flags like --user for custom installation locations. ```bash python setup.py install ``` -------------------------------- ### CMake Build Configuration for NuPIC.core Source: https://github.com/numenta/nupic.core/wiki/Windows-Development Example CMake settings for building NuPIC.core, specifying source, binary, installation, and Python extension directories. ```bash rem Clone the repo git clone https://github.com/numenta/nupic.core.git cd nupic.core rem Setup Python x64 to use MinGWPy GCC compilers copy nupic.core\external\windows64-gcc\bin\distutils.cfg C:\Python27-x64\Lib\distutils rem Setup nupic.core and a place to store build files cd nupic.core set NUPIC_CORE=%CD% mkdir build\scripts cd build\scripts rem Run cmake to generator MinGW Makefiles cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=..\release -DPY_EXTENSIONS_DIR=..\..\bindings\py\nupic\bindings ..\.. rem Build and install NuPIC.core, and build SWIG binding libraries mingw32-make -f Makefile install rem Install Python SWIG nupic.bindings cd %NUPIC_CORE% python setup.py install ``` -------------------------------- ### Install Targets Including Executables and Libraries Source: https://github.com/numenta/nupic.core/wiki/Development-Workflow Specify which targets, including static libraries, executables, and test binaries, should be installed and their destination directories. ```cmake install(TARGETS ${LIB_STATIC_NUPICCORE} ${LIB_STATIC_GTEST} ${EXECUTABLE_HELLOREGION} ${EXECUTABLE_HTMTEST} ${EXECUTABLE_GTESTS} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) ``` -------------------------------- ### Install clang-format on Linux Source: https://github.com/numenta/nupic.core/blob/master/githooks/README.md Use apt to install clang-format on Debian-based Linux systems. ```shell apt install clang-format ``` -------------------------------- ### Check nupic-bindings Installation Source: https://github.com/numenta/nupic.core/blob/master/README.md Verifies the installation of nupic.bindings by running the nupic-bindings-check script. Ensure the Python bin directory is in your PATH. ```bash nupic-bindings-check ``` -------------------------------- ### Run C++ Tests Source: https://github.com/numenta/nupic.core/blob/master/README.md Navigate to the build release binary directory and execute the C++ test executables to verify the installation. ```bash cd $NUPIC_CORE/build/release/bin ./cpp_region_test ./unit_tests ... ``` -------------------------------- ### Install nupic.bindings Python Package Source: https://github.com/numenta/nupic.core/blob/master/README.md Install the `nupic.bindings` Python package using pip. Use `--user` or other flags as needed for installation location. On Linux, this performs a source installation requiring prerequisites. ```bash pip install nupic.bindings ``` -------------------------------- ### Install nupic.bindings Python Library (Develop Mode) Source: https://github.com/numenta/nupic.core/blob/master/README.md Install the nupic.bindings Python library in development mode. This command will automatically trigger the CMake/make process if extensions are not already built. Use --user for user-specific installation to avoid permission issues. ```python cd $NUPIC_CORE python setup.py develop ``` ```python python setup.py develop --user ``` -------------------------------- ### CSVReader Example with Tab Separation and Comments Source: https://github.com/numenta/nupic.core/blob/master/external/common/include/CSV_README.md Shows reading a CSV file with 3 columns, using tabs as separators, and ignoring lines starting with '#'. ```cpp CSVReader<3, trim_chars<' '>, no_quote_escape<' '>, single_line_comment<'#'> > ``` -------------------------------- ### Manual Installation of NuPIC C++ Core Source: https://github.com/numenta/nupic.core/blob/master/external/windows64/README.md After building the C++ library, use this command to perform a manual installation. This copies binaries, headers, and library files to the specified CMAKE_INSTALL_PREFIX. ```bash cd %NUPIC_CORE%\build\scripts cmake.exe -DBUILD_TYPE=Release -P cmake_install.cmake ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/numenta/nupic.core/blob/master/README.md Installs required Python packages like NumPy and pycapnp using pip. Ensure you have Python 2.7 and pip installed. ```bash pip install -r bindings/py/requirements.txt ``` -------------------------------- ### Installing nupic.core with Custom Build Path Source: https://github.com/numenta/nupic.core/wiki/Troubleshooting After configuring CMake and potentially modifying setup.py, use this command to install the nupic.core python bindings, specifying the custom build directory. ```bash python setup.py install --nupic-core-dir=$NUPIC_CORE/build/release ``` -------------------------------- ### Setup Include Directories Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures system and project include paths, including NumPy headers and project source directories. Ensures that C++ code can find necessary headers during compilation. ```cmake if("${PROJECT_BUILD_ARTIFACTS_DIR}" STREQUAL "") set(PROJECT_BUILD_ARTIFACTS_DIR "${PROJECT_BINARY_DIR}/artifacts") endif() include_directories(SYSTEM ${src_numpy_core}/include ${PROJECT_BINARY_DIR}) include_directories(${PROJECT_SOURCE_DIR}) ``` -------------------------------- ### Install clang-format on Mac OS Source: https://github.com/numenta/nupic.core/blob/master/githooks/README.md Use Homebrew to install clang-format on macOS systems. ```shell brew install clang-format ``` -------------------------------- ### Create Executable with libnupic_core_solo Source: https://github.com/numenta/nupic.core/wiki/Development-Workflow Define an executable target, link it with common libraries including `libnupic_core_solo`, and set compile and link properties. This example uses `helloregion`. ```cmake set(EXECUTABLE_HELLOREGION helloregion) add_executable(${EXECUTABLE_HELLOREGION} examples/regions/helloregions.cpp) target_link_libraries(${EXECUTABLE_HELLOREGION} ${COMMON_LIBS}) set_target_properties(${EXECUTABLE_HELLOREGION} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS}) LINK_FLAGS "-m${BITNESS} ${STDLIB}") add_dependencies(${EXECUTABLE_HELLOREGION} ${COMMON_LIBS}) ``` -------------------------------- ### Setup Unit Tests Executable Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Sets up the build for the project's unit tests. This includes defining the test executable, listing all test source files, linking Google Test and common test libraries, and applying specific compiler and linker flags. ```cmake set(src_executable_gtests unit_tests) add_executable(${src_executable_gtests} test/unit/algorithms/AnomalyTest.cpp test/unit/algorithms/Cells4Test.cpp test/unit/algorithms/CondProbTableTest.cpp test/unit/algorithms/ConnectionsTest.cpp test/unit/algorithms/NearestNeighborUnitTest.cpp test/unit/algorithms/SDRClassifierTest.cpp test/unit/algorithms/SegmentTest.cpp test/unit/algorithms/SpatialPoolerTest.cpp test/unit/algorithms/SvmTest.cpp test/unit/algorithms/TemporalMemoryTest.cpp test/unit/encoders/ScalarEncoderTest.cpp test/unit/engine/InputTest.cpp test/unit/engine/LinkTest.cpp test/unit/engine/NetworkTest.cpp test/unit/engine/UniformLinkPolicyTest.cpp test/unit/engine/YAMLUtilsTest.cpp test/unit/math/DenseTensorUnitTest.cpp test/unit/math/DomainUnitTest.cpp test/unit/math/IndexUnitTest.cpp test/unit/math/MathsTest.cpp test/unit/math/SegmentMatrixAdapterTest.cpp test/unit/math/SparseBinaryMatrixTest.cpp test/unit/math/SparseMatrix01UnitTest.cpp test/unit/math/SparseMatrixTest.cpp test/unit/math/SparseMatrixUnitTest.cpp test/unit/math/SparseTensorUnitTest.cpp test/unit/math/TopologyTest.cpp test/unit/ntypes/ArrayTest.cpp test/unit/ntypes/BufferTest.cpp test/unit/ntypes/CollectionTest.cpp test/unit/ntypes/DimensionsTest.cpp test/unit/ntypes/MemParserTest.cpp test/unit/ntypes/MemStreamTest.cpp test/unit/ntypes/NodeSetTest.cpp test/unit/ntypes/ScalarTest.cpp test/unit/ntypes/ValueTest.cpp test/unit/os/DirectoryTest.cpp test/unit/os/EnvTest.cpp test/unit/os/OSTest.cpp test/unit/os/PathTest.cpp test/unit/os/RegexTest.cpp test/unit/os/TimerTest.cpp test/unit/py_support/PyHelpersTest.cpp test/unit/types/BasicTypeTest.cpp test/unit/types/ExceptionTest.cpp test/unit/types/FractionTest.cpp test/unit/UnitTestMain.cpp test/unit/utils/GroupByTest.cpp test/unit/utils/MovingAverageTest.cpp test/unit/utils/RandomTest.cpp test/unit/utils/WatcherTest.cpp) target_link_libraries(${src_executable_gtests} ${src_lib_static_gtest} ${src_common_test_exe_libs}) set_target_properties(${src_executable_gtests} PROPERTIES COMPILE_FLAGS ${src_compile_flags} LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") ``` -------------------------------- ### Install nupic.bindings Python Library (Mac OS X) Source: https://github.com/numenta/nupic.core/blob/master/README.md On Mac OS X, specify ARCHFLAGS to ensure correct architecture compilation when installing the nupic.bindings Python library. ```bash ARCHFLAGS="-arch x86_64" python setup.py develop ``` -------------------------------- ### Setup connections_performance_test Executable Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Defines the 'connections_performance_test' executable, links it with common test libraries, and sets compiler and linker flags for optimized builds. A custom target 'tests_connections_performance' is created to execute this test. ```cmake set(src_executable_connectionsperformancetest connections_performance_test) add_executable(${src_executable_connectionsperformancetest} test/integration/ConnectionsPerformanceTest.cpp) target_link_libraries(${src_executable_connectionsperformancetest} ${src_common_test_exe_libs}) set_target_properties(${src_executable_connectionsperformancetest} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_connectionsperformancetest} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") add_custom_target(tests_connections_performance COMMAND ${src_executable_connectionsperformancetest} DEPENDS ${src_executable_connectionsperformancetest} COMMENT "Executing test ${src_executable_connectionsperformancetest}" VERBATIM) ``` -------------------------------- ### CSVReader Example with Trimming and Quoting Source: https://github.com/numenta/nupic.core/blob/master/external/common/include/CSV_README.md Demonstrates reading a CSV file with 4 columns, trimming spaces, and using double quotes for escaping with a comma as a separator. ```cpp CSVReader<4, trim_chars<' '>, double_quote_escape<',','"'> > ``` -------------------------------- ### Setup gtest Library Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures the gtest library as a static library with specified compile and link flags. This is used for testing purposes. ```cmake set(src_lib_static_gtest gtest) add_library(${src_lib_static_gtest} STATIC ${REPOSITORY_DIR}/external/common/src/gtest/gtest-all.cpp) set_target_properties(${src_lib_static_gtest} PROPERTIES COMPILE_FLAGS "${src_compile_flags}" LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") ``` -------------------------------- ### Build NuPIC Core with CMake and MinGW Makefiles Source: https://github.com/numenta/nupic.core/blob/master/external/windows64-gcc/README.md Clones the NuPIC Core repository, sets up the environment, configures the build using CMake with MinGW Makefiles generator, and then builds and installs the C++ library and Python bindings. ```bash rem Clone the repo git clone https://github.com/numenta/nupic.core.git cd nupic.core rem Setup Python x64 to use MinGWPy GCC compilers copy nupic.core\external\windows64-gcc\bin\distutils.cfg C:\Python27-x64\Lib\distutils rem Setup nupic.core and a place to store build files cd nupic.core set NUPIC_CORE=%CD% mkdir build\scripts cd build\scripts rem Run cmake to generator MinGW Makefiles cmake -G "MinGW Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX=..\release \ -DPY_EXTENSIONS_DIR=..\..\bindings\py\src\nupic\bindings \ ..\.. rem Build and install NuPIC.core, and build SWIG binding libraries mingw32-make -f Makefile install rem Install Python SWIG nupic.bindings cd %NUPIC_CORE% python setup.py install ``` -------------------------------- ### GCC Linking Example for Threads Source: https://github.com/numenta/nupic.core/blob/master/external/common/include/CSV_README.md This example shows the correct way to link a C++ program using GCC when the CSV parser's threading features are enabled. It highlights the importance of adding '-lpthread' as the last argument. ```bash g++ -std=c++0x a.o b.o -o prog -lpthread ``` -------------------------------- ### Compiling nupic.core with Custom Cap'n Proto Path Source: https://github.com/numenta/nupic.core/wiki/Troubleshooting Use this command to configure the nupic.core build when Cap'n Proto is installed in a custom location. Ensure the paths to Cap'n Proto include directories and libraries. ```bash cmake $NUPIC_CORE -DCMAKE_INSTALL_PREFIX=../release \ -DCAPNP_INCLUDE_DIRS=/path/to/capnproto/build/include \ -DCAPNP_LIBRARIES='/path/to/capnproto/build/lib/libkj.a;/path/to/capnproto/build/lib/libcapnp.a;/path/to/capnproto/build/lib/libcapnpc.a' \ -DCAPNP_EXECUTABLE=/path/to/capnproto/build/bin/capnp \ -DCAPNPC_CXX_EXECUTABLE=/path/to/capnproto/build/bin/capnpc-c++ ``` -------------------------------- ### Install MinGWPy GCC for Python Source: https://github.com/numenta/nupic.core/blob/master/external/windows64-gcc/README.md Installs the MinGWPy GCC compiler for Python. Ensure your Python environment is set up correctly. ```bash %PYTHONHOME%\Scripts\pip.exe install -i https://pypi.anaconda.org/carlkl/simple mingwpy ``` -------------------------------- ### Install NumPy C++ Headers Source: https://github.com/numenta/nupic.core/blob/master/external/windows64-gcc/README.md Installs a specific version of the NumPy Python package to obtain its C++ headers. This is required for building NuPIC Core. ```bash %PYTHONHOME%\Scripts\pip.exe install numpy==1.11.2 ``` -------------------------------- ### Setup CppRegionTest Executable and Target Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures the build for the CppRegionTest executable. It defines the executable name, source file, links common test libraries, and sets compiler/linker properties. A custom target 'tests_cpp_region' is created to execute this test. ```cmake set(src_executable_cppregiontest cpp_region_test) add_executable(${src_executable_cppregiontest} test/integration/CppRegionTest.cpp) target_link_libraries(${src_executable_cppregiontest} ${src_common_test_exe_libs}) set_target_properties(${src_executable_cppregiontest} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_cppregiontest} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") add_custom_target(tests_cpp_region COMMAND ${src_executable_cppregiontest} DEPENDS ${src_executable_cppregiontest} COMMENT "Executing test ${src_executable_cppregiontest}" VERBATIM) ``` -------------------------------- ### Import NuPIC Bindings in Python Source: https://github.com/numenta/nupic.core/blob/master/README.md Import the NuPIC bindings library into your Python script after successful installation. ```python import nupic.bindings ``` -------------------------------- ### Setup PyRegionTest Executable and Target Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Configures the build for the PyRegionTest executable. Similar to CppRegionTest, it defines the executable, source file, links common libraries, and sets properties. A custom target 'tests_py_region' is defined to run this test. ```cmake set(src_executable_pyregiontest py_region_test) add_executable(${src_executable_pyregiontest} test/integration/PyRegionTest.cpp) target_link_libraries(${src_executable_pyregiontest} ${src_common_test_exe_libs}) set_target_properties(${src_executable_pyregiontest} PROPERTIES COMPILE_FLAGS ${src_compile_flags}) set_target_properties(${src_executable_pyregiontest} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}") add_custom_target(tests_py_region COMMAND ${src_executable_pyregiontest} DEPENDS ${src_executable_pyregiontest} COMMENT "Executing test ${src_executable_pyregiontest}" VERBATIM) ``` -------------------------------- ### Basic CSV Reading Example Source: https://github.com/numenta/nupic.core/blob/master/external/common/include/CSV_README.md This snippet demonstrates how to read a CSV file, parse its header, and iterate through rows, extracting specific columns. It assumes the CSV file has columns named 'vendor', 'size', and 'speed'. ```cpp # include "csv.h" int main(){ io::CSVReader<3> in("ram.csv"); in.read_header(io::ignore_extra_column, "vendor", "size", "speed"); std::string vendor; int size; double speed; while(in.read_row(vendor, size, speed)){ // do stuff with the data } } ``` -------------------------------- ### Configure C++ Build Files with CMake Source: https://github.com/numenta/nupic.core/blob/master/README.md Use this command to configure the C++ build files. Adjust CMAKE_BUILD_TYPE for release or debug builds. NUPIC_BUILD_PYEXT_MODULES controls Python extension building. CMAKE_INSTALL_PREFIX and PY_EXTENSIONS_DIR are optional for specifying installation and Python extension directories. ```bash mkdir -p $NUPIC_CORE/build/scripts cd $NUPIC_CORE/build/scripts cmake $NUPIC_CORE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release -DPY_EXTENSIONS_DIR=$NUPIC_CORE/bindings/py/src/nupic/bindings ``` -------------------------------- ### Run Doxygen to Build Documentation Source: https://github.com/numenta/nupic.core/blob/master/README.md Execute this command to generate documentation. The project version is automatically read from the VERSION file. Documentation will be output to the 'html' directory. ```bash PROJECT_VERSION=`cat VERSION` doxygen ``` -------------------------------- ### Run nupic.bindings Python Tests Source: https://github.com/numenta/nupic.core/blob/master/README.md Execute the tests for the nupic.bindings Python library using the setup.py script. ```python python setup.py test ``` -------------------------------- ### Run C++ Tests Source: https://github.com/numenta/nupic.core/blob/master/external/windows64-gcc/README.md Executes C++ unit tests for the NuPIC Core library after building and installation. ```bash cd %NUPIC_CORE%\build\release\bin cpp_region_test unit_tests ``` -------------------------------- ### Define Dependencies for nupic_core_solo Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Specifies the external libraries that the nupic_core_solo static library depends on. These are typically headers installed by other projects. ```cmake add_dependencies(${src_lib_static_nupiccore_solo} ${YAML_CPP_STATIC_LIB_TARGET} ${YAML_STATIC_LIB_TARGET} ${APR1_STATIC_LIB_TARGET} ${APRUTIL1_STATIC_LIB_TARGET} ${Z_STATIC_LIB_TARGET}) ``` -------------------------------- ### Generate MSVC 2015 Solution Files Source: https://github.com/numenta/nupic.core/blob/master/external/windows64/README.md Use this command to generate Visual Studio 2015 64-bit solution and project files for the NuPIC C++ Core library. Ensure you are in the correct directory and have set the NUPIC_CORE environment variable. ```bash rem Clone the repo git clone https://github.com/numenta/nupic.core.git rem Setup nupic.core and a place to store build files cd nupic.core set NUPIC_CORE=%CD% mkdir build\scripts cd build\scripts rem Run cmake to generator MSVC 2015 solution and project files cmake -G "Visual Studio 14 2015 Win64" \ -DCMAKE_INSTALL_PREFIX=..\release \ -DPY_EXTENSIONS_DIR=..\..\bindings\py\src\nupic\bindings \ ..\.. ``` -------------------------------- ### Find Python Interpreter and NumPy Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Locates Python 2.7 and its NumPy installation to determine include paths. This is essential for building C++ extensions that interface with Python. ```cmake find_package(PythonInterp 2.7 REQUIRED) message(STATUS "CMAKE Found python interpreter ${PYTHON_EXECUTABLE} version=${PYTHON_VERSION_STRING}") execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import numpy; import os; import sys; sys.stdout.write(os.path.dirname(numpy.get_include()))" OUTPUT_VARIABLE src_numpy_core) # Quick way to fixup directory paths to NumPy get_filename_component(src_numpy_core ${src_numpy_core}/include/.. ABSOLUTE) message(STATUS "src_numpy_core = ${src_numpy_core}") ``` -------------------------------- ### CMake Configuration and Build for NuPIC Core Source: https://github.com/numenta/nupic.core/blob/master/external/windows32-gcc/README.md Clones the NuPIC Core repository, sets up environment variables, generates MinGW Makefiles using CMake, and builds the C++ library and SWIG bindings. ```shell rem Clone the repo git clone https://github.com/numenta/nupic.core.git cd nupic.core rem Setup Python x86 to use MinGWPy GCC compilers copy nupic.core\external\windows32-gcc\bin\distutils.cfg C:\Python27\Lib\distutils rem Setup nupic.core and a place to store build files cd nupic.core set NUPIC_CORE=%CD% mkdir build\scripts cd build\scripts rem Run cmake to generator MinGW Makefiles cmake -G "MinGW Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX=..\release \ -DPY_EXTENSIONS_DIR=..\..\bindings\py\src\nupic\bindings \ ..\.. rem Build and install NuPIC.core, and build SWIG binding libraries mingw32-make -f Makefile install rem Install Python SWIG nupic.bindings cd %NUPIC_CORE% python setup.py install ``` -------------------------------- ### Prepending Boilerplate to Python Proxy Modules Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Adds a custom command to a SWIG target to prepend boilerplate code to the generated Python proxy module. This ensures custom initialization or setup is included. ```cmake function(PREPEND_BOILERPLATE_TO_PYTHON_PROXY_MODULE MODULE_NAME) # Add a custom command to the Swig target to prepend boilerplate to the # swig-generated python proxy module # ${CMAKE_SWIG_OUTDIR}/${MODULE_NAME}.py. # # :param MODULE_NAME: the custom command will be added to the target # corresponding to this Swig module name. set(preamble_filepath "${CMAKE_SOURCE_DIR}/src/nupic/bindings/swig_proxy_preamble.py") set(module_filepath "${CMAKE_SWIG_OUTDIR}/${MODULE_NAME}.py") add_custom_command( TARGET ${SWIG_MODULE_${MODULE_NAME}_REAL_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -DSRC_FILE_1=${preamble_filepath} -DSRC_FILE_2=${module_filepath} -DTARGET_FILE=${module_filepath} -P ${CMAKE_SOURCE_DIR}/src/ConcatTwoFiles.cmake COMMENT "Prepending ${preamble_filepath} to swig-generated module ${module_filepath}" ) endfunction(PREPEND_BOILERPLATE_TO_PYTHON_PROXY_MODULE) ``` -------------------------------- ### Configure Cap'n Proto with CMake Source: https://github.com/numenta/nupic.core/blob/master/external/windows64/README.md Use CMake to generate Visual Studio project files for Cap'n Proto, specifying build options and library paths. Ensure Visual Studio is not running during this process. ```bash cd %NUPIC_CORE%\build\capnproto-c++-win32-0.5.3\capnproto-c++-0.5.3 vcvarsall.bat cmake -G "Visual Studio 14 2015 Win64" -DCAPNP_LITE=1 -DEXTERNAL_CAPNP=1 -DCAPNP_INCLUDE_DIRS=.\src -DCAPNP_LIB_KJ=.\lib -DCAPNP_LIB_CAPNP=.\lib -DCAPNP_EXECUTABLE="..\capnproto-tools-win32-0.5.3\capnp.exe" -DCAPNPC_CXX_EXECUTABLE="..\capnproto-tools-win32-0.5.3\capnpc-c++.exe" ``` -------------------------------- ### Building SWIG Python Extensions Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Defines a function to create a SWIG extension target for Python, handling SWIG module generation, linking, and optional installation. It manages different CMake versions for SWIG module creation. ```cmake function(BUILD_EXTENSION MODULE_NAME) # Create a nupic.bindings swig extension target with the given Swig module # name. Also, if PY_EXTENSIONS_DIR is specified, request # installation of the extension library and python proxy module. # # The real target name is ${SWIG_MODULE_${MODULE_NAME}_REAL_NAME}. set(source_interface_file nupic/bindings/${MODULE_NAME}.i) set_source_files_properties(${source_interface_file} PROPERTIES CPLUSPLUS ON SWIG_MODULE_NAME ${MODULE_NAME}) # Regenerate SWIG bindings if any headers change. set(SWIG_MODULE_${MODULE_NAME}_EXTRA_DEPS ${swig_header_deps}) # # Create custom command for generating files from SWIG # # Note: swig_add_module outputs ${swig_generated_file_fullname} if (CMAKE_VERSION VERSION_LESS "3.8") swig_add_module(${MODULE_NAME} python ${source_interface_file}) else() SWIG_ADD_LIBRARY(${MODULE_NAME} LANGUAGE python SOURCES ${source_interface_file}) endif() set_source_files_properties( ${swig_generated_file_fullname} PROPERTIES GENERATED TRUE COMPILE_FLAGS ${src_swig_generated_file_compile_flags}) swig_link_libraries(${MODULE_NAME} ${_SRC_SWIG_LINK_LIBRARIES}) prepend_boilerplate_to_python_proxy_module(${MODULE_NAME}) set(real_target "${SWIG_MODULE_${MODULE_NAME}_REAL_NAME}") set(extra_deps ${_SRC_SWIG_EXTRA_DEPS}) set(link_flags ${_SRC_SWIG_EXTENSION_LINK_FLAGS}) # Create an export map and update extra dependencies and link flags. This # export map prevents runtime-link preemption of statically-linked # libraries, such as -static-libstdc++, and limits the shared object's # symbol visibility to only the python extension's init function. NOTE Not # sure what, if anything, to do for MSVC at this time. set(extension_init_func "init${real_target}") if("${PLATFORM}" STREQUAL "darwin") set(link_flags "${link_flags} -Wl,-exported_symbol,_${extension_init_func}") elseif("${PLATFORM}" STREQUAL "linux" OR MINGW) set(export_map_file "${CMAKE_CURRENT_BINARY_DIR}/${real_target}_generated.expmap") # list(APPEND extra_deps "${export_map_file}") set(link_flags "${link_flags} -Wl,--version-script=${export_map_file}") set(export_map_contents "{global: ${extension_init_func}; local: *;};") message(STATUS "Writing export map file ${export_map_file} " "(${export_map_contents}).") file(WRITE ${export_map_file} "${export_map_contents}") endif() add_dependencies(${real_target} ${extra_deps}) set_target_properties(${real_target} PROPERTIES LINK_FLAGS "${link_flags}") # If a path is specified, copy extensions files to proper location. if (PY_EXTENSIONS_DIR) install(TARGETS ${real_target} LIBRARY DESTINATION ${PY_EXTENSIONS_DIR}) install(FILES ${PROJECT_BINARY_DIR}/${MODULE_NAME}.py DESTINATION ${PY_EXTENSIONS_DIR}) endif(PY_EXTENSIONS_DIR) message( STATUS "Created Swig target ${real_target} for swig module ${MODULE_NAME}. " "extra_deps=${extra_deps}, link_flags=${link_flags}") endfunction(BUILD_EXTENSION) ``` -------------------------------- ### Iterating Through Lines with LineReader Source: https://github.com/numenta/nupic.core/blob/master/external/common/include/CSV_README.md Demonstrates how to iterate over all lines in a file using the LineReader's next_line() method. The loop continues as long as next_line() returns a valid pointer to a line. ```cpp LineReader in(...); while(char*line = in.next_line()){ ... } ``` -------------------------------- ### Define Common Test Executable Libraries Source: https://github.com/numenta/nupic.core/blob/master/src/CMakeLists.txt Sets a variable to hold common libraries required for test executables, including the combined nupiccore static library, Python libraries, and common OS libraries. This is a common setup for multiple test targets. ```cmake set(src_common_test_exe_libs ${src_lib_static_nupiccore_combined} ${PYTHON_LIBRARIES} ${src_common_os_libs}) message(STATUS "src_common_test_exe_libs = ${src_common_test_exe_libs}") ``` -------------------------------- ### Build NuPIC Core C++ Libraries Source: https://github.com/numenta/nupic.core/blob/master/README.md Execute the make command to build the C++ libraries. The -j flag specifies the number of parallel jobs to speed up the compilation process. ```bash # While still in $NUPIC_CORE/build/scripts make -j3 ``` -------------------------------- ### Profile C++ Application with Valgrind Source: https://github.com/numenta/nupic.core/blob/master/src/examples/algorithms/README.md Run the compiled C++ application using Valgrind's callgrind tool to profile execution time and memory usage. This generates a callgrind output file for analysis. ```bash valgrind --tool=callgrind ./hello_sp_tp ```