Compare commits
12
Commits
9b20278395
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11da534fd6 | ||
|
|
d7b74ab40f | ||
|
|
70e80327ef | ||
|
|
e6e9fe1026 | ||
|
|
f5e0ee209b | ||
|
|
47671354ce | ||
|
|
c7e87fe191 | ||
|
|
441540a996 | ||
|
|
52684e6b8a | ||
|
|
a30b410f89 | ||
|
|
8fd1b7762e | ||
|
|
189d605bfa |
@@ -32,3 +32,5 @@
|
|||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
# Build folder
|
||||||
|
build/
|
||||||
|
|||||||
@@ -1,373 +0,0 @@
|
|||||||
# This is the CMakeCache file.
|
|
||||||
# For build in directory: /home/atlas/Documents/Git/panic/build
|
|
||||||
# It was generated by CMake: /usr/bin/cmake
|
|
||||||
# You can edit this file to change values found and used by cmake.
|
|
||||||
# If you do not want to change any of the values, simply exit the editor.
|
|
||||||
# If you do want to change a value, simply edit, save, and exit the editor.
|
|
||||||
# The syntax for the file is as follows:
|
|
||||||
# KEY:TYPE=VALUE
|
|
||||||
# KEY is the name of a variable in the cache.
|
|
||||||
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
|
|
||||||
# VALUE is the current value for the KEY.
|
|
||||||
|
|
||||||
########################
|
|
||||||
# EXTERNAL cache entries
|
|
||||||
########################
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_AR:FILEPATH=/usr/bin/ar
|
|
||||||
|
|
||||||
//Choose the type of build, options are: None Debug Release RelWithDebInfo
|
|
||||||
// MinSizeRel ...
|
|
||||||
CMAKE_BUILD_TYPE:STRING=
|
|
||||||
|
|
||||||
//Enable/Disable color output during build.
|
|
||||||
CMAKE_COLOR_MAKEFILE:BOOL=ON
|
|
||||||
|
|
||||||
//CXX compiler
|
|
||||||
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++
|
|
||||||
|
|
||||||
//A wrapper around 'ar' adding the appropriate '--plugin' option
|
|
||||||
// for the GCC compiler
|
|
||||||
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-13
|
|
||||||
|
|
||||||
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
|
|
||||||
// for the GCC compiler
|
|
||||||
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-13
|
|
||||||
|
|
||||||
//Flags used by the CXX compiler during all build types.
|
|
||||||
CMAKE_CXX_FLAGS:STRING=
|
|
||||||
|
|
||||||
//Flags used by the CXX compiler during DEBUG builds.
|
|
||||||
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
|
|
||||||
|
|
||||||
//Flags used by the CXX compiler during MINSIZEREL builds.
|
|
||||||
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
|
|
||||||
|
|
||||||
//Flags used by the CXX compiler during RELEASE builds.
|
|
||||||
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
|
|
||||||
|
|
||||||
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
|
|
||||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND
|
|
||||||
|
|
||||||
//Flags used by the linker during all build types.
|
|
||||||
CMAKE_EXE_LINKER_FLAGS:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during DEBUG builds.
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during MINSIZEREL builds.
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during RELEASE builds.
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during RELWITHDEBINFO builds.
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
|
||||||
|
|
||||||
//Enable/Disable output of compile commands during generation.
|
|
||||||
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=
|
|
||||||
|
|
||||||
//Value Computed by CMake.
|
|
||||||
CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/atlas/Documents/Git/panic/build/CMakeFiles/pkgRedirects
|
|
||||||
|
|
||||||
//Install path prefix, prepended onto install directories.
|
|
||||||
CMAKE_INSTALL_PREFIX:PATH=/usr/local
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_LINKER:FILEPATH=/usr/bin/ld
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/gmake
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of modules during
|
|
||||||
// all build types.
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of modules during
|
|
||||||
// DEBUG builds.
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of modules during
|
|
||||||
// MINSIZEREL builds.
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of modules during
|
|
||||||
// RELEASE builds.
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of modules during
|
|
||||||
// RELWITHDEBINFO builds.
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_NM:FILEPATH=/usr/bin/nm
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
CMAKE_PROJECT_DESCRIPTION:STATIC=
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
CMAKE_PROJECT_NAME:STATIC=panic
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_READELF:FILEPATH=/usr/bin/readelf
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of shared libraries
|
|
||||||
// during all build types.
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of shared libraries
|
|
||||||
// during DEBUG builds.
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of shared libraries
|
|
||||||
// during MINSIZEREL builds.
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of shared libraries
|
|
||||||
// during RELEASE builds.
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of shared libraries
|
|
||||||
// during RELWITHDEBINFO builds.
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
|
||||||
|
|
||||||
//If set, runtime paths are not added when installing shared libraries,
|
|
||||||
// but are added when building.
|
|
||||||
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
|
|
||||||
|
|
||||||
//If set, runtime paths are not added when using shared libraries.
|
|
||||||
CMAKE_SKIP_RPATH:BOOL=NO
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of static libraries
|
|
||||||
// during all build types.
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of static libraries
|
|
||||||
// during DEBUG builds.
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of static libraries
|
|
||||||
// during MINSIZEREL builds.
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of static libraries
|
|
||||||
// during RELEASE builds.
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=
|
|
||||||
|
|
||||||
//Flags used by the linker during the creation of static libraries
|
|
||||||
// during RELWITHDEBINFO builds.
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_STRIP:FILEPATH=/usr/bin/strip
|
|
||||||
|
|
||||||
//Path to a program.
|
|
||||||
CMAKE_TAPI:FILEPATH=CMAKE_TAPI-NOTFOUND
|
|
||||||
|
|
||||||
//If this value is on, makefiles will be generated without the
|
|
||||||
// .SILENT directive, and all commands will be echoed to the console
|
|
||||||
// during the make. This is useful for debugging only. With Visual
|
|
||||||
// Studio IDE projects all commands are done without /nologo.
|
|
||||||
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
|
|
||||||
|
|
||||||
//CXX compiler flags for OpenMP parallelization
|
|
||||||
OpenMP_CXX_FLAGS:STRING=-fopenmp
|
|
||||||
|
|
||||||
//CXX compiler libraries for OpenMP parallelization
|
|
||||||
OpenMP_CXX_LIB_NAMES:STRING=gomp;pthread
|
|
||||||
|
|
||||||
//Path to the gomp library for OpenMP
|
|
||||||
OpenMP_gomp_LIBRARY:FILEPATH=/usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so
|
|
||||||
|
|
||||||
//Path to the pthread library for OpenMP
|
|
||||||
OpenMP_pthread_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpthread.a
|
|
||||||
|
|
||||||
//Enable OpenMP support
|
|
||||||
PANIC_ENABLE_OPENMP:BOOL=ON
|
|
||||||
|
|
||||||
//Number of OpenMP threads. 0 means OpenMP default.
|
|
||||||
PANIC_OMP_NUM_THREADS:STRING=0
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
panic_BINARY_DIR:STATIC=/home/atlas/Documents/Git/panic/build
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
panic_IS_TOP_LEVEL:STATIC=ON
|
|
||||||
|
|
||||||
//Value Computed by CMake
|
|
||||||
panic_SOURCE_DIR:STATIC=/home/atlas/Documents/Git/panic
|
|
||||||
|
|
||||||
|
|
||||||
########################
|
|
||||||
# INTERNAL cache entries
|
|
||||||
########################
|
|
||||||
|
|
||||||
//ADVANCED property for variable: CMAKE_ADDR2LINE
|
|
||||||
CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_AR
|
|
||||||
CMAKE_AR-ADVANCED:INTERNAL=1
|
|
||||||
//This is the directory where this CMakeCache.txt was created
|
|
||||||
CMAKE_CACHEFILE_DIR:INTERNAL=/home/atlas/Documents/Git/panic/build
|
|
||||||
//Major version of cmake used to create the current loaded cache
|
|
||||||
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
|
|
||||||
//Minor version of cmake used to create the current loaded cache
|
|
||||||
CMAKE_CACHE_MINOR_VERSION:INTERNAL=28
|
|
||||||
//Patch version of cmake used to create the current loaded cache
|
|
||||||
CMAKE_CACHE_PATCH_VERSION:INTERNAL=3
|
|
||||||
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
|
|
||||||
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
|
|
||||||
//Path to CMake executable.
|
|
||||||
CMAKE_COMMAND:INTERNAL=/usr/bin/cmake
|
|
||||||
//Path to cpack program executable.
|
|
||||||
CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack
|
|
||||||
//Path to ctest program executable.
|
|
||||||
CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_COMPILER
|
|
||||||
CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
|
|
||||||
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
|
|
||||||
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS
|
|
||||||
CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG
|
|
||||||
CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL
|
|
||||||
CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE
|
|
||||||
CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
||||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_DLLTOOL
|
|
||||||
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
|
|
||||||
//Executable file format
|
|
||||||
CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF
|
|
||||||
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
|
|
||||||
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
|
|
||||||
CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
|
|
||||||
//Name of external makefile project generator.
|
|
||||||
CMAKE_EXTRA_GENERATOR:INTERNAL=
|
|
||||||
//Name of generator.
|
|
||||||
CMAKE_GENERATOR:INTERNAL=Unix Makefiles
|
|
||||||
//Generator instance identifier.
|
|
||||||
CMAKE_GENERATOR_INSTANCE:INTERNAL=
|
|
||||||
//Name of generator platform.
|
|
||||||
CMAKE_GENERATOR_PLATFORM:INTERNAL=
|
|
||||||
//Name of generator toolset.
|
|
||||||
CMAKE_GENERATOR_TOOLSET:INTERNAL=
|
|
||||||
//Source directory with the top level CMakeLists.txt file for this
|
|
||||||
// project
|
|
||||||
CMAKE_HOME_DIRECTORY:INTERNAL=/home/atlas/Documents/Git/panic
|
|
||||||
//Install .so files without execute permission.
|
|
||||||
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_LINKER
|
|
||||||
CMAKE_LINKER-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
|
|
||||||
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
|
|
||||||
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_NM
|
|
||||||
CMAKE_NM-ADVANCED:INTERNAL=1
|
|
||||||
//number of local generators
|
|
||||||
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_OBJCOPY
|
|
||||||
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_OBJDUMP
|
|
||||||
CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
|
|
||||||
//Platform information initialized
|
|
||||||
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_RANLIB
|
|
||||||
CMAKE_RANLIB-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_READELF
|
|
||||||
CMAKE_READELF-ADVANCED:INTERNAL=1
|
|
||||||
//Path to CMake installation.
|
|
||||||
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.28
|
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
|
|
||||||
CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_SKIP_RPATH
|
|
||||||
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
|
|
||||||
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_STRIP
|
|
||||||
CMAKE_STRIP-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: CMAKE_TAPI
|
|
||||||
CMAKE_TAPI-ADVANCED:INTERNAL=1
|
|
||||||
//uname command
|
|
||||||
CMAKE_UNAME:INTERNAL=/usr/bin/uname
|
|
||||||
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
|
|
||||||
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
|
|
||||||
//Details about finding OpenMP
|
|
||||||
FIND_PACKAGE_MESSAGE_DETAILS_OpenMP:INTERNAL=[TRUE][c ][v4.5()]
|
|
||||||
//Details about finding OpenMP_CXX
|
|
||||||
FIND_PACKAGE_MESSAGE_DETAILS_OpenMP_CXX:INTERNAL=[-fopenmp][/usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so][/usr/lib/x86_64-linux-gnu/libpthread.a][v4.5()]
|
|
||||||
//Result of TRY_COMPILE
|
|
||||||
OpenMP_COMPILE_RESULT_CXX_fopenmp:INTERNAL=TRUE
|
|
||||||
//ADVANCED property for variable: OpenMP_CXX_FLAGS
|
|
||||||
OpenMP_CXX_FLAGS-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: OpenMP_CXX_LIB_NAMES
|
|
||||||
OpenMP_CXX_LIB_NAMES-ADVANCED:INTERNAL=1
|
|
||||||
//CXX compiler's OpenMP specification date
|
|
||||||
OpenMP_CXX_SPEC_DATE:INTERNAL=201511
|
|
||||||
//Result of TRY_COMPILE
|
|
||||||
OpenMP_SPECTEST_CXX_:INTERNAL=TRUE
|
|
||||||
//ADVANCED property for variable: OpenMP_gomp_LIBRARY
|
|
||||||
OpenMP_gomp_LIBRARY-ADVANCED:INTERNAL=1
|
|
||||||
//ADVANCED property for variable: OpenMP_pthread_LIBRARY
|
|
||||||
OpenMP_pthread_LIBRARY-ADVANCED:INTERNAL=1
|
|
||||||
//linker supports push/pop state
|
|
||||||
_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED:INTERNAL=TRUE
|
|
||||||
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
set(CMAKE_CXX_COMPILER "/usr/bin/c++")
|
|
||||||
set(CMAKE_CXX_COMPILER_ARG1 "")
|
|
||||||
set(CMAKE_CXX_COMPILER_ID "GNU")
|
|
||||||
set(CMAKE_CXX_COMPILER_VERSION "13.3.0")
|
|
||||||
set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "")
|
|
||||||
set(CMAKE_CXX_COMPILER_WRAPPER "")
|
|
||||||
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "17")
|
|
||||||
set(CMAKE_CXX_EXTENSIONS_COMPUTED_DEFAULT "ON")
|
|
||||||
set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20;cxx_std_23")
|
|
||||||
set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters")
|
|
||||||
set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates")
|
|
||||||
set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates")
|
|
||||||
set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17")
|
|
||||||
set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20")
|
|
||||||
set(CMAKE_CXX23_COMPILE_FEATURES "cxx_std_23")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_PLATFORM_ID "Linux")
|
|
||||||
set(CMAKE_CXX_SIMULATE_ID "")
|
|
||||||
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "GNU")
|
|
||||||
set(CMAKE_CXX_SIMULATE_VERSION "")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_AR "/usr/bin/ar")
|
|
||||||
set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar-13")
|
|
||||||
set(CMAKE_RANLIB "/usr/bin/ranlib")
|
|
||||||
set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib-13")
|
|
||||||
set(CMAKE_LINKER "/usr/bin/ld")
|
|
||||||
set(CMAKE_MT "")
|
|
||||||
set(CMAKE_TAPI "CMAKE_TAPI-NOTFOUND")
|
|
||||||
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
|
||||||
set(CMAKE_CXX_COMPILER_LOADED 1)
|
|
||||||
set(CMAKE_CXX_COMPILER_WORKS TRUE)
|
|
||||||
set(CMAKE_CXX_ABI_COMPILED TRUE)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_COMPILER_ID_RUN 1)
|
|
||||||
set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;mpp;CPP;ixx;cppm;ccm;cxxm;c++m)
|
|
||||||
set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
|
|
||||||
|
|
||||||
foreach (lang C OBJC OBJCXX)
|
|
||||||
if (CMAKE_${lang}_COMPILER_ID_RUN)
|
|
||||||
foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS)
|
|
||||||
list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_LINKER_PREFERENCE 30)
|
|
||||||
set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1)
|
|
||||||
set(CMAKE_CXX_LINKER_DEPFILE_SUPPORTED TRUE)
|
|
||||||
|
|
||||||
# Save compiler ABI information.
|
|
||||||
set(CMAKE_CXX_SIZEOF_DATA_PTR "8")
|
|
||||||
set(CMAKE_CXX_COMPILER_ABI "ELF")
|
|
||||||
set(CMAKE_CXX_BYTE_ORDER "LITTLE_ENDIAN")
|
|
||||||
set(CMAKE_CXX_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
|
|
||||||
|
|
||||||
if(CMAKE_CXX_SIZEOF_DATA_PTR)
|
|
||||||
set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ABI)
|
|
||||||
set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
|
|
||||||
set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "")
|
|
||||||
if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX)
|
|
||||||
set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/13;/usr/include/x86_64-linux-gnu/c++/13;/usr/include/c++/13/backward;/usr/lib/gcc/x86_64-linux-gnu/13/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include")
|
|
||||||
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc")
|
|
||||||
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/13;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
|
|
||||||
set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
|
|
||||||
Binary file not shown.
@@ -1,15 +0,0 @@
|
|||||||
set(CMAKE_HOST_SYSTEM "Linux-6.17.0-35-generic")
|
|
||||||
set(CMAKE_HOST_SYSTEM_NAME "Linux")
|
|
||||||
set(CMAKE_HOST_SYSTEM_VERSION "6.17.0-35-generic")
|
|
||||||
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_SYSTEM "Linux-6.17.0-35-generic")
|
|
||||||
set(CMAKE_SYSTEM_NAME "Linux")
|
|
||||||
set(CMAKE_SYSTEM_VERSION "6.17.0-35-generic")
|
|
||||||
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
|
|
||||||
|
|
||||||
set(CMAKE_CROSSCOMPILING "FALSE")
|
|
||||||
|
|
||||||
set(CMAKE_SYSTEM_LOADED 1)
|
|
||||||
@@ -1,869 +0,0 @@
|
|||||||
/* This source file must have a .cpp extension so that all C++ compilers
|
|
||||||
recognize the extension without flags. Borland does not know .cxx for
|
|
||||||
example. */
|
|
||||||
#ifndef __cplusplus
|
|
||||||
# error "A C compiler has been selected for C++."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(__has_include)
|
|
||||||
/* If the compiler does not have __has_include, pretend the answer is
|
|
||||||
always no. */
|
|
||||||
# define __has_include(x) 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Version number components: V=Version, R=Revision, P=Patch
|
|
||||||
Version date components: YYYY=Year, MM=Month, DD=Day */
|
|
||||||
|
|
||||||
#if defined(__COMO__)
|
|
||||||
# define COMPILER_ID "Comeau"
|
|
||||||
/* __COMO_VERSION__ = VRR */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100)
|
|
||||||
|
|
||||||
#elif defined(__INTEL_COMPILER) || defined(__ICC)
|
|
||||||
# define COMPILER_ID "Intel"
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
# define SIMULATE_ID "MSVC"
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC__)
|
|
||||||
# define SIMULATE_ID "GNU"
|
|
||||||
# endif
|
|
||||||
/* __INTEL_COMPILER = VRP prior to 2021, and then VVVV for 2021 and later,
|
|
||||||
except that a few beta releases use the old format with V=2021. */
|
|
||||||
# if __INTEL_COMPILER < 2021 || __INTEL_COMPILER == 202110 || __INTEL_COMPILER == 202111
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
|
|
||||||
# if defined(__INTEL_COMPILER_UPDATE)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
|
|
||||||
# else
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER_UPDATE)
|
|
||||||
/* The third version component from --version is an update index,
|
|
||||||
but no macro is provided for it. */
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(0)
|
|
||||||
# endif
|
|
||||||
# if defined(__INTEL_COMPILER_BUILD_DATE)
|
|
||||||
/* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
|
|
||||||
# endif
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
/* _MSC_VER = VVRR */
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC__)
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
|
|
||||||
# elif defined(__GNUG__)
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(__GNUG__)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC_MINOR__)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC_PATCHLEVEL__)
|
|
||||||
# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif (defined(__clang__) && defined(__INTEL_CLANG_COMPILER)) || defined(__INTEL_LLVM_COMPILER)
|
|
||||||
# define COMPILER_ID "IntelLLVM"
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# define SIMULATE_ID "MSVC"
|
|
||||||
#endif
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
# define SIMULATE_ID "GNU"
|
|
||||||
#endif
|
|
||||||
/* __INTEL_LLVM_COMPILER = VVVVRP prior to 2021.2.0, VVVVRRPP for 2021.2.0 and
|
|
||||||
* later. Look for 6 digit vs. 8 digit version number to decide encoding.
|
|
||||||
* VVVV is no smaller than the current year when a version is released.
|
|
||||||
*/
|
|
||||||
#if __INTEL_LLVM_COMPILER < 1000000L
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/10 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 10)
|
|
||||||
#else
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/10000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/100 % 100)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 100)
|
|
||||||
#endif
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
/* _MSC_VER = VVRR */
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
|
|
||||||
#endif
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
|
|
||||||
#elif defined(__GNUG__)
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(__GNUG__)
|
|
||||||
#endif
|
|
||||||
#if defined(__GNUC_MINOR__)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
|
|
||||||
#endif
|
|
||||||
#if defined(__GNUC_PATCHLEVEL__)
|
|
||||||
# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__PATHCC__)
|
|
||||||
# define COMPILER_ID "PathScale"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
|
|
||||||
# if defined(__PATHCC_PATCHLEVEL__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
|
|
||||||
# define COMPILER_ID "Embarcadero"
|
|
||||||
# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
|
|
||||||
# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF)
|
|
||||||
|
|
||||||
#elif defined(__BORLANDC__)
|
|
||||||
# define COMPILER_ID "Borland"
|
|
||||||
/* __BORLANDC__ = 0xVRR */
|
|
||||||
# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
|
|
||||||
# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
|
|
||||||
|
|
||||||
#elif defined(__WATCOMC__) && __WATCOMC__ < 1200
|
|
||||||
# define COMPILER_ID "Watcom"
|
|
||||||
/* __WATCOMC__ = VVRR */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
|
|
||||||
# if (__WATCOMC__ % 10) > 0
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__WATCOMC__)
|
|
||||||
# define COMPILER_ID "OpenWatcom"
|
|
||||||
/* __WATCOMC__ = VVRP + 1100 */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
|
|
||||||
# if (__WATCOMC__ % 10) > 0
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__SUNPRO_CC)
|
|
||||||
# define COMPILER_ID "SunPro"
|
|
||||||
# if __SUNPRO_CC >= 0x5100
|
|
||||||
/* __SUNPRO_CC = 0xVRRP */
|
|
||||||
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12)
|
|
||||||
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF)
|
|
||||||
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF)
|
|
||||||
# else
|
|
||||||
/* __SUNPRO_CC = 0xVRP */
|
|
||||||
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8)
|
|
||||||
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF)
|
|
||||||
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__HP_aCC)
|
|
||||||
# define COMPILER_ID "HP"
|
|
||||||
/* __HP_aCC = VVRRPP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100)
|
|
||||||
|
|
||||||
#elif defined(__DECCXX)
|
|
||||||
# define COMPILER_ID "Compaq"
|
|
||||||
/* __DECCXX_VER = VVRRTPPPP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000)
|
|
||||||
|
|
||||||
#elif defined(__IBMCPP__) && defined(__COMPILER_VER__)
|
|
||||||
# define COMPILER_ID "zOS"
|
|
||||||
/* __IBMCPP__ = VRP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)
|
|
||||||
|
|
||||||
#elif defined(__open_xl__) && defined(__clang__)
|
|
||||||
# define COMPILER_ID "IBMClang"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__open_xl_version__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__open_xl_release__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__open_xl_modification__)
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(__open_xl_ptf_fix_level__)
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__ibmxl__) && defined(__clang__)
|
|
||||||
# define COMPILER_ID "XLClang"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800
|
|
||||||
# define COMPILER_ID "XL"
|
|
||||||
/* __IBMCPP__ = VRP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)
|
|
||||||
|
|
||||||
#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800
|
|
||||||
# define COMPILER_ID "VisualAge"
|
|
||||||
/* __IBMCPP__ = VRP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)
|
|
||||||
|
|
||||||
#elif defined(__NVCOMPILER)
|
|
||||||
# define COMPILER_ID "NVHPC"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__NVCOMPILER_MAJOR__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__NVCOMPILER_MINOR__)
|
|
||||||
# if defined(__NVCOMPILER_PATCHLEVEL__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__NVCOMPILER_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__PGI)
|
|
||||||
# define COMPILER_ID "PGI"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__PGIC__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
|
|
||||||
# if defined(__PGIC_PATCHLEVEL__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__clang__) && defined(__cray__)
|
|
||||||
# define COMPILER_ID "CrayClang"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__cray_major__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__cray_minor__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__cray_patchlevel__)
|
|
||||||
# define COMPILER_VERSION_INTERNAL_STR __clang_version__
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(_CRAYC)
|
|
||||||
# define COMPILER_ID "Cray"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
|
|
||||||
|
|
||||||
#elif defined(__TI_COMPILER_VERSION__)
|
|
||||||
# define COMPILER_ID "TI"
|
|
||||||
/* __TI_COMPILER_VERSION__ = VVVRRRPPP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
|
|
||||||
|
|
||||||
#elif defined(__CLANG_FUJITSU)
|
|
||||||
# define COMPILER_ID "FujitsuClang"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__FCC_major__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__FCC_minor__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__FCC_patchlevel__)
|
|
||||||
# define COMPILER_VERSION_INTERNAL_STR __clang_version__
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__FUJITSU)
|
|
||||||
# define COMPILER_ID "Fujitsu"
|
|
||||||
# if defined(__FCC_version__)
|
|
||||||
# define COMPILER_VERSION __FCC_version__
|
|
||||||
# elif defined(__FCC_major__)
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__FCC_major__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__FCC_minor__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__FCC_patchlevel__)
|
|
||||||
# endif
|
|
||||||
# if defined(__fcc_version)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__fcc_version)
|
|
||||||
# elif defined(__FCC_VERSION)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__FCC_VERSION)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__ghs__)
|
|
||||||
# define COMPILER_ID "GHS"
|
|
||||||
/* __GHS_VERSION_NUMBER = VVVVRP */
|
|
||||||
# ifdef __GHS_VERSION_NUMBER
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__TASKING__)
|
|
||||||
# define COMPILER_ID "Tasking"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__VERSION__/1000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__VERSION__ % 100)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__VERSION__)
|
|
||||||
|
|
||||||
#elif defined(__ORANGEC__)
|
|
||||||
# define COMPILER_ID "OrangeC"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__ORANGEC_MAJOR__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__ORANGEC_MINOR__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__ORANGEC_PATCHLEVEL__)
|
|
||||||
|
|
||||||
#elif defined(__SCO_VERSION__)
|
|
||||||
# define COMPILER_ID "SCO"
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && !defined(__clang__)
|
|
||||||
# define COMPILER_ID "ARMCC"
|
|
||||||
#if __ARMCC_VERSION >= 1000000
|
|
||||||
/* __ARMCC_VERSION = VRRPPPP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
|
|
||||||
#else
|
|
||||||
/* __ARMCC_VERSION = VRPPPP */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__clang__) && defined(__apple_build_version__)
|
|
||||||
# define COMPILER_ID "AppleClang"
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
# define SIMULATE_ID "MSVC"
|
|
||||||
# endif
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
/* _MSC_VER = VVRR */
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
|
|
||||||
# endif
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
|
|
||||||
|
|
||||||
#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION)
|
|
||||||
# define COMPILER_ID "ARMClang"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION/100 % 100)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION)
|
|
||||||
|
|
||||||
#elif defined(__clang__)
|
|
||||||
# define COMPILER_ID "Clang"
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
# define SIMULATE_ID "MSVC"
|
|
||||||
# endif
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
/* _MSC_VER = VVRR */
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__LCC__) && (defined(__GNUC__) || defined(__GNUG__) || defined(__MCST__))
|
|
||||||
# define COMPILER_ID "LCC"
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__LCC__ / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__LCC__ % 100)
|
|
||||||
# if defined(__LCC_MINOR__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__LCC_MINOR__)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
|
||||||
# define SIMULATE_ID "GNU"
|
|
||||||
# define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
|
|
||||||
# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
|
|
||||||
# if defined(__GNUC_PATCHLEVEL__)
|
|
||||||
# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
|
||||||
# define COMPILER_ID "GNU"
|
|
||||||
# if defined(__GNUC__)
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__GNUC__)
|
|
||||||
# else
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__GNUG__)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC_MINOR__)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
|
|
||||||
# endif
|
|
||||||
# if defined(__GNUC_PATCHLEVEL__)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
# define COMPILER_ID "MSVC"
|
|
||||||
/* _MSC_VER = VVRR */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
|
|
||||||
# if defined(_MSC_FULL_VER)
|
|
||||||
# if _MSC_VER >= 1400
|
|
||||||
/* _MSC_FULL_VER = VVRRPPPPP */
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
|
|
||||||
# else
|
|
||||||
/* _MSC_FULL_VER = VVRRPPPP */
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# if defined(_MSC_BUILD)
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(_ADI_COMPILER)
|
|
||||||
# define COMPILER_ID "ADSP"
|
|
||||||
#if defined(__VERSIONNUM__)
|
|
||||||
/* __VERSIONNUM__ = 0xVVRRPPTT */
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC(__VERSIONNUM__ >> 24 & 0xFF)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(__VERSIONNUM__ >> 16 & 0xFF)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__VERSIONNUM__ >> 8 & 0xFF)
|
|
||||||
# define COMPILER_VERSION_TWEAK DEC(__VERSIONNUM__ & 0xFF)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
|
|
||||||
# define COMPILER_ID "IAR"
|
|
||||||
# if defined(__VER__) && defined(__ICCARM__)
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000)
|
|
||||||
# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
|
|
||||||
# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__) || defined(__ICCSTM8__))
|
|
||||||
# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100)
|
|
||||||
# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100))
|
|
||||||
# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__)
|
|
||||||
# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
|
|
||||||
/* These compilers are either not known or too old to define an
|
|
||||||
identification macro. Try to identify the platform and guess that
|
|
||||||
it is the native compiler. */
|
|
||||||
#elif defined(__hpux) || defined(__hpua)
|
|
||||||
# define COMPILER_ID "HP"
|
|
||||||
|
|
||||||
#else /* unknown compiler */
|
|
||||||
# define COMPILER_ID ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Construct the string literal in pieces to prevent the source from
|
|
||||||
getting matched. Store it in a pointer rather than an array
|
|
||||||
because some compilers will just produce instructions to fill the
|
|
||||||
array rather than assigning a pointer to a static array. */
|
|
||||||
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
|
|
||||||
#ifdef SIMULATE_ID
|
|
||||||
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __QNXNTO__
|
|
||||||
char const* qnxnto = "INFO" ":" "qnxnto[]";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
|
|
||||||
char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define STRINGIFY_HELPER(X) #X
|
|
||||||
#define STRINGIFY(X) STRINGIFY_HELPER(X)
|
|
||||||
|
|
||||||
/* Identify known platforms by name. */
|
|
||||||
#if defined(__linux) || defined(__linux__) || defined(linux)
|
|
||||||
# define PLATFORM_ID "Linux"
|
|
||||||
|
|
||||||
#elif defined(__MSYS__)
|
|
||||||
# define PLATFORM_ID "MSYS"
|
|
||||||
|
|
||||||
#elif defined(__CYGWIN__)
|
|
||||||
# define PLATFORM_ID "Cygwin"
|
|
||||||
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
# define PLATFORM_ID "MinGW"
|
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
# define PLATFORM_ID "Darwin"
|
|
||||||
|
|
||||||
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
||||||
# define PLATFORM_ID "Windows"
|
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD)
|
|
||||||
# define PLATFORM_ID "FreeBSD"
|
|
||||||
|
|
||||||
#elif defined(__NetBSD__) || defined(__NetBSD)
|
|
||||||
# define PLATFORM_ID "NetBSD"
|
|
||||||
|
|
||||||
#elif defined(__OpenBSD__) || defined(__OPENBSD)
|
|
||||||
# define PLATFORM_ID "OpenBSD"
|
|
||||||
|
|
||||||
#elif defined(__sun) || defined(sun)
|
|
||||||
# define PLATFORM_ID "SunOS"
|
|
||||||
|
|
||||||
#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
|
|
||||||
# define PLATFORM_ID "AIX"
|
|
||||||
|
|
||||||
#elif defined(__hpux) || defined(__hpux__)
|
|
||||||
# define PLATFORM_ID "HP-UX"
|
|
||||||
|
|
||||||
#elif defined(__HAIKU__)
|
|
||||||
# define PLATFORM_ID "Haiku"
|
|
||||||
|
|
||||||
#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
|
|
||||||
# define PLATFORM_ID "BeOS"
|
|
||||||
|
|
||||||
#elif defined(__QNX__) || defined(__QNXNTO__)
|
|
||||||
# define PLATFORM_ID "QNX"
|
|
||||||
|
|
||||||
#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
|
|
||||||
# define PLATFORM_ID "Tru64"
|
|
||||||
|
|
||||||
#elif defined(__riscos) || defined(__riscos__)
|
|
||||||
# define PLATFORM_ID "RISCos"
|
|
||||||
|
|
||||||
#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
|
|
||||||
# define PLATFORM_ID "SINIX"
|
|
||||||
|
|
||||||
#elif defined(__UNIX_SV__)
|
|
||||||
# define PLATFORM_ID "UNIX_SV"
|
|
||||||
|
|
||||||
#elif defined(__bsdos__)
|
|
||||||
# define PLATFORM_ID "BSDOS"
|
|
||||||
|
|
||||||
#elif defined(_MPRAS) || defined(MPRAS)
|
|
||||||
# define PLATFORM_ID "MP-RAS"
|
|
||||||
|
|
||||||
#elif defined(__osf) || defined(__osf__)
|
|
||||||
# define PLATFORM_ID "OSF1"
|
|
||||||
|
|
||||||
#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
|
|
||||||
# define PLATFORM_ID "SCO_SV"
|
|
||||||
|
|
||||||
#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
|
|
||||||
# define PLATFORM_ID "ULTRIX"
|
|
||||||
|
|
||||||
#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
|
|
||||||
# define PLATFORM_ID "Xenix"
|
|
||||||
|
|
||||||
#elif defined(__WATCOMC__)
|
|
||||||
# if defined(__LINUX__)
|
|
||||||
# define PLATFORM_ID "Linux"
|
|
||||||
|
|
||||||
# elif defined(__DOS__)
|
|
||||||
# define PLATFORM_ID "DOS"
|
|
||||||
|
|
||||||
# elif defined(__OS2__)
|
|
||||||
# define PLATFORM_ID "OS2"
|
|
||||||
|
|
||||||
# elif defined(__WINDOWS__)
|
|
||||||
# define PLATFORM_ID "Windows3x"
|
|
||||||
|
|
||||||
# elif defined(__VXWORKS__)
|
|
||||||
# define PLATFORM_ID "VxWorks"
|
|
||||||
|
|
||||||
# else /* unknown platform */
|
|
||||||
# define PLATFORM_ID
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__INTEGRITY)
|
|
||||||
# if defined(INT_178B)
|
|
||||||
# define PLATFORM_ID "Integrity178"
|
|
||||||
|
|
||||||
# else /* regular Integrity */
|
|
||||||
# define PLATFORM_ID "Integrity"
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# elif defined(_ADI_COMPILER)
|
|
||||||
# define PLATFORM_ID "ADSP"
|
|
||||||
|
|
||||||
#else /* unknown platform */
|
|
||||||
# define PLATFORM_ID
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* For windows compilers MSVC and Intel we can determine
|
|
||||||
the architecture of the compiler being used. This is because
|
|
||||||
the compilers do not have flags that can change the architecture,
|
|
||||||
but rather depend on which compiler is being used
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32) && defined(_MSC_VER)
|
|
||||||
# if defined(_M_IA64)
|
|
||||||
# define ARCHITECTURE_ID "IA64"
|
|
||||||
|
|
||||||
# elif defined(_M_ARM64EC)
|
|
||||||
# define ARCHITECTURE_ID "ARM64EC"
|
|
||||||
|
|
||||||
# elif defined(_M_X64) || defined(_M_AMD64)
|
|
||||||
# define ARCHITECTURE_ID "x64"
|
|
||||||
|
|
||||||
# elif defined(_M_IX86)
|
|
||||||
# define ARCHITECTURE_ID "X86"
|
|
||||||
|
|
||||||
# elif defined(_M_ARM64)
|
|
||||||
# define ARCHITECTURE_ID "ARM64"
|
|
||||||
|
|
||||||
# elif defined(_M_ARM)
|
|
||||||
# if _M_ARM == 4
|
|
||||||
# define ARCHITECTURE_ID "ARMV4I"
|
|
||||||
# elif _M_ARM == 5
|
|
||||||
# define ARCHITECTURE_ID "ARMV5I"
|
|
||||||
# else
|
|
||||||
# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# elif defined(_M_MIPS)
|
|
||||||
# define ARCHITECTURE_ID "MIPS"
|
|
||||||
|
|
||||||
# elif defined(_M_SH)
|
|
||||||
# define ARCHITECTURE_ID "SHx"
|
|
||||||
|
|
||||||
# else /* unknown architecture */
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__WATCOMC__)
|
|
||||||
# if defined(_M_I86)
|
|
||||||
# define ARCHITECTURE_ID "I86"
|
|
||||||
|
|
||||||
# elif defined(_M_IX86)
|
|
||||||
# define ARCHITECTURE_ID "X86"
|
|
||||||
|
|
||||||
# else /* unknown architecture */
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
|
|
||||||
# if defined(__ICCARM__)
|
|
||||||
# define ARCHITECTURE_ID "ARM"
|
|
||||||
|
|
||||||
# elif defined(__ICCRX__)
|
|
||||||
# define ARCHITECTURE_ID "RX"
|
|
||||||
|
|
||||||
# elif defined(__ICCRH850__)
|
|
||||||
# define ARCHITECTURE_ID "RH850"
|
|
||||||
|
|
||||||
# elif defined(__ICCRL78__)
|
|
||||||
# define ARCHITECTURE_ID "RL78"
|
|
||||||
|
|
||||||
# elif defined(__ICCRISCV__)
|
|
||||||
# define ARCHITECTURE_ID "RISCV"
|
|
||||||
|
|
||||||
# elif defined(__ICCAVR__)
|
|
||||||
# define ARCHITECTURE_ID "AVR"
|
|
||||||
|
|
||||||
# elif defined(__ICC430__)
|
|
||||||
# define ARCHITECTURE_ID "MSP430"
|
|
||||||
|
|
||||||
# elif defined(__ICCV850__)
|
|
||||||
# define ARCHITECTURE_ID "V850"
|
|
||||||
|
|
||||||
# elif defined(__ICC8051__)
|
|
||||||
# define ARCHITECTURE_ID "8051"
|
|
||||||
|
|
||||||
# elif defined(__ICCSTM8__)
|
|
||||||
# define ARCHITECTURE_ID "STM8"
|
|
||||||
|
|
||||||
# else /* unknown architecture */
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__ghs__)
|
|
||||||
# if defined(__PPC64__)
|
|
||||||
# define ARCHITECTURE_ID "PPC64"
|
|
||||||
|
|
||||||
# elif defined(__ppc__)
|
|
||||||
# define ARCHITECTURE_ID "PPC"
|
|
||||||
|
|
||||||
# elif defined(__ARM__)
|
|
||||||
# define ARCHITECTURE_ID "ARM"
|
|
||||||
|
|
||||||
# elif defined(__x86_64__)
|
|
||||||
# define ARCHITECTURE_ID "x64"
|
|
||||||
|
|
||||||
# elif defined(__i386__)
|
|
||||||
# define ARCHITECTURE_ID "X86"
|
|
||||||
|
|
||||||
# else /* unknown architecture */
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#elif defined(__TI_COMPILER_VERSION__)
|
|
||||||
# if defined(__TI_ARM__)
|
|
||||||
# define ARCHITECTURE_ID "ARM"
|
|
||||||
|
|
||||||
# elif defined(__MSP430__)
|
|
||||||
# define ARCHITECTURE_ID "MSP430"
|
|
||||||
|
|
||||||
# elif defined(__TMS320C28XX__)
|
|
||||||
# define ARCHITECTURE_ID "TMS320C28x"
|
|
||||||
|
|
||||||
# elif defined(__TMS320C6X__) || defined(_TMS320C6X)
|
|
||||||
# define ARCHITECTURE_ID "TMS320C6x"
|
|
||||||
|
|
||||||
# else /* unknown architecture */
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# elif defined(__ADSPSHARC__)
|
|
||||||
# define ARCHITECTURE_ID "SHARC"
|
|
||||||
|
|
||||||
# elif defined(__ADSPBLACKFIN__)
|
|
||||||
# define ARCHITECTURE_ID "Blackfin"
|
|
||||||
|
|
||||||
#elif defined(__TASKING__)
|
|
||||||
|
|
||||||
# if defined(__CTC__) || defined(__CPTC__)
|
|
||||||
# define ARCHITECTURE_ID "TriCore"
|
|
||||||
|
|
||||||
# elif defined(__CMCS__)
|
|
||||||
# define ARCHITECTURE_ID "MCS"
|
|
||||||
|
|
||||||
# elif defined(__CARM__)
|
|
||||||
# define ARCHITECTURE_ID "ARM"
|
|
||||||
|
|
||||||
# elif defined(__CARC__)
|
|
||||||
# define ARCHITECTURE_ID "ARC"
|
|
||||||
|
|
||||||
# elif defined(__C51__)
|
|
||||||
# define ARCHITECTURE_ID "8051"
|
|
||||||
|
|
||||||
# elif defined(__CPCP__)
|
|
||||||
# define ARCHITECTURE_ID "PCP"
|
|
||||||
|
|
||||||
# else
|
|
||||||
# define ARCHITECTURE_ID ""
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
# define ARCHITECTURE_ID
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Convert integer to decimal digit literals. */
|
|
||||||
#define DEC(n) \
|
|
||||||
('0' + (((n) / 10000000)%10)), \
|
|
||||||
('0' + (((n) / 1000000)%10)), \
|
|
||||||
('0' + (((n) / 100000)%10)), \
|
|
||||||
('0' + (((n) / 10000)%10)), \
|
|
||||||
('0' + (((n) / 1000)%10)), \
|
|
||||||
('0' + (((n) / 100)%10)), \
|
|
||||||
('0' + (((n) / 10)%10)), \
|
|
||||||
('0' + ((n) % 10))
|
|
||||||
|
|
||||||
/* Convert integer to hex digit literals. */
|
|
||||||
#define HEX(n) \
|
|
||||||
('0' + ((n)>>28 & 0xF)), \
|
|
||||||
('0' + ((n)>>24 & 0xF)), \
|
|
||||||
('0' + ((n)>>20 & 0xF)), \
|
|
||||||
('0' + ((n)>>16 & 0xF)), \
|
|
||||||
('0' + ((n)>>12 & 0xF)), \
|
|
||||||
('0' + ((n)>>8 & 0xF)), \
|
|
||||||
('0' + ((n)>>4 & 0xF)), \
|
|
||||||
('0' + ((n) & 0xF))
|
|
||||||
|
|
||||||
/* Construct a string literal encoding the version number. */
|
|
||||||
#ifdef COMPILER_VERSION
|
|
||||||
char const* info_version = "INFO" ":" "compiler_version[" COMPILER_VERSION "]";
|
|
||||||
|
|
||||||
/* Construct a string literal encoding the version number components. */
|
|
||||||
#elif defined(COMPILER_VERSION_MAJOR)
|
|
||||||
char const info_version[] = {
|
|
||||||
'I', 'N', 'F', 'O', ':',
|
|
||||||
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
|
|
||||||
COMPILER_VERSION_MAJOR,
|
|
||||||
# ifdef COMPILER_VERSION_MINOR
|
|
||||||
'.', COMPILER_VERSION_MINOR,
|
|
||||||
# ifdef COMPILER_VERSION_PATCH
|
|
||||||
'.', COMPILER_VERSION_PATCH,
|
|
||||||
# ifdef COMPILER_VERSION_TWEAK
|
|
||||||
'.', COMPILER_VERSION_TWEAK,
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
']','\0'};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Construct a string literal encoding the internal version number. */
|
|
||||||
#ifdef COMPILER_VERSION_INTERNAL
|
|
||||||
char const info_version_internal[] = {
|
|
||||||
'I', 'N', 'F', 'O', ':',
|
|
||||||
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_',
|
|
||||||
'i','n','t','e','r','n','a','l','[',
|
|
||||||
COMPILER_VERSION_INTERNAL,']','\0'};
|
|
||||||
#elif defined(COMPILER_VERSION_INTERNAL_STR)
|
|
||||||
char const* info_version_internal = "INFO" ":" "compiler_version_internal[" COMPILER_VERSION_INTERNAL_STR "]";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Construct a string literal encoding the version number components. */
|
|
||||||
#ifdef SIMULATE_VERSION_MAJOR
|
|
||||||
char const info_simulate_version[] = {
|
|
||||||
'I', 'N', 'F', 'O', ':',
|
|
||||||
's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
|
|
||||||
SIMULATE_VERSION_MAJOR,
|
|
||||||
# ifdef SIMULATE_VERSION_MINOR
|
|
||||||
'.', SIMULATE_VERSION_MINOR,
|
|
||||||
# ifdef SIMULATE_VERSION_PATCH
|
|
||||||
'.', SIMULATE_VERSION_PATCH,
|
|
||||||
# ifdef SIMULATE_VERSION_TWEAK
|
|
||||||
'.', SIMULATE_VERSION_TWEAK,
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
']','\0'};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Construct the string literal in pieces to prevent the source from
|
|
||||||
getting matched. Store it in a pointer rather than an array
|
|
||||||
because some compilers will just produce instructions to fill the
|
|
||||||
array rather than assigning a pointer to a static array. */
|
|
||||||
char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
|
|
||||||
char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L
|
|
||||||
# if defined(__INTEL_CXX11_MODE__)
|
|
||||||
# if defined(__cpp_aggregate_nsdmi)
|
|
||||||
# define CXX_STD 201402L
|
|
||||||
# else
|
|
||||||
# define CXX_STD 201103L
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define CXX_STD 199711L
|
|
||||||
# endif
|
|
||||||
#elif defined(_MSC_VER) && defined(_MSVC_LANG)
|
|
||||||
# define CXX_STD _MSVC_LANG
|
|
||||||
#else
|
|
||||||
# define CXX_STD __cplusplus
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char* info_language_standard_default = "INFO" ":" "standard_default["
|
|
||||||
#if CXX_STD > 202002L
|
|
||||||
"23"
|
|
||||||
#elif CXX_STD > 201703L
|
|
||||||
"20"
|
|
||||||
#elif CXX_STD >= 201703L
|
|
||||||
"17"
|
|
||||||
#elif CXX_STD >= 201402L
|
|
||||||
"14"
|
|
||||||
#elif CXX_STD >= 201103L
|
|
||||||
"11"
|
|
||||||
#else
|
|
||||||
"98"
|
|
||||||
#endif
|
|
||||||
"]";
|
|
||||||
|
|
||||||
const char* info_language_extensions_default = "INFO" ":" "extensions_default["
|
|
||||||
#if (defined(__clang__) || defined(__GNUC__) || defined(__xlC__) || \
|
|
||||||
defined(__TI_COMPILER_VERSION__)) && \
|
|
||||||
!defined(__STRICT_ANSI__)
|
|
||||||
"ON"
|
|
||||||
#else
|
|
||||||
"OFF"
|
|
||||||
#endif
|
|
||||||
"]";
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
int require = 0;
|
|
||||||
require += info_compiler[argc];
|
|
||||||
require += info_platform[argc];
|
|
||||||
require += info_arch[argc];
|
|
||||||
#ifdef COMPILER_VERSION_MAJOR
|
|
||||||
require += info_version[argc];
|
|
||||||
#endif
|
|
||||||
#ifdef COMPILER_VERSION_INTERNAL
|
|
||||||
require += info_version_internal[argc];
|
|
||||||
#endif
|
|
||||||
#ifdef SIMULATE_ID
|
|
||||||
require += info_simulate[argc];
|
|
||||||
#endif
|
|
||||||
#ifdef SIMULATE_VERSION_MAJOR
|
|
||||||
require += info_simulate_version[argc];
|
|
||||||
#endif
|
|
||||||
#if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
|
|
||||||
require += info_cray[argc];
|
|
||||||
#endif
|
|
||||||
require += info_language_standard_default[argc];
|
|
||||||
require += info_language_extensions_default[argc];
|
|
||||||
(void)argv;
|
|
||||||
return require;
|
|
||||||
}
|
|
||||||
@@ -1,518 +0,0 @@
|
|||||||
|
|
||||||
---
|
|
||||||
events:
|
|
||||||
-
|
|
||||||
kind: "message-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineSystem.cmake:233 (message)"
|
|
||||||
- "CMakeLists.txt:6 (project)"
|
|
||||||
message: |
|
|
||||||
The system is: Linux - 6.17.0-35-generic - x86_64
|
|
||||||
-
|
|
||||||
kind: "message-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerId.cmake:17 (message)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerId.cmake:64 (__determine_compiler_id_test)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCXXCompiler.cmake:126 (CMAKE_DETERMINE_COMPILER_ID)"
|
|
||||||
- "CMakeLists.txt:6 (project)"
|
|
||||||
message: |
|
|
||||||
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
|
|
||||||
Compiler: /usr/bin/c++
|
|
||||||
Build flags:
|
|
||||||
Id flags:
|
|
||||||
|
|
||||||
The output was:
|
|
||||||
0
|
|
||||||
|
|
||||||
|
|
||||||
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
|
|
||||||
|
|
||||||
The CXX compiler identification is GNU, found in:
|
|
||||||
/home/atlas/Documents/Git/panic/build/CMakeFiles/3.28.3/CompilerIdCXX/a.out
|
|
||||||
|
|
||||||
-
|
|
||||||
kind: "try_compile-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerABI.cmake:57 (try_compile)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)"
|
|
||||||
- "CMakeLists.txt:6 (project)"
|
|
||||||
checks:
|
|
||||||
- "Detecting CXX compiler ABI info"
|
|
||||||
directories:
|
|
||||||
source: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl"
|
|
||||||
binary: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl"
|
|
||||||
cmakeVariables:
|
|
||||||
CMAKE_CXX_FLAGS: ""
|
|
||||||
CMAKE_CXX_FLAGS_DEBUG: "-g"
|
|
||||||
CMAKE_EXE_LINKER_FLAGS: ""
|
|
||||||
buildResult:
|
|
||||||
variable: "CMAKE_CXX_ABI_COMPILED"
|
|
||||||
cached: true
|
|
||||||
stdout: |
|
|
||||||
Change Dir: '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl'
|
|
||||||
|
|
||||||
Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_41a54/fast
|
|
||||||
/usr/bin/gmake -f CMakeFiles/cmTC_41a54.dir/build.make CMakeFiles/cmTC_41a54.dir/build
|
|
||||||
gmake[1]: Entering directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl'
|
|
||||||
Building CXX object CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o
|
|
||||||
/usr/bin/c++ -v -o CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -c /usr/share/cmake-3.28/Modules/CMakeCXXCompilerABI.cpp
|
|
||||||
Using built-in specs.
|
|
||||||
COLLECT_GCC=/usr/bin/c++
|
|
||||||
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
|
|
||||||
OFFLOAD_TARGET_DEFAULT=1
|
|
||||||
Target: x86_64-linux-gnu
|
|
||||||
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
|
|
||||||
Thread model: posix
|
|
||||||
Supported LTO compression algorithms: zlib zstd
|
|
||||||
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1)
|
|
||||||
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/'
|
|
||||||
/usr/libexec/gcc/x86_64-linux-gnu/13/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /usr/share/cmake-3.28/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpdir CMakeFiles/cmTC_41a54.dir/ -dumpbase CMakeCXXCompilerABI.cpp.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc09Jdka.s
|
|
||||||
GNU C++17 (Ubuntu 13.3.0-6ubuntu2~24.04.1) version 13.3.0 (x86_64-linux-gnu)
|
|
||||||
compiled by GNU C version 13.3.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP
|
|
||||||
|
|
||||||
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
|
|
||||||
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/13"
|
|
||||||
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
|
|
||||||
#include "..." search starts here:
|
|
||||||
#include <...> search starts here:
|
|
||||||
/usr/include/c++/13
|
|
||||||
/usr/include/x86_64-linux-gnu/c++/13
|
|
||||||
/usr/include/c++/13/backward
|
|
||||||
/usr/lib/gcc/x86_64-linux-gnu/13/include
|
|
||||||
/usr/local/include
|
|
||||||
/usr/include/x86_64-linux-gnu
|
|
||||||
/usr/include
|
|
||||||
End of search list.
|
|
||||||
Compiler executable checksum: 7896445e4990772fdae9dc0659a99266
|
|
||||||
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/'
|
|
||||||
as -v --64 -o CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o /tmp/cc09Jdka.s
|
|
||||||
GNU assembler version 2.42 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.42
|
|
||||||
COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/
|
|
||||||
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/
|
|
||||||
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.'
|
|
||||||
Linking CXX executable cmTC_41a54
|
|
||||||
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_41a54.dir/link.txt --verbose=1
|
|
||||||
/usr/bin/c++ -v CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_41a54
|
|
||||||
Using built-in specs.
|
|
||||||
COLLECT_GCC=/usr/bin/c++
|
|
||||||
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
|
|
||||||
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
|
|
||||||
OFFLOAD_TARGET_DEFAULT=1
|
|
||||||
Target: x86_64-linux-gnu
|
|
||||||
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
|
|
||||||
Thread model: posix
|
|
||||||
Supported LTO compression algorithms: zlib zstd
|
|
||||||
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1)
|
|
||||||
COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/
|
|
||||||
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/
|
|
||||||
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_41a54' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'cmTC_41a54.'
|
|
||||||
/usr/libexec/gcc/x86_64-linux-gnu/13/collect2 -plugin /usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper -plugin-opt=-fresolution=/tmp/ccnZOIwX.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_41a54 /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/13 -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/13/../../.. CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o
|
|
||||||
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_41a54' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'cmTC_41a54.'
|
|
||||||
gmake[1]: Leaving directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl'
|
|
||||||
|
|
||||||
exitCode: 0
|
|
||||||
-
|
|
||||||
kind: "message-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerABI.cmake:127 (message)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)"
|
|
||||||
- "CMakeLists.txt:6 (project)"
|
|
||||||
message: |
|
|
||||||
Parsed CXX implicit include dir info: rv=done
|
|
||||||
found start of include info
|
|
||||||
found start of implicit include info
|
|
||||||
add: [/usr/include/c++/13]
|
|
||||||
add: [/usr/include/x86_64-linux-gnu/c++/13]
|
|
||||||
add: [/usr/include/c++/13/backward]
|
|
||||||
add: [/usr/lib/gcc/x86_64-linux-gnu/13/include]
|
|
||||||
add: [/usr/local/include]
|
|
||||||
add: [/usr/include/x86_64-linux-gnu]
|
|
||||||
add: [/usr/include]
|
|
||||||
end of search list found
|
|
||||||
collapse include dir [/usr/include/c++/13] ==> [/usr/include/c++/13]
|
|
||||||
collapse include dir [/usr/include/x86_64-linux-gnu/c++/13] ==> [/usr/include/x86_64-linux-gnu/c++/13]
|
|
||||||
collapse include dir [/usr/include/c++/13/backward] ==> [/usr/include/c++/13/backward]
|
|
||||||
collapse include dir [/usr/lib/gcc/x86_64-linux-gnu/13/include] ==> [/usr/lib/gcc/x86_64-linux-gnu/13/include]
|
|
||||||
collapse include dir [/usr/local/include] ==> [/usr/local/include]
|
|
||||||
collapse include dir [/usr/include/x86_64-linux-gnu] ==> [/usr/include/x86_64-linux-gnu]
|
|
||||||
collapse include dir [/usr/include] ==> [/usr/include]
|
|
||||||
implicit include dirs: [/usr/include/c++/13;/usr/include/x86_64-linux-gnu/c++/13;/usr/include/c++/13/backward;/usr/lib/gcc/x86_64-linux-gnu/13/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include]
|
|
||||||
|
|
||||||
|
|
||||||
-
|
|
||||||
kind: "message-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerABI.cmake:159 (message)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)"
|
|
||||||
- "CMakeLists.txt:6 (project)"
|
|
||||||
message: |
|
|
||||||
Parsed CXX implicit link information:
|
|
||||||
link line regex: [^( *|.*[/\\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\\]+-)?ld|collect2)[^/\\]*( |$)]
|
|
||||||
ignore line: [Change Dir: '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl']
|
|
||||||
ignore line: []
|
|
||||||
ignore line: [Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_41a54/fast]
|
|
||||||
ignore line: [/usr/bin/gmake -f CMakeFiles/cmTC_41a54.dir/build.make CMakeFiles/cmTC_41a54.dir/build]
|
|
||||||
ignore line: [gmake[1]: Entering directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-iBVTGl']
|
|
||||||
ignore line: [Building CXX object CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o]
|
|
||||||
ignore line: [/usr/bin/c++ -v -o CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -c /usr/share/cmake-3.28/Modules/CMakeCXXCompilerABI.cpp]
|
|
||||||
ignore line: [Using built-in specs.]
|
|
||||||
ignore line: [COLLECT_GCC=/usr/bin/c++]
|
|
||||||
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa]
|
|
||||||
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
|
|
||||||
ignore line: [Target: x86_64-linux-gnu]
|
|
||||||
ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c ada c++ go d fortran objc obj-c++ m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2]
|
|
||||||
ignore line: [Thread model: posix]
|
|
||||||
ignore line: [Supported LTO compression algorithms: zlib zstd]
|
|
||||||
ignore line: [gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) ]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/']
|
|
||||||
ignore line: [ /usr/libexec/gcc/x86_64-linux-gnu/13/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /usr/share/cmake-3.28/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpdir CMakeFiles/cmTC_41a54.dir/ -dumpbase CMakeCXXCompilerABI.cpp.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc09Jdka.s]
|
|
||||||
ignore line: [GNU C++17 (Ubuntu 13.3.0-6ubuntu2~24.04.1) version 13.3.0 (x86_64-linux-gnu)]
|
|
||||||
ignore line: [ compiled by GNU C version 13.3.0 GMP version 6.3.0 MPFR version 4.2.1 MPC version 1.3.1 isl version isl-0.26-GMP]
|
|
||||||
ignore line: []
|
|
||||||
ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
|
|
||||||
ignore line: [ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/13"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"]
|
|
||||||
ignore line: [#include "..." search starts here:]
|
|
||||||
ignore line: [#include <...> search starts here:]
|
|
||||||
ignore line: [ /usr/include/c++/13]
|
|
||||||
ignore line: [ /usr/include/x86_64-linux-gnu/c++/13]
|
|
||||||
ignore line: [ /usr/include/c++/13/backward]
|
|
||||||
ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/13/include]
|
|
||||||
ignore line: [ /usr/local/include]
|
|
||||||
ignore line: [ /usr/include/x86_64-linux-gnu]
|
|
||||||
ignore line: [ /usr/include]
|
|
||||||
ignore line: [End of search list.]
|
|
||||||
ignore line: [Compiler executable checksum: 7896445e4990772fdae9dc0659a99266]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/']
|
|
||||||
ignore line: [ as -v --64 -o CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o /tmp/cc09Jdka.s]
|
|
||||||
ignore line: [GNU assembler version 2.42 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.42]
|
|
||||||
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/]
|
|
||||||
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.']
|
|
||||||
ignore line: [Linking CXX executable cmTC_41a54]
|
|
||||||
ignore line: [/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_41a54.dir/link.txt --verbose=1]
|
|
||||||
ignore line: [/usr/bin/c++ -v CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_41a54 ]
|
|
||||||
ignore line: [Using built-in specs.]
|
|
||||||
ignore line: [COLLECT_GCC=/usr/bin/c++]
|
|
||||||
ignore line: [COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper]
|
|
||||||
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa]
|
|
||||||
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
|
|
||||||
ignore line: [Target: x86_64-linux-gnu]
|
|
||||||
ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c ada c++ go d fortran objc obj-c++ m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2]
|
|
||||||
ignore line: [Thread model: posix]
|
|
||||||
ignore line: [Supported LTO compression algorithms: zlib zstd]
|
|
||||||
ignore line: [gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) ]
|
|
||||||
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/]
|
|
||||||
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_41a54' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'cmTC_41a54.']
|
|
||||||
link line: [ /usr/libexec/gcc/x86_64-linux-gnu/13/collect2 -plugin /usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper -plugin-opt=-fresolution=/tmp/ccnZOIwX.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_41a54 /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/13 -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/13/../../.. CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o]
|
|
||||||
arg [/usr/libexec/gcc/x86_64-linux-gnu/13/collect2] ==> ignore
|
|
||||||
arg [-plugin] ==> ignore
|
|
||||||
arg [/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so] ==> ignore
|
|
||||||
arg [-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper] ==> ignore
|
|
||||||
arg [-plugin-opt=-fresolution=/tmp/ccnZOIwX.res] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lc] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
|
|
||||||
arg [--build-id] ==> ignore
|
|
||||||
arg [--eh-frame-hdr] ==> ignore
|
|
||||||
arg [-m] ==> ignore
|
|
||||||
arg [elf_x86_64] ==> ignore
|
|
||||||
arg [--hash-style=gnu] ==> ignore
|
|
||||||
arg [--as-needed] ==> ignore
|
|
||||||
arg [-dynamic-linker] ==> ignore
|
|
||||||
arg [/lib64/ld-linux-x86-64.so.2] ==> ignore
|
|
||||||
arg [-pie] ==> ignore
|
|
||||||
arg [-znow] ==> ignore
|
|
||||||
arg [-zrelro] ==> ignore
|
|
||||||
arg [-o] ==> ignore
|
|
||||||
arg [cmTC_41a54] ==> ignore
|
|
||||||
arg [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o] ==> obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o]
|
|
||||||
arg [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o] ==> obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o]
|
|
||||||
arg [/usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o] ==> obj [/usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib]
|
|
||||||
arg [-L/lib/x86_64-linux-gnu] ==> dir [/lib/x86_64-linux-gnu]
|
|
||||||
arg [-L/lib/../lib] ==> dir [/lib/../lib]
|
|
||||||
arg [-L/usr/lib/x86_64-linux-gnu] ==> dir [/usr/lib/x86_64-linux-gnu]
|
|
||||||
arg [-L/usr/lib/../lib] ==> dir [/usr/lib/../lib]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../..] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../..]
|
|
||||||
arg [CMakeFiles/cmTC_41a54.dir/CMakeCXXCompilerABI.cpp.o] ==> ignore
|
|
||||||
arg [-lstdc++] ==> lib [stdc++]
|
|
||||||
arg [-lm] ==> lib [m]
|
|
||||||
arg [-lgcc_s] ==> lib [gcc_s]
|
|
||||||
arg [-lgcc] ==> lib [gcc]
|
|
||||||
arg [-lc] ==> lib [c]
|
|
||||||
arg [-lgcc_s] ==> lib [gcc_s]
|
|
||||||
arg [-lgcc] ==> lib [gcc]
|
|
||||||
arg [/usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o] ==> obj [/usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o]
|
|
||||||
arg [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o] ==> obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o]
|
|
||||||
collapse obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o] ==> [/usr/lib/x86_64-linux-gnu/Scrt1.o]
|
|
||||||
collapse obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o] ==> [/usr/lib/x86_64-linux-gnu/crti.o]
|
|
||||||
collapse obj [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o] ==> [/usr/lib/x86_64-linux-gnu/crtn.o]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13] ==> [/usr/lib/gcc/x86_64-linux-gnu/13]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib] ==> [/usr/lib]
|
|
||||||
collapse library dir [/lib/x86_64-linux-gnu] ==> [/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/lib/../lib] ==> [/lib]
|
|
||||||
collapse library dir [/usr/lib/x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/usr/lib/../lib] ==> [/usr/lib]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../..] ==> [/usr/lib]
|
|
||||||
implicit libs: [stdc++;m;gcc_s;gcc;c;gcc_s;gcc]
|
|
||||||
implicit objs: [/usr/lib/x86_64-linux-gnu/Scrt1.o;/usr/lib/x86_64-linux-gnu/crti.o;/usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o;/usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o;/usr/lib/x86_64-linux-gnu/crtn.o]
|
|
||||||
implicit dirs: [/usr/lib/gcc/x86_64-linux-gnu/13;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib]
|
|
||||||
implicit fwks: []
|
|
||||||
|
|
||||||
|
|
||||||
-
|
|
||||||
kind: "try_compile-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:219 (try_compile)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:486 (_OPENMP_GET_FLAGS)"
|
|
||||||
- "CMakeLists.txt:77 (find_package)"
|
|
||||||
description: "Detecting CXX OpenMP compiler info"
|
|
||||||
directories:
|
|
||||||
source: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz"
|
|
||||||
binary: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz"
|
|
||||||
cmakeVariables:
|
|
||||||
CMAKE_CXX_FLAGS: ""
|
|
||||||
CMAKE_CXX_FLAGS_DEBUG: "-g"
|
|
||||||
CMAKE_EXE_LINKER_FLAGS: ""
|
|
||||||
buildResult:
|
|
||||||
variable: "OpenMP_COMPILE_RESULT_CXX_fopenmp"
|
|
||||||
cached: true
|
|
||||||
stdout: |
|
|
||||||
Change Dir: '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz'
|
|
||||||
|
|
||||||
Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_0b68f/fast
|
|
||||||
/usr/bin/gmake -f CMakeFiles/cmTC_0b68f.dir/build.make CMakeFiles/cmTC_0b68f.dir/build
|
|
||||||
gmake[1]: Entering directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz'
|
|
||||||
Building CXX object CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o
|
|
||||||
/usr/bin/c++ -fopenmp -v -std=c++11 -o CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -c /home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz/OpenMPTryFlag.cpp
|
|
||||||
Using built-in specs.
|
|
||||||
COLLECT_GCC=/usr/bin/c++
|
|
||||||
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
|
|
||||||
OFFLOAD_TARGET_DEFAULT=1
|
|
||||||
Target: x86_64-linux-gnu
|
|
||||||
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
|
|
||||||
Thread model: posix
|
|
||||||
Supported LTO compression algorithms: zlib zstd
|
|
||||||
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1)
|
|
||||||
COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/'
|
|
||||||
/usr/libexec/gcc/x86_64-linux-gnu/13/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D_REENTRANT /home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz/OpenMPTryFlag.cpp -quiet -dumpdir CMakeFiles/cmTC_0b68f.dir/ -dumpbase OpenMPTryFlag.cpp.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++11 -version -fopenmp -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccCnQ37x.s
|
|
||||||
GNU C++11 (Ubuntu 13.3.0-6ubuntu2~24.04.1) version 13.3.0 (x86_64-linux-gnu)
|
|
||||||
compiled by GNU C version 13.3.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP
|
|
||||||
|
|
||||||
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
|
|
||||||
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/13"
|
|
||||||
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"
|
|
||||||
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
|
|
||||||
#include "..." search starts here:
|
|
||||||
#include <...> search starts here:
|
|
||||||
/usr/include/c++/13
|
|
||||||
/usr/include/x86_64-linux-gnu/c++/13
|
|
||||||
/usr/include/c++/13/backward
|
|
||||||
/usr/lib/gcc/x86_64-linux-gnu/13/include
|
|
||||||
/usr/local/include
|
|
||||||
/usr/include/x86_64-linux-gnu
|
|
||||||
/usr/include
|
|
||||||
End of search list.
|
|
||||||
Compiler executable checksum: 7896445e4990772fdae9dc0659a99266
|
|
||||||
COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/'
|
|
||||||
as -v --64 -o CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o /tmp/ccCnQ37x.s
|
|
||||||
GNU assembler version 2.42 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.42
|
|
||||||
COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/
|
|
||||||
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/
|
|
||||||
COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.'
|
|
||||||
Linking CXX executable cmTC_0b68f
|
|
||||||
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0b68f.dir/link.txt --verbose=1
|
|
||||||
/usr/bin/c++ -fopenmp -v CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -o cmTC_0b68f -v
|
|
||||||
Using built-in specs.
|
|
||||||
COLLECT_GCC=/usr/bin/c++
|
|
||||||
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
|
|
||||||
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
|
|
||||||
OFFLOAD_TARGET_DEFAULT=1
|
|
||||||
Target: x86_64-linux-gnu
|
|
||||||
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
|
|
||||||
Thread model: posix
|
|
||||||
Supported LTO compression algorithms: zlib zstd
|
|
||||||
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1)
|
|
||||||
COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/
|
|
||||||
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/
|
|
||||||
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/13/libgomp.spec
|
|
||||||
COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-o' 'cmTC_0b68f' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'cmTC_0b68f.'
|
|
||||||
/usr/libexec/gcc/x86_64-linux-gnu/13/collect2 -plugin /usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper -plugin-opt=-fresolution=/tmp/cc3uGT27.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_0b68f /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o /usr/lib/gcc/x86_64-linux-gnu/13/crtoffloadbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/13 -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/13/../../.. CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -lstdc++ -lm -lgomp -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o /usr/lib/gcc/x86_64-linux-gnu/13/crtoffloadend.o
|
|
||||||
COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-o' 'cmTC_0b68f' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'cmTC_0b68f.'
|
|
||||||
gmake[1]: Leaving directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz'
|
|
||||||
|
|
||||||
exitCode: 0
|
|
||||||
-
|
|
||||||
kind: "message-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:262 (message)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:486 (_OPENMP_GET_FLAGS)"
|
|
||||||
- "CMakeLists.txt:77 (find_package)"
|
|
||||||
message: |
|
|
||||||
Parsed CXX OpenMP implicit link information from above output:
|
|
||||||
link line regex: [^( *|.*[/\\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\\]+-)?ld|collect2)[^/\\]*( |$)]
|
|
||||||
ignore line: [Change Dir: '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz']
|
|
||||||
ignore line: []
|
|
||||||
ignore line: [Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_0b68f/fast]
|
|
||||||
ignore line: [/usr/bin/gmake -f CMakeFiles/cmTC_0b68f.dir/build.make CMakeFiles/cmTC_0b68f.dir/build]
|
|
||||||
ignore line: [gmake[1]: Entering directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz']
|
|
||||||
ignore line: [Building CXX object CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o]
|
|
||||||
ignore line: [/usr/bin/c++ -fopenmp -v -std=c++11 -o CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -c /home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz/OpenMPTryFlag.cpp]
|
|
||||||
ignore line: [Using built-in specs.]
|
|
||||||
ignore line: [COLLECT_GCC=/usr/bin/c++]
|
|
||||||
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa]
|
|
||||||
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
|
|
||||||
ignore line: [Target: x86_64-linux-gnu]
|
|
||||||
ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c ada c++ go d fortran objc obj-c++ m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2]
|
|
||||||
ignore line: [Thread model: posix]
|
|
||||||
ignore line: [Supported LTO compression algorithms: zlib zstd]
|
|
||||||
ignore line: [gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) ]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/']
|
|
||||||
ignore line: [ /usr/libexec/gcc/x86_64-linux-gnu/13/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D_REENTRANT /home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-0Y8Dzz/OpenMPTryFlag.cpp -quiet -dumpdir CMakeFiles/cmTC_0b68f.dir/ -dumpbase OpenMPTryFlag.cpp.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++11 -version -fopenmp -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccCnQ37x.s]
|
|
||||||
ignore line: [GNU C++11 (Ubuntu 13.3.0-6ubuntu2~24.04.1) version 13.3.0 (x86_64-linux-gnu)]
|
|
||||||
ignore line: [ compiled by GNU C version 13.3.0 GMP version 6.3.0 MPFR version 4.2.1 MPC version 1.3.1 isl version isl-0.26-GMP]
|
|
||||||
ignore line: []
|
|
||||||
ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
|
|
||||||
ignore line: [ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/13"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"]
|
|
||||||
ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"]
|
|
||||||
ignore line: [#include "..." search starts here:]
|
|
||||||
ignore line: [#include <...> search starts here:]
|
|
||||||
ignore line: [ /usr/include/c++/13]
|
|
||||||
ignore line: [ /usr/include/x86_64-linux-gnu/c++/13]
|
|
||||||
ignore line: [ /usr/include/c++/13/backward]
|
|
||||||
ignore line: [ /usr/lib/gcc/x86_64-linux-gnu/13/include]
|
|
||||||
ignore line: [ /usr/local/include]
|
|
||||||
ignore line: [ /usr/include/x86_64-linux-gnu]
|
|
||||||
ignore line: [ /usr/include]
|
|
||||||
ignore line: [End of search list.]
|
|
||||||
ignore line: [Compiler executable checksum: 7896445e4990772fdae9dc0659a99266]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/']
|
|
||||||
ignore line: [ as -v --64 -o CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o /tmp/ccCnQ37x.s]
|
|
||||||
ignore line: [GNU assembler version 2.42 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.42]
|
|
||||||
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/]
|
|
||||||
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-std=c++11' '-o' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.']
|
|
||||||
ignore line: [Linking CXX executable cmTC_0b68f]
|
|
||||||
ignore line: [/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0b68f.dir/link.txt --verbose=1]
|
|
||||||
ignore line: [/usr/bin/c++ -fopenmp -v CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -o cmTC_0b68f -v ]
|
|
||||||
ignore line: [Using built-in specs.]
|
|
||||||
ignore line: [COLLECT_GCC=/usr/bin/c++]
|
|
||||||
ignore line: [COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper]
|
|
||||||
ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa]
|
|
||||||
ignore line: [OFFLOAD_TARGET_DEFAULT=1]
|
|
||||||
ignore line: [Target: x86_64-linux-gnu]
|
|
||||||
ignore line: [Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c ada c++ go d fortran objc obj-c++ m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32 m64 mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2]
|
|
||||||
ignore line: [Thread model: posix]
|
|
||||||
ignore line: [Supported LTO compression algorithms: zlib zstd]
|
|
||||||
ignore line: [gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) ]
|
|
||||||
ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/13/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/]
|
|
||||||
ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/13/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/13/../../../:/lib/:/usr/lib/]
|
|
||||||
ignore line: [Reading specs from /usr/lib/gcc/x86_64-linux-gnu/13/libgomp.spec]
|
|
||||||
ignore line: [COLLECT_GCC_OPTIONS='-fopenmp' '-v' '-o' 'cmTC_0b68f' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread' '-dumpdir' 'cmTC_0b68f.']
|
|
||||||
link line: [ /usr/libexec/gcc/x86_64-linux-gnu/13/collect2 -plugin /usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper -plugin-opt=-fresolution=/tmp/cc3uGT27.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o cmTC_0b68f /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o /usr/lib/gcc/x86_64-linux-gnu/13/crtoffloadbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/13 -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/13/../../.. CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o -lstdc++ -lm -lgomp -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/13/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crtn.o /usr/lib/gcc/x86_64-linux-gnu/13/crtoffloadend.o]
|
|
||||||
arg [/usr/libexec/gcc/x86_64-linux-gnu/13/collect2] ==> ignore
|
|
||||||
arg [-plugin] ==> ignore
|
|
||||||
arg [/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so] ==> ignore
|
|
||||||
arg [-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper] ==> ignore
|
|
||||||
arg [-plugin-opt=-fresolution=/tmp/cc3uGT27.res] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lpthread] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lc] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
|
|
||||||
arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
|
|
||||||
arg [--build-id] ==> ignore
|
|
||||||
arg [--eh-frame-hdr] ==> ignore
|
|
||||||
arg [-m] ==> ignore
|
|
||||||
arg [elf_x86_64] ==> ignore
|
|
||||||
arg [--hash-style=gnu] ==> ignore
|
|
||||||
arg [--as-needed] ==> ignore
|
|
||||||
arg [-dynamic-linker] ==> ignore
|
|
||||||
arg [/lib64/ld-linux-x86-64.so.2] ==> ignore
|
|
||||||
arg [-pie] ==> ignore
|
|
||||||
arg [-znow] ==> ignore
|
|
||||||
arg [-zrelro] ==> ignore
|
|
||||||
arg [-o] ==> ignore
|
|
||||||
arg [cmTC_0b68f] ==> ignore
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib]
|
|
||||||
arg [-L/lib/x86_64-linux-gnu] ==> dir [/lib/x86_64-linux-gnu]
|
|
||||||
arg [-L/lib/../lib] ==> dir [/lib/../lib]
|
|
||||||
arg [-L/usr/lib/x86_64-linux-gnu] ==> dir [/usr/lib/x86_64-linux-gnu]
|
|
||||||
arg [-L/usr/lib/../lib] ==> dir [/usr/lib/../lib]
|
|
||||||
arg [-L/usr/lib/gcc/x86_64-linux-gnu/13/../../..] ==> dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../..]
|
|
||||||
arg [CMakeFiles/cmTC_0b68f.dir/OpenMPTryFlag.cpp.o] ==> ignore
|
|
||||||
arg [-lstdc++] ==> lib [stdc++]
|
|
||||||
arg [-lm] ==> lib [m]
|
|
||||||
arg [-lgomp] ==> lib [gomp]
|
|
||||||
arg [-lgcc_s] ==> lib [gcc_s]
|
|
||||||
arg [-lgcc] ==> lib [gcc]
|
|
||||||
arg [-lpthread] ==> lib [pthread]
|
|
||||||
arg [-lc] ==> lib [c]
|
|
||||||
arg [-lgcc_s] ==> lib [gcc_s]
|
|
||||||
arg [-lgcc] ==> lib [gcc]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13] ==> [/usr/lib/gcc/x86_64-linux-gnu/13]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../../../lib] ==> [/usr/lib]
|
|
||||||
collapse library dir [/lib/x86_64-linux-gnu] ==> [/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/lib/../lib] ==> [/lib]
|
|
||||||
collapse library dir [/usr/lib/x86_64-linux-gnu] ==> [/usr/lib/x86_64-linux-gnu]
|
|
||||||
collapse library dir [/usr/lib/../lib] ==> [/usr/lib]
|
|
||||||
collapse library dir [/usr/lib/gcc/x86_64-linux-gnu/13/../../..] ==> [/usr/lib]
|
|
||||||
implicit libs: [stdc++;m;gomp;gcc_s;gcc;pthread;c;gcc_s;gcc]
|
|
||||||
implicit objs: []
|
|
||||||
implicit dirs: [/usr/lib/gcc/x86_64-linux-gnu/13;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib]
|
|
||||||
implicit fwks: []
|
|
||||||
|
|
||||||
|
|
||||||
-
|
|
||||||
kind: "try_compile-v1"
|
|
||||||
backtrace:
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:420 (try_compile)"
|
|
||||||
- "/usr/share/cmake-3.28/Modules/FindOpenMP.cmake:560 (_OPENMP_GET_SPEC_DATE)"
|
|
||||||
- "CMakeLists.txt:77 (find_package)"
|
|
||||||
description: "Detecting CXX OpenMP version"
|
|
||||||
directories:
|
|
||||||
source: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf"
|
|
||||||
binary: "/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf"
|
|
||||||
cmakeVariables:
|
|
||||||
CMAKE_CXX_FLAGS: ""
|
|
||||||
CMAKE_CXX_FLAGS_DEBUG: "-g"
|
|
||||||
CMAKE_EXE_LINKER_FLAGS: ""
|
|
||||||
buildResult:
|
|
||||||
variable: "OpenMP_SPECTEST_CXX_"
|
|
||||||
cached: true
|
|
||||||
stdout: |
|
|
||||||
Change Dir: '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf'
|
|
||||||
|
|
||||||
Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_71bac/fast
|
|
||||||
/usr/bin/gmake -f CMakeFiles/cmTC_71bac.dir/build.make CMakeFiles/cmTC_71bac.dir/build
|
|
||||||
gmake[1]: Entering directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf'
|
|
||||||
Building CXX object CMakeFiles/cmTC_71bac.dir/OpenMPCheckVersion.cpp.o
|
|
||||||
/usr/bin/c++ -fopenmp -std=c++11 -o CMakeFiles/cmTC_71bac.dir/OpenMPCheckVersion.cpp.o -c /home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf/OpenMPCheckVersion.cpp
|
|
||||||
Linking CXX executable cmTC_71bac
|
|
||||||
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_71bac.dir/link.txt --verbose=1
|
|
||||||
/usr/bin/c++ -fopenmp CMakeFiles/cmTC_71bac.dir/OpenMPCheckVersion.cpp.o -o cmTC_71bac
|
|
||||||
gmake[1]: Leaving directory '/home/atlas/Documents/Git/panic/build/CMakeFiles/CMakeScratch/TryCompile-kDANSf'
|
|
||||||
|
|
||||||
exitCode: 0
|
|
||||||
...
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# Relative path conversion top directories.
|
|
||||||
set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/atlas/Documents/Git/panic")
|
|
||||||
set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/atlas/Documents/Git/panic/build")
|
|
||||||
|
|
||||||
# Force unix paths in dependencies.
|
|
||||||
set(CMAKE_FORCE_UNIX_PATHS 1)
|
|
||||||
|
|
||||||
|
|
||||||
# The C and CXX include file regular expressions for this directory.
|
|
||||||
set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$")
|
|
||||||
set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$")
|
|
||||||
set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})
|
|
||||||
set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})
|
|
||||||
Binary file not shown.
@@ -1,111 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# The generator used is:
|
|
||||||
set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles")
|
|
||||||
|
|
||||||
# The top level Makefile was generated from the following files:
|
|
||||||
set(CMAKE_MAKEFILE_DEPENDS
|
|
||||||
"CMakeCache.txt"
|
|
||||||
"/home/atlas/Documents/Git/panic/CMakeLists.txt"
|
|
||||||
"CMakeFiles/3.28.3/CMakeCXXCompiler.cmake"
|
|
||||||
"CMakeFiles/3.28.3/CMakeSystem.cmake"
|
|
||||||
"CMakeFiles/VerifyGlobs.cmake"
|
|
||||||
"CMakeFiles/cmake.verify_globs"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeCXXCompiler.cmake.in"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeCXXCompilerABI.cpp"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeCXXInformation.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeCommonLanguageInclude.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeCompilerIdDetection.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineCXXCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineCompileFeatures.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerABI.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineCompilerId.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeDetermineSystem.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeFindBinUtils.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeGenericSystem.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeInitializeConfigs.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeLanguageInformation.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeParseImplicitIncludeInfo.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeParseImplicitLinkInfo.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeParseLibraryArchitecture.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeSystem.cmake.in"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeSystemSpecificInformation.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeSystemSpecificInitialize.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeTestCompilerCommon.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/CMakeUnixFindMake.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/ADSP-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/ARMCC-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/ARMClang-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/AppleClang-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Borland-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/CMakeCommonCompilerMacros.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Clang-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Clang-DetermineCompilerInternal.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Cray-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/CrayClang-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Embarcadero-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Fujitsu-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/FujitsuClang-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/GHS-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/GNU-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/GNU-CXX.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/GNU-FindBinUtils.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/GNU.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/HP-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/IAR-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/IBMClang-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Intel-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/IntelLLVM-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/LCC-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/MSVC-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/NVHPC-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/NVIDIA-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/OrangeC-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/PGI-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/PathScale-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/SCO-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/TI-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Tasking-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/Watcom-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/XL-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/XLClang-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/FindOpenMP.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/FindPackageMessage.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Internal/FeatureTesting.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/Linux-Determine-CXX.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/Linux-GNU-CXX.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/Linux-GNU.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/Linux-Initialize.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/Linux.cmake"
|
|
||||||
"/usr/share/cmake-3.28/Modules/Platform/UnixPaths.cmake"
|
|
||||||
)
|
|
||||||
|
|
||||||
# The corresponding makefile is:
|
|
||||||
set(CMAKE_MAKEFILE_OUTPUTS
|
|
||||||
"Makefile"
|
|
||||||
"CMakeFiles/cmake.check_cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Byproducts of CMake generate step:
|
|
||||||
set(CMAKE_MAKEFILE_PRODUCTS
|
|
||||||
"CMakeFiles/3.28.3/CMakeSystem.cmake"
|
|
||||||
"CMakeFiles/3.28.3/CMakeCXXCompiler.cmake"
|
|
||||||
"CMakeFiles/3.28.3/CMakeCXXCompiler.cmake"
|
|
||||||
"CMakeFiles/CMakeDirectoryInformation.cmake"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Dependency information for all targets:
|
|
||||||
set(CMAKE_DEPEND_INFO_FILES
|
|
||||||
"CMakeFiles/panic.dir/DependInfo.cmake"
|
|
||||||
)
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# Default target executed when no arguments are given to make.
|
|
||||||
default_target: all
|
|
||||||
.PHONY : default_target
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Special targets provided by cmake.
|
|
||||||
|
|
||||||
# Disable implicit rules so canonical targets will work.
|
|
||||||
.SUFFIXES:
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : %,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : SCCS/s.%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : s.%
|
|
||||||
|
|
||||||
.SUFFIXES: .hpux_make_needs_suffix_list
|
|
||||||
|
|
||||||
# Command-line flag to silence nested $(MAKE).
|
|
||||||
$(VERBOSE)MAKESILENT = -s
|
|
||||||
|
|
||||||
#Suppress display of executed commands.
|
|
||||||
$(VERBOSE).SILENT:
|
|
||||||
|
|
||||||
# A target that is always out of date.
|
|
||||||
cmake_force:
|
|
||||||
.PHONY : cmake_force
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Set environment variables for the build.
|
|
||||||
|
|
||||||
# The shell in which to execute make rules.
|
|
||||||
SHELL = /bin/sh
|
|
||||||
|
|
||||||
# The CMake executable.
|
|
||||||
CMAKE_COMMAND = /usr/bin/cmake
|
|
||||||
|
|
||||||
# The command to remove a file.
|
|
||||||
RM = /usr/bin/cmake -E rm -f
|
|
||||||
|
|
||||||
# Escaping for special characters.
|
|
||||||
EQUALS = =
|
|
||||||
|
|
||||||
# The top-level source directory on which CMake was run.
|
|
||||||
CMAKE_SOURCE_DIR = /home/atlas/Documents/Git/panic
|
|
||||||
|
|
||||||
# The top-level build directory on which CMake was run.
|
|
||||||
CMAKE_BINARY_DIR = /home/atlas/Documents/Git/panic/build
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Directory level rules for the build root directory
|
|
||||||
|
|
||||||
# The main recursive "all" target.
|
|
||||||
all: CMakeFiles/panic.dir/all
|
|
||||||
.PHONY : all
|
|
||||||
|
|
||||||
# The main recursive "preinstall" target.
|
|
||||||
preinstall:
|
|
||||||
.PHONY : preinstall
|
|
||||||
|
|
||||||
# The main recursive "clean" target.
|
|
||||||
clean: CMakeFiles/panic.dir/clean
|
|
||||||
.PHONY : clean
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Target rules for target CMakeFiles/panic.dir
|
|
||||||
|
|
||||||
# All Build rule for target.
|
|
||||||
CMakeFiles/panic.dir/all:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/depend
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/build
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=1,2,3,4,5 "Built target panic"
|
|
||||||
.PHONY : CMakeFiles/panic.dir/all
|
|
||||||
|
|
||||||
# Build rule for subdir invocation for target.
|
|
||||||
CMakeFiles/panic.dir/rule: cmake_check_build_system
|
|
||||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/atlas/Documents/Git/panic/build/CMakeFiles 5
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 CMakeFiles/panic.dir/all
|
|
||||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/atlas/Documents/Git/panic/build/CMakeFiles 0
|
|
||||||
.PHONY : CMakeFiles/panic.dir/rule
|
|
||||||
|
|
||||||
# Convenience name for target.
|
|
||||||
panic: CMakeFiles/panic.dir/rule
|
|
||||||
.PHONY : panic
|
|
||||||
|
|
||||||
# clean rule for target.
|
|
||||||
CMakeFiles/panic.dir/clean:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/clean
|
|
||||||
.PHONY : CMakeFiles/panic.dir/clean
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Special targets to cleanup operation of make.
|
|
||||||
|
|
||||||
# Special rule to run CMake to check the build system integrity.
|
|
||||||
# No rule that depends on this can have commands that come from listfiles
|
|
||||||
# because they might be regenerated.
|
|
||||||
cmake_check_build_system:
|
|
||||||
$(CMAKE_COMMAND) -P /home/atlas/Documents/Git/panic/build/CMakeFiles/VerifyGlobs.cmake
|
|
||||||
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
|
|
||||||
.PHONY : cmake_check_build_system
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
/home/atlas/Documents/Git/panic/build/CMakeFiles/panic.dir
|
|
||||||
/home/atlas/Documents/Git/panic/build/CMakeFiles/edit_cache.dir
|
|
||||||
/home/atlas/Documents/Git/panic/build/CMakeFiles/rebuild_cache.dir
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by CMake Version 3.28
|
|
||||||
cmake_policy(SET CMP0009 NEW)
|
|
||||||
|
|
||||||
# PANIC_SOURCES at CMakeLists.txt:40 (file)
|
|
||||||
file(GLOB_RECURSE NEW_GLOB LIST_DIRECTORIES false "/home/atlas/Documents/Git/panic/src/*.cpp")
|
|
||||||
set(OLD_GLOB
|
|
||||||
"/home/atlas/Documents/Git/panic/src/io/print_tensor.cpp"
|
|
||||||
"/home/atlas/Documents/Git/panic/src/tensor/matrix.cpp"
|
|
||||||
"/home/atlas/Documents/Git/panic/src/tensor/vector.cpp"
|
|
||||||
)
|
|
||||||
if(NOT "${NEW_GLOB}" STREQUAL "${OLD_GLOB}")
|
|
||||||
message("-- GLOB mismatch!")
|
|
||||||
file(TOUCH_NOCREATE "/home/atlas/Documents/Git/panic/build/CMakeFiles/cmake.verify_globs")
|
|
||||||
endif()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
# This file is generated by cmake for dependency checking of the CMakeCache.txt file
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
# This file is generated by CMake for checking of the VerifyGlobs.cmake file
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
# Consider dependencies only in project.
|
|
||||||
set(CMAKE_DEPENDS_IN_PROJECT_ONLY OFF)
|
|
||||||
|
|
||||||
# The set of languages for which implicit dependencies are needed:
|
|
||||||
set(CMAKE_DEPENDS_LANGUAGES
|
|
||||||
)
|
|
||||||
|
|
||||||
# The set of dependency files which are needed:
|
|
||||||
set(CMAKE_DEPENDS_DEPENDENCY_FILES
|
|
||||||
"/home/atlas/Documents/Git/panic/main.cpp" "CMakeFiles/panic.dir/main.cpp.o" "gcc" "CMakeFiles/panic.dir/main.cpp.o.d"
|
|
||||||
"/home/atlas/Documents/Git/panic/src/io/print_tensor.cpp" "CMakeFiles/panic.dir/src/io/print_tensor.cpp.o" "gcc" "CMakeFiles/panic.dir/src/io/print_tensor.cpp.o.d"
|
|
||||||
"/home/atlas/Documents/Git/panic/src/tensor/matrix.cpp" "CMakeFiles/panic.dir/src/tensor/matrix.cpp.o" "gcc" "CMakeFiles/panic.dir/src/tensor/matrix.cpp.o.d"
|
|
||||||
"/home/atlas/Documents/Git/panic/src/tensor/vector.cpp" "CMakeFiles/panic.dir/src/tensor/vector.cpp.o" "gcc" "CMakeFiles/panic.dir/src/tensor/vector.cpp.o.d"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Targets to which this target links which contain Fortran sources.
|
|
||||||
set(CMAKE_Fortran_TARGET_LINKED_INFO_FILES
|
|
||||||
)
|
|
||||||
|
|
||||||
# Targets to which this target links which contain Fortran sources.
|
|
||||||
set(CMAKE_Fortran_TARGET_FORWARD_LINKED_INFO_FILES
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fortran module output directory.
|
|
||||||
set(CMAKE_Fortran_TARGET_MODULE_DIR "")
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# Delete rule output on recipe failure.
|
|
||||||
.DELETE_ON_ERROR:
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Special targets provided by cmake.
|
|
||||||
|
|
||||||
# Disable implicit rules so canonical targets will work.
|
|
||||||
.SUFFIXES:
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : %,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : SCCS/s.%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : s.%
|
|
||||||
|
|
||||||
.SUFFIXES: .hpux_make_needs_suffix_list
|
|
||||||
|
|
||||||
# Command-line flag to silence nested $(MAKE).
|
|
||||||
$(VERBOSE)MAKESILENT = -s
|
|
||||||
|
|
||||||
#Suppress display of executed commands.
|
|
||||||
$(VERBOSE).SILENT:
|
|
||||||
|
|
||||||
# A target that is always out of date.
|
|
||||||
cmake_force:
|
|
||||||
.PHONY : cmake_force
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Set environment variables for the build.
|
|
||||||
|
|
||||||
# The shell in which to execute make rules.
|
|
||||||
SHELL = /bin/sh
|
|
||||||
|
|
||||||
# The CMake executable.
|
|
||||||
CMAKE_COMMAND = /usr/bin/cmake
|
|
||||||
|
|
||||||
# The command to remove a file.
|
|
||||||
RM = /usr/bin/cmake -E rm -f
|
|
||||||
|
|
||||||
# Escaping for special characters.
|
|
||||||
EQUALS = =
|
|
||||||
|
|
||||||
# The top-level source directory on which CMake was run.
|
|
||||||
CMAKE_SOURCE_DIR = /home/atlas/Documents/Git/panic
|
|
||||||
|
|
||||||
# The top-level build directory on which CMake was run.
|
|
||||||
CMAKE_BINARY_DIR = /home/atlas/Documents/Git/panic/build
|
|
||||||
|
|
||||||
# Include any dependencies generated for this target.
|
|
||||||
include CMakeFiles/panic.dir/depend.make
|
|
||||||
# Include any dependencies generated by the compiler for this target.
|
|
||||||
include CMakeFiles/panic.dir/compiler_depend.make
|
|
||||||
|
|
||||||
# Include the progress variables for this target.
|
|
||||||
include CMakeFiles/panic.dir/progress.make
|
|
||||||
|
|
||||||
# Include the compile flags for this target's objects.
|
|
||||||
include CMakeFiles/panic.dir/flags.make
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/main.cpp.o: CMakeFiles/panic.dir/flags.make
|
|
||||||
CMakeFiles/panic.dir/main.cpp.o: /home/atlas/Documents/Git/panic/main.cpp
|
|
||||||
CMakeFiles/panic.dir/main.cpp.o: CMakeFiles/panic.dir/compiler_depend.ts
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/panic.dir/main.cpp.o"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/panic.dir/main.cpp.o -MF CMakeFiles/panic.dir/main.cpp.o.d -o CMakeFiles/panic.dir/main.cpp.o -c /home/atlas/Documents/Git/panic/main.cpp
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/main.cpp.i: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Preprocessing CXX source to CMakeFiles/panic.dir/main.cpp.i"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/atlas/Documents/Git/panic/main.cpp > CMakeFiles/panic.dir/main.cpp.i
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/main.cpp.s: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Compiling CXX source to assembly CMakeFiles/panic.dir/main.cpp.s"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/atlas/Documents/Git/panic/main.cpp -o CMakeFiles/panic.dir/main.cpp.s
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/io/print_tensor.cpp.o: CMakeFiles/panic.dir/flags.make
|
|
||||||
CMakeFiles/panic.dir/src/io/print_tensor.cpp.o: /home/atlas/Documents/Git/panic/src/io/print_tensor.cpp
|
|
||||||
CMakeFiles/panic.dir/src/io/print_tensor.cpp.o: CMakeFiles/panic.dir/compiler_depend.ts
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Building CXX object CMakeFiles/panic.dir/src/io/print_tensor.cpp.o"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/panic.dir/src/io/print_tensor.cpp.o -MF CMakeFiles/panic.dir/src/io/print_tensor.cpp.o.d -o CMakeFiles/panic.dir/src/io/print_tensor.cpp.o -c /home/atlas/Documents/Git/panic/src/io/print_tensor.cpp
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/io/print_tensor.cpp.i: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Preprocessing CXX source to CMakeFiles/panic.dir/src/io/print_tensor.cpp.i"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/atlas/Documents/Git/panic/src/io/print_tensor.cpp > CMakeFiles/panic.dir/src/io/print_tensor.cpp.i
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/io/print_tensor.cpp.s: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Compiling CXX source to assembly CMakeFiles/panic.dir/src/io/print_tensor.cpp.s"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/atlas/Documents/Git/panic/src/io/print_tensor.cpp -o CMakeFiles/panic.dir/src/io/print_tensor.cpp.s
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/matrix.cpp.o: CMakeFiles/panic.dir/flags.make
|
|
||||||
CMakeFiles/panic.dir/src/tensor/matrix.cpp.o: /home/atlas/Documents/Git/panic/src/tensor/matrix.cpp
|
|
||||||
CMakeFiles/panic.dir/src/tensor/matrix.cpp.o: CMakeFiles/panic.dir/compiler_depend.ts
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Building CXX object CMakeFiles/panic.dir/src/tensor/matrix.cpp.o"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/panic.dir/src/tensor/matrix.cpp.o -MF CMakeFiles/panic.dir/src/tensor/matrix.cpp.o.d -o CMakeFiles/panic.dir/src/tensor/matrix.cpp.o -c /home/atlas/Documents/Git/panic/src/tensor/matrix.cpp
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/matrix.cpp.i: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Preprocessing CXX source to CMakeFiles/panic.dir/src/tensor/matrix.cpp.i"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/atlas/Documents/Git/panic/src/tensor/matrix.cpp > CMakeFiles/panic.dir/src/tensor/matrix.cpp.i
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/matrix.cpp.s: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Compiling CXX source to assembly CMakeFiles/panic.dir/src/tensor/matrix.cpp.s"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/atlas/Documents/Git/panic/src/tensor/matrix.cpp -o CMakeFiles/panic.dir/src/tensor/matrix.cpp.s
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/vector.cpp.o: CMakeFiles/panic.dir/flags.make
|
|
||||||
CMakeFiles/panic.dir/src/tensor/vector.cpp.o: /home/atlas/Documents/Git/panic/src/tensor/vector.cpp
|
|
||||||
CMakeFiles/panic.dir/src/tensor/vector.cpp.o: CMakeFiles/panic.dir/compiler_depend.ts
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_4) "Building CXX object CMakeFiles/panic.dir/src/tensor/vector.cpp.o"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/panic.dir/src/tensor/vector.cpp.o -MF CMakeFiles/panic.dir/src/tensor/vector.cpp.o.d -o CMakeFiles/panic.dir/src/tensor/vector.cpp.o -c /home/atlas/Documents/Git/panic/src/tensor/vector.cpp
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/vector.cpp.i: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Preprocessing CXX source to CMakeFiles/panic.dir/src/tensor/vector.cpp.i"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/atlas/Documents/Git/panic/src/tensor/vector.cpp > CMakeFiles/panic.dir/src/tensor/vector.cpp.i
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/src/tensor/vector.cpp.s: cmake_force
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green "Compiling CXX source to assembly CMakeFiles/panic.dir/src/tensor/vector.cpp.s"
|
|
||||||
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/atlas/Documents/Git/panic/src/tensor/vector.cpp -o CMakeFiles/panic.dir/src/tensor/vector.cpp.s
|
|
||||||
|
|
||||||
# Object files for target panic
|
|
||||||
panic_OBJECTS = \
|
|
||||||
"CMakeFiles/panic.dir/main.cpp.o" \
|
|
||||||
"CMakeFiles/panic.dir/src/io/print_tensor.cpp.o" \
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/matrix.cpp.o" \
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/vector.cpp.o"
|
|
||||||
|
|
||||||
# External object files for target panic
|
|
||||||
panic_EXTERNAL_OBJECTS =
|
|
||||||
|
|
||||||
panic: CMakeFiles/panic.dir/main.cpp.o
|
|
||||||
panic: CMakeFiles/panic.dir/src/io/print_tensor.cpp.o
|
|
||||||
panic: CMakeFiles/panic.dir/src/tensor/matrix.cpp.o
|
|
||||||
panic: CMakeFiles/panic.dir/src/tensor/vector.cpp.o
|
|
||||||
panic: CMakeFiles/panic.dir/build.make
|
|
||||||
panic: /usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so
|
|
||||||
panic: /usr/lib/x86_64-linux-gnu/libpthread.a
|
|
||||||
panic: CMakeFiles/panic.dir/link.txt
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --bold --progress-dir=/home/atlas/Documents/Git/panic/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_5) "Linking CXX executable panic"
|
|
||||||
$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/panic.dir/link.txt --verbose=$(VERBOSE)
|
|
||||||
|
|
||||||
# Rule to build all files generated by this target.
|
|
||||||
CMakeFiles/panic.dir/build: panic
|
|
||||||
.PHONY : CMakeFiles/panic.dir/build
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/clean:
|
|
||||||
$(CMAKE_COMMAND) -P CMakeFiles/panic.dir/cmake_clean.cmake
|
|
||||||
.PHONY : CMakeFiles/panic.dir/clean
|
|
||||||
|
|
||||||
CMakeFiles/panic.dir/depend:
|
|
||||||
cd /home/atlas/Documents/Git/panic/build && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/atlas/Documents/Git/panic /home/atlas/Documents/Git/panic /home/atlas/Documents/Git/panic/build /home/atlas/Documents/Git/panic/build /home/atlas/Documents/Git/panic/build/CMakeFiles/panic.dir/DependInfo.cmake "--color=$(COLOR)"
|
|
||||||
.PHONY : CMakeFiles/panic.dir/depend
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
file(REMOVE_RECURSE
|
|
||||||
"CMakeFiles/panic.dir/main.cpp.o"
|
|
||||||
"CMakeFiles/panic.dir/main.cpp.o.d"
|
|
||||||
"CMakeFiles/panic.dir/src/io/print_tensor.cpp.o"
|
|
||||||
"CMakeFiles/panic.dir/src/io/print_tensor.cpp.o.d"
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/matrix.cpp.o"
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/matrix.cpp.o.d"
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/vector.cpp.o"
|
|
||||||
"CMakeFiles/panic.dir/src/tensor/vector.cpp.o.d"
|
|
||||||
"panic"
|
|
||||||
"panic.pdb"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Per-language clean rules from dependency scanning.
|
|
||||||
foreach(lang CXX)
|
|
||||||
include(CMakeFiles/panic.dir/cmake_clean_${lang}.cmake OPTIONAL)
|
|
||||||
endforeach()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# Empty compiler generated dependencies file for panic.
|
|
||||||
# This may be replaced when dependencies are built.
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Timestamp file for compiler generated dependencies management for panic.
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# Empty dependencies file for panic.
|
|
||||||
# This may be replaced when dependencies are built.
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# compile CXX with /usr/bin/c++
|
|
||||||
CXX_DEFINES = -DPANIC_OMP_ALLOW_NESTED=0 -DPANIC_OMP_NUM_THREADS=0 -DPANIC_USE_OPENMP=1
|
|
||||||
|
|
||||||
CXX_INCLUDES = -I/home/atlas/Documents/Git/panic/include
|
|
||||||
|
|
||||||
CXX_FLAGS = -std=c++11 -fopenmp
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/usr/bin/c++ CMakeFiles/panic.dir/main.cpp.o CMakeFiles/panic.dir/src/io/print_tensor.cpp.o CMakeFiles/panic.dir/src/tensor/matrix.cpp.o CMakeFiles/panic.dir/src/tensor/vector.cpp.o -o panic /usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so /usr/lib/x86_64-linux-gnu/libpthread.a
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
CMAKE_PROGRESS_1 = 1
|
|
||||||
CMAKE_PROGRESS_2 = 2
|
|
||||||
CMAKE_PROGRESS_3 = 3
|
|
||||||
CMAKE_PROGRESS_4 = 4
|
|
||||||
CMAKE_PROGRESS_5 = 5
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
5
|
|
||||||
-264
@@ -1,264 +0,0 @@
|
|||||||
# CMAKE generated file: DO NOT EDIT!
|
|
||||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.28
|
|
||||||
|
|
||||||
# Default target executed when no arguments are given to make.
|
|
||||||
default_target: all
|
|
||||||
.PHONY : default_target
|
|
||||||
|
|
||||||
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
|
|
||||||
.NOTPARALLEL:
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Special targets provided by cmake.
|
|
||||||
|
|
||||||
# Disable implicit rules so canonical targets will work.
|
|
||||||
.SUFFIXES:
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : %,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : RCS/%,v
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : SCCS/s.%
|
|
||||||
|
|
||||||
# Disable VCS-based implicit rules.
|
|
||||||
% : s.%
|
|
||||||
|
|
||||||
.SUFFIXES: .hpux_make_needs_suffix_list
|
|
||||||
|
|
||||||
# Command-line flag to silence nested $(MAKE).
|
|
||||||
$(VERBOSE)MAKESILENT = -s
|
|
||||||
|
|
||||||
#Suppress display of executed commands.
|
|
||||||
$(VERBOSE).SILENT:
|
|
||||||
|
|
||||||
# A target that is always out of date.
|
|
||||||
cmake_force:
|
|
||||||
.PHONY : cmake_force
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Set environment variables for the build.
|
|
||||||
|
|
||||||
# The shell in which to execute make rules.
|
|
||||||
SHELL = /bin/sh
|
|
||||||
|
|
||||||
# The CMake executable.
|
|
||||||
CMAKE_COMMAND = /usr/bin/cmake
|
|
||||||
|
|
||||||
# The command to remove a file.
|
|
||||||
RM = /usr/bin/cmake -E rm -f
|
|
||||||
|
|
||||||
# Escaping for special characters.
|
|
||||||
EQUALS = =
|
|
||||||
|
|
||||||
# The top-level source directory on which CMake was run.
|
|
||||||
CMAKE_SOURCE_DIR = /home/atlas/Documents/Git/panic
|
|
||||||
|
|
||||||
# The top-level build directory on which CMake was run.
|
|
||||||
CMAKE_BINARY_DIR = /home/atlas/Documents/Git/panic/build
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Targets provided globally by CMake.
|
|
||||||
|
|
||||||
# Special rule for the target edit_cache
|
|
||||||
edit_cache:
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "No interactive CMake dialog available..."
|
|
||||||
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
|
|
||||||
.PHONY : edit_cache
|
|
||||||
|
|
||||||
# Special rule for the target edit_cache
|
|
||||||
edit_cache/fast: edit_cache
|
|
||||||
.PHONY : edit_cache/fast
|
|
||||||
|
|
||||||
# Special rule for the target rebuild_cache
|
|
||||||
rebuild_cache:
|
|
||||||
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..."
|
|
||||||
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
|
||||||
.PHONY : rebuild_cache
|
|
||||||
|
|
||||||
# Special rule for the target rebuild_cache
|
|
||||||
rebuild_cache/fast: rebuild_cache
|
|
||||||
.PHONY : rebuild_cache/fast
|
|
||||||
|
|
||||||
# The main all target
|
|
||||||
all: cmake_check_build_system
|
|
||||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/atlas/Documents/Git/panic/build/CMakeFiles /home/atlas/Documents/Git/panic/build//CMakeFiles/progress.marks
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
|
|
||||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/atlas/Documents/Git/panic/build/CMakeFiles 0
|
|
||||||
.PHONY : all
|
|
||||||
|
|
||||||
# The main clean target
|
|
||||||
clean:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
|
|
||||||
.PHONY : clean
|
|
||||||
|
|
||||||
# The main clean target
|
|
||||||
clean/fast: clean
|
|
||||||
.PHONY : clean/fast
|
|
||||||
|
|
||||||
# Prepare targets for installation.
|
|
||||||
preinstall: all
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
|
||||||
.PHONY : preinstall
|
|
||||||
|
|
||||||
# Prepare targets for installation.
|
|
||||||
preinstall/fast:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
|
||||||
.PHONY : preinstall/fast
|
|
||||||
|
|
||||||
# clear depends
|
|
||||||
depend:
|
|
||||||
$(CMAKE_COMMAND) -P /home/atlas/Documents/Git/panic/build/CMakeFiles/VerifyGlobs.cmake
|
|
||||||
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
|
|
||||||
.PHONY : depend
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Target rules for targets named panic
|
|
||||||
|
|
||||||
# Build rule for target.
|
|
||||||
panic: cmake_check_build_system
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 panic
|
|
||||||
.PHONY : panic
|
|
||||||
|
|
||||||
# fast build rule for target.
|
|
||||||
panic/fast:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/build
|
|
||||||
.PHONY : panic/fast
|
|
||||||
|
|
||||||
main.o: main.cpp.o
|
|
||||||
.PHONY : main.o
|
|
||||||
|
|
||||||
# target to build an object file
|
|
||||||
main.cpp.o:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/main.cpp.o
|
|
||||||
.PHONY : main.cpp.o
|
|
||||||
|
|
||||||
main.i: main.cpp.i
|
|
||||||
.PHONY : main.i
|
|
||||||
|
|
||||||
# target to preprocess a source file
|
|
||||||
main.cpp.i:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/main.cpp.i
|
|
||||||
.PHONY : main.cpp.i
|
|
||||||
|
|
||||||
main.s: main.cpp.s
|
|
||||||
.PHONY : main.s
|
|
||||||
|
|
||||||
# target to generate assembly for a file
|
|
||||||
main.cpp.s:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/main.cpp.s
|
|
||||||
.PHONY : main.cpp.s
|
|
||||||
|
|
||||||
src/io/print_tensor.o: src/io/print_tensor.cpp.o
|
|
||||||
.PHONY : src/io/print_tensor.o
|
|
||||||
|
|
||||||
# target to build an object file
|
|
||||||
src/io/print_tensor.cpp.o:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/io/print_tensor.cpp.o
|
|
||||||
.PHONY : src/io/print_tensor.cpp.o
|
|
||||||
|
|
||||||
src/io/print_tensor.i: src/io/print_tensor.cpp.i
|
|
||||||
.PHONY : src/io/print_tensor.i
|
|
||||||
|
|
||||||
# target to preprocess a source file
|
|
||||||
src/io/print_tensor.cpp.i:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/io/print_tensor.cpp.i
|
|
||||||
.PHONY : src/io/print_tensor.cpp.i
|
|
||||||
|
|
||||||
src/io/print_tensor.s: src/io/print_tensor.cpp.s
|
|
||||||
.PHONY : src/io/print_tensor.s
|
|
||||||
|
|
||||||
# target to generate assembly for a file
|
|
||||||
src/io/print_tensor.cpp.s:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/io/print_tensor.cpp.s
|
|
||||||
.PHONY : src/io/print_tensor.cpp.s
|
|
||||||
|
|
||||||
src/tensor/matrix.o: src/tensor/matrix.cpp.o
|
|
||||||
.PHONY : src/tensor/matrix.o
|
|
||||||
|
|
||||||
# target to build an object file
|
|
||||||
src/tensor/matrix.cpp.o:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/matrix.cpp.o
|
|
||||||
.PHONY : src/tensor/matrix.cpp.o
|
|
||||||
|
|
||||||
src/tensor/matrix.i: src/tensor/matrix.cpp.i
|
|
||||||
.PHONY : src/tensor/matrix.i
|
|
||||||
|
|
||||||
# target to preprocess a source file
|
|
||||||
src/tensor/matrix.cpp.i:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/matrix.cpp.i
|
|
||||||
.PHONY : src/tensor/matrix.cpp.i
|
|
||||||
|
|
||||||
src/tensor/matrix.s: src/tensor/matrix.cpp.s
|
|
||||||
.PHONY : src/tensor/matrix.s
|
|
||||||
|
|
||||||
# target to generate assembly for a file
|
|
||||||
src/tensor/matrix.cpp.s:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/matrix.cpp.s
|
|
||||||
.PHONY : src/tensor/matrix.cpp.s
|
|
||||||
|
|
||||||
src/tensor/vector.o: src/tensor/vector.cpp.o
|
|
||||||
.PHONY : src/tensor/vector.o
|
|
||||||
|
|
||||||
# target to build an object file
|
|
||||||
src/tensor/vector.cpp.o:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/vector.cpp.o
|
|
||||||
.PHONY : src/tensor/vector.cpp.o
|
|
||||||
|
|
||||||
src/tensor/vector.i: src/tensor/vector.cpp.i
|
|
||||||
.PHONY : src/tensor/vector.i
|
|
||||||
|
|
||||||
# target to preprocess a source file
|
|
||||||
src/tensor/vector.cpp.i:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/vector.cpp.i
|
|
||||||
.PHONY : src/tensor/vector.cpp.i
|
|
||||||
|
|
||||||
src/tensor/vector.s: src/tensor/vector.cpp.s
|
|
||||||
.PHONY : src/tensor/vector.s
|
|
||||||
|
|
||||||
# target to generate assembly for a file
|
|
||||||
src/tensor/vector.cpp.s:
|
|
||||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/panic.dir/build.make CMakeFiles/panic.dir/src/tensor/vector.cpp.s
|
|
||||||
.PHONY : src/tensor/vector.cpp.s
|
|
||||||
|
|
||||||
# Help Target
|
|
||||||
help:
|
|
||||||
@echo "The following are some of the valid targets for this Makefile:"
|
|
||||||
@echo "... all (the default if no target is provided)"
|
|
||||||
@echo "... clean"
|
|
||||||
@echo "... depend"
|
|
||||||
@echo "... edit_cache"
|
|
||||||
@echo "... rebuild_cache"
|
|
||||||
@echo "... panic"
|
|
||||||
@echo "... main.o"
|
|
||||||
@echo "... main.i"
|
|
||||||
@echo "... main.s"
|
|
||||||
@echo "... src/io/print_tensor.o"
|
|
||||||
@echo "... src/io/print_tensor.i"
|
|
||||||
@echo "... src/io/print_tensor.s"
|
|
||||||
@echo "... src/tensor/matrix.o"
|
|
||||||
@echo "... src/tensor/matrix.i"
|
|
||||||
@echo "... src/tensor/matrix.s"
|
|
||||||
@echo "... src/tensor/vector.o"
|
|
||||||
@echo "... src/tensor/vector.i"
|
|
||||||
@echo "... src/tensor/vector.s"
|
|
||||||
.PHONY : help
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#=============================================================================
|
|
||||||
# Special targets to cleanup operation of make.
|
|
||||||
|
|
||||||
# Special rule to run CMake to check the build system integrity.
|
|
||||||
# No rule that depends on this can have commands that come from listfiles
|
|
||||||
# because they might be regenerated.
|
|
||||||
cmake_check_build_system:
|
|
||||||
$(CMAKE_COMMAND) -P /home/atlas/Documents/Git/panic/build/CMakeFiles/VerifyGlobs.cmake
|
|
||||||
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
|
|
||||||
.PHONY : cmake_check_build_system
|
|
||||||
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
# Install script for directory: /home/atlas/Documents/Git/panic
|
|
||||||
|
|
||||||
# Set the install prefix
|
|
||||||
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
|
||||||
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
|
||||||
endif()
|
|
||||||
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
|
||||||
|
|
||||||
# Set the install configuration name.
|
|
||||||
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
|
||||||
if(BUILD_TYPE)
|
|
||||||
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
|
||||||
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
|
||||||
else()
|
|
||||||
set(CMAKE_INSTALL_CONFIG_NAME "")
|
|
||||||
endif()
|
|
||||||
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Set the component getting installed.
|
|
||||||
if(NOT CMAKE_INSTALL_COMPONENT)
|
|
||||||
if(COMPONENT)
|
|
||||||
message(STATUS "Install component: \"${COMPONENT}\"")
|
|
||||||
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
|
|
||||||
else()
|
|
||||||
set(CMAKE_INSTALL_COMPONENT)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Install shared libraries without execute permission?
|
|
||||||
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
|
||||||
set(CMAKE_INSTALL_SO_NO_EXE "1")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Is this installation the result of a crosscompile?
|
|
||||||
if(NOT DEFINED CMAKE_CROSSCOMPILING)
|
|
||||||
set(CMAKE_CROSSCOMPILING "FALSE")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Set default install directory permissions.
|
|
||||||
if(NOT DEFINED CMAKE_OBJDUMP)
|
|
||||||
set(CMAKE_OBJDUMP "/usr/bin/objdump")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_INSTALL_COMPONENT)
|
|
||||||
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
|
|
||||||
else()
|
|
||||||
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
|
||||||
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
|
||||||
file(WRITE "/home/atlas/Documents/Git/panic/build/${CMAKE_INSTALL_MANIFEST}"
|
|
||||||
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
|
||||||
BIN
Binary file not shown.
@@ -52,40 +52,52 @@
|
|||||||
namespace panic {
|
namespace panic {
|
||||||
namespace constants{
|
namespace constants{
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// Type Name : panic::pi
|
// Type Name : panic::constants::pi
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default difinition of pi (3.14159265358979323846) used inside PANIC.
|
// Default difinition of pi (3.14159265358979323846) used inside PANIC.
|
||||||
// static_cast makes sure the right number of decimals are used when defining the constant.
|
// static_cast makes sure the right number of decimals are used when defining the constant.
|
||||||
//
|
//
|
||||||
// Underlying Type:
|
// Underlying Type:
|
||||||
// panic::real_t
|
// panic::types::real_t
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
static const panic::types::real_t pi = static_cast<panic::types::real_t>(3.14159265358979323846);
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Type Name : panic::constants::half_pi
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default difinition of pi (3.14159265358979323846) used inside PANIC.
|
||||||
|
// static_cast makes sure the right number of decimals are used when defining the constant.
|
||||||
|
//
|
||||||
|
// Underlying Type:
|
||||||
|
// panic::types::real_t
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
static const panic::types::real_t half_pi = pi / static_cast<panic::types::real_t>(2);
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
static const panic::real_t pi = static_cast<panic::real_t>(3.14159265358979323846);
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Type Name : panic::tau
|
// Type Name : panic::constants::tau
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default difinition of tau (6.28318530717958647692) used inside PANIC.
|
// Default difinition of tau (6.28318530717958647692) used inside PANIC.
|
||||||
// static_cast makes sure the right number of decimals are used when defining the constant.
|
// static_cast makes sure the right number of decimals are used when defining the constant.
|
||||||
//
|
//
|
||||||
// Underlying Type:
|
// Underlying Type:
|
||||||
// panic::real_t
|
// panic::types::real_t
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
static const panic::real_t tau = static_cast<panic::real_t>(6.28318530717958647692);
|
static const panic::types::real_t tau = static_cast<panic::types::real_t>(6.28318530717958647692);
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Type Name : panic::e
|
// Type Name : panic::constants::e
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default difinition of eulers number, e (2.71828182845904523536) used inside PANIC.
|
// Default difinition of eulers number, e (2.71828182845904523536) used inside PANIC.
|
||||||
// static_cast makes sure the right number of decimals are used when defining the constant.
|
// static_cast makes sure the right number of decimals are used when defining the constant.
|
||||||
//
|
//
|
||||||
// Underlying Type:
|
// Underlying Type:
|
||||||
// panic::real_t
|
// panic::types::real_t
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
static const panic::real_t e = static_cast<panic::real_t>(2.71828182845904523536);
|
static const panic::types::real_t e = static_cast<panic::types::real_t>(2.71828182845904523536);
|
||||||
|
|
||||||
} // namespace constants
|
} // namespace constants
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|||||||
+33
-1
@@ -130,6 +130,23 @@
|
|||||||
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
|
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
|
||||||
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) num_threads(PANIC_OMP_NUM_THREADS)))
|
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) num_threads(PANIC_OMP_NUM_THREADS)))
|
||||||
|
|
||||||
|
|
||||||
|
// Expands to:
|
||||||
|
// #pragma omp parallel for if(condition)
|
||||||
|
// num_threads(PANIC_OMP_NUM_THREADS)
|
||||||
|
// schedule(static)
|
||||||
|
// reduction(operation:variable)
|
||||||
|
//
|
||||||
|
// Runs the loop in parallel only when condition is true.
|
||||||
|
// Each thread receives a private copy of variable.
|
||||||
|
// Afterward, OpenMP combines those copies using operation.
|
||||||
|
// schedule(static) assigns fixed groups of iterations to each thread.
|
||||||
|
#define PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(condition, operation, variable) \
|
||||||
|
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) \
|
||||||
|
num_threads(PANIC_OMP_NUM_THREADS) \
|
||||||
|
schedule(static) \
|
||||||
|
reduction(operation:variable)))
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Expands to:
|
// Expands to:
|
||||||
@@ -147,6 +164,21 @@
|
|||||||
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
|
#define PANIC_OMP_PARALLEL_FOR_IF(condition) \
|
||||||
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition)))
|
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition)))
|
||||||
|
|
||||||
|
// Expands to:
|
||||||
|
// #pragma omp parallel for if(condition)
|
||||||
|
// num_threads(PANIC_OMP_NUM_THREADS)
|
||||||
|
// schedule(static)
|
||||||
|
// reduction(operation:variable)
|
||||||
|
//
|
||||||
|
// Runs the loop in parallel only when condition is true.
|
||||||
|
// Each thread receives a private copy of variable.
|
||||||
|
// Afterward, OpenMP combines those copies using operation.
|
||||||
|
// schedule(static) assigns fixed groups of iterations to each thread.
|
||||||
|
#define PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(condition, operation, variable) \
|
||||||
|
_Pragma(PANIC_STRINGIFY(omp parallel for if(condition) \
|
||||||
|
schedule(static) \
|
||||||
|
reduction(operation:variable)))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -168,7 +200,7 @@
|
|||||||
//
|
//
|
||||||
// That means the same code still works on microcontrollers and non-OpenMP builds.
|
// That means the same code still works on microcontrollers and non-OpenMP builds.
|
||||||
#define PANIC_OMP_PARALLEL_FOR
|
#define PANIC_OMP_PARALLEL_FOR
|
||||||
#define PANIC_OMP_PARALLEL_FOR_IF(condition)
|
#define PANIC_OMP_PARALLEL_FOR_IF(condition) static_cast<void>(sizeof(condition));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// TYPE DESCRIPTION
|
// TYPE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// Type Name : panic::uint_t
|
// Type Name : panic::types::uint_t
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default unsigned integer type used inside PANIC.
|
// Default unsigned integer type used inside PANIC.
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
// uint32_t
|
// uint32_t
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Type Name : panic::int_t
|
// Type Name : panic::types::int_t
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default signed integer type used inside PANIC.
|
// Default signed integer type used inside PANIC.
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
// int32_t
|
// int32_t
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Type Name : panic::real_t
|
// Type Name : panic::types::real_t
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Default floating-point type used inside PANIC.
|
// Default floating-point type used inside PANIC.
|
||||||
@@ -73,11 +73,12 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace panic {
|
namespace panic {
|
||||||
|
namespace types{
|
||||||
|
|
||||||
typedef uint32_t uint_t;
|
typedef uint32_t uint_t;
|
||||||
typedef int32_t int_t;
|
typedef int32_t int_t;
|
||||||
typedef float real_t;
|
typedef float real_t;
|
||||||
|
} // namespace types
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+39
-61
@@ -31,74 +31,52 @@
|
|||||||
* Functions to print out tensors with std::cout << x std::endl;
|
* Functions to print out tensors with std::cout << x std::endl;
|
||||||
*
|
*
|
||||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
#pragma one
|
#pragma once
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// INCLUDE DESCRIPTION
|
|
||||||
//-----------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
// DEFINE DESCRIPTION
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace io{
|
namespace io{
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
/**
|
||||||
// Function Name : panic::io::print_vector
|
* @brief prints out vector to iostream.
|
||||||
//
|
*
|
||||||
// Description:
|
* Computes:
|
||||||
// Prints a vector out in the terminal
|
* @code
|
||||||
//
|
* print_vector(a)
|
||||||
// Inputs:
|
* @endcode
|
||||||
// v const panic::tensor::uint_vector&
|
*
|
||||||
// const panic::tensor::int_vector&
|
* @tparam T Numeric element type.
|
||||||
// const panic::tensor::real_vector&
|
* @param a Input vector.
|
||||||
// vector to print
|
*
|
||||||
//
|
* @return true if @p a was successfully printed.
|
||||||
// Outputs:
|
* @return false if printing of @p c failed.
|
||||||
// None.
|
*
|
||||||
//
|
* @note N/A
|
||||||
// Returns:
|
*/
|
||||||
// void
|
template <typename T>
|
||||||
//
|
bool print_vector(const panic::tensor::vector<T>& v);
|
||||||
// Notes:
|
|
||||||
// The vector is printed out in square brackets.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void print_vector(const panic::tensor::uint_vector& v);
|
|
||||||
void print_vector(const panic::tensor::int_vector& v);
|
|
||||||
void print_vector(const panic::tensor::real_vector& v);
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
/**
|
||||||
// Function Name : panic::io::print_matrix
|
* @brief prints out matrix to iostream.
|
||||||
//
|
*
|
||||||
// Description:
|
* Computes:
|
||||||
// Prints a matrix out in the terminal
|
* @code
|
||||||
//
|
* print_matrix(a)
|
||||||
// Inputs:
|
* @endcode
|
||||||
// v const panic::tensor::uint_matrix&
|
*
|
||||||
// const panic::tensor::int_matrix&
|
* @tparam T Numeric element type.
|
||||||
// const panic::tensor::real_matrix&
|
* @param A Input matrix.
|
||||||
// matrix to print
|
*
|
||||||
//
|
* @return true if @p A was successfully printed.
|
||||||
// Outputs:
|
* @return false if printing of @p C failed.
|
||||||
// None.
|
*
|
||||||
//
|
* @note N/A
|
||||||
// Returns:
|
*/
|
||||||
// void
|
template <typename T>
|
||||||
//
|
bool print_matrix(const panic::tensor::matrix<T>& A);
|
||||||
// Notes:
|
|
||||||
// The matrix is printed out in square brackets.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void print_matrix(const panic::tensor::uint_matrix& v);
|
|
||||||
void print_matrix(const panic::tensor::int_matrix& v);
|
|
||||||
void print_matrix(const panic::tensor::real_matrix& v);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,286 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: add.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to add panic::tensor togther;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a scalar to every element of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] + k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value added to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a scalar added to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] + k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value added to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a vector elementwise too a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] + b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a vector added elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] + b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param k Scalar value added to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a scalar to every element of a matix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) + k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value added to each element of @p A.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a scalar added to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) + k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value added to each element of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) + B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix added elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) + B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) + b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) + b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) + b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) + b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: argmax.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to find the index of the maximum value;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the index of maximum value of a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::types::uint_t argmax(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the index of the maximum value of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param b Output vector for index
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool argmax(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& b);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the index of the maximum value of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::types::uint_t argmax(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the index of the maximum values row-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output vector with indexes. Resized to match @p A.cols().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool argmax_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the index of the maiximum row-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::uint_vector argmax_rowwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the index of the maximum values column-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output matrix. Resized to match @p A.rows().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool argmax_colwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the index of the maiximum column-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::uint_vector argmax_colwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,812 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: clip.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions that clips the value
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max values in the vector or scalar.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] < k)
|
||||||
|
* c[i] = k
|
||||||
|
* else
|
||||||
|
* c[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a cliped max value in the vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] < k)
|
||||||
|
* result[i] = k
|
||||||
|
* else
|
||||||
|
* result[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> clip_lower(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max elementwise in the vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] < b[i])
|
||||||
|
* c[i] = b[i]
|
||||||
|
* else
|
||||||
|
* c[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing cliped max elementwise of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] < b[i])
|
||||||
|
* result[i] = b[i]
|
||||||
|
* else
|
||||||
|
* result[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> clip_lower(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < k)
|
||||||
|
* C(i,j) = k
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing matrix to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the cliped max elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < k)
|
||||||
|
* result(i,j) = k
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_lower(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max of a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < B(i,j))
|
||||||
|
* C(i,j) = B(i,j)
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix elementwise cliped to the maixmum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < B(i,j))
|
||||||
|
* result(i,j) = B(i,j)
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_lower(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max of a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < b[j])
|
||||||
|
* C(i,j) = b[j])
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a vector rowwise cliped to the maixmum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < b[j])
|
||||||
|
* result(i,j) = b[j])
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_lower_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the max of a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < b[i])
|
||||||
|
* C(i,j) = b[i])
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_lower_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a vector rowwise cliped to the maixmum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) < b[i])
|
||||||
|
* result(i,j) = b[i])
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_lower_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min values in the vector or scalar.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] > k)
|
||||||
|
* c[i] = k
|
||||||
|
* else
|
||||||
|
* c[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a cliped min value in the vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] > k)
|
||||||
|
* result[i] = k
|
||||||
|
* else
|
||||||
|
* result[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> clip_higher(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min elementwise in the vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] > b[i])
|
||||||
|
* c[i] = b[i]
|
||||||
|
* else
|
||||||
|
* c[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing cliped min elementwise of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (a[i] > b[i])
|
||||||
|
* result[i] = b[i]
|
||||||
|
* else
|
||||||
|
* result[i] = a[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> clip_higher(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > k)
|
||||||
|
* C(i,j) = k
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing matrix to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the cliped min elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > k)
|
||||||
|
* result(i,j) = k
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_higher(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min of a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > B(i,j))
|
||||||
|
* C(i,j) = B(i,j)
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix elementwise cliped to the maixmum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > B(i,j))
|
||||||
|
* result(i,j) = B(i,j)
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_higher(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min of a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > b[j])
|
||||||
|
* C(i,j) = b[j])
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a vector rowwise cliped to the minimum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > b[j])
|
||||||
|
* result(i,j) = b[j])
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_higher_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the min of a vector columnwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > b[i])
|
||||||
|
* C(i,j) = b[i])
|
||||||
|
* else
|
||||||
|
* C(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if matrix sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip_higher_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a vector column-wise cliped to the minimum.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* if (A(i,j) > b[i])
|
||||||
|
* result(i,j) = b[i])
|
||||||
|
* else
|
||||||
|
* result(i,j) = A(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip_higher_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips values in the vector or scalar.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param lower Scalar value compared to each element of @p a.
|
||||||
|
* @param higher Scalar value compared to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip(const panic::tensor::vector<T>& a, const T lower, const T higher, const panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a cliped value in the vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param lower Scalar value compared to each element of @p a.
|
||||||
|
* @param higher Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> clip(const panic::tensor::vector<T>& a, const T lower, const T higher);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clips the elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param lower Scalar value compared to each element of @p a.
|
||||||
|
* @param higher Scalar value compared to each element of @p a.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing matrix to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool clip(const panic::tensor::matrix<T>& A, const T lower, const T higher, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the cliped min elementwise in the matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param lower Scalar value compared to each element of @p a.
|
||||||
|
* @param higher Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> clip(const panic::tensor::matrix<T>& A, const T lower, const T higher);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: div.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to divide panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* @file mul.hpp
|
||||||
|
* @brief Public API for multiplying operations on PANIC vectors and matrices.
|
||||||
|
*
|
||||||
|
* This header contains the declarations that users of the math module should call.
|
||||||
|
* The comments here describe how each function is used, what dimensions are required,
|
||||||
|
* and what is returned on failure.
|
||||||
|
*
|
||||||
|
* Implementation details, OpenMP thresholds, and explicit template instantiations are
|
||||||
|
* kept in mul.cpp.
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a scalar to every element of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] / k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value multiplied to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a scalar divided to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] / k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value miltiplied to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divide a vector elementwise too a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] / b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a vector diveded elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] / b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param k Scalar value multiplied to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a scalar to every element of a matix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) / k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a scalar diveded to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) / k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) / B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix divided elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) / B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) / b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) / b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) / b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Divides a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) / b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: dot.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate dot product of tensors;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp> // for panic::real_matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns dor product of vector and vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector for dot product. Need to be @p a.size()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T dot(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector of dot product of a matrix and vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param b Input vector. @ p b.size needs to be the size of @p A.cols.
|
||||||
|
* @param c Output vector with result.
|
||||||
|
*
|
||||||
|
* @return true if success
|
||||||
|
* @return false if resizeing fails or dimention mismatch
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool dot(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector of dot product of a matrix and vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param b Input vector. @ p b.size needs to be the size of @p A.cols.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> dot(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: equal.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to find the equal in panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* @file mul.hpp
|
||||||
|
* @brief Public API for multiplying operations on PANIC vectors and matrices.
|
||||||
|
*
|
||||||
|
* This header contains the declarations that users of the math module should call.
|
||||||
|
* The comments here describe how each function is used, what dimensions are required,
|
||||||
|
* and what is returned on failure.
|
||||||
|
*
|
||||||
|
* Implementation details, OpenMP thresholds, and explicit template instantiations are
|
||||||
|
* kept in mul.cpp.
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the equal for a scalar to every element of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a scalar equaled to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> equal(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal a vector elementwise too a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a vector with equals elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param k Scalar value compared to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> equal(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a scalar to every element of a matix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a scalar equal compared to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix equal compaed elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool equal_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Equal compared a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: exp.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate the exponential of numbers
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief calculates the exponential of a value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = exp(k)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param k Value to take the exp of.
|
||||||
|
*
|
||||||
|
* @return The calculated value
|
||||||
|
*
|
||||||
|
* @note This function is omp-friendly.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T exp(const T x);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the exponential elementwise in a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = exp(a[i])
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool exp(const panic::tensor::vector<T>& a, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the exponential elementwise in a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = exp(a[i])
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> exp(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the expnential elementwise of a matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = exp(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool exp(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the calculated ecponential elementwise of the matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = exp(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> exp(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: log.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate the natural logorithem of numbers
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief calculates the log of a value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = log(k)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param x Value to take the log of.
|
||||||
|
*
|
||||||
|
* @return The calculated value
|
||||||
|
*
|
||||||
|
* @note This function is omp-friendly.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T log(const T x);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the natrual logorithmic elementwise in a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = log(a[i])
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool log(const panic::tensor::vector<T>& a, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the natrual log elementwise in a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = log(a[i])
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> log(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates the natrual log elementwise of a matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = log(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool log(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the calculated natrual log elementwise of the matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = log(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> log(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: matmul.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 24-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to print out tensors with std::cout << x std::endl;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
#include <tensor/matrix.hpp> // for panic::real_matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates matrix multiplication of two matrices.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(n, p) = A(n,m) + B(m,p)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. @ p B.rows needs to be the size of @p A.cols.
|
||||||
|
* @param C Output matrix. Resized to C(A.rows, B.cols).
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed or A==B.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing matrix to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix of multiplication of two matrices.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(n, p) = A(n,m) + B(m,p)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. @ p B.rows needs to be the size of @p A.cols.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: max.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to find the maximum value;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum value of a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = max(a)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T max(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum value of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = max(A)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T max(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the maximum values row-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i) = max(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output matrix. Resized to match @p A.cols().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool max_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the maiximum row-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = max(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> max_rowwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the maximum values column-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(j) = max(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output matrix. Resized to match @p A.rows().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool max_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the maiximum column-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[j] = max(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> max_colwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: mean.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate mean of tensor arrays
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the mean value of a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = mean(a)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::types::real_t mean(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the mean value of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = mean(A)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::types::real_t mean(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the mean values row-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c(i) = mean(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param c Output vector. Resized to match @p A.rows().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mean_rowwise(const panic::tensor::real_matrix& A, panic::tensor::real_vector& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the mean row-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = mean(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::real_vector mean_rowwise(const panic::tensor::real_matrix& A);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the mean values column-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(j) = mean(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output matrix. Resized to match @p A.cols().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mean_colwise(const panic::tensor::real_matrix& A, panic::tensor::real_vector& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the mean column-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[j] = mean(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::real_vector mean_colwise(const panic::tensor::real_matrix& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: mul.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to multiply panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* @file mul.hpp
|
||||||
|
* @brief Public API for multiplying operations on PANIC vectors and matrices.
|
||||||
|
*
|
||||||
|
* This header contains the declarations that users of the math module should call.
|
||||||
|
* The comments here describe how each function is used, what dimensions are required,
|
||||||
|
* and what is returned on failure.
|
||||||
|
*
|
||||||
|
* Implementation details, OpenMP thresholds, and explicit template instantiations are
|
||||||
|
* kept in mul.cpp.
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a scalar to every element of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] * k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value multiplied to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a scalar multiplied to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] * k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value miltiplied to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> mul(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a vector elementwise too a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] * b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a vector miltiplied elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] * b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param k Scalar value multiplied to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> mul(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a scalar to every element of a matix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) * k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a scalar multiplied to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) * k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value multiplied to each element of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) * B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix multiplied elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) * B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) * b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) * b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) * b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool mul_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Muliplies a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) * b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,286 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sub.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to subtracts panic::tensor togther;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subs a scalar to every element of a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] - k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value added to each element of @p a.
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a scalar subtraced to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] - k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
* @param k Scalar value subtracted to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a vector elementwise too a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = a[i] - b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param c Output vector. Resized to match @p a.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new vector containing a vector subtracted elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = a[i] - b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a First vector.
|
||||||
|
* @param b Second vector. Must have size of @p a
|
||||||
|
* @param k Scalar value subtracted to each element of @p a.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a scalar to every element of a matix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) - k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value added to each element of @p A.
|
||||||
|
* @param C Output Matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if resizing @p C failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a scalar subtracted to every element.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) - k
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param k Scalar value subtracted to each element of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const T k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a matrix elementwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) - B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A First matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing a matrix subtracted elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) - B(i,j)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Second matrix. Must have size of @p A.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) - b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a vector rowwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) - b[j]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.cols().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(i,j) = A(i,j) - b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
* @param C Output matrix. Resized to match @p A.
|
||||||
|
*
|
||||||
|
* @return true if @p C was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief subtracts a vector colwise too a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result(i,j) = A(i,j) - b[i]
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Matrix.
|
||||||
|
* @param b Vector. Must have size of @p A.rows().
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sum.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to sum up arrays
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the sum value of a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = sum(a)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Input vector.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T sum(const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the sum value of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = sum(A)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T sum(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the sum values row-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c(i) = sum(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param c Output vector. Resized to match @p A.cols().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sum_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the sum row-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = sum(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sum_rowwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the sumation values column-wise of a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* C(j) = sum(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param C Output matrix. Resized to match @p A.rows().
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if vector sizes do not match or resizing @p c failed.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sum_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix containing the sumation column-wise elementwise.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[j] = sum(A(i,j))
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty matrix if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sum_colwise(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: transpose.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to transpose a matrix;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp> // for panic::real_matrix
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transposes a matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* B = transpose(A)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
* @param B Output matrix with result.
|
||||||
|
*
|
||||||
|
* @return true if success
|
||||||
|
* @return false if resizeing fails or dimention mismatch
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool transpose(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a new matrix of the transposed A.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result = transpose(A)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param A Input matrix.
|
||||||
|
*
|
||||||
|
* @return A new matrix containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new matrix.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> transpose(const panic::tensor::matrix<T>& A);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: cos.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate cossinus of x;
|
||||||
|
* This uses panic::math::sin
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates cos value of x
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c = cos(a)
|
||||||
|
* @endcode
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param x Real input value
|
||||||
|
*
|
||||||
|
* @return Cosinus of x
|
||||||
|
*
|
||||||
|
* @note This function is omp-friendly
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T cos(const T x);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sin.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate sinus of x;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace math{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates sin value of x
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c = sin(a)
|
||||||
|
* @endcode
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param x Real input value
|
||||||
|
*
|
||||||
|
* @return Sinus of x
|
||||||
|
*
|
||||||
|
* @note This function is omp-friendly
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T sin(const T x);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: activation_relu.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-08-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the activation layer for ReLU
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <neural_network/layer/layer.hpp> // for base layer struct
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for ReLU activation layer used in neural networks
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::neural_network::activation_ReLU myactivation();
|
||||||
|
* myactivation.forward(inputMatrix);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* The struct is used in PANIC nural_network library.
|
||||||
|
*/
|
||||||
|
struct activation_relu : public layer{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
activation_relu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default de-constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~activation_relu() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Forward function for layer
|
||||||
|
*
|
||||||
|
* @param inputs Data input for forward pass.
|
||||||
|
*
|
||||||
|
* @Note Calculates -> outputs = inputs * weights + biases
|
||||||
|
*/
|
||||||
|
bool forward(const panic::tensor::real_matrix& input_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Backward function for layer
|
||||||
|
*
|
||||||
|
* @param inputs Data input for bacward pass.
|
||||||
|
*
|
||||||
|
* @Note Calculates derivative of forward function.
|
||||||
|
*/
|
||||||
|
bool backward(const panic::tensor::real_matrix& dvalues);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: activation_softmax.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-08-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the activation layer for Softmax
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <neural_network/layer/layer.hpp> // for base layer struct
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for softmax activation layer used in neural networks
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::neural_network::activation_softmax myactivation();
|
||||||
|
* myactivation.forward(inputMatrix);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* The struct is used in PANIC nural_network library.
|
||||||
|
*/
|
||||||
|
struct activation_softmax : public layer{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
activation_softmax();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default de-constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~activation_softmax() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Forward function for layer
|
||||||
|
*
|
||||||
|
* @param inputs Data input for forward pass.
|
||||||
|
*
|
||||||
|
* @Note Calculates -> outputs = inputs * weights + biases
|
||||||
|
*/
|
||||||
|
bool forward(const panic::tensor::real_matrix& input_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Backward function for layer
|
||||||
|
*
|
||||||
|
* @param inputs Data input for bacward pass.
|
||||||
|
*
|
||||||
|
* @Note Calculates derivative of forward function.
|
||||||
|
*/
|
||||||
|
bool backward(const panic::tensor::real_matrix& dvalues);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: sine_data.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generates a dataset of sines values
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* csine(10, 1, X, y)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param samples Number of samples dataset.
|
||||||
|
* @param lenght Interval of the sinus cuve form zero.
|
||||||
|
* @param X Output X matrix
|
||||||
|
* @param y Output y matrix
|
||||||
|
*
|
||||||
|
* @return true if @p X and @p y was resized and filled successfully.
|
||||||
|
* @return false if resizing @p X or @p y failed.
|
||||||
|
*
|
||||||
|
* @note This funtion writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::vector<T>& y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generates a dataset of sines and cosine values
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* csine(10, 1, X, y)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param samples Number of samples dataset.
|
||||||
|
* @param lenght Interval of the sinus cuve form zero.
|
||||||
|
* @param X Output X matrix
|
||||||
|
* @param y Output y matrix
|
||||||
|
*
|
||||||
|
* @return true if @p X and @p y was resized and filled successfully.
|
||||||
|
* @return false if resizing @p X or @p y failed.
|
||||||
|
*
|
||||||
|
* @note This funtion writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool sine_cosine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::matrix<T>& y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: spiral_data.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generates a dataset of spiral values
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* spiral_data(10, 1, X, y)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param samples Number of samples dataset.
|
||||||
|
* @param classes Number of classes in the spiral data.
|
||||||
|
* @param X Output X matrix
|
||||||
|
* @param y Output y matrix
|
||||||
|
*
|
||||||
|
* @return true if @p X and @p y was resized and filled successfully.
|
||||||
|
* @return false if resizing @p X or @p y failed.
|
||||||
|
*
|
||||||
|
* @note This funtion writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool spiral_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: vertical_data.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generates a dataset of vertical values
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* vertical_data(10, 1, X, y)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param samples Number of samples dataset.
|
||||||
|
* @param classes Number of classes in the vertical data.
|
||||||
|
* @param X Output X matrix
|
||||||
|
* @param y Output y matrix
|
||||||
|
*
|
||||||
|
* @return true if @p X and @p y was resized and filled successfully.
|
||||||
|
* @return false if resizing @p X or @p y failed.
|
||||||
|
*
|
||||||
|
* @note This funtion writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool vertical_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
*
|
*
|
||||||
* Project Name: PANIC
|
* Project Name: PANIC
|
||||||
* Module Name: neural_network
|
* Module Name: neural_network
|
||||||
* File Name: layer_dense.hpp
|
* File Name: layer.hpp
|
||||||
* Revision: 0.1.0
|
* Revision: 0.1.0
|
||||||
* Date: 23-06-2026
|
* Date: 23-06-2026
|
||||||
* Author: Michelle Bausager
|
* Author: Michelle Bausager
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Defines the dense layers used in neural network
|
* Defines the base layers struct used in other layers in neural network
|
||||||
*
|
*
|
||||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -36,114 +36,81 @@
|
|||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// DEFINE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Type Name : panic::neural_network::layer_dense
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// A dense layer to use in neural networks
|
|
||||||
//
|
|
||||||
// Member Variables:
|
|
||||||
// length panic::uint_t
|
|
||||||
// Number of elements in the vector.
|
|
||||||
//
|
|
||||||
// data panic::real_t*
|
|
||||||
// Pointer to the allocated vector data.
|
|
||||||
//
|
|
||||||
// Notes:
|
|
||||||
// This vector uses dynamic allocation with new[] and delete[].
|
|
||||||
// Copying performs a deep copy.
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace tensor{
|
namespace neural_network{
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct vector{
|
|
||||||
panic::uint_t length;
|
|
||||||
T* data;
|
|
||||||
|
|
||||||
// empty contructor
|
|
||||||
vector();
|
|
||||||
|
|
||||||
// contructor with size allocation
|
/**
|
||||||
vector(panic::uint_t size);
|
* @brief Base layer for the rest of the neural network library to use
|
||||||
|
*
|
||||||
|
* This base layer should be used in all layers/activations that have a forward and backward function
|
||||||
|
* This is done so it's easy to make a list of layers in the model to loop over.
|
||||||
|
* The virtual means it should use derived object's version when called with a pointer.
|
||||||
|
* The =0 means the derivative object NEEDS to have these functions to work.
|
||||||
|
*
|
||||||
|
* The struct is used for PANIC neural_network library.
|
||||||
|
*/
|
||||||
|
struct layer{
|
||||||
|
|
||||||
// contructor with size allocation and sets it all to a value
|
/**
|
||||||
vector(panic::uint_t size, T value);
|
* @brief Emphty output matrix to store layer input
|
||||||
|
*
|
||||||
|
* Output shape:
|
||||||
|
* samples x neuron_count
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix inputs;
|
||||||
|
|
||||||
// copy-contructor
|
/**
|
||||||
// vector a(3);
|
* @brief Emphty output matrix to store layer output
|
||||||
// vector b = a;
|
*
|
||||||
vector(const vector& other);
|
* Output shape:
|
||||||
|
* samples x neuron_count
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix outputs;
|
||||||
|
|
||||||
// de-contructor, releases memory
|
/**
|
||||||
~vector();
|
* @brief Emphty matrix to store output for backward pass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix dinputs;
|
||||||
|
|
||||||
// copy-assignment
|
/**
|
||||||
//vector a(5);
|
* @brief Default de-constructor
|
||||||
//vector b(3);
|
*
|
||||||
//b = a;
|
*/
|
||||||
vector& operator=(const vector& other);
|
virtual ~layer() = default;
|
||||||
|
|
||||||
// function returns size.
|
|
||||||
// const tells compiler that the fuction don't edit the objert.
|
|
||||||
panic::uint_t size() const;
|
|
||||||
|
|
||||||
// function to resize data vector (I need a new that don't save the vlaues)
|
/**
|
||||||
bool resize(panic::uint_t new_size);
|
* @brief Virtual forward function for derivative layers
|
||||||
|
*
|
||||||
|
* @param inputs Data matrix input for forward function.
|
||||||
|
*
|
||||||
|
* @Note It's equal to 0 because it make the derivative
|
||||||
|
* object NEEDS to have these function to work.
|
||||||
|
*/
|
||||||
|
virtual bool forward(const panic::tensor::real_matrix& inputs) = 0;
|
||||||
|
|
||||||
// fill data with value
|
/**
|
||||||
bool fill(T value);
|
* @brief Virtual backward function for derivative layers
|
||||||
|
*
|
||||||
// lets you read and write v[index]
|
* @param dinputs Data matrix input for backward function.
|
||||||
T& operator[](panic::uint_t index);
|
*
|
||||||
|
* @Note It's equal to 0 because it make the derivative
|
||||||
// lets you read v[index] from a const vector
|
* object NEEDS to have these function to work.
|
||||||
const T& operator[](panic::uint_t index) const;
|
*/
|
||||||
|
virtual bool backward(const panic::tensor::real_matrix& dinputs) = 0;
|
||||||
// lets you read and write v.at(index)
|
|
||||||
T& at(panic::uint_t index);
|
|
||||||
|
|
||||||
// lets you read v.at(index) from a const vector
|
|
||||||
const T& at(panic::uint_t index) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE ALIASES
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
typedef vector<panic::real_t> real_vector;
|
|
||||||
typedef vector<panic::int_t> int_vector;
|
|
||||||
typedef vector<panic::uint_t> uint_vector;
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// EXPLICIT TEMPLATE DECLARATION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern template struct vector<panic::real_t>;
|
|
||||||
extern template struct vector<panic::int_t>;
|
|
||||||
extern template struct vector<panic::uint_t>;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
} // namespace tensor
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
* Module Name: neural_network
|
* Module Name: neural_network
|
||||||
* File Name: layer_dense.hpp
|
* File Name: layer_dense.hpp
|
||||||
* Revision: 0.1.0
|
* Revision: 0.1.0
|
||||||
* Date: 23-06-2026
|
* Date: 28-08-2026
|
||||||
* Author: Michelle Bausager
|
* Author: Michelle Bausager
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@@ -32,109 +32,96 @@
|
|||||||
*
|
*
|
||||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <neural_network/layer/layer.hpp> // for base layer struct
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// DEFINE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Type Name : panic::neural_network::layer_dense
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// A dense layer to use in neural networks
|
|
||||||
//
|
|
||||||
// Member Variables:
|
|
||||||
// length panic::uint_t
|
|
||||||
// Number of elements in the vector.
|
|
||||||
//
|
|
||||||
// data panic::real_t*
|
|
||||||
// Pointer to the allocated vector data.
|
|
||||||
//
|
|
||||||
// Notes:
|
|
||||||
// This vector uses dynamic allocation with new[] and delete[].
|
|
||||||
// Copying performs a deep copy.
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace tensor{
|
namespace neural_network{
|
||||||
|
|
||||||
template <typename T>
|
/**
|
||||||
struct vector{
|
* @brief struct for dense layer object used in neural networks
|
||||||
panic::uint_t length;
|
*
|
||||||
T* data;
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::neural_network::layer_dense myDenseLayer(3, 5);
|
||||||
|
* myDenseLayer.forward(inputMatrix);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* The struct is used in PANIC nural_network library.
|
||||||
|
*/
|
||||||
|
struct layer_dense : public layer{
|
||||||
|
|
||||||
// empty contructor
|
/**
|
||||||
vector();
|
* @brief Emphty matrix to store input data
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix ipnuts;
|
||||||
|
|
||||||
// contructor with size allocation
|
/**
|
||||||
vector(panic::uint_t size);
|
* @brief Emphty weight matrix to store layer weights
|
||||||
|
*
|
||||||
|
* Weight shape:
|
||||||
|
* input_size x neuron_count
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix weights;
|
||||||
|
panic::tensor::real_matrix dweights;
|
||||||
|
|
||||||
// contructor with size allocation and sets it all to a value
|
/**
|
||||||
vector(panic::uint_t size, T value);
|
* @brief Emphty bias vector to store layer bias
|
||||||
|
*
|
||||||
|
* Bias shape:
|
||||||
|
* 1 x neuron_count
|
||||||
|
*/
|
||||||
|
panic::tensor::real_vector biases;
|
||||||
|
panic::tensor::real_vector dbiases;
|
||||||
|
|
||||||
// copy-contructor
|
/**
|
||||||
// vector a(3);
|
* @brief Empthy constructor
|
||||||
// vector b = a;
|
*
|
||||||
vector(const vector& other);
|
*/
|
||||||
|
layer_dense();
|
||||||
|
|
||||||
// de-contructor, releases memory
|
/**
|
||||||
~vector();
|
* @brief Constructor with input size and amount of neurons
|
||||||
|
*
|
||||||
|
* @param input_size Input size of data to the network.
|
||||||
|
* @param neurons Amount of neurons in the layer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
layer_dense(panic::types::uint_t input_size, panic::types::uint_t neurons);
|
||||||
|
|
||||||
// copy-assignment
|
/**
|
||||||
//vector a(5);
|
* @brief Default de-constructor
|
||||||
//vector b(3);
|
*
|
||||||
//b = a;
|
*/
|
||||||
vector& operator=(const vector& other);
|
~layer_dense() = default;
|
||||||
|
|
||||||
// function returns size.
|
/**
|
||||||
// const tells compiler that the fuction don't edit the objert.
|
* @brief Forward function for layer
|
||||||
panic::uint_t size() const;
|
*
|
||||||
|
* @param inputs Data input for forward pass.
|
||||||
// function to resize data vector (I need a new that don't save the vlaues)
|
*
|
||||||
bool resize(panic::uint_t new_size);
|
* @Note Calculates -> outputs = inputs * weights + biases
|
||||||
|
*/
|
||||||
// fill data with value
|
bool forward(const panic::tensor::real_matrix& input_data);
|
||||||
bool fill(T value);
|
|
||||||
|
|
||||||
// lets you read and write v[index]
|
|
||||||
T& operator[](panic::uint_t index);
|
|
||||||
|
|
||||||
// lets you read v[index] from a const vector
|
|
||||||
const T& operator[](panic::uint_t index) const;
|
|
||||||
|
|
||||||
// lets you read and write v.at(index)
|
|
||||||
T& at(panic::uint_t index);
|
|
||||||
|
|
||||||
// lets you read v.at(index) from a const vector
|
|
||||||
const T& at(panic::uint_t index) const;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Backward function for layer
|
||||||
|
*
|
||||||
|
* @param inputs Data input for bacward pass.
|
||||||
|
*
|
||||||
|
* @Note Calculates derivative of forward function.
|
||||||
|
*/
|
||||||
|
bool backward(const panic::tensor::real_matrix& dvalues);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE ALIASES
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
typedef vector<panic::real_t> real_vector;
|
|
||||||
typedef vector<panic::int_t> int_vector;
|
|
||||||
typedef vector<panic::uint_t> uint_vector;
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// EXPLICIT TEMPLATE DECLARATION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern template struct vector<panic::real_t>;
|
|
||||||
extern template struct vector<panic::int_t>;
|
|
||||||
extern template struct vector<panic::uint_t>;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
} // namespace tensor
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: loss.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base loss struct used in other loss functions in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base loss for the rest of the neural network library to use
|
||||||
|
*
|
||||||
|
* This base layer should be used in all loss functions.
|
||||||
|
* This is done so it's easy to make new loss functions in the model.
|
||||||
|
* The virtual means it should use derived object's version when called with a pointer.
|
||||||
|
* The derived object can use overloading on forward, or just use one of them, to support one-shot encoding.
|
||||||
|
*
|
||||||
|
* The struct is used for PANIC neural_network library.
|
||||||
|
*/
|
||||||
|
struct loss{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Emphty vector to store sample losses
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
panic::tensor::real_vector sample_losses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mean loss over the entire batch.
|
||||||
|
*/
|
||||||
|
panic::types::real_t data_loss;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Matrix for backwards pass
|
||||||
|
*/
|
||||||
|
panic::tensor::real_matrix dinputs;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default de-constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
virtual ~loss() = default;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual forward function for derivative loss functions
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
* @Note If the derivatived object does not use this,
|
||||||
|
* it returns false.
|
||||||
|
*/
|
||||||
|
virtual bool forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual forward function for derivative loss functions
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Matrix of true label of data.
|
||||||
|
*
|
||||||
|
* @Note If the derivatived object does not use this,
|
||||||
|
* it returns false.
|
||||||
|
*/
|
||||||
|
virtual bool forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual calculate function that calculates the loss
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool calculate(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual calculate function that calculates the loss
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Matrix of true label of data.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool calculate(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: loss_categorical_crossentropy.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base loss_categorical_crossentropy used in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/loss/loss.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief loss_categorical_crossentropy used in the rest of the neural network library
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The struct is used for PANIC neural_network library.
|
||||||
|
*/
|
||||||
|
struct loss_categorical_crossentropy: loss{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief forward function to calculate losses
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief forward function to calculate losses
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
* @Note Overloaded if one-shot endcoded
|
||||||
|
* is used.
|
||||||
|
*/
|
||||||
|
bool forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief backward function to calculate from losses
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool backward(
|
||||||
|
const panic::tensor::real_matrix& dvalues,
|
||||||
|
const panic::tensor::uint_vector& y_true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief backward function to calculate from losses
|
||||||
|
*
|
||||||
|
* @param y_pred Matrix of model predection.
|
||||||
|
* @param y_true Vector of true label of data.
|
||||||
|
*
|
||||||
|
* @Note Overloaded if one-shot endcoded
|
||||||
|
* is used.
|
||||||
|
*/
|
||||||
|
bool backward(
|
||||||
|
const panic::tensor::real_matrix& dvalues,
|
||||||
|
const panic::tensor::real_matrix& y_true);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: model.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base model struct used in in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::types::uint_t, int_t and real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix
|
||||||
|
|
||||||
|
#include <neural_network/layer/layer.hpp> // Base layer struct
|
||||||
|
#include <neural_network/layer/layer_dense.hpp> // fully connected dense layer
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// TYPE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Basic neural network model.
|
||||||
|
*
|
||||||
|
* The model owns an array of layer pointers
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* layer_count stores how many layers the model currently has.
|
||||||
|
*
|
||||||
|
* layers is a "pointer to pointers" -> layer** layers;
|
||||||
|
* That means it points to an array where each element is a layer*
|
||||||
|
*
|
||||||
|
* The struct is used for PANIC neural_network library.
|
||||||
|
*/
|
||||||
|
struct model{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief a pointer to a pointer of layers
|
||||||
|
*
|
||||||
|
* An example:
|
||||||
|
* layers[0] points to a layer_dense
|
||||||
|
* layers[1] points to an actication function
|
||||||
|
* layers[2] points to another layer_dense
|
||||||
|
*
|
||||||
|
* @note The model owns these layers and deletes them in clear().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
layer** layers;
|
||||||
|
|
||||||
|
// Number of layers currently stored in the model.
|
||||||
|
/**
|
||||||
|
* @brief Stores the number of layers
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
panic::types::uint_t layer_count;
|
||||||
|
|
||||||
|
// model output (may be deleted and also used for debug)
|
||||||
|
panic::tensor::real_matrix outputs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
model();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief De-constructor
|
||||||
|
*
|
||||||
|
* @note Calls clear() to delete all layers and releases the layer pointer array
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~model();
|
||||||
|
|
||||||
|
// Add an already-created layer to the model.
|
||||||
|
// Helper function for e.g. model.add_dense(5,5)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper function for adding layers
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* layer_dense* new_layer = new layer_dense(3, 4);
|
||||||
|
* add(new_layer)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note it adds an already-inplemented layer to the model.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool add(layer* new_layer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a dense layer to the model.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* model.add_layer_dense(3,4);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param inputs_size Input size of the data.
|
||||||
|
* @param neuron_count Number of neurons in the layer.
|
||||||
|
*
|
||||||
|
* @return true if layer is added
|
||||||
|
*
|
||||||
|
* @note This function is convenient, but it allocates a new layer.
|
||||||
|
*/
|
||||||
|
bool add_layer_dense(
|
||||||
|
panic::types::uint_t input_size,
|
||||||
|
panic::types::uint_t neuron_count
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a activation ReLU layer to the model.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* model.add_activation_relu(3,4);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return true if layer is added
|
||||||
|
*
|
||||||
|
* @note This function is convenient, but it allocates a new layer.
|
||||||
|
*/
|
||||||
|
bool add_activation_relu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a activation Softmax layer to the model.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* model.add_activation_softmax(3,4);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return true if layer is added
|
||||||
|
*
|
||||||
|
* @note This function is convenient, but it allocates a new layer.
|
||||||
|
*/
|
||||||
|
bool add_activation_softmax();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loops over all layers forward function
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* model.forward(input_data_matrix)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param inputs Input data.
|
||||||
|
*
|
||||||
|
* @return true looped over every layer.
|
||||||
|
*
|
||||||
|
* @note It takes the privious layer outputs and uses it as
|
||||||
|
* the next layers input in the forward function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool forward(const panic::tensor::real_matrix& inputs);
|
||||||
|
|
||||||
|
// Delete all layers and reset the model.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clears and deletes all layers and resets the model
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* model.clear();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Primary used in the de-construtor.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: random
|
||||||
|
* File Name: seed.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 28-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines seed for use in other functions in random/
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace random{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for seed object used in random/
|
||||||
|
*
|
||||||
|
* The struct is used for PANIC random library.
|
||||||
|
*/
|
||||||
|
struct seed_t{
|
||||||
|
|
||||||
|
// Variable to store the value the random value is based on.
|
||||||
|
panic::types::uint_t value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
seed_t();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Contructor with seed.
|
||||||
|
*
|
||||||
|
* @param seed The seed that is used as the base for the object.
|
||||||
|
*/
|
||||||
|
seed_t(panic::types::uint_t seed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function to set the seed..
|
||||||
|
*
|
||||||
|
* @param seed The seed that is used as the base for the object.
|
||||||
|
*/
|
||||||
|
bool set(panic::types::uint_t seed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a random number based on seed and index
|
||||||
|
*
|
||||||
|
* @param index Value the random number will be drawn from.
|
||||||
|
*
|
||||||
|
* @Note this can be used with omp in a loop if the index in the loop
|
||||||
|
* is used as the input to this function.
|
||||||
|
*/
|
||||||
|
panic::types::uint_t state_at(panic::types::uint_t index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the base seed value.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
panic::types::uint_t get();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// VARIABLE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// FUNCTION PROTOTYPE
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: random
|
||||||
|
* File Name: uniform.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defindes the functions that returns values based on a uniform distribution.
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// DEFINE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// TYPE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::seed
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// base for random libary
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
namespace panic{
|
||||||
|
namespace random{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a value from a uniform distribution bewteen 0 and 1.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c = uniform();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @return a value from a uniform distribution between 0 and 1
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
panic::types::real_t uniform();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a value from a uniform distribution with limits.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c = uniform(0.1f, 42.0f);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param min minimum limit for return value.
|
||||||
|
* @param max maximum limit for return value.
|
||||||
|
*
|
||||||
|
* @return a value from a uniform distribution with limits
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T uniform(const T min, const T max);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filleds a vector with values from a uniform distribution from 0 to 1.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::tensor::vector a(5);
|
||||||
|
* uniform(a);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Output vector filled iwht new values
|
||||||
|
*
|
||||||
|
* @return True of vector is filled correctly
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
bool uniform(panic::tensor::real_vector& a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filleds a vector with values from a uniform distribution from min to max.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::tensor::real_vector a(5);
|
||||||
|
* uniform(a, 1.0f, 42.0f);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Output vector filled iwht new values
|
||||||
|
* @param min minimum limit for return value.
|
||||||
|
* @param max maximum limit for return value.
|
||||||
|
*
|
||||||
|
* @return True of vector is filled correctly
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool uniform(panic::tensor::vector<T>& a, const T min, const T max);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filleds a matrix with values from a uniform distribution from 0 to 1.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::tensor::matrix A(5);
|
||||||
|
* uniform(A);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Output matrix filled with new values
|
||||||
|
*
|
||||||
|
* @return True of matrix is filled correctly
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
bool uniform(panic::tensor::real_matrix& A);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filleds a matrix with values from a uniform distribution from min to max.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* panic::tensor::real_matrix A(5,5);
|
||||||
|
* uniform(A, 1.0f, 42.0f);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param a Output matrix filled with new values
|
||||||
|
* @param min minimum limit for return value.
|
||||||
|
* @param max maximum limit for return value.
|
||||||
|
*
|
||||||
|
* @return True of matrix is filled correctly
|
||||||
|
*
|
||||||
|
* @note This is not a omp-safe function
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool uniform(panic::tensor::matrix<T>& A, const T min, const T max);
|
||||||
|
/*
|
||||||
|
|
||||||
|
panic::tensor::real_vector uniform_vector(panic::tensor::real_vector& a);
|
||||||
|
panic::tensor::real_vector uniform_vector(const panic::types::real_t min, const panic::types::real_t max);
|
||||||
|
|
||||||
|
// Create and return vector
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Create and return matrix
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: eye.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate eye matrices
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp> // for panic::vector
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace tensor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Outputs an eye matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param size Number or rows and columns.
|
||||||
|
* @param A Output matrix
|
||||||
|
*
|
||||||
|
* @return true if @p A was resized and filled successfully.
|
||||||
|
* @return false if resizing @p A failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool eye(const panic::types::uint_t size, panic::tensor::matrix<T> A);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a eye matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param T Numeric element type.
|
||||||
|
* @param size Number of rows and columns.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
//template <typename T>
|
||||||
|
//panic::tensor::matrix<T> eye(const T size);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: linspace.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate linspace tensors
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace tensor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Outputs a linear line in a vector
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* c[i] = linspace(-5, 5, 10, true);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param start Start of the line.
|
||||||
|
* @param stop End of the line.
|
||||||
|
* @param num Number of points in the array.
|
||||||
|
* @param endpoint If the endpint should be the same as @p stop.
|
||||||
|
* @param c Output vector.
|
||||||
|
*
|
||||||
|
* @return true if @p c was resized and filled successfully.
|
||||||
|
* @return false if resizing @p c failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool linspace(const T start,
|
||||||
|
const T stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
panic::tensor::vector<T>& c,
|
||||||
|
const bool endpoint=true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a vector with linear line.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* result[i] = linspace(-5, 5, 10, true);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param T Numeric element type.
|
||||||
|
* @param start Start of the line.
|
||||||
|
* @param stop End of the line.
|
||||||
|
* @param num Number of points in the array.
|
||||||
|
* @param endpoint If the endpint should be the same as @p stop.
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> linspace(const T start,
|
||||||
|
const T stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
const bool endpoint=true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: one_hot.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to one_hot matrices
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp> // for panic::vector
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace tensor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Outputs an one_hot matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @tparam T Numeric element type.
|
||||||
|
* @param size Number of columns.
|
||||||
|
* @param a Input vector that contains here 1 should be
|
||||||
|
* @param B Output matrix
|
||||||
|
*
|
||||||
|
* @return true if @p B was resized and filled successfully.
|
||||||
|
* @return false if resizing @p B failed.
|
||||||
|
*
|
||||||
|
* @note This overload writes the result into an existing vector to avoid
|
||||||
|
* unnecessary temporary allocations.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
bool one_hot(const panic::types::uint_t size, const panic::tensor::uint_vector& a, panic::tensor::matrix<T>& B);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a one_hot matrix
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param T Numeric element type.
|
||||||
|
* @param size Number of columns.
|
||||||
|
* @param a Input vector that contains here 1 should be
|
||||||
|
*
|
||||||
|
* @return A new vector containing the result.
|
||||||
|
* @return An empty vector if the operation fails.
|
||||||
|
*
|
||||||
|
* @note This overload is convenient, but may allocate a new vector.
|
||||||
|
*/
|
||||||
|
//template <typename T>
|
||||||
|
//panic::tensor::matrix<T> one_hot(const panic::types::uint_t size, const panic::tensor::vector<T>& a);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
+181
-73
@@ -36,90 +36,206 @@
|
|||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// DEFINE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Type Name : panic::tensor::matrix
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Dynamic matrix storing T values.
|
|
||||||
// The matrix owns its memory and releases it in the destructor.
|
|
||||||
//
|
|
||||||
// Member Variables:
|
|
||||||
// n panic::uint_t
|
|
||||||
// Number of rows in the matrix.
|
|
||||||
// m panic::uint_t
|
|
||||||
// Number of columns in the matrix.
|
|
||||||
//
|
|
||||||
// data T*
|
|
||||||
// Pointer to the allocated matrix data.
|
|
||||||
//
|
|
||||||
// Notes:
|
|
||||||
// This matrix uses dynamic allocation with new[] and delete[].
|
|
||||||
// Copying performs a deep copy.
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace tensor{
|
namespace tensor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for matrix object
|
||||||
|
*
|
||||||
|
* The struct is used for all PANIC libraries
|
||||||
|
* It uses dynamic allocation with new[] nad delete[].
|
||||||
|
* Copying performs a deep copy.
|
||||||
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct matrix{
|
struct matrix{
|
||||||
panic::uint_t n;
|
// Variable for number of rows
|
||||||
panic::uint_t m;
|
panic::types::uint_t n;
|
||||||
panic::uint_t length;
|
// Variable for number of cols
|
||||||
|
panic::types::uint_t m;
|
||||||
|
// Variable for length of data array
|
||||||
|
panic::types::uint_t length;
|
||||||
|
// Pointer to data array
|
||||||
T* data;
|
T* data;
|
||||||
|
|
||||||
// empty contructor
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
matrix();
|
matrix();
|
||||||
|
|
||||||
// contructor with size allocation
|
/**
|
||||||
matrix(panic::uint_t rows, panic::uint_t cols);
|
* @brief Contructor with size allocation.
|
||||||
|
*
|
||||||
|
* @param rows Number of rows in the matrix
|
||||||
|
* @param cols Number of columns in the matrix
|
||||||
|
*/
|
||||||
|
matrix(panic::types::uint_t rows, panic::types::uint_t cols);
|
||||||
|
|
||||||
// contructor with size allocation and sets it all to a value
|
/**
|
||||||
matrix(panic::uint_t rows, panic::uint_t cols, T value);
|
* @brief Contructor with size allocation and sets it all to a value.
|
||||||
|
*
|
||||||
|
* @param rows Number of rows in the matrix
|
||||||
|
* @param cols Number of columns in the matrix
|
||||||
|
* @param value all the values in the matrix.
|
||||||
|
*/
|
||||||
|
matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value);
|
||||||
|
|
||||||
// copy-contructor
|
/**
|
||||||
// matrix A(3,3);
|
* @brief Copy-contructor.
|
||||||
// matrix B = A;
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* matrix A(3,3);
|
||||||
|
* matrix B = A;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
matrix(const matrix& other);
|
matrix(const matrix& other);
|
||||||
|
|
||||||
// de-contructor, releases memory
|
/**
|
||||||
|
* @brief De-contructor, releases memory.
|
||||||
|
*
|
||||||
|
* @note Releases memory.
|
||||||
|
*/
|
||||||
~matrix();
|
~matrix();
|
||||||
|
|
||||||
// copy-assignment
|
/**
|
||||||
//matrix A(5);
|
* @brief Copy-assignment.
|
||||||
//matrix B(3);
|
*
|
||||||
//B = A;
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* matrix A(3,3);
|
||||||
|
* matrix B(5,8);
|
||||||
|
* B = A;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
matrix& operator=(const matrix& other);
|
matrix& operator=(const matrix& other);
|
||||||
|
|
||||||
// function returns rows.
|
/**
|
||||||
// const tells compiler that the fuction don't edit the objert.
|
* @brief Returns number of rows.
|
||||||
panic::uint_t rows() const;
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = A.rows();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note The const tells compiler that the fuction don't edit the objert.
|
||||||
|
*/
|
||||||
|
panic::types::uint_t rows() const;
|
||||||
|
|
||||||
// function returns columns.
|
/**
|
||||||
// const tells compiler that the fuction don't edit the objert.
|
* @brief Returns number of columns.
|
||||||
panic::uint_t cols() const;
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* m = A.cols();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note The const tells compiler that the fuction don't edit the objert.
|
||||||
|
*/
|
||||||
|
panic::types::uint_t cols() const;
|
||||||
|
|
||||||
// function to resize data vector
|
/**
|
||||||
bool resize(panic::uint_t new_n, panic::uint_t new_m);
|
* @brief Function to resize data matrix.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.resize(3,4);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note It hold all the privious functions if avaliable.
|
||||||
|
*/
|
||||||
|
bool resize(panic::types::uint_t new_n, panic::types::uint_t new_m);
|
||||||
|
|
||||||
// fill data with value
|
/**
|
||||||
|
* @brief Fill data with value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.fill(3.1415);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the matrix.
|
||||||
|
*/
|
||||||
bool fill(T value);
|
bool fill(T value);
|
||||||
|
|
||||||
// lets you read and write matrix data using row and column
|
/**
|
||||||
// Example:
|
* @brief Read and write matrix data using row and column
|
||||||
// A(1, 2)
|
*
|
||||||
// This is unchecked and fast.
|
* Computes:
|
||||||
T& operator()(panic::uint_t index_n, panic::uint_t index_m);
|
* @code
|
||||||
|
* n = A(1,2);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is unchecked and fast.
|
||||||
|
*/
|
||||||
|
T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m);
|
||||||
|
|
||||||
// lets you read matrix data using row and column from a const matrix
|
|
||||||
const T& operator()(panic::uint_t index_n, panic::uint_t index_m) const;
|
/**
|
||||||
|
* @brief Read from const matrix data using row and column
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = const A(1,2);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is unchecked and fast.
|
||||||
|
*/
|
||||||
|
const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filles and set a row to a value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.set_row(1, 3);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the matrix.
|
||||||
|
*/
|
||||||
|
bool set_row(const panic::types::uint_t index_row, const T v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filles and set a row to a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.set_row(1, vector);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the matrix.
|
||||||
|
*/
|
||||||
|
bool set_row(const panic::types::uint_t index_row, const panic::tensor::vector<T> v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filles and set a column to a value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.set_column(1, 3);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the matrix.
|
||||||
|
*/
|
||||||
|
bool set_col(const panic::types::uint_t index_col, const T v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Filles and set a column to a vector.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* A.set_col(1, vector);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the matrix.
|
||||||
|
*/
|
||||||
|
bool set_col(const panic::types::uint_t index_col, const panic::tensor::vector<T> v);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -128,28 +244,20 @@ struct matrix{
|
|||||||
// TYPE ALIASES
|
// TYPE ALIASES
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef matrix<panic::real_t> real_matrix;
|
typedef matrix<panic::types::real_t> real_matrix;
|
||||||
typedef matrix<panic::int_t> int_matrix;
|
typedef matrix<panic::types::int_t> int_matrix;
|
||||||
typedef matrix<panic::uint_t> uint_matrix;
|
typedef matrix<panic::types::uint_t> uint_matrix;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// EXPLICIT TEMPLATE DECLARATION
|
// EXPLICIT TEMPLATE DECLARATION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
extern template struct matrix<panic::real_t>;
|
extern template struct matrix<panic::types::real_t>;
|
||||||
extern template struct matrix<panic::int_t>;
|
extern template struct matrix<panic::types::int_t>;
|
||||||
extern template struct matrix<panic::uint_t>;
|
extern template struct matrix<panic::types::uint_t>;
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
} // namespace tensor
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+136
-65
@@ -37,84 +37,161 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// DEFINE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Type Name : panic::tensor::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Dynamic vector storing panic::real_t values.
|
|
||||||
// The vector owns its memory and releases it in the destructor.
|
|
||||||
//
|
|
||||||
// Member Variables:
|
|
||||||
// length panic::uint_t
|
|
||||||
// Number of elements in the vector.
|
|
||||||
//
|
|
||||||
// data panic::real_t*
|
|
||||||
// Pointer to the allocated vector data.
|
|
||||||
//
|
|
||||||
// Notes:
|
|
||||||
// This vector uses dynamic allocation with new[] and delete[].
|
|
||||||
// Copying performs a deep copy.
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace tensor{
|
namespace tensor{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for vector object
|
||||||
|
*
|
||||||
|
* The struct is used for all PANIC libraries
|
||||||
|
* It uses dynamic allocation with new[] nad delete[].
|
||||||
|
* Copying performs a deep copy.
|
||||||
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct vector{
|
struct vector{
|
||||||
panic::uint_t length;
|
// Variable to store the length of the data array
|
||||||
|
panic::types::uint_t length;
|
||||||
|
// Pointer to the data array
|
||||||
T* data;
|
T* data;
|
||||||
|
|
||||||
// empty contructor
|
/**
|
||||||
|
* @brief Empthy constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
vector();
|
vector();
|
||||||
|
|
||||||
// contructor with size allocation
|
/**
|
||||||
vector(panic::uint_t size);
|
* @brief Contructor with size allocation.
|
||||||
|
*
|
||||||
|
* @param size Number of elemets in the vector
|
||||||
|
*/
|
||||||
|
vector(panic::types::uint_t size);
|
||||||
|
|
||||||
// contructor with size allocation and sets it all to a value
|
/**
|
||||||
vector(panic::uint_t size, T value);
|
* @brief Contructor with size allocation and sets it all to a value.
|
||||||
|
*
|
||||||
|
* @param size Number of elemets in the vector
|
||||||
|
* @param value all the values in the vactor.
|
||||||
|
*/
|
||||||
|
vector(panic::types::uint_t size, T value);
|
||||||
|
|
||||||
// copy-contructor
|
/**
|
||||||
// vector a(3);
|
* @brief Copy-contructor.
|
||||||
// vector b = a;
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* vector a(3);
|
||||||
|
* vector b = a;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
vector(const vector& other);
|
vector(const vector& other);
|
||||||
|
|
||||||
// de-contructor, releases memory
|
/**
|
||||||
|
* @brief De-contructor, releases memory.
|
||||||
|
*
|
||||||
|
* @note Releases memory.
|
||||||
|
*/
|
||||||
~vector();
|
~vector();
|
||||||
|
|
||||||
// copy-assignment
|
/**
|
||||||
//vector a(5);
|
* @brief Copy-assignment.
|
||||||
//vector b(3);
|
*
|
||||||
//b = a;
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* vector a(3);
|
||||||
|
* vector b(5);
|
||||||
|
* b = a;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
vector& operator=(const vector& other);
|
vector& operator=(const vector& other);
|
||||||
|
|
||||||
// function returns size.
|
/**
|
||||||
// const tells compiler that the fuction don't edit the objert.
|
* @brief Returns number of elements/size.
|
||||||
panic::uint_t size() const;
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* m = a.size();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note The const tells compiler that the fuction don't edit the objert.
|
||||||
|
*/
|
||||||
|
panic::types::uint_t size() const;
|
||||||
|
|
||||||
// function to resize data vector (I need a new that don't save the vlaues)
|
/**
|
||||||
bool resize(panic::uint_t new_size);
|
* @brief Function to resize data vactor.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* a.resize(6);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note It hold all the privious functions if avaliable.
|
||||||
|
*/
|
||||||
|
bool resize(panic::types::uint_t new_size);
|
||||||
|
|
||||||
// fill data with value
|
/**
|
||||||
|
* @brief Fill data with value.
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* a.fill(3.1415);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Sets all values in the vactor.
|
||||||
|
*/
|
||||||
bool fill(T value);
|
bool fill(T value);
|
||||||
|
|
||||||
// lets you read and write v[index]
|
/**
|
||||||
T& operator[](panic::uint_t index);
|
* @brief Read and write vactor data using index
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = a[3];
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is unchecked and fast.
|
||||||
|
*/
|
||||||
|
T& operator[](panic::types::uint_t index);
|
||||||
|
|
||||||
// lets you read v[index] from a const vector
|
/**
|
||||||
const T& operator[](panic::uint_t index) const;
|
* @brief Read from const vector data using index
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = const a[3];
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is unchecked and fast.
|
||||||
|
*/
|
||||||
|
const T& operator[](panic::types::uint_t index) const;
|
||||||
|
|
||||||
// lets you read and write v.at(index)
|
/**
|
||||||
T& at(panic::uint_t index);
|
* @brief Read and write vactor data using index
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = a.at(3);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is checked and not fast.
|
||||||
|
*/
|
||||||
|
T& at(panic::types::uint_t index);
|
||||||
|
|
||||||
// lets you read v.at(index) from a const vector
|
/**
|
||||||
const T& at(panic::uint_t index) const;
|
* @brief Read from const vector data using index
|
||||||
|
*
|
||||||
|
* Computes:
|
||||||
|
* @code
|
||||||
|
* n = const a.at(3);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note This is checked and not fast.
|
||||||
|
*/
|
||||||
|
const T& at(panic::types::uint_t index) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,28 +200,22 @@ struct vector{
|
|||||||
// TYPE ALIASES
|
// TYPE ALIASES
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef vector<panic::real_t> real_vector;
|
typedef vector<panic::types::real_t> real_vector;
|
||||||
typedef vector<panic::int_t> int_vector;
|
typedef vector<panic::types::int_t> int_vector;
|
||||||
typedef vector<panic::uint_t> uint_vector;
|
typedef vector<panic::types::uint_t> uint_vector;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// EXPLICIT TEMPLATE DECLARATION
|
// EXPLICIT TEMPLATE DECLARATION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
extern template struct vector<panic::real_t>;
|
extern template struct vector<panic::types::real_t>;
|
||||||
extern template struct vector<panic::int_t>;
|
extern template struct vector<panic::types::int_t>;
|
||||||
extern template struct vector<panic::uint_t>;
|
extern template struct vector<panic::types::uint_t>;
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
} // namespace tensor
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,51 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <config/omp.hpp>
|
||||||
#include <iostream> // std::cout, std::endl
|
#include <iostream> // std::cout, std::endl
|
||||||
#include <config/types.hpp> // include types to use
|
#include <config/types.hpp> // include types to use
|
||||||
#include <config/constants.hpp> // Math constants
|
#include <config/constants.hpp> // Math constants
|
||||||
#include <tensor/vector.hpp>
|
#include <tensor/vector.hpp>
|
||||||
#include <tensor/matrix.hpp>
|
#include <tensor/matrix.hpp>
|
||||||
#include <io/print_tensor.hpp>
|
#include <io/print_tensor.hpp>
|
||||||
|
#include <math/matmul.hpp>
|
||||||
|
#include <neural_network/layer/layer_dense.hpp>
|
||||||
|
#include <math/add.hpp>
|
||||||
|
#include <random/uniform.hpp>
|
||||||
|
#include <neural_network/layer/layer_dense.hpp>
|
||||||
|
#include <neural_network/model/model.hpp>
|
||||||
|
|
||||||
|
#include <math/mul.hpp>
|
||||||
|
#include <math/clip.hpp>
|
||||||
|
#include <neural_network/activation/activation_relu.hpp>
|
||||||
|
#include <tensor/generators/linspace.hpp>
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
#include <neural_network/datasets/sine_data.hpp>
|
||||||
|
#include <neural_network/datasets/spiral_data.hpp>
|
||||||
|
#include <neural_network/datasets/vertical_data.hpp>
|
||||||
|
#include <math/exp.hpp>
|
||||||
|
#include <math/sub.hpp>
|
||||||
|
#include <neural_network/loss/loss_categorical_crossentropy.hpp>
|
||||||
|
#include <math/log.hpp>
|
||||||
|
#include <math/argmax.hpp>
|
||||||
|
#include <math/equal.hpp>
|
||||||
|
#include <math/mean.hpp>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// For omp tesing:
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
#if PANIC_HAS_OPENMP
|
||||||
|
#include <omp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// DEFINE DESCRIPTION
|
// DEFINE DESCRIPTION
|
||||||
@@ -48,15 +87,610 @@
|
|||||||
// #define TEST_FALG 1
|
// #define TEST_FALG 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : benchmark_omp_min_work
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Measures an operation with one thread and with all available threads.
|
||||||
|
//
|
||||||
|
// It then tests several possible omp_min_work values and estimates which
|
||||||
|
// threshold best matches the measured results.
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void benchmark_omp_min_work(){
|
||||||
|
|
||||||
|
#if !PANIC_HAS_OPENMP
|
||||||
|
|
||||||
|
std::cout << "OpenMP is not enabled.\n";
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// OPENMP SETTINGS
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
omp_set_dynamic(0);
|
||||||
|
|
||||||
|
const int parallel_thread_count = omp_get_max_threads();
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 1:
|
||||||
|
// Sizes to test.
|
||||||
|
//
|
||||||
|
// This list is suitable for vector operations.
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const panic::types::uint_t sizes[] = {
|
||||||
|
100,
|
||||||
|
250,
|
||||||
|
500,
|
||||||
|
1000,
|
||||||
|
2000,
|
||||||
|
4000,
|
||||||
|
8000,
|
||||||
|
12000,
|
||||||
|
16000,
|
||||||
|
24000,
|
||||||
|
32000,
|
||||||
|
50000,
|
||||||
|
75000,
|
||||||
|
100000,
|
||||||
|
150000,
|
||||||
|
250000,
|
||||||
|
500000,
|
||||||
|
1000000,
|
||||||
|
2000000,
|
||||||
|
5000000
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Example sizes for square matrix multiplication:
|
||||||
|
|
||||||
|
const panic::types::uint_t sizes[] = {
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
16,
|
||||||
|
20,
|
||||||
|
24,
|
||||||
|
32,
|
||||||
|
48,
|
||||||
|
64,
|
||||||
|
96,
|
||||||
|
128,
|
||||||
|
192,
|
||||||
|
256,
|
||||||
|
384,
|
||||||
|
512
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
const std::size_t number_of_sizes =
|
||||||
|
sizeof(sizes) / sizeof(sizes[0]);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 2:
|
||||||
|
// Possible omp_min_work values to test.
|
||||||
|
//
|
||||||
|
// These are work values, not necessarily vector or matrix sizes.
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const std::uint64_t omp_min_work_values[] = {
|
||||||
|
0,
|
||||||
|
50,
|
||||||
|
100,
|
||||||
|
150,
|
||||||
|
200,
|
||||||
|
250,
|
||||||
|
300,
|
||||||
|
350,
|
||||||
|
400,
|
||||||
|
450,
|
||||||
|
500,
|
||||||
|
600,
|
||||||
|
750,
|
||||||
|
1000,
|
||||||
|
1500,
|
||||||
|
2000,
|
||||||
|
4000,
|
||||||
|
8000,
|
||||||
|
16000,
|
||||||
|
32000
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Example omp_min_work values for matrix multiplication:
|
||||||
|
|
||||||
|
const std::uint64_t omp_min_work_values[] = {
|
||||||
|
0,
|
||||||
|
1000,
|
||||||
|
5000,
|
||||||
|
10000,
|
||||||
|
25000,
|
||||||
|
50000,
|
||||||
|
100000,
|
||||||
|
250000,
|
||||||
|
500000,
|
||||||
|
1000000,
|
||||||
|
2000000,
|
||||||
|
5000000,
|
||||||
|
10000000,
|
||||||
|
25000000,
|
||||||
|
50000000,
|
||||||
|
100000000
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
const std::size_t number_of_omp_min_work_values =
|
||||||
|
sizeof(omp_min_work_values) /
|
||||||
|
sizeof(omp_min_work_values[0]);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// BENCHMARK SETTINGS
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// The benchmark tries to perform approximately this much work for each size.
|
||||||
|
const std::uint64_t target_total_work = 50000000;
|
||||||
|
|
||||||
|
// Minimum and maximum number of repetitions for each size.
|
||||||
|
const std::uint64_t minimum_repetitions = 3;
|
||||||
|
const std::uint64_t maximum_repetitions = 1000;
|
||||||
|
|
||||||
|
// Prevent the compiler from treating all calculated results as unused.
|
||||||
|
volatile panic::types::real_t benchmark_sink = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// ARRAYS FOR THE MEASURED RESULTS
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::uint64_t measured_work[number_of_sizes];
|
||||||
|
|
||||||
|
double one_thread_results[number_of_sizes];
|
||||||
|
double parallel_results[number_of_sizes];
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRINT BENCHMARK INFORMATION
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< std::right
|
||||||
|
<< std::setw(12) << "Size"
|
||||||
|
<< std::setw(16) << "Work"
|
||||||
|
<< std::setw(14) << "Repetitions"
|
||||||
|
<< std::setw(18) << "1 thread (us)"
|
||||||
|
<< std::setw(18) << "Parallel (us)"
|
||||||
|
<< std::setw(12) << "Speedup"
|
||||||
|
<< std::setw(14) << "Fastest"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< std::string(104, '-')
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// TEST EVERY SIZE
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
for (std::size_t size_index = 0;
|
||||||
|
size_index < number_of_sizes;
|
||||||
|
++size_index){
|
||||||
|
|
||||||
|
const panic::types::uint_t size =
|
||||||
|
sizes[size_index];
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 3:
|
||||||
|
// Initialize the vectors or matrices used by the operation.
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Vector-add example:
|
||||||
|
|
||||||
|
panic::tensor::real_vector a(size, 1.0f);
|
||||||
|
panic::tensor::real_vector b(size, 2.0f);
|
||||||
|
panic::tensor::real_vector c(size);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Square-matrix multiplication example:
|
||||||
|
|
||||||
|
panic::tensor::real_matrix a(
|
||||||
|
size,
|
||||||
|
size,
|
||||||
|
0.01f
|
||||||
|
);
|
||||||
|
|
||||||
|
panic::tensor::real_matrix b(
|
||||||
|
size,
|
||||||
|
size,
|
||||||
|
0.02f
|
||||||
|
);
|
||||||
|
|
||||||
|
panic::tensor::real_matrix c(
|
||||||
|
size,
|
||||||
|
size
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 4:
|
||||||
|
// Calculate work in the same way as the function being tested.
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Vector operation:
|
||||||
|
|
||||||
|
const std::uint64_t work =
|
||||||
|
static_cast<std::uint64_t>(size);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Square matrix add:
|
||||||
|
|
||||||
|
const std::uint64_t work =
|
||||||
|
static_cast<std::uint64_t>(size) *
|
||||||
|
static_cast<std::uint64_t>(size);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Square matrix multiplication:
|
||||||
|
|
||||||
|
const std::uint64_t work =
|
||||||
|
static_cast<std::uint64_t>(size) *
|
||||||
|
static_cast<std::uint64_t>(size) *
|
||||||
|
static_cast<std::uint64_t>(size);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// CALCULATE NUMBER OF REPETITIONS
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::uint64_t repetitions =
|
||||||
|
target_total_work / work;
|
||||||
|
|
||||||
|
if (repetitions < minimum_repetitions){
|
||||||
|
repetitions = minimum_repetitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repetitions > maximum_repetitions){
|
||||||
|
repetitions = maximum_repetitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// MEASURE WITH ONE THREAD AND ALL THREADS
|
||||||
|
//
|
||||||
|
// test == 0: one OpenMP thread
|
||||||
|
// test == 1: all available OpenMP threads
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
double measured_time_us[2] = {
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int test = 0; test < 2; ++test){
|
||||||
|
|
||||||
|
if (test == 0){
|
||||||
|
omp_set_num_threads(1);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
omp_set_num_threads(
|
||||||
|
parallel_thread_count
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// WARM-UP
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
for (std::size_t warmup = 0;
|
||||||
|
warmup < 2;
|
||||||
|
++warmup){
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 5:
|
||||||
|
// Put the operation being tested here.
|
||||||
|
//------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
panic::math::add(a, b, c);
|
||||||
|
|
||||||
|
// Matrix multiplication:
|
||||||
|
// panic::math::matmul(a, b, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// TIMED LOOP
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const std::chrono::steady_clock::time_point start =
|
||||||
|
std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
for (std::uint64_t repetition = 0;
|
||||||
|
repetition < repetitions;
|
||||||
|
++repetition){
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------------
|
||||||
|
// EDIT 6:
|
||||||
|
// Put the same operation here.
|
||||||
|
//------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
panic::math::add(a, b, c);
|
||||||
|
|
||||||
|
// Matrix multiplication:
|
||||||
|
// panic::math::matmul(a, b, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::chrono::steady_clock::time_point end =
|
||||||
|
std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// CALCULATE AVERAGE TIME PER OPERATION
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const double total_time_us =
|
||||||
|
std::chrono::duration<double, std::micro>(
|
||||||
|
end - start
|
||||||
|
).count();
|
||||||
|
|
||||||
|
measured_time_us[test] =
|
||||||
|
total_time_us /
|
||||||
|
static_cast<double>(repetitions);
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// READ ONE RESULT
|
||||||
|
//
|
||||||
|
// Change this if the output cannot be accessed with c[size / 2].
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
benchmark_sink += c[size / 2];
|
||||||
|
|
||||||
|
/*
|
||||||
|
// For a matrix:
|
||||||
|
|
||||||
|
benchmark_sink += c(
|
||||||
|
size / 2,
|
||||||
|
size / 2
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// STORE RESULTS
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const double one_thread_us =
|
||||||
|
measured_time_us[0];
|
||||||
|
|
||||||
|
const double parallel_us =
|
||||||
|
measured_time_us[1];
|
||||||
|
|
||||||
|
measured_work[size_index] = work;
|
||||||
|
one_thread_results[size_index] = one_thread_us;
|
||||||
|
parallel_results[size_index] = parallel_us;
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRINT RESULTS FOR THIS SIZE
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const double speedup =
|
||||||
|
one_thread_us / parallel_us;
|
||||||
|
|
||||||
|
const char* fastest;
|
||||||
|
|
||||||
|
if (parallel_us < one_thread_us){
|
||||||
|
fastest = "parallel";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fastest = "one_thread";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< std::right
|
||||||
|
<< std::setw(12) << size
|
||||||
|
<< std::setw(16) << work
|
||||||
|
<< std::setw(14) << repetitions
|
||||||
|
<< std::setw(18) << std::fixed << std::setprecision(3)
|
||||||
|
<< one_thread_us
|
||||||
|
<< std::setw(18) << parallel_us
|
||||||
|
<< std::setw(12) << speedup
|
||||||
|
<< std::setw(14) << fastest
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// TEST THE POSSIBLE OMP_MIN_WORK VALUES
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::uint64_t best_omp_min_work = 0;
|
||||||
|
|
||||||
|
double best_score =
|
||||||
|
std::numeric_limits<double>::max();
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "\n"
|
||||||
|
<< "omp_min_work"
|
||||||
|
<< ", average_slowdown"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
for (std::size_t threshold_index = 0;
|
||||||
|
threshold_index < number_of_omp_min_work_values;
|
||||||
|
++threshold_index){
|
||||||
|
|
||||||
|
const std::uint64_t omp_min_work =
|
||||||
|
omp_min_work_values[threshold_index];
|
||||||
|
|
||||||
|
double score = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// SEE WHICH VERSION THIS THRESHOLD WOULD SELECT
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
for (std::size_t size_index = 0;
|
||||||
|
size_index < number_of_sizes;
|
||||||
|
++size_index){
|
||||||
|
|
||||||
|
double selected_time_us;
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// This uses > because the PANIC functions currently use:
|
||||||
|
//
|
||||||
|
// work > omp_min_work
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if (measured_work[size_index] > omp_min_work){
|
||||||
|
|
||||||
|
// This threshold would select OpenMP.
|
||||||
|
selected_time_us =
|
||||||
|
parallel_results[size_index];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
// This threshold would select serial execution.
|
||||||
|
selected_time_us =
|
||||||
|
one_thread_results[size_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// FIND THE FASTEST MEASURED VERSION FOR THIS SIZE
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
double fastest_time_us =
|
||||||
|
one_thread_results[size_index];
|
||||||
|
|
||||||
|
if (
|
||||||
|
parallel_results[size_index] <
|
||||||
|
fastest_time_us
|
||||||
|
){
|
||||||
|
fastest_time_us =
|
||||||
|
parallel_results[size_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
// CALCULATE HOW MUCH SLOWER THE SELECTED VERSION IS
|
||||||
|
//
|
||||||
|
// 1.0 means the threshold selected the fastest version.
|
||||||
|
// 1.1 means it was 10% slower than the fastest version.
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
score +=
|
||||||
|
selected_time_us /
|
||||||
|
fastest_time_us;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// CALCULATE THE AVERAGE SCORE
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
score /=
|
||||||
|
static_cast<double>(number_of_sizes);
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRINT THIS OMP_MIN_WORK RESULT
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< omp_min_work
|
||||||
|
<< ", "
|
||||||
|
<< std::fixed
|
||||||
|
<< std::setprecision(4)
|
||||||
|
<< score
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
// SAVE THE BEST OMP_MIN_WORK
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if (score < best_score){
|
||||||
|
|
||||||
|
best_score = score;
|
||||||
|
best_omp_min_work = omp_min_work;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRINT FINAL ESTIMATE
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "\n"
|
||||||
|
<< "Best estimated omp_min_work: "
|
||||||
|
<< best_omp_min_work
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "Average slowdown score: "
|
||||||
|
<< std::fixed
|
||||||
|
<< std::setprecision(4)
|
||||||
|
<< best_score
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "\n"
|
||||||
|
<< "A score of 1.0000 means the threshold selected the\n"
|
||||||
|
<< "fastest measured version for every tested size.\n";
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRINT CHECKSUM
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "Benchmark checksum: "
|
||||||
|
<< benchmark_sink
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// VARIABLE DESCRIPTION
|
// VARIABLE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// Variable difinition like:
|
// Variable difinition like:
|
||||||
panic::real_t x = 2.4;
|
panic::types::real_t x = 2.4;
|
||||||
|
|
||||||
panic::tensor::real_vector a(3);
|
panic::tensor::real_vector a(3);
|
||||||
panic::tensor::uint_vector b(3);
|
panic::tensor::uint_vector b(3);
|
||||||
panic::tensor::int_vector c(10);
|
panic::tensor::int_vector c(3);
|
||||||
|
|
||||||
panic::tensor::real_matrix A(2,2, 1);
|
panic::tensor::real_matrix A(2,2, 1);
|
||||||
panic::tensor::uint_matrix B(2,2, 2);
|
panic::tensor::uint_matrix B(2,2, 2);
|
||||||
@@ -70,25 +704,63 @@ panic::tensor::int_matrix C(2,2, 3);
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
//benchmark_omp_min_work();
|
||||||
|
|
||||||
|
// Comment out benchmark_omp_min_work() when it is not needed.
|
||||||
|
|
||||||
|
std::cout << "neural_network" << std::endl;
|
||||||
|
|
||||||
|
panic::tensor::real_matrix X;
|
||||||
|
panic::tensor::uint_vector y;
|
||||||
|
|
||||||
|
panic::types::uint_t samples = 10;
|
||||||
|
panic::types::uint_t classes = 3;
|
||||||
|
|
||||||
|
|
||||||
|
// create spiral data
|
||||||
|
panic::neural_network::spiral_data(samples, classes, X, y);
|
||||||
|
|
||||||
|
// Initilise my model
|
||||||
|
panic::neural_network::model mymodel;
|
||||||
|
|
||||||
|
// Create Dense layer with 2 input features and 3 output values
|
||||||
|
mymodel.add_layer_dense(2,3);
|
||||||
|
|
||||||
|
// Create an activation ReLU layer
|
||||||
|
mymodel.add_activation_relu();
|
||||||
|
|
||||||
|
// Create a second dense layer with 3 inputs and 3 outputs
|
||||||
|
mymodel.add_layer_dense(3, 3);
|
||||||
|
|
||||||
|
// Create activation softmax layer
|
||||||
|
mymodel.add_activation_softmax();
|
||||||
|
|
||||||
|
// create loss function
|
||||||
|
panic::neural_network::loss_categorical_crossentropy loss_function;
|
||||||
|
|
||||||
|
mymodel.forward(X);
|
||||||
|
|
||||||
|
loss_function.calculate(mymodel.outputs, y);
|
||||||
|
|
||||||
|
panic::tensor::uint_vector prediction;
|
||||||
|
prediction = panic::math::argmax_rowwise(mymodel.outputs);
|
||||||
|
|
||||||
|
panic::types::real_t accuracy;
|
||||||
|
panic::tensor::uint_vector comparisons;
|
||||||
|
|
||||||
|
comparisons = panic::math::equal(prediction, y);
|
||||||
|
|
||||||
|
accuracy = panic::math::mean(comparisons);
|
||||||
|
|
||||||
|
std::cout << "loss: " << loss_function.data_loss << std::endl;
|
||||||
|
|
||||||
|
std::cout << "acc: " << accuracy << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
a[2] = 1.2;
|
|
||||||
b[2] = 3;
|
|
||||||
c[2] = -3;
|
|
||||||
panic::io::print_vector(a);
|
|
||||||
panic::io::print_vector(b);
|
|
||||||
panic::io::print_vector(c);
|
|
||||||
std::cout << a[100] << std::endl;
|
|
||||||
std::cout << a.at(100) << std::endl;
|
|
||||||
std::cout << panic::constants::pi << std::endl;
|
|
||||||
std::cout << 1.23249238423847 << std::endl;
|
|
||||||
|
|
||||||
A(1,0) = 1.2;
|
|
||||||
B(1,0) = 3;
|
|
||||||
C(1,0) = -2;
|
|
||||||
|
|
||||||
panic::io::print_matrix(A);
|
|
||||||
panic::io::print_matrix(B);
|
|
||||||
panic::io::print_matrix(C);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+54
-58
@@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
* Project Name: PANIC
|
* Project Name: PANIC
|
||||||
* Module Name: io
|
* Module Name: io
|
||||||
* File Name: print_tensor.hpp
|
* File Name: print_tensor.cpp
|
||||||
* Revision: 0.1.0
|
* Revision: 0.1.0
|
||||||
* Date: 21-06-2026
|
* Date: 21-06-2026
|
||||||
* Author: Michelle Bausager
|
* Author: Michelle Bausager
|
||||||
@@ -35,9 +35,11 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//-----------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
#include <io/print_tensor.hpp>
|
||||||
#include <iostream> // for std::cout, std::endl
|
#include <iostream> // for std::cout, std::endl
|
||||||
#include <tensor/vector.hpp> // for panic::tensor::vector
|
|
||||||
#include <tensor/matrix.hpp>
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// DEFINE DESCRIPTION
|
// DEFINE DESCRIPTION
|
||||||
@@ -60,32 +62,32 @@ namespace panic {
|
|||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// The vector is printed out in square brackets.
|
// The vector is printed out in square brackets.
|
||||||
// Overloaded for panic::uint, panic::int and panic::real
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void print_vector(const panic::tensor::uint_vector& v){
|
template <typename T>
|
||||||
|
bool print_vector(const panic::tensor::vector<T>& v){
|
||||||
std::cout << "[";
|
std::cout << "[";
|
||||||
for (panic::uint_t i = 0; i < v.size()-1; ++i){
|
for (panic::types::uint_t i = 0; i < v.size()-1; ++i){
|
||||||
std::cout << v[i] << ", ";
|
std::cout << v[i] << ", ";
|
||||||
}
|
}
|
||||||
std::cout << v[v.size()-1]<< "]" << std::endl;
|
std::cout << v[v.size()-1]<< "]" << std::endl;
|
||||||
|
|
||||||
}
|
return true;
|
||||||
void print_vector(const panic::tensor::int_vector& v){
|
|
||||||
std::cout << "[";
|
|
||||||
for (panic::uint_t i = 0; i < v.size()-1; ++i){
|
|
||||||
std::cout << v[i] << ", ";
|
|
||||||
}
|
|
||||||
std::cout << v[v.size()-1]<< "]" << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void print_vector(const panic::tensor::real_vector& v){
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
std::cout << "[";
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
for (panic::uint_t i = 0; i < v.size()-1; ++i){
|
//
|
||||||
std::cout << v[i] << ", ";
|
// The implementation is in this .cpp file.
|
||||||
}
|
// Build the overload for the official PANIC numeric types.
|
||||||
std::cout << v[v.size()-1]<< "]" << std::endl;
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool print_vector<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& v
|
||||||
|
);
|
||||||
|
template bool print_vector<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& v
|
||||||
|
);
|
||||||
|
template bool print_vector<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& v
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -94,52 +96,46 @@ void print_vector(const panic::tensor::real_vector& v){
|
|||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// The matrix is printed out in square brackets.
|
// The matrix is printed out in square brackets.
|
||||||
// Overloaded for panic::uint, panic::int and panic::real
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void print_matrix(const panic::tensor::uint_matrix& A){
|
template <typename T>
|
||||||
|
bool print_matrix(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
std::cout << "[";
|
std::cout << "[";
|
||||||
for (panic::uint_t i = 0; i < A.rows(); ++i){
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i){
|
||||||
std::cout << "[";
|
std::cout << "[";
|
||||||
for (panic::uint_t j = 0; j < A.cols(); ++j){
|
|
||||||
std::cout << A(i,j) << ", ";
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
||||||
}
|
std::cout << A(i, j);
|
||||||
if (i < A.rows()-1){
|
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]" << std::endl;
|
if (j + 1 < A.cols()){
|
||||||
}else{
|
std::cout << ", ";
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "]";
|
||||||
|
|
||||||
|
if (i + 1 < A.rows())
|
||||||
|
std::cout << "," << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "]" << std::endl;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_matrix(const panic::tensor::int_matrix& A){
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
std::cout << "[";
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
for (panic::uint_t i = 0; i < A.rows(); ++i){
|
//
|
||||||
std::cout << "[";
|
// The implementation is in this .cpp file.
|
||||||
for (panic::uint_t j = 0; j < A.cols(); ++j){
|
// Build the overload for the official PANIC numeric types.
|
||||||
std::cout << A(i,j) << ", ";
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
}
|
template bool print_matrix<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
if (i < A.rows()-1){
|
);
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]" << std::endl;
|
template bool print_matrix<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
}else{
|
);
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl;
|
template bool print_matrix<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_matrix(const panic::tensor::real_matrix& A){
|
|
||||||
std::cout << "[";
|
|
||||||
for (panic::uint_t i = 0; i < A.rows(); ++i){
|
|
||||||
std::cout << "[";
|
|
||||||
for (panic::uint_t j = 0; j < A.cols(); ++j){
|
|
||||||
std::cout << A(i,j) << ", ";
|
|
||||||
}
|
|
||||||
if (i < A.rows()-1){
|
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]" << std::endl;
|
|
||||||
}else{
|
|
||||||
std::cout << A(A.rows()-1,A.cols()-1) << "]]" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace io
|
} // namespace io
|
||||||
|
|||||||
@@ -0,0 +1,583 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: add.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to add panic::tensors togther;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/add.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t add_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] + k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool add<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool add<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!add(a, k, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] + b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!add(a, b, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
add(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) + k;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!add(A, k, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a matrix to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( (rows != B.rows()) || (cols != B.cols())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) + B(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool add(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a matrix to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!add(A, B, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
add(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( cols != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) + b[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool add_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool add_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!add_rowwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
add_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
add_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
add_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( rows != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > add_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
const T temp = b[i];
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) + temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool add_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool add_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::add_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
|
||||||
|
if (!add_colwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
add_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
add_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
add_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,387 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: argmax.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to find the index of the maximum value;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/argmax.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t argmax_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the argmax index for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::types::uint_t argmax(const panic::tensor::vector<T>& a){
|
||||||
|
|
||||||
|
panic::types::uint_t idx = 0;
|
||||||
|
|
||||||
|
if (a.size() == 0){
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
if (a[idx] < a[i]){
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t argmax(const panic::tensor::vector<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::uint_t argmax(const panic::tensor::vector<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::uint_t argmax(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the argmax value for a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool argmax(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if (!b.resize(2)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
b.fill(0);
|
||||||
|
|
||||||
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i) {
|
||||||
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
||||||
|
if (A(b[0], b[1]) < A(i,j)) {
|
||||||
|
b[0] = i;
|
||||||
|
b[1] = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool argmax<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& a,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& a,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& a,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the argmax value for a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::uint_vector argmax(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
panic::tensor::uint_vector b;
|
||||||
|
|
||||||
|
if (! argmax(A, b)){
|
||||||
|
return panic::tensor::uint_vector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::uint_vector argmax<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector argmax<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector argmax<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the index value of maximum row-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool argmax_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(rows) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
b.fill(0);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > argmax_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
if (A(i, b[i]) < A(i,j)){
|
||||||
|
b[i] = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool argmax_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns index row-wise max values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::uint_vector argmax_rowwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::uint_vector b;
|
||||||
|
|
||||||
|
if (!argmax_rowwise(A, b)){
|
||||||
|
return panic::tensor::uint_vector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the index of the maximum column-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool argmax_colwise(const panic::tensor::matrix<T>& A, panic::tensor::uint_vector& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
b.fill(0);
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > argmax_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < rows; ++j){
|
||||||
|
|
||||||
|
if(A(j, b[i]) < A(j,i)){
|
||||||
|
b[i] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool argmax_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
template bool argmax_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::uint_vector& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::argmax_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns column-wise max index values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::uint_vector argmax_colwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::uint_vector b;
|
||||||
|
|
||||||
|
if (!argmax_colwise(A, b)){
|
||||||
|
return panic::tensor::uint_vector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::uint_vector
|
||||||
|
argmax_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
+1464
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,625 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: div.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to divdes panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/div.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t div_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divedes a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k == T{0}){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > div_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] / k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool div<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool div<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const T k){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!div(a, k, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
// Check all divisors in parallel.
|
||||||
|
// valid remains true only if every divisor is nonzero.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF( a.size() > div_omp_min_work, &&, valid )
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
const bool nonzero = b[i] != T{0};
|
||||||
|
valid = valid && nonzero;
|
||||||
|
|
||||||
|
if (nonzero){
|
||||||
|
c[i] = a[i] / b[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> div(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!div(a, b, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
div(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k == T{0}){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > div_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) / k;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const T k){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!div(A, k, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( (rows != B.rows()) || (cols != B.cols())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
// Check all divisors in parallel.
|
||||||
|
// valid remains true only if every divisor is nonzero.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF( work > div_omp_min_work, &&, valid )
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i) {
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j) {
|
||||||
|
|
||||||
|
const bool nonzero = B(i,j) != T{0};
|
||||||
|
valid = valid && nonzero;
|
||||||
|
|
||||||
|
if (nonzero) {
|
||||||
|
C(i,j) = A(i,j) / B(i,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool div(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!div(A, B, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
div(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( cols != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
// Check all divisors in parallel.
|
||||||
|
// valid remains true only if every divisor is nonzero.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF( work > div_omp_min_work, &&, valid )
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
const bool nonzero = b[i] != T{0};
|
||||||
|
valid = valid && nonzero;
|
||||||
|
for (panic::types::uint_t j = 0; j < rows; ++j){
|
||||||
|
if (nonzero){
|
||||||
|
C(j,i) = A(j,i) / b[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool div_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool div_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!div_rowwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
div_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
div_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
div_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( rows != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
// Check all divisors in parallel.
|
||||||
|
// valid remains true only if every divisor is nonzero.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF( work > div_omp_min_work, &&, valid )
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
const bool nonzero = b[i] != T{0};
|
||||||
|
valid = valid && nonzero;
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
if (nonzero){
|
||||||
|
C(i,j) = A(i,j) / b[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool div_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool div_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool div_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::div_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Divides a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> div_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
|
||||||
|
if (!div_colwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
div_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
div_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
div_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: dot.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate dot product of tensors;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
#include <math/dot.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp> // for panic::tensor::matrix
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t dot_omp_min_work = 500;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::dot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply sum two vector.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T dot(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
T result = T{0};
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the maximum in parallel for large vectors.
|
||||||
|
// Each thread computes a partial sum, then OpenMP combines them into result.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(a.size() > dot_omp_min_work, +, result)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
result += a[i]*b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t dot(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::types::int_t dot(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::types::real_t dot(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::dot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply sum a matrix and vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool dot(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (b.size() != A.rows()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
c.fill(0);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(A.rows()*A.cols() > dot_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
||||||
|
c[i] += A(i,j) * b[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool dot(
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
template bool dot(
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
template bool dot(
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::dot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply sum a matrix and vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> dot(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
panic::tensor::vector<T> c;
|
||||||
|
|
||||||
|
if (! dot(A,b,c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t> dot(
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
template panic::tensor::vector<panic::types::int_t> dot(
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t> dot(
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,614 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: equal.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to find the equal in panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/equal.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t equal_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Equal compares a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
if (a[i] == k){
|
||||||
|
c[i] = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
c[i] = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool equal<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool equal<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Equal compared a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> equal(const panic::tensor::vector<T>& a, const T k){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!equal(a, k, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Equal compared a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
if (a[i] == b[i]){
|
||||||
|
c[i] = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
c[i] = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> equal(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!equal(a, b, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
equal(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
if (A(i,j) == k){
|
||||||
|
C(i,j) = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
C(i,j) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal(const panic::tensor::matrix<T>& A, const T k){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!equal(A, k, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( (rows != B.rows()) || (cols != B.cols())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
if ( A(i,j) == B(i,j)){
|
||||||
|
C(i,j) = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
C(i,j) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool equal(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!equal(A, B, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
equal(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal compared a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( cols != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
if (A(i,j) == b[j]){
|
||||||
|
C(i,j) = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
C(i,j) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool equal_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool equal_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal_rowwise a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!equal_rowwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
equal_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
equal_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
equal_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal_colwise a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool equal_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( rows != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > equal_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < rows; ++j){
|
||||||
|
if (A(j,i) == b[i]){
|
||||||
|
C(j,i) == T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
C(j,i) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool equal_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool equal_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool equal_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::equal_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// equal_colwise a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> equal_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
|
||||||
|
if (!equal_colwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
equal_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
equal_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
equal_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,298 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: exp.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate the exponential of numbers
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/exp.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t exp_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::exp
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the exponential
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T exp(const T x){
|
||||||
|
|
||||||
|
// The identity:
|
||||||
|
//
|
||||||
|
// e^(-x) = 1 / e^x
|
||||||
|
//
|
||||||
|
// lets the rest of the function work only with positive values.
|
||||||
|
if (x < static_cast<T>(0)) {
|
||||||
|
return static_cast<T>(1) / exp(-x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Natural logarithm of 2.
|
||||||
|
//
|
||||||
|
// This is useful because:
|
||||||
|
//
|
||||||
|
// e^(ln(2)) = 2
|
||||||
|
//
|
||||||
|
const T ln2 = static_cast<T>(0.69314718055994530942);
|
||||||
|
|
||||||
|
// Split x into:
|
||||||
|
//
|
||||||
|
// x = k * ln(2) + r
|
||||||
|
//
|
||||||
|
// For example, when x = 2:
|
||||||
|
//
|
||||||
|
// k = floor(2 / ln(2)) = 2
|
||||||
|
// r = 2 - 2 * ln(2) ≈ 0.6137
|
||||||
|
//
|
||||||
|
// This makes r small, which makes the Taylor series
|
||||||
|
// converge much faster.
|
||||||
|
const panic::types::uint_t k = static_cast<panic::types::uint_t>(x / ln2);
|
||||||
|
|
||||||
|
const T r = x - static_cast<T>(k) * ln2;
|
||||||
|
|
||||||
|
// Taylor series:
|
||||||
|
//
|
||||||
|
// r² r³ r⁴
|
||||||
|
// e^r = 1 + r + ---- + ---- + ---- + ...
|
||||||
|
// 2! 3! 4!
|
||||||
|
//
|
||||||
|
// result starts with the first term: 1.
|
||||||
|
T result = static_cast<T>(1);
|
||||||
|
|
||||||
|
// term also starts at 1, representing:
|
||||||
|
//
|
||||||
|
// r^0 / 0! = 1
|
||||||
|
T term = static_cast<T>(1);
|
||||||
|
|
||||||
|
|
||||||
|
for (panic::types::uint_t n = 1; n <= 15; ++n){
|
||||||
|
|
||||||
|
// Produce the next Taylor term from the previous one.
|
||||||
|
//
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// n = 1: term = 1 * r / 1 = r
|
||||||
|
// n = 2: term = r * r / 2 = r² / 2!
|
||||||
|
// n = 3: term = r²/2 * r/3 = r³ / 3!
|
||||||
|
//
|
||||||
|
// This avoids separately calculating powers and factorials.
|
||||||
|
term *= r / static_cast<T>(n);
|
||||||
|
|
||||||
|
// Add the new term to the approximation.
|
||||||
|
result += term;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We currently have e^r.
|
||||||
|
//
|
||||||
|
// From:
|
||||||
|
//
|
||||||
|
// x = k * ln(2) + r
|
||||||
|
//
|
||||||
|
// we get:
|
||||||
|
//
|
||||||
|
// e^x = e^(k * ln(2)) * e^r
|
||||||
|
// = 2^k * e^r
|
||||||
|
//
|
||||||
|
// Therefore, multiply the result by 2 exactly k times.
|
||||||
|
for (panic::types::uint_t i = 0; i < k; ++i) {
|
||||||
|
result *= static_cast<T>(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t exp<panic::types::real_t>(const panic::types::real_t x
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::exp
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the exponential elementwise of a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool exp(const panic::tensor::vector<T>& a, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > exp_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = exp(a[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool exp<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::exp
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the exponential elementwise for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> exp(const panic::tensor::vector<T>& a){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!exp(a, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
exp(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::exp
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// calculates the exponential elementwise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool exp(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > exp_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = exp(A(i,j));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool exp(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::exp
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the exponential element-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> exp(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!exp(A, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
exp(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,388 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: log.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate the natrual logorithem of numbers
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/log.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t log_omp_min_work = 250;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::log
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the natural log
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T log(const T x){
|
||||||
|
|
||||||
|
T result = T{0};
|
||||||
|
|
||||||
|
const T zero = T{0};
|
||||||
|
const T one = T{1};
|
||||||
|
const T two = T{2};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The real natural logarithm is only defined for
|
||||||
|
* positive numbers.
|
||||||
|
*
|
||||||
|
* log(0) approaches negative infinity, while negative
|
||||||
|
* x would require complex numbers.
|
||||||
|
*/
|
||||||
|
if (x <= zero){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NaN is the only floating-point value that is not
|
||||||
|
* equal to itself.
|
||||||
|
*/
|
||||||
|
if (x != x){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is ln(2).
|
||||||
|
*
|
||||||
|
* We need it later because we rewrite the input as:
|
||||||
|
*
|
||||||
|
* input = value * 2^exponent
|
||||||
|
*
|
||||||
|
* Therefore:
|
||||||
|
*
|
||||||
|
* ln(input) = ln(value) + exponent * ln(2)
|
||||||
|
*/
|
||||||
|
static const T ln_2 = static_cast<T>(0.69314718055994530942);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* value will be reduced to the interval [1, 2).
|
||||||
|
*
|
||||||
|
* exponent records how many powers of two were removed
|
||||||
|
* or added.
|
||||||
|
*/
|
||||||
|
T value = x;
|
||||||
|
panic::types::int_t exponent = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* x = 20
|
||||||
|
*
|
||||||
|
* 20 / 2 = 10
|
||||||
|
* 10 / 2 = 5
|
||||||
|
* 5 / 2 = 2.5
|
||||||
|
* 2.5 / 2 = 1.25
|
||||||
|
*
|
||||||
|
* Therefore:
|
||||||
|
*
|
||||||
|
* 20 = 1.25 * 2^4
|
||||||
|
*
|
||||||
|
* So value becomes 1.25 and exponent becomes 4.
|
||||||
|
*/
|
||||||
|
while (value >= two){
|
||||||
|
value *= T{0.5};
|
||||||
|
++exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For an input smaller than 1, multiply by two until it
|
||||||
|
* reaches [1, 2).
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* 0.25 * 2 = 0.5
|
||||||
|
* 0.5 * 2 = 1
|
||||||
|
*
|
||||||
|
* Therefore:
|
||||||
|
*
|
||||||
|
* 0.25 = 1 * 2^-2
|
||||||
|
*/
|
||||||
|
while (value < one){
|
||||||
|
value *= two;
|
||||||
|
--exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Transform value into a smaller number near zero:
|
||||||
|
*
|
||||||
|
* y = (value - 1) / (value + 1)
|
||||||
|
*
|
||||||
|
* Since value is in [1, 2), y is in [0, 1/3).
|
||||||
|
*
|
||||||
|
* Small y values are useful because powers such as
|
||||||
|
* y^3, y^5 and y^7 become small very quickly.
|
||||||
|
*/
|
||||||
|
const T y = (value - one) / (value + one);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The series uses only odd powers:
|
||||||
|
*
|
||||||
|
* y, y^3, y^5, y^7, ...
|
||||||
|
*
|
||||||
|
* Multiplying by y^2 moves from one odd power to the next:
|
||||||
|
*
|
||||||
|
* y * y^2 = y^3
|
||||||
|
* y^3 * y^2 = y^5
|
||||||
|
*/
|
||||||
|
const T y_squared = y * y;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* term begins as y^1.
|
||||||
|
*/
|
||||||
|
T term = y;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Accumulates:
|
||||||
|
*
|
||||||
|
* y + y^3/3 + y^5/5 + ...
|
||||||
|
*/
|
||||||
|
T sum = zero;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Twenty terms are more than enough for float
|
||||||
|
* after the range reduction above.
|
||||||
|
*
|
||||||
|
* A fixed number of iterations also makes the runtime
|
||||||
|
* predictable.
|
||||||
|
*/
|
||||||
|
for (panic::types::uint_t i = 0; i < 20; ++i){
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The denominators are:
|
||||||
|
*
|
||||||
|
* 1, 3, 5, 7, ...
|
||||||
|
*
|
||||||
|
* which are generated by 2*i + 1.
|
||||||
|
*/
|
||||||
|
const panic::types::uint_t denominator =
|
||||||
|
2 * i + 1;
|
||||||
|
|
||||||
|
sum += term / static_cast<T>(denominator);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Advance:
|
||||||
|
*
|
||||||
|
* y -> y^3 -> y^5 -> y^7
|
||||||
|
*/
|
||||||
|
term *= y_squared;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The series calculates:
|
||||||
|
*
|
||||||
|
* ln(value) =
|
||||||
|
* 2 * (y + y^3/3 + y^5/5 + ...)
|
||||||
|
*
|
||||||
|
* Then restore the power of two removed during range
|
||||||
|
* reduction:
|
||||||
|
*
|
||||||
|
* ln(input) =
|
||||||
|
* ln(value) + exponent * ln(2)
|
||||||
|
*/
|
||||||
|
result = two * sum + static_cast<T>(exponent) * ln_2;
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t log<panic::types::real_t>(const panic::types::real_t x
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::log
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the natrual log elementwise of a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool log(const panic::tensor::vector<T>& a, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > log_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = log(a[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool log<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::log
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the natrual log elementwise for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> log(const panic::tensor::vector<T>& a){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!log(a, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
log(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::log
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// calculates the natrual log elementwise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool log(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > log_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = log(A(i,j));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool log(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::log
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the natrual log element-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> log(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!log(A, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
log(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: matmul.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 24-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to print out tensors with std::cout << x std::endl;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
#include <math/matmul.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp> // for panic::tensor::matrix
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t matmul_omp_min_work = 10000;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::matmul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply two matrices into C.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
const panic::types::uint_t rows = A.rows();
|
||||||
|
const panic::types::uint_t cols = B.cols();
|
||||||
|
const panic::types::uint_t inner = A.cols();
|
||||||
|
|
||||||
|
|
||||||
|
// Dimention mismacth
|
||||||
|
if( inner != B.rows()){
|
||||||
|
C.resize(0,0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In-place case: matmul(A, B, A) or matmul(A, B, B)
|
||||||
|
// This is not allowed since operation is unsafe.
|
||||||
|
// Use A = matmul(A, B) or B = matmul(A, B) instead.
|
||||||
|
if (&C == &A || &C == &B){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!C.resize(rows, cols)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const panic::types::uint_t work = rows*cols*inner;
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > matmul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
T sum = static_cast<T>(0);
|
||||||
|
for (panic::types::uint_t k = 0; k < inner; ++k){
|
||||||
|
sum += A(i,k) * B(k,j);
|
||||||
|
}
|
||||||
|
C(i,j) = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool matmul<panic::types::uint_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
template bool matmul<panic::types::int_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
template bool matmul<panic::types::real_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::matmul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply two matrices and returns the result.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!matmul(A,B,C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t> matmul<panic::types::uint_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
template panic::tensor::matrix<panic::types::int_t> matmul<panic::types::int_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
template panic::tensor::matrix<panic::types::real_t> matmul<panic::types::real_t>(
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: add.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to add panic::tensors togther;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/max.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t max_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the max value for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T max(const panic::tensor::vector<T>& a){
|
||||||
|
|
||||||
|
T y = a[0];
|
||||||
|
|
||||||
|
// Find the maximum in parallel for large vectors.
|
||||||
|
// Each thread computes a local maximum, then OpenMP combines them into y.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(a.size() > max_omp_min_work, max, y)
|
||||||
|
for (panic::types::uint_t i = 1; i < a.size(); ++i) {
|
||||||
|
if (a[i] > y) {
|
||||||
|
y = a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t max<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::int_t max<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t max<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the max value for a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T max(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
T y = A(0,0);
|
||||||
|
|
||||||
|
// Find the maximum in parallel for large vectors.
|
||||||
|
// Each thread computes a local maximum, then OpenMP combines them into y.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(work > max_omp_min_work, max, y)
|
||||||
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i) {
|
||||||
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
||||||
|
if (A(i,j) > y) {
|
||||||
|
y = A(i,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t max<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::int_t max<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t max<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the maximum row-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool max_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(rows) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each thread handles separate rows and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > max_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
b[i] = A(i,0);
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
if (b[i] < A(i,j)){
|
||||||
|
b[i] = A(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool max_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool max_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool max_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns row-wise max values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> max_rowwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::vector<T> b;
|
||||||
|
|
||||||
|
if (!max_rowwise(A, b)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
max_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
max_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
max_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the maximum column-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool max_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each thread handles separate cols and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > max_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
b[i] = A(0,i);
|
||||||
|
for (panic::types::uint_t j = 0; j < rows; ++j){
|
||||||
|
if (b[i] < A(j,i)){
|
||||||
|
b[i] = A(j,i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool max_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool max_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool max_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::max_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns column-wise max values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> max_colwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::vector<T> b;
|
||||||
|
|
||||||
|
if (!max_colwise(A, b)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
max_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
max_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
max_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: mean.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate mean of tensor arrays
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/mean.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
#include <math/sum.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t mean_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the mean value for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::types::real_t mean(const panic::tensor::vector<T>& a){
|
||||||
|
|
||||||
|
const panic::types::real_t sum = static_cast<panic::types::real_t>(panic::math::sum(a));
|
||||||
|
|
||||||
|
return sum / static_cast<panic::types::real_t>(a.size());
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t mean<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t mean<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t mean<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the mean value for a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::types::real_t mean(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
panic::types::real_t sum = static_cast<panic::types::real_t> (panic::math::sum(A));
|
||||||
|
|
||||||
|
return sum / static_cast<panic::types::real_t>(work);
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t mean<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t mean<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t mean<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the mean row-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//template <typename T>
|
||||||
|
bool mean_rowwise(const panic::tensor::real_matrix& A, panic::tensor::real_vector& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(rows) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sum_rowwise(A, b)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Each thread handles separate rows and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(rows > mean_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
b[i] /= cols;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}/*
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mean_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool mean_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool mean_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns row-wise sum values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//template <typename T>
|
||||||
|
panic::tensor::real_vector mean_rowwise(const panic::tensor::real_matrix& A){
|
||||||
|
panic::tensor::real_vector b;
|
||||||
|
|
||||||
|
if (!mean_rowwise(A, b)){
|
||||||
|
return panic::tensor::real_vector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}/*
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
mean_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
mean_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
mean_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the mean column-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//template <typename T>
|
||||||
|
bool mean_colwise(const panic::tensor::real_matrix& A, panic::tensor::real_vector& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! sum_colwise(A,b)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each thread handles separate cols and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > mean_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
b[i] /= cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}/*
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mean_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool mean_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool mean_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mean_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns column-wise mean values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//template <typename T>
|
||||||
|
panic::tensor::real_vector mean_colwise(const panic::tensor::real_matrix& A){
|
||||||
|
panic::tensor::real_vector b;
|
||||||
|
|
||||||
|
if (!mean_colwise(A, b)){
|
||||||
|
return panic::tensor::real_vector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}/*
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
mean_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
mean_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
mean_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);*/
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,587 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: mul.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to multiply panic::tensor
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/mul.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t mul_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] * k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool mul<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool mul<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> mul(const panic::tensor::vector<T>& a, const T k){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!mul(a, k, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] * b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> mul(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!mul(a, b, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
mul(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) * k;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul(const panic::tensor::matrix<T>& A, const T k){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!mul(A, k, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( (rows != B.rows()) || (cols != B.cols())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) * B(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool mul(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a matrix to a matrix elementwise
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!mul(A, B, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
mul(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( cols != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) * b[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool mul_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool mul_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!mul_rowwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
mul_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
mul_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
mul_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool mul_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( rows != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > mul_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
const T temp = b[i];
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) * temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool mul_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool mul_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool mul_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::mul_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiplies a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> mul_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
|
||||||
|
if (!mul_colwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
mul_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
mul_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
mul_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,582 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sub.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to subtracts panic::tensors togther;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/sub.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t sub_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] - k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool sub<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool sub<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a constant to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const T k){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!sub(a, k, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c){
|
||||||
|
|
||||||
|
if (a.size() != b.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.resize(a.size())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(a.size() > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i){
|
||||||
|
c[i] = a[i] - b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a vector to a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sub(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::vector<T> c(a.size());
|
||||||
|
|
||||||
|
if (!sub(a, b, c)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
sub(const panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) - k;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a constant to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const T k){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!sub(A, k, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::types::uint_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::types::int_t k
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::types::real_t k
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a matrix to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( (rows != B.rows()) || (cols != B.cols())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
C(i,j) = A(i,j) - B(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool sub(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a matrix to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!sub(A, B, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
sub(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( cols != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) - b[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool sub_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool sub_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a vector row-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
if (!sub_rowwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
sub_rowwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
sub_rowwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
sub_rowwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracs a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( rows != b.size() ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !C.resize(rows, cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sub_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
|
||||||
|
C(i,j) = A(i,j) - b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sub_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& C
|
||||||
|
);
|
||||||
|
template bool sub_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& C
|
||||||
|
);
|
||||||
|
template bool sub_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& C
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sub_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// subtracts a vector coloumn-wise to a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> sub_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b){
|
||||||
|
panic::tensor::matrix<T> C;
|
||||||
|
|
||||||
|
|
||||||
|
if (!sub_colwise(A, b, C)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return C;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t>
|
||||||
|
sub_colwise(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t>
|
||||||
|
sub_colwise(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t>
|
||||||
|
sub_colwise(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sum.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to sum up arrays
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <math/sum.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t sum_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the sum value for a vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T sum(const panic::tensor::vector<T>& a){
|
||||||
|
|
||||||
|
T result = T{0};
|
||||||
|
|
||||||
|
// Find the maximum in parallel for large vectors.
|
||||||
|
// Each thread computes a partial sum, then OpenMP combines them into result.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(a.size() > sum_omp_min_work, +, result)
|
||||||
|
for (panic::types::uint_t i = 0; i < a.size(); ++i) {
|
||||||
|
result += a[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t sum<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::int_t sum<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t sum<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the sum value for a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T sum(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
T result = A(0,0);
|
||||||
|
|
||||||
|
// Find the maximum in parallel for large vectors.
|
||||||
|
// Each thread computes a partial sum, then OpenMP combines them into result.
|
||||||
|
PANIC_OMP_PARALLEL_FOR_REDUCTION_IF(work > sum_omp_min_work, +, result)
|
||||||
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i) {
|
||||||
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
||||||
|
result += A(i,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t sum<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::int_t sum<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& a
|
||||||
|
);
|
||||||
|
template panic::types::real_t sum<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the sum row-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sum_rowwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(rows) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each thread handles separate rows and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sum_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
b[i] = T{0};
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
b[i] += A(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sum_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool sum_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool sum_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum_rowwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns row-wise sum values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sum_rowwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::vector<T> b;
|
||||||
|
|
||||||
|
if (!sum_rowwise(A, b)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
sum_rowwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
sum_rowwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
sum_rowwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Find the sum column-wise of a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sum_colwise(const panic::tensor::matrix<T>& A, panic::tensor::vector<T>& b){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !b.resize(cols) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each thread handles separate cols and writes to a separate b[i].
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > sum_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < cols; ++i){
|
||||||
|
b[i] = T{0};
|
||||||
|
for (panic::types::uint_t j = 0; j < rows; ++j){
|
||||||
|
b[i] += A(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sum_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& b
|
||||||
|
);
|
||||||
|
template bool sum_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& b
|
||||||
|
);
|
||||||
|
template bool sum_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& b
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sum_colwise
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns column-wise sum values
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> sum_colwise(const panic::tensor::matrix<T>& A){
|
||||||
|
panic::tensor::vector<T> b;
|
||||||
|
|
||||||
|
if (!sum_colwise(A, b)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t>
|
||||||
|
sum_colwise<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t>
|
||||||
|
sum_colwise<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t>
|
||||||
|
sum_colwise<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: transpose.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to transpose a matrix;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
#include <math/transpose.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/matrix.hpp> // for panic::tensor::matrix
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t transpose_omp_min_work = 500;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::transpose
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Transposes a matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool transpose(const panic::tensor::matrix<T>& A, panic::tensor::matrix<T>& B){
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if ( !B.resize(cols, rows) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > transpose_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
B(j,i) = A(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool transpose(const panic::tensor::matrix<panic::types::uint_t>& A,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template bool transpose(const panic::tensor::matrix<panic::types::int_t>& A,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template bool transpose(const panic::tensor::matrix<panic::types::real_t>& A,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::dot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Multiply sum a matrix and vector
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> transpose(const panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
panic::tensor::matrix<T> B;
|
||||||
|
|
||||||
|
if (! transpose(A,B)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return B;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t> transpose(
|
||||||
|
const panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
template panic::tensor::matrix<panic::types::int_t> transpose(
|
||||||
|
const panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t> transpose(
|
||||||
|
const panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: cos.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate cossinus of x;
|
||||||
|
* This uses panic::math::sin
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <math/trigonometry/cos.hpp>
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/constants.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sin
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates cosinus of x
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T cos(const T x){
|
||||||
|
|
||||||
|
return panic::math::sin(x + static_cast<T>(panic::constants::half_pi));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t cos<panic::types::real_t>(const panic::types::real_t x
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: math
|
||||||
|
* File Name: sin.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to calculate sinus of x;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/constants.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace math {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::sin
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates sinus of x
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T sin(const T x){
|
||||||
|
|
||||||
|
T temp = x;
|
||||||
|
|
||||||
|
// Reduce x to [-pi, pi].
|
||||||
|
while (temp > panic::constants::pi){
|
||||||
|
temp -= panic::constants::tau;
|
||||||
|
}
|
||||||
|
while (temp < -panic::constants::pi){
|
||||||
|
temp += panic::constants::tau;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce x further to [-pi/2, pi/2].
|
||||||
|
if (temp > panic::constants::half_pi){
|
||||||
|
temp = panic::constants::pi - temp;
|
||||||
|
}else if (x < -panic::constants::half_pi){
|
||||||
|
temp = -panic::constants::pi - temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const panic::types::real_t x2 = temp * temp;
|
||||||
|
|
||||||
|
|
||||||
|
// Taylor polynomial: // x - x^3/3! + x^5/5! - x^7/7! + x^9/9!
|
||||||
|
return temp * (static_cast<panic::types::real_t>(1.0)
|
||||||
|
+ x2*( static_cast<panic::types::real_t>(-1.0 / 6.0)
|
||||||
|
+ x2*( static_cast<panic::types::real_t>(1.0 / 120.0)
|
||||||
|
+ x2*( static_cast<panic::types::real_t>(-1.0 / 5040.0)
|
||||||
|
+ x2*static_cast<panic::types::real_t>(1.0 / 362880.0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::real_t sin<panic::types::real_t>(const panic::types::real_t x
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace math
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: activation_relu.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-08-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the activation layer for ReLU
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/activation/activation_relu.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <math/clip.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t activation_ReLU_omp_min_size = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::neural_network::activation_relu
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates an empty layer.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
activation_relu::activation_relu() {
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::activation_relu.forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculated the forward pass:
|
||||||
|
// outputs = max(inputs, 0)
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool activation_relu::forward(const panic::tensor::real_matrix& input_data){
|
||||||
|
|
||||||
|
inputs = input_data;
|
||||||
|
|
||||||
|
panic::math::clip_lower(inputs, 0.0f, outputs);
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::activation_relu.backward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculated the backward pass:
|
||||||
|
// ??
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool activation_relu::backward(const panic::tensor::real_matrix& dvalues){
|
||||||
|
|
||||||
|
// Zero gradients where input values were negative
|
||||||
|
panic::types::real_t zero = 0;
|
||||||
|
dinputs = panic::math::clip_lower(dvalues, zero);
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: activation_softmax.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-08-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the activation layer for Softmax
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/activation/activation_softmax.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <math/exp.hpp>
|
||||||
|
#include <math/max.hpp>
|
||||||
|
#include <math/sum.hpp>
|
||||||
|
#include <math/div.hpp>
|
||||||
|
#include <math/sub.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t activation_softmax_omp_min_size = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::neural_network::activation_softmax
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates an empty layer.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
activation_softmax::activation_softmax() {
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::activation_softmax.forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculated the forward pass:
|
||||||
|
// outputs = max(inputs, 0)
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool activation_softmax::forward(const panic::tensor::real_matrix& input_data){
|
||||||
|
|
||||||
|
inputs = input_data;
|
||||||
|
|
||||||
|
panic::tensor::real_vector row_maximums;
|
||||||
|
panic::tensor::real_vector row_sums;
|
||||||
|
|
||||||
|
// Each row represents one sample.
|
||||||
|
// Find the maximum class score in each sample
|
||||||
|
//
|
||||||
|
// row_maximums[i] = max(inputs(i, 0), ..., inputs(i, cols - 1))
|
||||||
|
if (! panic::math::max_rowwise(inputs, row_maximums)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// row_maximums contains one value per row, so it behaves
|
||||||
|
// like a column vector broadcast across all columns:
|
||||||
|
//
|
||||||
|
// outputs(i, j) = inputs(i, j) - row_maximums[i]
|
||||||
|
if (!panic::math::sub_colwise(inputs, row_maximums, outputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the shifted scores into positive exponential values
|
||||||
|
if (!panic::math::exp(outputs, outputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum the exponential values in each sample
|
||||||
|
//
|
||||||
|
// row_sums[i] = sum(outputs(i, 0), ..., outputs(i, cols - 1))
|
||||||
|
if (!panic::math::sum_rowwise(outputs, row_sums)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// row_sums contains one value per row, so broadcast it
|
||||||
|
// across all columns and normalize each sample:
|
||||||
|
//
|
||||||
|
// outputs(i, j) = outputs(i, j) / row_sums[i]
|
||||||
|
if (!panic::math::div_colwise(outputs, row_sums, outputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::activation_softmax.backward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculated the backward pass:
|
||||||
|
// ??
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool activation_softmax::backward(const panic::tensor::real_matrix& dvalues){
|
||||||
|
|
||||||
|
const panic::types::uint_t rows = dvalues.rows();
|
||||||
|
const panic::types::uint_t cols = dvalues.cols();
|
||||||
|
const panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
if (outputs.rows() != rows || outputs.cols() != cols ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dinputs.resize(rows, cols)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > activation_softmax_omp_min_size)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
panic::types::real_t dot = 0;
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
dot += outputs(i,j) * dvalues(i,j);
|
||||||
|
}
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
dinputs(i,j) = outputs(i,j) * (dvalues(i,j) -dot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: sine_data.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <neural_network/datasets/sine_data.hpp>
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
#include <math/trigonometry/cos.hpp>
|
||||||
|
|
||||||
|
#include <tensor/generators/linspace.hpp>
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t sine_data_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::sine_data
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Generates dataset with sinus curve
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::vector<T>& y){
|
||||||
|
|
||||||
|
if ( !X.resize(samples, 1) || !y.resize(samples) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
X.set_col(0, panic::tensor::linspace(static_cast<T>(0), // start
|
||||||
|
lenght, // stop
|
||||||
|
samples // num
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(samples > sine_data_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < samples; ++i){
|
||||||
|
y[i] = panic::math::sin(X(i,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sine_data<panic::types::real_t>(const panic::types::uint_t samples,
|
||||||
|
const panic::types::real_t lenght,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& X,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::sine_cosine_data
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Generates dataset with sinus and a cosine curve
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool sine_cosine_data(const panic::types::uint_t samples, const T lenght, panic::tensor::matrix<T>& X, panic::tensor::matrix<T>& y){
|
||||||
|
|
||||||
|
if ( !X.resize(samples, 1) || !y.resize(samples,2) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
X.set_col(0, panic::tensor::linspace(static_cast<T>(0), // start
|
||||||
|
lenght, // stop
|
||||||
|
samples // num
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(samples > sine_data_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < samples; ++i){
|
||||||
|
y(i,0) = panic::math::sin(X(i,0));
|
||||||
|
y(i,1) = panic::math::cos(X(i,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool sine_cosine_data<panic::types::real_t>(const panic::types::uint_t samples,
|
||||||
|
const panic::types::real_t lenght,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& X,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: spiral_data.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <neural_network/datasets/spiral_data.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
#include <math/trigonometry/cos.hpp>
|
||||||
|
#include <math/add.hpp>
|
||||||
|
#include <random/uniform.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t spiral_data_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::spiral_data
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Generates dataset with spiral data
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool spiral_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y){
|
||||||
|
|
||||||
|
|
||||||
|
if ( !X.resize(samples*classes, 2) || !y.resize(samples*classes) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(samples*classes > spiral_data_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < classes; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < samples; ++j){
|
||||||
|
|
||||||
|
const T radius = static_cast<T>(j)/static_cast<T>(samples-1);
|
||||||
|
|
||||||
|
const T angle = static_cast<T>(i)*T{4} + (T{4}*radius);
|
||||||
|
|
||||||
|
const panic::types::uint_t row_index = (i*samples) + j;
|
||||||
|
|
||||||
|
X(row_index, 0) = radius*panic::math::cos(angle*T{2.5});
|
||||||
|
X(row_index, 1) = radius*panic::math::sin(angle*T{2.5});
|
||||||
|
|
||||||
|
y[row_index] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
panic::tensor::matrix<T> random_matrix(samples*classes, 2);
|
||||||
|
panic::random::uniform(random_matrix, T{-0.15}, T{0.15});
|
||||||
|
|
||||||
|
if (!panic::math::add(X, random_matrix, X)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool spiral_data<panic::types::real_t>(const panic::types::uint_t samples,
|
||||||
|
const panic::types::uint_t classes,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& X,
|
||||||
|
panic::tensor::uint_vector& y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: vertical_data.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate dataset for neural networks;
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <neural_network/datasets/vertical_data.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <math/trigonometry/sin.hpp>
|
||||||
|
#include <math/trigonometry/cos.hpp>
|
||||||
|
#include <math/add.hpp>
|
||||||
|
#include <random/uniform.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t vertical_data_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace neural_network {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::vertical_data
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Generates dataset with vertical data
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool vertical_data(const panic::types::uint_t samples, const panic::types::uint_t classes, panic::tensor::matrix<T>& X, panic::tensor::uint_vector& y){
|
||||||
|
|
||||||
|
|
||||||
|
if ( !X.resize(samples*classes, 2) || !y.resize(samples*classes) ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
panic::tensor::vector<T> x_diviation(samples*classes);
|
||||||
|
panic::tensor::vector<T> y_diviation(samples*classes);
|
||||||
|
|
||||||
|
panic::random::uniform(x_diviation, T{-0.1}, T{0.1});
|
||||||
|
panic::random::uniform(y_diviation, T{-0.5}, T{0.5});
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(samples*classes > vertical_data_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < classes; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < samples; ++j){
|
||||||
|
|
||||||
|
const panic::types::uint_t row_index = (i*samples) + j;
|
||||||
|
|
||||||
|
X(row_index, 0) = static_cast<T>(i)/static_cast<T>(classes) + x_diviation[row_index];
|
||||||
|
X(row_index, 1) = T{0.5} + y_diviation[row_index];
|
||||||
|
y[row_index] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool vertical_data<panic::types::real_t>(const panic::types::uint_t samples,
|
||||||
|
const panic::types::uint_t classes,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& X,
|
||||||
|
panic::tensor::uint_vector& y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
*
|
|
||||||
* PANIC
|
|
||||||
* Portable Algorithms and Numerics In C++
|
|
||||||
*
|
|
||||||
* Scientific computing from scratch, with feeling.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2026 Michelle Bausager
|
|
||||||
*
|
|
||||||
* This file is part of PANIC.
|
|
||||||
*
|
|
||||||
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
|
||||||
* You may redistribute and/or modify it under the terms of the GPL.
|
|
||||||
*
|
|
||||||
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the LICENSE file for the full license text.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*
|
|
||||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
*
|
|
||||||
* Project Name: PANIC
|
|
||||||
* Module Name: neural_network
|
|
||||||
* File Name: layer_dense.cpp
|
|
||||||
* Revision: 0.1.0
|
|
||||||
* Date: 23-06-2026
|
|
||||||
* Author: Michelle Bausager
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Defines the dense layers used in neural network
|
|
||||||
*
|
|
||||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// INCLUDE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
#include <tensor/vector.hpp>
|
|
||||||
#include <config/omp.hpp>
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// DEFINE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// TYPE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
static const panic::uint_t vector_omp_min_size = 10000;
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
|
||||||
namespace tensor{
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Creates an empty vector.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::vector() {
|
|
||||||
length = 0;
|
|
||||||
data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Creates a vector with size allocation and initializes all values to zero.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::vector(panic::uint_t size){
|
|
||||||
length = size;
|
|
||||||
|
|
||||||
if (length == 0){
|
|
||||||
data = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new T[length];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < size; ++i){
|
|
||||||
data[i] = static_cast<T>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Creates a vector with size allocation and initializes all values.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::vector(panic::uint_t size, T value){
|
|
||||||
length = size;
|
|
||||||
|
|
||||||
if (size == 0){
|
|
||||||
data = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new T[size];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < size; ++i){
|
|
||||||
data[i] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Copy-contructor, makes a deep copy of another vector like this:
|
|
||||||
// vector a(3);
|
|
||||||
// vector b = a;
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::vector(const vector& other){
|
|
||||||
length = other.length;
|
|
||||||
|
|
||||||
if (length == 0){
|
|
||||||
data = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new T[length];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < length; ++i){
|
|
||||||
data[i] = other.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Deconstructor Name : panic::tensor::vector::~vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Deletes the data and releases the memory.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::~vector(){
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = 0;
|
|
||||||
length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::operator=
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Copy-assignment. Copies from another vector like this:
|
|
||||||
// vector a(5);
|
|
||||||
// vector b(3);
|
|
||||||
// b = a;
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>& vector<T>::operator=(const vector& other){
|
|
||||||
if (this == &other){
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* new_data = 0;
|
|
||||||
|
|
||||||
if (other.length > 0){
|
|
||||||
new_data = new T[other.length];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < other.length; ++i){
|
|
||||||
new_data[i] = other.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = new_data;
|
|
||||||
length = other.length;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::resize
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Returns the length/size of the vector
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
panic::uint_t vector<T>::size() const{
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::resize
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Resizes the vector to new length and keeps old values
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
bool vector<T>::resize(panic::uint_t new_size){
|
|
||||||
if (new_size == length){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_size == 0){
|
|
||||||
data = 0;
|
|
||||||
length = 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* new_data = new T[new_size];
|
|
||||||
panic::uint_t copy_size = length;
|
|
||||||
|
|
||||||
if (new_size < length){
|
|
||||||
copy_size = new_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(copy_size > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < copy_size; ++i){
|
|
||||||
new_data[i] = data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(copy_size - new_size > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = copy_size; i < new_size; ++i){
|
|
||||||
new_data[i] = static_cast<T>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = new_data;
|
|
||||||
length = new_size;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::fill
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Fills te vector with a value
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
bool vector<T>::fill(T value){
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < length; ++i){
|
|
||||||
data[i] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::operator[]
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read and write v[index]
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
T& vector<T>::operator[](panic::uint_t index){
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::operator[]
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read v[index] from a const vector
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
const T& vector<T>::operator[](panic::uint_t index) const{
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::at
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read and write v.at(index) with index bounse
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
T& vector<T>::at(panic::uint_t index){
|
|
||||||
|
|
||||||
if (index >= length){
|
|
||||||
return data[length-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::at
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read v[index] from a const vector with index bounse
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
const T& vector<T>::at(panic::uint_t index) const{
|
|
||||||
if (index >= length){
|
|
||||||
return data[length-1];
|
|
||||||
}
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// EXPLICIT TEMPLATE INSTANTIATION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template struct vector<panic::real_t>;
|
|
||||||
template struct vector<panic::int_t>;
|
|
||||||
template struct vector<panic::uint_t>;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
|
||||||
} // namespace panic
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* Module Name: neural_network
|
* Module Name: neural_network
|
||||||
* File Name: layer_dense.cpp
|
* File Name: layer_dense.cpp
|
||||||
* Revision: 0.1.0
|
* Revision: 0.1.0
|
||||||
* Date: 23-06-2026
|
* Date: 28-07-2026
|
||||||
* Author: Michelle Bausager
|
* Author: Michelle Bausager
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@@ -35,295 +35,116 @@
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// INCLUDE DESCRIPTION
|
// INCLUDE DESCRIPTION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
#include <tensor/vector.hpp>
|
#include <neural_network/layer/layer_dense.hpp>
|
||||||
#include <config/omp.hpp>
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
#include <math/matmul.hpp>
|
||||||
// DEFINE DESCRIPTION
|
#include <math/mul.hpp>
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
#include <math/add.hpp>
|
||||||
|
#include <random/uniform.hpp>
|
||||||
|
|
||||||
|
#include <math/transpose.hpp>
|
||||||
|
#include <math/sum.hpp>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
// TYPE DESCRIPTION
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t layer_dense_omp_min_size = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// VARIABLE DESCRIPTION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
static const panic::uint_t vector_omp_min_size = 10000;
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// FUNCTION PROTOTYPE
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
namespace panic{
|
namespace panic{
|
||||||
namespace tensor{
|
namespace neural_network{
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
// Constructor Name : panic::neural_network::layer_dense
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Creates an empty vector.
|
// Creates an empty layer.
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
layer_dense::layer_dense() {
|
||||||
vector<T>::vector() {
|
weights.resize(0,0);
|
||||||
length = 0;
|
biases.resize(0);
|
||||||
data = 0;
|
dweights.resize(0,0);
|
||||||
|
dbiases.resize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
// Constructor Name : panic::neural_network::layer_dense
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Creates a vector with size allocation and initializes all values to zero.
|
// Creates an empty layer with neurons.
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
layer_dense::layer_dense(panic::types::uint_t input_size, panic::types::uint_t neurons) {
|
||||||
vector<T>::vector(panic::uint_t size){
|
weights.resize(input_size, neurons);
|
||||||
length = size;
|
panic::random::uniform(weights);
|
||||||
|
panic::math::mul(weights, 0.01f, weights);
|
||||||
|
|
||||||
if (length == 0){
|
biases.resize(neurons);
|
||||||
data = 0;
|
biases.fill(0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new T[length];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < size; ++i){
|
|
||||||
data[i] = static_cast<T>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
// Function Name : panic::neural_network::layer_dense.forward
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Creates a vector with size allocation and initializes all values.
|
// Calculated the forward pass:
|
||||||
|
// outputs = inputs * weights + biases
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
bool layer_dense::forward(const panic::tensor::real_matrix& input_data){
|
||||||
vector<T>::vector(panic::uint_t size, T value){
|
|
||||||
length = size;
|
|
||||||
|
|
||||||
if (size == 0){
|
inputs = input_data;
|
||||||
data = 0;
|
|
||||||
return;
|
if (inputs.cols() != weights.rows()){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new T[size];
|
if (!outputs.resize(inputs.rows(), weights.cols())){
|
||||||
|
return false;
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < size; ++i){
|
|
||||||
data[i] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor Name : panic::tensor::vector::vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Copy-contructor, makes a deep copy of another vector like this:
|
|
||||||
// vector a(3);
|
|
||||||
// vector b = a;
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::vector(const vector& other){
|
|
||||||
length = other.length;
|
|
||||||
|
|
||||||
if (length == 0){
|
|
||||||
data = 0;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new T[length];
|
if (!panic::math::matmul(inputs, weights, outputs)){
|
||||||
|
return false;
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < length; ++i){
|
|
||||||
data[i] = other.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Deconstructor Name : panic::tensor::vector::~vector
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Deletes the data and releases the memory.
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>::~vector(){
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = 0;
|
|
||||||
length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::operator=
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Copy-assignment. Copies from another vector like this:
|
|
||||||
// vector a(5);
|
|
||||||
// vector b(3);
|
|
||||||
// b = a;
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
vector<T>& vector<T>::operator=(const vector& other){
|
|
||||||
if (this == &other){
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T* new_data = 0;
|
if (!panic::math::add_rowwise(outputs, biases, outputs)){
|
||||||
|
return false;
|
||||||
if (other.length > 0){
|
|
||||||
new_data = new T[other.length];
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < other.length; ++i){
|
|
||||||
new_data[i] = other.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = new_data;
|
|
||||||
length = other.length;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::resize
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Returns the length/size of the vector
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
panic::uint_t vector<T>::size() const{
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::resize
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Resizes the vector to new length and keeps old values
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
bool vector<T>::resize(panic::uint_t new_size){
|
|
||||||
if (new_size == length){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_size == 0){
|
|
||||||
data = 0;
|
|
||||||
length = 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* new_data = new T[new_size];
|
|
||||||
panic::uint_t copy_size = length;
|
|
||||||
|
|
||||||
if (new_size < length){
|
|
||||||
copy_size = new_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(copy_size > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < copy_size; ++i){
|
|
||||||
new_data[i] = data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(copy_size - new_size > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = copy_size; i < new_size; ++i){
|
|
||||||
new_data[i] = static_cast<T>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = new_data;
|
|
||||||
length = new_size;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::fill
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Fills te vector with a value
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
bool vector<T>::fill(T value){
|
|
||||||
PANIC_OMP_PARALLEL_FOR_IF(length > vector_omp_min_size)
|
|
||||||
for (panic::uint_t i = 0; i < length; ++i){
|
|
||||||
data[i] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
// Function Name : panic::tensor::vector::operator[]
|
// Function Name : panic::neural_network::layer_dense.backward
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Lets you read and write v[index]
|
// Calculated the backward pass:
|
||||||
|
// ??
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
bool layer_dense::backward(const panic::tensor::real_matrix& dvalues){
|
||||||
T& vector<T>::operator[](panic::uint_t index){
|
|
||||||
return data[index];
|
|
||||||
|
// Gradients on parameters
|
||||||
|
dweights = panic::math::matmul(panic::math::transpose(inputs), dvalues);
|
||||||
|
dbiases = panic::math::sum_colwise(dvalues);
|
||||||
|
|
||||||
|
// Gradients on values
|
||||||
|
dinputs = panic::math::matmul(dvalues, panic::math::transpose(weights));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::operator[]
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read v[index] from a const vector
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
const T& vector<T>::operator[](panic::uint_t index) const{
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::at
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read and write v.at(index) with index bounse
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
T& vector<T>::at(panic::uint_t index){
|
|
||||||
|
|
||||||
if (index >= length){
|
|
||||||
return data[length-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Function Name : panic::tensor::vector::at
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Lets you read v[index] from a const vector with index bounse
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <typename T>
|
|
||||||
const T& vector<T>::at(panic::uint_t index) const{
|
|
||||||
if (index >= length){
|
|
||||||
return data[length-1];
|
|
||||||
}
|
|
||||||
return data[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// EXPLICIT TEMPLATE INSTANTIATION
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template struct vector<panic::real_t>;
|
|
||||||
template struct vector<panic::int_t>;
|
|
||||||
template struct vector<panic::uint_t>;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace tensor
|
} // namespace tensor
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: loss.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base loss struct used in other loss functions in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/loss/loss.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
|
#include <math/mean.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t loss_omp_min_size = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss::calculate
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the mean loss on class targets.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss::calculate(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true){
|
||||||
|
|
||||||
|
// Calculate sample losses
|
||||||
|
if (!forward(y_pred, y_true)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate mean loss
|
||||||
|
data_loss = panic::math::mean(sample_losses);
|
||||||
|
|
||||||
|
//return calculate_mean();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss::calculate
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the mean loss using matrix targets.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss::calculate(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true){
|
||||||
|
|
||||||
|
if (!forward(y_pred, y_true)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data_loss = panic::math::mean(sample_losses);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss::forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default implementation. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss::forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true){
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss::forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default matrix-target implementation. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss::forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true){
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss::calculate_mean
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Calculates the average of all sample loss values.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss::calculate_mean(){
|
||||||
|
|
||||||
|
if (sample_losses.size() == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
panic::types::real_t sum =
|
||||||
|
static_cast<panic::types::real_t>(0);
|
||||||
|
|
||||||
|
for (
|
||||||
|
panic::types::uint_t i = 0;
|
||||||
|
i < sample_losses.size();
|
||||||
|
++i
|
||||||
|
){
|
||||||
|
sum += sample_losses[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
data_loss =
|
||||||
|
sum /
|
||||||
|
static_cast<panic::types::real_t>(sample_losses.size());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: loss_categorical_crossentropy.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 30-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base loss_categorical_crossentropy used in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/loss/loss_categorical_crossentropy.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||||
|
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
|
#include <math/clip.hpp>
|
||||||
|
#include <math/log.hpp>
|
||||||
|
#include <math/mul.hpp>
|
||||||
|
#include <tensor/generators/one_hot.hpp>
|
||||||
|
#include <math/div.hpp>
|
||||||
|
|
||||||
|
#include <math/sum.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t loss_categorical_crossentropy_omp_min_size = 500;
|
||||||
|
|
||||||
|
static const panic::types::real_t clip_min = 1e-7;
|
||||||
|
static const panic::types::real_t clip_max = 1 - 1e-7;
|
||||||
|
static const panic::types::real_t neg = -1;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss_categorical_crossentropy::forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default implementation for catecorical labels. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss_categorical_crossentropy::forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::uint_vector& y_true){
|
||||||
|
|
||||||
|
// Number of samples in a batch
|
||||||
|
const panic::types::uint_t samples = y_pred.rows();
|
||||||
|
|
||||||
|
if (samples != y_true.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// clip data to prevent log by 0
|
||||||
|
// Clip both sides to not drag the mean towards any value
|
||||||
|
panic::tensor::real_matrix y_pred_cliped = panic::math::clip(y_pred, clip_min, clip_max);
|
||||||
|
|
||||||
|
// Vector to hold the correct confidences
|
||||||
|
panic::tensor::real_vector correct_confidences(samples);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(samples > loss_categorical_crossentropy_omp_min_size)
|
||||||
|
for (panic::types::uint_t i = 0; i < samples; ++i){
|
||||||
|
const panic::types::uint_t idx = y_true[i];
|
||||||
|
|
||||||
|
//if (idx >= y_pred.cols()){
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
correct_confidences[i] = y_pred_cliped(i, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate losses
|
||||||
|
panic::tensor::real_vector negative_log_likelihoos(samples);
|
||||||
|
|
||||||
|
negative_log_likelihoos = panic::math::mul(panic::math::log(correct_confidences), neg);
|
||||||
|
|
||||||
|
sample_losses = negative_log_likelihoos;
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss_categorical_crossentropy::forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default one-hot encoded labels implementation. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss_categorical_crossentropy::forward(
|
||||||
|
const panic::tensor::real_matrix& y_pred,
|
||||||
|
const panic::tensor::real_matrix& y_true){
|
||||||
|
|
||||||
|
|
||||||
|
if (y_pred.rows() != y_true.rows() || y_pred.cols() != y_true.cols()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number of samples in a batch
|
||||||
|
const panic::types::uint_t samples = y_pred.rows();
|
||||||
|
|
||||||
|
|
||||||
|
// clip data to prevent log by 0
|
||||||
|
// Clip both sides to not drag the mean towards any value
|
||||||
|
panic::tensor::real_matrix y_pred_cliped = panic::math::clip(y_pred, clip_min, clip_max);
|
||||||
|
|
||||||
|
// Vector to hold the correct confidences
|
||||||
|
panic::tensor::real_vector correct_confidences(samples);
|
||||||
|
|
||||||
|
|
||||||
|
correct_confidences = panic::math::sum_rowwise(panic::math::mul(y_pred_cliped, y_true));
|
||||||
|
|
||||||
|
|
||||||
|
// Calculate losses
|
||||||
|
panic::tensor::real_vector negative_log_likelihoos(samples);
|
||||||
|
|
||||||
|
negative_log_likelihoos = panic::math::mul(panic::math::log(correct_confidences), neg);
|
||||||
|
|
||||||
|
sample_losses = negative_log_likelihoos;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss_categorical_crossentropy::backward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default implementation for catecorical labels. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss_categorical_crossentropy::backward(
|
||||||
|
const panic::tensor::real_matrix& dvalues,
|
||||||
|
const panic::tensor::uint_vector& y_true){
|
||||||
|
|
||||||
|
if (dvalues.rows() == 0 || dvalues.cols() == 0 || y_true.size() != dvalues.rows()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
panic::tensor::real_matrix y_true_one_hot;
|
||||||
|
|
||||||
|
// Transforms it to one_hot
|
||||||
|
if (! panic::tensor::one_hot(dvalues.cols(), y_true, y_true_one_hot)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uses other backward overloaded function to handle the rest.
|
||||||
|
return backward(dvalues, y_true_one_hot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::loss_categorical_crossentropy::backward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Default one-hot encoded labels implementation. Derived classes can override it.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool loss_categorical_crossentropy::backward(
|
||||||
|
const panic::tensor::real_matrix& dvalues,
|
||||||
|
const panic::tensor::real_matrix& y_true){
|
||||||
|
|
||||||
|
// Number of samples
|
||||||
|
const panic::types::uint_t samples = dvalues.rows();
|
||||||
|
|
||||||
|
if (samples == 0 || dvalues.cols() == 0 || y_true.rows() != dvalues.rows() || y_true.cols() != dvalues.cols()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dinputs = y_true / dvalues
|
||||||
|
if (!panic::math::div(y_true, dvalues, dinputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale = -1 / samples
|
||||||
|
const panic::types::real_t scale = -static_cast<panic::types::real_t>(1) / static_cast<panic::types::real_t>(samples);
|
||||||
|
|
||||||
|
|
||||||
|
// dinputs *= scale
|
||||||
|
if (!panic::math::mul(dinputs, scale, dinputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,295 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: neural_network
|
||||||
|
* File Name: model.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 25-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the base model struct used in in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <neural_network/model/model.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
#include <tensor/matrix.hpp>
|
||||||
|
|
||||||
|
#include <neural_network/layer/layer_dense.hpp>
|
||||||
|
|
||||||
|
#include <neural_network/activation/activation_relu.hpp>
|
||||||
|
#include <neural_network/activation/activation_softmax.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// IMPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic{
|
||||||
|
namespace neural_network{
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::neural_network::model
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates an empty model.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
model::model(){
|
||||||
|
|
||||||
|
// No layers yet.
|
||||||
|
layers = 0;
|
||||||
|
|
||||||
|
// Number of layers is zero.
|
||||||
|
layer_count = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Destructor Name : panic::neural_network::model::~model
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Deletes all layers owned by the model.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
model::~model(){
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::add
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Adds a layer to the model.
|
||||||
|
//
|
||||||
|
// The layer pointer array
|
||||||
|
// is resized every time a new layer is added.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool model::add(layer* new_layer){
|
||||||
|
|
||||||
|
// Do not add a null layer.
|
||||||
|
if (new_layer == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The new array needs room for all old layers plus the new one.
|
||||||
|
const panic::types::uint_t new_layer_count = layer_count + 1;
|
||||||
|
|
||||||
|
// Allocate a new array of layer pointers.
|
||||||
|
//
|
||||||
|
// layer* means "pointer to one layer"
|
||||||
|
// layer** means "pointer to many layer pointers"
|
||||||
|
//
|
||||||
|
// So this creates:
|
||||||
|
//
|
||||||
|
// [ layer* ][ layer* ][ layer* ] ...
|
||||||
|
//
|
||||||
|
layer** new_layers = new layer*[new_layer_count];
|
||||||
|
|
||||||
|
// Copy the old layer pointers into the new array.
|
||||||
|
//
|
||||||
|
// Important:
|
||||||
|
// This does not copy the layers themselves.
|
||||||
|
// It only copies the addresses of the layers.
|
||||||
|
for (panic::types::uint_t i = 0; i < layer_count; ++i){
|
||||||
|
new_layers[i] = layers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the new layer at the end.
|
||||||
|
new_layers[layer_count] = new_layer;
|
||||||
|
|
||||||
|
// Delete the old array of pointers.
|
||||||
|
//
|
||||||
|
// Important:
|
||||||
|
// Do NOT delete layers[i] here.
|
||||||
|
// The actual layer objects are still used in new_layers.
|
||||||
|
//
|
||||||
|
// This only deletes the old pointer array.
|
||||||
|
delete[] layers;
|
||||||
|
|
||||||
|
// Make the model use the new bigger array.
|
||||||
|
layers = new_layers;
|
||||||
|
|
||||||
|
// Update the layer count.
|
||||||
|
layer_count = new_layer_count;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::add_layer_dense
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a dense layer and adds it to the model.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// model.add_layer_dense(100, 64);
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool model::add_layer_dense(
|
||||||
|
panic::types::uint_t input_size,
|
||||||
|
panic::types::uint_t neuron_count){
|
||||||
|
|
||||||
|
// Create the dense layer.
|
||||||
|
layer_dense* new_layer = new layer_dense(input_size, neuron_count);
|
||||||
|
|
||||||
|
if (new_layer == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add it to the model.
|
||||||
|
//
|
||||||
|
// If add() fails, delete the layer so we do not leak memory.
|
||||||
|
if (!add(new_layer)){
|
||||||
|
delete new_layer;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::add_activation_relu
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a activation ReLU layer and adds it to the model.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// model.activation_relu();
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool model::add_activation_relu(){
|
||||||
|
|
||||||
|
// Create the ReLU layer.
|
||||||
|
activation_relu* new_layer = new activation_relu();
|
||||||
|
|
||||||
|
if (new_layer == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add it to the model.
|
||||||
|
//
|
||||||
|
// If add() fails, delete the layer so we do not leak memory.
|
||||||
|
if (!add(new_layer)){
|
||||||
|
delete new_layer;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::add_activation_softmax
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a activation Softmax layer and adds it to the model.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// model.activation_softmax();
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool model::add_activation_softmax(){
|
||||||
|
|
||||||
|
// Create the ReLU layer.
|
||||||
|
activation_softmax* new_layer = new activation_softmax();
|
||||||
|
|
||||||
|
if (new_layer == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add it to the model.
|
||||||
|
//
|
||||||
|
// If add() fails, delete the layer so we do not leak memory.
|
||||||
|
if (!add(new_layer)){
|
||||||
|
delete new_layer;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::forward
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Runs the input through every layer in order.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool model::forward(const panic::tensor::real_matrix& inputs){
|
||||||
|
|
||||||
|
// If the model has no layers, just copy inputs to outputs.
|
||||||
|
if (layer_count == 0){
|
||||||
|
outputs = inputs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First layer receives the original model input.
|
||||||
|
if (!layers[0]->forward(inputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every next layer receives the output from the previous layer.
|
||||||
|
// If it fails, return false
|
||||||
|
for (panic::types::uint_t i = 1; i < layer_count; ++i){
|
||||||
|
|
||||||
|
if (!layers[i]->forward(layers[i - 1] -> outputs)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The model output is the output of the last layer.
|
||||||
|
outputs = layers[layer_count - 1] -> outputs;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::neural_network::model::clear
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Deletes all layers and resets the model.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void model::clear(){
|
||||||
|
|
||||||
|
if (layers != 0){
|
||||||
|
|
||||||
|
// Delete each actual layer object.
|
||||||
|
for (panic::types::uint_t i = 0; i < layer_count; ++i){
|
||||||
|
delete layers[i];
|
||||||
|
layers[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the array that stored the layer pointers.
|
||||||
|
delete[] layers;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset to empty state.
|
||||||
|
layers = 0;
|
||||||
|
layer_count = 0;
|
||||||
|
|
||||||
|
outputs.resize(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace neural_network
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: random
|
||||||
|
* File Name: seed.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 28-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines seed for use in other functions in random/
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <random/seed.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// FUNCTION PROTOTYPE
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
namespace panic{
|
||||||
|
namespace random{
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::random::seed::seed_t
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates an seed object.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
seed_t::seed_t(){
|
||||||
|
value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::random::seed::seed_t
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates an seed object with a specific seed.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
seed_t::seed_t(panic::types::uint_t seed){
|
||||||
|
set(seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::random::seed::set_seed
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Sets the seed to a none-zero value
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool seed_t::set(panic::types::uint_t seed){
|
||||||
|
|
||||||
|
if (seed == 0){
|
||||||
|
value = 1;
|
||||||
|
}else{
|
||||||
|
value = seed;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::random::seed::get
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns the seed.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
panic::types::uint_t seed_t::get(){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Constructor Name : panic::random::seed::state_at
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Returns a pshodo-random number based on the input index and the seed value.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
panic::types::uint_t seed_t::state_at(panic::types::uint_t index) const{
|
||||||
|
|
||||||
|
panic::types::uint_t state = value + index;
|
||||||
|
|
||||||
|
// Mix it a few times so close indexes do not start too similarly.
|
||||||
|
//next_state(state);
|
||||||
|
//next_state(state);
|
||||||
|
//next_state(state);
|
||||||
|
|
||||||
|
state ^= state >> 16;
|
||||||
|
state *= static_cast<panic::types::uint_t>(0x7feb352d);
|
||||||
|
state ^= state >> 15;
|
||||||
|
state *= static_cast<panic::types::uint_t>(0x846ca68b);
|
||||||
|
state ^= state >> 16;
|
||||||
|
|
||||||
|
return state;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,260 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: random
|
||||||
|
* File Name: uniform.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-06-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Defines the dense layers used in neural network
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INCLUDE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
#include <random/uniform.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <random/seed.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// VARIABLE DESCRIPTION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
static const panic::types::uint_t uniform_omp_min_work = 5000;
|
||||||
|
static const panic::types::uint_t max_uint_t = ~static_cast<panic::types::uint_t>(0);
|
||||||
|
static const panic::types::real_t real_max_unit = static_cast<panic::types::real_t>(max_uint_t);
|
||||||
|
|
||||||
|
static panic::types::uint_t uniform_state = static_cast<panic::types::uint_t>(1);
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// FUNCTION PROTOTYPE
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
namespace panic{
|
||||||
|
namespace random{
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// returns a value from a uniform distribution bewteen 0 and 1
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
panic::types::real_t uniform(){
|
||||||
|
panic::random::seed_t seed;
|
||||||
|
uniform_state += static_cast<panic::types::uint_t>(1);
|
||||||
|
seed.set(uniform_state);
|
||||||
|
|
||||||
|
return (static_cast<panic::types::real_t>(seed.state_at(seed.get()) / real_max_unit));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// returns a value from a uniform distribution bewteen min and max
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
T uniform(const T min, const T max){
|
||||||
|
return (min + static_cast<T>(static_cast<panic::types::real_t>((max - min)) * uniform()));
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::types::uint_t
|
||||||
|
uniform<panic::types::uint_t>(const panic::types::uint_t min,
|
||||||
|
const panic::types::uint_t mix
|
||||||
|
);
|
||||||
|
template panic::types::int_t
|
||||||
|
uniform<panic::types::int_t>(const panic::types::int_t min,
|
||||||
|
const panic::types::int_t max
|
||||||
|
);
|
||||||
|
template panic::types::real_t
|
||||||
|
uniform<panic::types::real_t>(const panic::types::real_t min,
|
||||||
|
const panic::types::real_t max
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Fills a vector with a uniform distribution
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool uniform(panic::tensor::real_vector& a){
|
||||||
|
|
||||||
|
panic::random::seed_t seed;
|
||||||
|
panic::types::uint_t work = a.size();
|
||||||
|
uniform_state += work;
|
||||||
|
seed.set(uniform_state);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > uniform_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < work; ++i){
|
||||||
|
a[i] = (static_cast<panic::types::real_t>(seed.state_at(i)) / real_max_unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Fills a vector with a uniform distribution with limits
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool uniform(panic::tensor::vector<T>& a, const T min, const T max){
|
||||||
|
|
||||||
|
panic::random::seed_t seed;
|
||||||
|
panic::types::uint_t work = a.size();
|
||||||
|
|
||||||
|
uniform_state += work;
|
||||||
|
seed.set(uniform_state);
|
||||||
|
|
||||||
|
panic::types::real_t temp = static_cast<panic::types::real_t>(max - min);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > uniform_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < work; ++i){
|
||||||
|
a[i] = min + static_cast<T>((temp*(static_cast<panic::types::real_t>(seed.state_at(i)) / real_max_unit)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool uniform<panic::types::uint_t>(panic::tensor::vector<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t min,
|
||||||
|
const panic::types::uint_t mix
|
||||||
|
);
|
||||||
|
template bool uniform<panic::types::int_t>(panic::tensor::vector<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t min,
|
||||||
|
const panic::types::int_t max
|
||||||
|
);
|
||||||
|
template bool uniform<panic::types::real_t>(panic::tensor::vector<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t min,
|
||||||
|
const panic::types::real_t max
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Fills a matrix with a uniform distribution
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool uniform(panic::tensor::real_matrix& A){
|
||||||
|
|
||||||
|
panic::random::seed_t seed;
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
uniform_state += work;
|
||||||
|
seed.set(uniform_state);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > uniform_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
panic::types::uint_t index = i * cols + j;
|
||||||
|
A(i,j) = (static_cast<panic::types::real_t>(seed.state_at(index)) / real_max_unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::random::uniform
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Fills a matrix with a uniform distribution with limits
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool uniform(panic::tensor::matrix<T>& A, const T min, const T max){
|
||||||
|
|
||||||
|
panic::random::seed_t seed;
|
||||||
|
|
||||||
|
panic::types::uint_t rows = A.rows();
|
||||||
|
panic::types::uint_t cols = A.cols();
|
||||||
|
|
||||||
|
panic::types::uint_t work = rows*cols;
|
||||||
|
|
||||||
|
uniform_state += work;
|
||||||
|
seed.set(uniform_state);
|
||||||
|
|
||||||
|
panic::types::real_t temp = static_cast<panic::types::real_t>(max - min);
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(work > uniform_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < rows; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < cols; ++j){
|
||||||
|
panic::types::uint_t index = i * cols + j;
|
||||||
|
A(i,j) = min + static_cast<T>((temp*(static_cast<panic::types::real_t>(seed.state_at(index)) / real_max_unit)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool uniform<panic::types::uint_t>(panic::tensor::matrix<panic::types::uint_t>& a,
|
||||||
|
const panic::types::uint_t min,
|
||||||
|
const panic::types::uint_t mix
|
||||||
|
);
|
||||||
|
template bool uniform<panic::types::int_t>(panic::tensor::matrix<panic::types::int_t>& a,
|
||||||
|
const panic::types::int_t min,
|
||||||
|
const panic::types::int_t max
|
||||||
|
);
|
||||||
|
template bool uniform<panic::types::real_t>(panic::tensor::matrix<panic::types::real_t>& a,
|
||||||
|
const panic::types::real_t min,
|
||||||
|
const panic::types::real_t max
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: eye.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate eye matrices
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <tensor/generators/eye.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t eye_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace tensor {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::tensor::eye
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a eye matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool eye(const panic::types::uint_t size, panic::tensor::matrix<T>& A){
|
||||||
|
|
||||||
|
if (!A.resize(size,size)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(size*size > eye_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < size; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < size; ++j){
|
||||||
|
if (i == j){
|
||||||
|
A(i,j) = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
A(i,j) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool eye(const panic::types::uint_t size,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& A
|
||||||
|
);
|
||||||
|
template bool eye(const panic::types::uint_t size,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& A
|
||||||
|
);
|
||||||
|
template bool eye(const panic::types::uint_t size,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& A
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::eye
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Retuens a eye matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> eye(const T size){
|
||||||
|
|
||||||
|
panic::tensor::matrix<T> A(static_cast<panic::types::uint_t>(size), static_cast<panic::types::uint_t>(size));
|
||||||
|
|
||||||
|
if (!eye(A.rows(), A)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return A;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t> eye(const panic::types::uint_t size
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t> eye(const panic::types::int_t size
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t> eye(const panic::types::real_t size
|
||||||
|
);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: linspace.cpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 29-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate linspace tensors
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <tensor/generators/linspace.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t linspace_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace tensor {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::tensor::linspace
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a vector with a line generated by linspace
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool linspace(const T start,
|
||||||
|
const T stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
panic::tensor::vector<T>& c,
|
||||||
|
const bool endpoint){
|
||||||
|
|
||||||
|
|
||||||
|
if (!c.resize(num)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
T step;
|
||||||
|
|
||||||
|
if (endpoint){
|
||||||
|
step = (stop - start) / static_cast<T>(num - 1);
|
||||||
|
}else{
|
||||||
|
step = (stop - start) / static_cast<T>(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(num > linspace_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < num; ++i){
|
||||||
|
c[i] = start + (step*static_cast<T>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool linspace<panic::types::uint_t>(const panic::types::uint_t start,
|
||||||
|
const panic::types::uint_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
panic::tensor::vector<panic::types::uint_t>& c,
|
||||||
|
const bool endpoint
|
||||||
|
|
||||||
|
);
|
||||||
|
template bool linspace<panic::types::int_t>(const panic::types::int_t start,
|
||||||
|
const panic::types::int_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
panic::tensor::vector<panic::types::int_t>& c,
|
||||||
|
const bool endpoint
|
||||||
|
);
|
||||||
|
template bool linspace<panic::types::real_t>(const panic::types::real_t start,
|
||||||
|
const panic::types::real_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
panic::tensor::vector<panic::types::real_t>& c,
|
||||||
|
const bool endpoint
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::linspace
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Retuens a vector with line of linspace
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::vector<T> linspace(const T start,
|
||||||
|
const T stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
const bool endpoint){
|
||||||
|
|
||||||
|
panic::tensor::vector<T> c(num);
|
||||||
|
|
||||||
|
if (!linspace(start, stop, num, c, endpoint)){
|
||||||
|
return panic::tensor::vector<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::vector<panic::types::uint_t> linspace<panic::types::uint_t>(const panic::types::uint_t start,
|
||||||
|
const panic::types::uint_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
const bool endpoint
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::int_t> linspace<panic::types::int_t>(const panic::types::int_t start,
|
||||||
|
const panic::types::int_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
const bool endpoint
|
||||||
|
);
|
||||||
|
template panic::tensor::vector<panic::types::real_t> linspace<panic::types::real_t>(const panic::types::real_t start,
|
||||||
|
const panic::types::real_t stop,
|
||||||
|
const panic::types::uint_t num,
|
||||||
|
const bool endpoint
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* PANIC
|
||||||
|
* Portable Algorithms and Numerics In C++
|
||||||
|
*
|
||||||
|
* Scientific computing from scratch, with feeling.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Michelle Bausager
|
||||||
|
*
|
||||||
|
* This file is part of PANIC.
|
||||||
|
*
|
||||||
|
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* You may redistribute and/or modify it under the terms of the GPL.
|
||||||
|
*
|
||||||
|
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the LICENSE file for the full license text.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
*
|
||||||
|
* Project Name: PANIC
|
||||||
|
* Module Name: tensor
|
||||||
|
* File Name: one_hot.hpp
|
||||||
|
* Revision: 0.1.0
|
||||||
|
* Date: 31-07-2026
|
||||||
|
* Author: Michelle Bausager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Functions to generate one_hot matrices
|
||||||
|
*
|
||||||
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||||
|
#include <tensor/generators/one_hot.hpp>
|
||||||
|
#include <config/omp.hpp>
|
||||||
|
#include <config/types.hpp>
|
||||||
|
|
||||||
|
#include <tensor/vector.hpp> // for panic::vector
|
||||||
|
#include <tensor/matrix.hpp> // for panic::matrix
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// PRIVATE CONSTANTS
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Minimum number of element operations before using the OpenMP-enabled loop.
|
||||||
|
*
|
||||||
|
* Small vectors and matrices are kept serial because the overhead of starting
|
||||||
|
* worker threads can be larger than the work itself.
|
||||||
|
*/
|
||||||
|
static const panic::types::uint_t one_hot_omp_min_work = 500;
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// INPLEMENTATION
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace panic {
|
||||||
|
namespace tensor {
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::tensor::one_hot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Creates a one_hot matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
bool one_hot(const panic::types::uint_t size, const panic::tensor::uint_vector & a, panic::tensor::matrix<T>& B){
|
||||||
|
|
||||||
|
if (!B.resize(size,size)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size != a.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PANIC_OMP_PARALLEL_FOR_IF(size*size > one_hot_omp_min_work)
|
||||||
|
for (panic::types::uint_t i = 0; i < size; ++i){
|
||||||
|
for (panic::types::uint_t j = 0; j < size; ++j){
|
||||||
|
if (a[i] == j){
|
||||||
|
B(i,j) = T{1};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
B(i,j) = T{0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template bool one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::uint_vector& a,
|
||||||
|
panic::tensor::matrix<panic::types::uint_t>& B
|
||||||
|
);
|
||||||
|
template bool one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::uint_vector& a,
|
||||||
|
panic::tensor::matrix<panic::types::int_t>& B
|
||||||
|
);
|
||||||
|
template bool one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::uint_vector& a,
|
||||||
|
panic::tensor::matrix<panic::types::real_t>& B
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// Function Name : panic::math::one_hot
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Retuens a one_hot matrix
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
panic::tensor::matrix<T> one_hot(const panic::types::uint_t size, const panic::tensor::uint_vector& a){
|
||||||
|
|
||||||
|
panic::tensor::matrix<T> B(size, size);
|
||||||
|
|
||||||
|
if (!one_hot(size, a, B)){
|
||||||
|
return panic::tensor::matrix<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return B;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// EXPLICIT TEMPLATE INSTANTIATION
|
||||||
|
//
|
||||||
|
// The implementation is in this .cpp file.
|
||||||
|
// Build the overload for the official PANIC numeric types.
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
template panic::tensor::matrix<panic::types::uint_t> one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::vector<panic::types::uint_t>& a
|
||||||
|
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::int_t> one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::vector<panic::types::int_t>& a
|
||||||
|
|
||||||
|
);
|
||||||
|
template panic::tensor::matrix<panic::types::real_t> one_hot(const panic::types::uint_t size,
|
||||||
|
const panic::tensor::vector<panic::types::real_t>& a
|
||||||
|
);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tensor
|
||||||
|
} // namespace panic
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user