Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cxxloop.alternatives/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(ogis-cxx-loop.example LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)


add_subdirectory(asciishapes)
add_subdirectory(matrix)
32 changes: 32 additions & 0 deletions cxxloop.alternatives/std-view-iota/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

set(THE_PROJECT cxxloop-alternative-view-iota)

project(${THE_PROJECT} LANGUAGES CXX)


set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

if (MSVC)
# warning level 4 and all warnings as errors
add_compile_options(/W4 /WX)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()

# Input
set(MATRIX_HDR matrix.hpp matrix_io.hpp)
set(MATRIX_SRC example_matrix.cpp main_matrix.cpp )


add_executable(${THE_PROJECT} ${MATRIX_HDR} ${MATRIX_SRC} )
target_link_libraries(${THE_PROJECT} cxxloop)

target_include_directories(${THE_PROJECT} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>
$<INSTALL_INTERFACE:.>
)


9 changes: 9 additions & 0 deletions cxxloop.alternatives/std-view-iota/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Matrix-Examples for the Compound-Group "LOOP" ##

- [main_matrix.cpp](main_matrix.cpp) : is the main entry point.

- [matrix.hpp](matrix.hpp) : Header-only functions to operate on the matrcies as descrtibed above using LOOP-compounds.

- [matrix_io.hpp](matrix_io.hpp) : Contains functions to print native double 2D-Arrays (matrices like double a[M][N]) of given size N x M.
- [example_matrix.cpp](example_matrix.cpp) : example calls to the functions of matrix.hpp and matrix_io.hpp. Is invoked by main.cpp.

67 changes: 67 additions & 0 deletions cxxloop.alternatives/std-view-iota/view-iota.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <iomanip>
#include <iostream>

#include "matrix.hpp"
#include "matrix_io.hpp"

void example_matrix() {

const int N = 4; // number-of rows
const int M = 10; // number-of columns

int A[N][M] = {};
int B[N * M] = {};
int C[N * M] = {};

int *a = &A[0][0];
{
matrix_set(a, 1, N, M);

std::cout << std::endl << "A" << std::endl;
matrix_print(a, N, M);

matrix_set(B, 0, N, M);
std::cout << std::endl << "B" << std::endl;
matrix_print(B, N, M);

std::cout << std::endl << "C" << std::endl;
matrix_set(C, 2, N, M);
matrix_print(C, N, M);
}

loop(2) {
std::cout << std::endl << "C+=A" << std::endl;
matrix_add(C, a, N, M);
matrix_print(C, N, M);
}

{
std::cout << std::endl << "B=C" << std::endl;
matrix_copy(B, C, N, M);
matrix_print(B, N, M);
}

{
std::cout << std::endl << "C+=B" << std::endl;
matrix_add(C, B, N, M);
matrix_print(C, N, M);
}

{
int n = N / 2;
int m = M / 2;
std::cout << std::endl
<< "C[0:" << n - 1 << "][0:" << m - 1 << "]+=10" << std::endl;
matrix_incr_w_stride(C, 10, n, m, M - m);
matrix_print(C, N, M);
}

{
int n = N / 2 + 1;
int m = M / 2 + 1;
std::cout << std::endl
<< "C[0:" << n - 1 << "][0:" << m - 1 << "]+=100" << std::endl;
matrix_incr_w_stride(C, 100, n, m, M - m);
matrix_print(C, N, M);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(ogis-cxxloop-ascciishapes LANGUAGES CXX)
project(ogis-cxxloop-examples-ascciishapes LANGUAGES CXX)

#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED NO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(FILES

cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

set(THE_PROJECT cxxloop-asciishapes-for-postops)
set(THE_PROJECT cxxloop-examples-asciishapes-loop-postops)

#set(CMAKE_CXX_STANDARD ${CXXLOOP_CXX_STANDARD})
#set(CMAKE_CXX_STANDARD_REQUIRED ${CXXLOOP_CXX_STANDARD_REQUIRED})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(FILES
main.cpp
)

set(THE_PROJECT cxxloop-asciishapes-loop)
set(THE_PROJECT cxxloop-examples-asciishapes-loop)

#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED NO)
Expand Down
5 changes: 3 additions & 2 deletions cxxloop.examples/cxxloop.examples/matrix/main_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
void example_matrix();

int main() {
// some more realistic examples of matrix operations
// using the new compound-statement
std::cout << "############ matrix-exammples " << std::endl;
example_matrix();
std::cout << "..DONE" << std ::endl;

return 0;
}
28 changes: 19 additions & 9 deletions cxxloop.examples/cxxloop.examples/matrix/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ inline void matrix_mpy(TTgtValuePtr tgt, TSrcAValuePtr srcA, TSrcBValuePtr srcB,
auto pCol = srcA;
auto pRow = srcB;

loop(nbofColums * nbofRows) // for each matrix element
loop_up_postops(nbofRows, row, pRow = srcB + row * nbofColums)
loop_postops(nbofColums, pRow += nbofColums) *tgt++ =
(*pCol++) * (*pRow);
loop(sizeA * sizeB) // for each matrix element
loop_up_postops(sizeB, row, pRow = srcB + row * sizeA)
loop_postops(sizeA, pRow += sizeA) *tgt++ = (*pCol++) * (*pRow);
}

template <typename TValueA, typename TValueB, typename TSize>
inline void dotproduct(TSize size, TValueA *pA, TValue *pB,
TIndexA indexA = char, TIndexA indexB = char) {
decltype(TValueA * TValueB) result = 0;
loop_postops(size, A += indexA, B += index) += (*pA++) * (*pB);
template <typename TValueTgt, typename TValueA, typename TValueB,
typename TSize>
inline TValueTgt *dotproduct(TSize size, TValueTgt *tgt, TValueA *pA,
TValueB *pB) {
decltype(*pA * *pB) result = 0;
loop_postops(size, pA++, pB++, tgt++) tgt += (*pA) * (*pB);
return tgt;
}

template <typename TValueA, typename TValueB, typename TSize,
typename TIndexA = char, typename TIndexB = char>
inline void dotproduct(TSize size, TValueA *pA, TValueB *pB, TIndexA indexA,
TIndexA indexB) {
decltype(*pA * *pB) result = 0;
loop_slice_postops(0, size, indexA, id, pB += indexB) result +=
(*pA++) * (*pB);
}
5 changes: 5 additions & 0 deletions cxxloop.tests/testing-loops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ add_subdirectory(test_cxxloop)
add_subdirectory(test_cxxloop_typed)

#POSTOPS

add_subdirectory(test_cxxloop_postops)
add_subdirectory(test_cxxloop_templates_postops)

#special
add_subdirectory(test_cxxloop_slice)
18 changes: 11 additions & 7 deletions cxxloop.tests/testing-loops/macro.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#pragma once
#include <iostream>
#include <string>

#define ASSERT_COUNTS(count, tobe_count) \
if (count != tobe_count) \
std::cout << __FUNCTION__ << "\t" << std::endl \
<< "\t" \
<< "count " << count << " is NOT the expeted: " << tobe_count \
<< std::endl
#define ASSERT_NOTED(as_is, to_be, text) \
if (as_is != to_be) \
std::cout << __FILE__ << "\n" \
<< __FUNCTION__ << "\t" << std::endl \
<< "\t" << text << "\t" << as_is \
<< " is NOT the expeted: " << to_be << std::endl

#define ASSERT_COUNTS(as_is, to_be) ASSERT_NOTED(as_is, to_be, "count")

inline void ASSERT_CONDITION(bool condition, const std::string &msg) {
if (!condition) std::cout << __FUNCTION__ << "\t" << msg << std::endl;
if (!condition)
std::cout << __FILE__ << "\n" << __FUNCTION__ << "\t" << msg << std::endl;
return;
}
Loading