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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[Dtype] Updates bool-case and adds ||
  • Loading branch information
dmed256 committed Jan 17, 2021
commit a27d35d3741389506fbc89c2db9c056dafeb19a1
18 changes: 18 additions & 0 deletions include/occa/dtype/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace occa {
class memory;

typedef std::vector<dtype_t> dtypeVector;

namespace dtype {
extern const dtype_t none;

Expand Down Expand Up @@ -85,8 +87,24 @@ namespace occa {
return get<typename typeMetadata<TM>::baseType>();
}

template <class TM = void, class ...Types>
dtypeVector getMany() {
dtypeVector types = { get<TM>() };

dtypeVector tail = getMany<Types...>();
types.insert(types.end(), tail.begin(), tail.end());

return types;
}

template <>
inline dtypeVector getMany() {
return {};
}

// Primitive types
template <> dtype_t get<void>();
template <> dtype_t get<bool>();
template <> dtype_t get<char>();
template <> dtype_t get<signed char>();
template <> dtype_t get<unsigned char>();
Expand Down
1 change: 1 addition & 0 deletions include/occa/dtype/dtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace occa {

bool operator == (const dtype_t &other) const;
bool operator != (const dtype_t &other) const;
const dtype_t& operator || (const dtype_t &other) const;

bool matches(const dtype_t &other) const;

Expand Down
4 changes: 4 additions & 0 deletions src/dtype/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ namespace occa {
}

// Primitive types
template <> dtype_t get<bool>() {
return bool_;
}

template <> dtype_t get<char>() {
return char_;
}
Expand Down
8 changes: 8 additions & 0 deletions src/dtype/dtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ namespace occa {
return !(*this == other);
}

const dtype_t& dtype_t::operator || (const dtype_t &other) const {
return (
(*this == dtype::none)
? other
: *this
);
}

bool dtype_t::matches(const dtype_t &other) const {
const dtype_t &a = self();
const dtype_t &b = other.self();
Expand Down