Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lifetime): extending the lifetime of temporary objects #160

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
15c4476
fix(lifetime): extending the lifetime of temporary objects
amitsingh19975 Feb 9, 2022
8f5a5d1
fix(comparision): use `same_exp` instead of `std::is_same`
amitsingh19975 Feb 10, 2022
8178c6c
refactor(comparision): decoupled `if constexpr` and cleaned-up compare.
amitsingh19975 Feb 10, 2022
9b8c4e1
test(enable): enable tests for expression templates
amitsingh19975 Feb 12, 2022
d70a701
fix(test): bind the prvalue (=3) to a variable
amitsingh19975 Feb 12, 2022
8ec747c
refactor(expression): add function cast_tensor_expression for casting
amitsingh19975 Feb 13, 2022
7a936dd
chore(expression): add `nodiscard`
amitsingh19975 Feb 13, 2022
b6a3dd8
refactor(comparision): remove the construction of a whole new tensor
amitsingh19975 Feb 13, 2022
3a013d0
fix(compare): get the value type after `cast_tensor_expression`
amitsingh19975 Feb 13, 2022
7b23092
refactor(expression): validate predicate and add noexcept
amitsingh19975 Feb 14, 2022
a90573c
refactor(eval): clean the implementation
amitsingh19975 Feb 14, 2022
2abe215
fix(expression): disable the move constructor for public use to avoid…
amitsingh19975 Feb 15, 2022
51674d5
refactor(expression): clean unnecessary code and fix the comparision …
amitsingh19975 Feb 15, 2022
b7de038
refactor(expression): use `std::invoke` and add types to functional o…
amitsingh19975 Feb 15, 2022
bc0afbd
refactor(expression): add `noexcept`, rearrange constructors, and rem…
amitsingh19975 Feb 16, 2022
00357a0
fix(test): remove the undefined behaviour if the type is not FP
amitsingh19975 Feb 16, 2022
549f8a0
refactor(expression): improve error message and simplified if-else.
amitsingh19975 Feb 16, 2022
23ba8fc
refactor(compare): combine two compare function into one for easier m…
amitsingh19975 Feb 16, 2022
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
47 changes: 47 additions & 0 deletions examples/tensor/simple_expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,53 @@ int main()
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "F=" << F << ";" << std::endl << std::endl;

// Calling overloaded operators
// and mixing expression templates with prvalues, rvalues, and lvalues
{
// NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
auto G = tensor(shape{3,3}, 3.f);
amitsingh19975 marked this conversation as resolved.
Show resolved Hide resolved
auto E_9 = G + G + G;

// formatted output
std::cout << "% --------------------------- " << std::endl;
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "E(9)=" << tensor(E_9) << ";" << std::endl << std::endl;

// NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
auto E_6 = G + 3.f;
amitsingh19975 marked this conversation as resolved.
Show resolved Hide resolved

// formatted output
std::cout << "% --------------------------- " << std::endl;
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "E(6)=" << tensor(E_6) << ";" << std::endl << std::endl;

// NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
auto const four = 4.f;
auto E_10 = E_6 + four;

// formatted output
std::cout << "% --------------------------- " << std::endl;
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "E(10)=" << tensor(E_10) << ";" << std::endl << std::endl;

// NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
auto E_23 = E_10 + E_10 + tensor(shape{3,3}, 3.f);
amitsingh19975 marked this conversation as resolved.
Show resolved Hide resolved

// formatted output
std::cout << "% --------------------------- " << std::endl;
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "E(23)=" << tensor(E_23) << ";" << std::endl << std::endl;

// NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
auto E_9_7 = tensor(shape{3,3}, 5.4f) + 4.3f;
amitsingh19975 marked this conversation as resolved.
Show resolved Hide resolved
amitsingh19975 marked this conversation as resolved.
Show resolved Hide resolved

// formatted output
std::cout << "% --------------------------- " << std::endl;
std::cout << "% --------------------------- " << std::endl << std::endl;
std::cout << "E(9.7)=" << tensor(E_9_7) << ";" << std::endl << std::endl;

}

} catch (const std::exception& e) {
std::cerr << "Cought exception " << e.what();
std::cerr << "in the main function of simple expression." << std::endl;
Expand Down
Loading