Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1// Copyright 2025 Eric Hermosis
2//
3// This file is part of the Tannic Tensor Library.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17
18#ifndef CONCEPTS_HPP
19#define CONCEPTS_HPP
20
33#include <concepts>
34#include <iterator>
35#include "types.hpp"
36
37namespace tannic {
38
39class Shape;
40class Strides;
41class Tensor;
42
85template<typename T>
86concept Expression = requires(const T expression) {
87 { expression.dtype() } -> std::same_as<type>;
88 { expression.shape() } -> std::same_as<Shape const&>;
89 { expression.strides() } -> std::same_as<Strides const&>;
90 expression.offset();
91 expression.forward();
92};
93
109template<typename T>
110concept Operator = requires(T operation, const Shape& first, const Shape& second) {
111 { T::promote(type{}, type{}) } -> std::same_as<type>;
112 { T::broadcast(first, second) } -> std::same_as<Shape>;
113};
114
123template<typename Function>
124concept Functional = requires(Function function, const Tensor& input, Tensor& output) {
125 { function(input, output) } -> std::same_as<void>;
126};
127
132template<typename T>
133concept Iterable = requires(T type) { std::begin(type); std::end(type); };
134
139template <typename T>
140concept Iterator = std::input_iterator<T>;
141
146template<typename T>
147concept Integral = std::is_integral_v<T>;
148
149
170template<typename T>
171concept Assignable = requires(T t, const std::byte* ptr, std::ptrdiff_t offset) {
172 { t.assign(ptr, offset) } -> std::same_as<void>;
173};
174
194template<typename T>
195concept Comparable = requires(const T t, const std::byte* ptr, std::ptrdiff_t offset) {
196 { t.compare(ptr, offset) } -> std::same_as<bool>;
197};
198
199} // namespace tannic
200
201#endif // CONCEPTS_HPP
Concept for types that can assign values.
Definition: concepts.hpp:171
Concept for types that can compare their value.
Definition: concepts.hpp:195
Defines the core protocol for all expression-like types in the Tannic Tensor Library.
Definition: concepts.hpp:86
Concept for unary mathematical function operations.
Definition: concepts.hpp:124
Requires a type to be an integral type (e.g., int, std::size_t).
Definition: concepts.hpp:147
Requires a type to be iterable via std::begin and std::end.
Definition: concepts.hpp:133
Requires a type to satisfy the C++20 std::input_iterator concept.
Definition: concepts.hpp:140
Concept defining requirements for tensor operation types.
Definition: concepts.hpp:110
Definition: buffer.hpp:41