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
84template<typename T>
85concept Expression = requires(const T expression) {
86 { expression.dtype() } -> std::same_as<type>;
87 { expression.shape() } -> std::same_as<Shape const&>;
88 { expression.strides() } -> std::same_as<Strides const&>;
89 expression.offset();
90 expression.forward();
91};
92
108template<typename T>
109concept Operator = requires(T operation, const Shape& first, const Shape& second) {
110 { T::promote(type{}, type{}) } -> std::same_as<type>;
111 { T::broadcast(first, second) } -> std::same_as<Shape>;
112};
113
122template<typename Function>
123concept Functional = requires(Function function, const Tensor& input, Tensor& output) {
124 { function(input, output) } -> std::same_as<void>;
125};
126
131template<typename T>
132concept Iterable = requires(T type) { std::begin(type); std::end(type); };
133
138template <typename T>
139concept Iterator = std::input_iterator<T>;
140
145template<typename T>
146concept Integral = std::is_integral_v<T>;
147
148
169template<typename T>
170concept Assignable = requires(T t, const std::byte* ptr, std::ptrdiff_t offset) {
171 { t.assign(ptr, offset) } -> std::same_as<void>;
172};
173
193template<typename T>
194concept Comparable = requires(const T t, const std::byte* ptr, std::ptrdiff_t offset) {
195 { t.compare(ptr, offset) } -> std::same_as<bool>;
196};
197
198} // namespace tannic
199
200#endif // CONCEPTS_HPP
Concept for types that can assign values.
Definition: concepts.hpp:170
Concept for types that can compare their value.
Definition: concepts.hpp:194
Defines the core protocol for all expression-like types in the Tannic Tensor Library.
Definition: concepts.hpp:85
Concept for unary mathematical function operations.
Definition: concepts.hpp:123
Requires a type to be an integral type (e.g., int, std::size_t).
Definition: concepts.hpp:146
Requires a type to be iterable via std::begin and std::end.
Definition: concepts.hpp:132
Requires a type to satisfy the C++20 std::input_iterator concept.
Definition: concepts.hpp:139
Concept defining requirements for tensor operation types.
Definition: concepts.hpp:109
Definition: buffer.hpp:41
Core type system for the Tannic Tensor Library.