Skip to content

C++ lazy expression template interface for vector types

Notifications You must be signed in to change notification settings

Panjaksli/LazyVal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LazyVal

Header only expression template interface for vector types in C++.

What can this do ?

  1. Do straightforward arithmetic operations with vector types (class only needs constructor(size), size() and operator[] methods) using operator overloading (+,-,*,/)
  2. Lazy evaluate only the needed results (no internal caching). Other than that, you can chain expresssions to your liking, without any additional runtime cost !
    Here is example of what you can do:
#include "lazyval.h"
using namespace Lazy;
auto a = std::vector<float>(48, 6);
// Create templated symbolic expression tree
auto t = 4 * (a + a + a + a + 4) / std::vector<float>(48, 6);
// Evaluate only t[4]
std::cout << t[4];
// Evaluate the whole vector, use this if you need to cache/get all the results.
std::vector<float> v = t;

Basics

The size is always equal to the smallest vector in the whole expression tree. Scalars apply to all elements, but don't affect the size.
For forced evaluation or conversion, please use either conversion operator or eval() member method.
If you want to apply a lambda over 1 - 3 operands, use map() functions.
Ternary operator is possible using cond() function.

Requirements

Works with C++17 and GCC, Clang. (Maybe MSVC too...)

About

C++ lazy expression template interface for vector types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages