Skip to content

Instantly share code, notes, and snippets.

@taless474
Created December 7, 2018 22:32
Show Gist options
  • Save taless474/6e3bf2d462aaca188360564c5b5b8494 to your computer and use it in GitHub Desktop.
Save taless474/6e3bf2d462aaca188360564c5b5b8494 to your computer and use it in GitHub Desktop.
Blaze test case
::rd /s /q cmake-build-debug
cmake -C cmake_cache.cmake -H. -Bcmake-build-debug -G"Visual Studio 15 2017 Win64"
::pause
cmake --build cmake-build-debug --config Debug --target app1
pause
start cmake-build-debug\hpxapp1.sln
set(CMAKE_BUILD_TYPE Debug CACHE STRING "")
set(CMAKE_TOOLCHAIN_FILE "C:/Repos/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "")
set(HPX_DIR "C:/Repos/hpx/cmake-build-debug/lib/cmake/HPX" CACHE PATH "")
cmake_minimum_required(VERSION 3.3.2)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(hpxapp1 CXX)
find_package(HPX REQUIRED)
find_package(blaze NO_CMAKE_PACKAGE_REGISTRY)
if(NOT blaze_FOUND)
message(FATAL_ERROR "Blaze could not be found. Please specify blaze_DIR to assist locating it.")
endif()
add_hpx_executable(
app1
SOURCES prog.cpp
COMPONENT_DEPENDENCIES iostreams
DEPENDENCIES blaze::blaze
)
target_compile_definitions(app1 PRIVATE BLAZE_USE_HPX_THREADS)
if (MSVC)
# windows.h conflicts with STL's min and max
target_compile_definitions(app1 PRIVATE NOMINMAX _CRT_SECURE_NO_WARNINGS)
# warning C4146: unary minus operator applied to unsigned type, result still unsigned
target_compile_options(app1 PRIVATE /wd4146)
# warning C4244: conversion from 'uint64_t' to 'int', possible loss of data
target_compile_options(app1 PRIVATE /wd4244)
# warning C4267: conversion from 'size_t' to 'int', possible loss of data
target_compile_options(app1 PRIVATE /wd4267)
# warning C4552: '*': operator has no effect; expected operator with side-effect
target_compile_options(app1 PRIVATE /wd4552)
# warning C4805: '==': unsafe mix of type 'const bool' and type 'const uint8_t' in operation
target_compile_options(app1 PRIVATE /wd4805)
endif()
#include <iostream>
#include <blaze/Math.h>
int main()
{
blaze::StaticMatrix<double, 3UL, 3UL> A{ { 1.0, 2.0, 3.0 }
, { 4.0, 1.0, 2.0 }
, { 3.0, 4.0, 1.0 } };
blaze::StaticMatrix<double, 3UL, 3UL> B;
// Evaluating the softmax function
B = blaze::softmax(A); // Results in ( 0.0157764 0.0428847 0.116573 )
// ( 0.316878 0.0157764 0.0428847 )
// ( 0.116573 0.316878 0.0157764 )
double s = blaze::sum(B); // Results in 1
std::cout << B << "\n" << s << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment