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

[Functional] Adds occa::function and occa::array #442

Merged
merged 20 commits into from
Jan 17, 2021
Merged

Conversation

dmed256
Copy link
Member

@dmed256 dmed256 commented Jan 3, 2021

Updates the occa::array to be a type-safe wrapper on occa::memory with flexible functional methods.

occa::function

We introduce a preprocessor macro called OCCA_FUNCTION that takes a C++ lambda and returns a typed occa::function!

Example

occa::function<bool(int, int, const int*)> func = (
  OCCA_FUNCTION({}, [](const int entry, const int index, const int *entries) -> bool {
    return false;
  })
);

The occa::function template definition is taken from std::function, where a user can define the return and argument types. It's also callable just like an std::function

func(0, 0, NULL);

occa::array

We introduce a simple wrapper on occa::memory which is typed and contains some of the core map and reduce functional methods.

Example

const double dynamicValue = 10;
const double compileTimeValue = 100;

occa::scope scope({
  // Passed as arguments
    {"dynamicValue", dynamicValue}
  }, {
  // Passed as compile-time #defines
    {"defines/compileTimeValue", compileTimeValue}
});

occa::array<double> doubleValues = (
  values.map(OCCA_FUNCTION(scope, [](int value) -> double {
    return compileTimeValue + (dynamicValue * value);
  }));  
);

Core methods

  • map
  • mapTo
  • forEach
  • reduce

Reduction

  • max
  • min
  • every
  • some

Re-indexing

  • reverse
  • shiftLeft
  • shiftRight

Slice/Concat

  • slice
  • concat

Utility

  • fill
  • cast

Search

  • find
  • findIndex
  • includes
  • indexOf
  • lastIndexOf

@dmed256 dmed256 force-pushed the experimental/function branch 8 times, most recently from 8b87967 to e10edcd Compare January 8, 2021 04:54
@dmed256 dmed256 force-pushed the experimental/function branch from e10edcd to ea65c13 Compare January 16, 2021 23:59
@dmed256 dmed256 force-pushed the experimental/function branch 2 times, most recently from b80af67 to 17bd1ca Compare January 17, 2021 05:28
@dmed256 dmed256 force-pushed the experimental/function branch from 17bd1ca to 204fd1a Compare January 17, 2021 05:43
@codecov
Copy link

codecov bot commented Jan 17, 2021

Codecov Report

Merging #442 (47fd96f) into main (483de16) will decrease coverage by 1.01%.
The diff coverage is 78.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #442      +/-   ##
==========================================
- Coverage   76.03%   75.02%   -1.02%     
==========================================
  Files         249      250       +1     
  Lines       18850    19104     +254     
==========================================
  Hits        14333    14333              
- Misses       4517     4771     +254     
Impacted Files Coverage Δ
include/occa/core/kernelArg.hpp 100.00% <ø> (ø)
include/occa/core/memory.hpp 100.00% <ø> (ø)
include/occa/functional/scope.hpp 0.00% <ø> (ø)
include/occa/types/json.hpp 71.34% <ø> (-1.65%) ⬇️
src/c/scope.cpp 92.85% <ø> (ø)
src/occa/internal/bin/occa.cpp 38.51% <0.00%> (ø)
src/occa/internal/c/types.cpp 80.00% <ø> (ø)
src/occa/internal/lang/file.cpp 93.50% <ø> (ø)
src/occa/internal/lang/modes/cuda.cpp 63.39% <0.00%> (-3.59%) ⬇️
src/functional/function.cpp 50.00% <50.00%> (ø)
... and 66 more

@dmed256 dmed256 marked this pull request as ready for review January 17, 2021 18:40
@dmed256 dmed256 merged commit 9443ce0 into main Jan 17, 2021
@dmed256 dmed256 deleted the experimental/function branch January 17, 2021 18:40
@dmed256 dmed256 changed the title [Experimental] Adding occa::function [Functional] Adds occa::function and occa::array Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant