spla
Loading...
Searching...
No Matches
op.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_OP_HPP
29#define SPLA_OP_HPP
30
31#include "object.hpp"
32#include "type.hpp"
33
34#include <string>
35
36namespace spla {
37
47 class Op : public Object {
48 public:
49 SPLA_API ~Op() override = default;
51 SPLA_API virtual std::string get_name() = 0;
52 SPLA_API virtual std::string get_key() = 0;
53 SPLA_API virtual std::string get_source_cl() = 0;
54 };
55
60 class OpUnary : public Op {
61 public:
62 SPLA_API ~OpUnary() override = default;
64 SPLA_API static ref_ptr<OpUnary> make_int(std::string name, std::string code, std::function<T_INT(T_INT)> function);
65 SPLA_API static ref_ptr<OpUnary> make_uint(std::string name, std::string code, std::function<T_UINT(T_UINT)> function);
66 SPLA_API static ref_ptr<OpUnary> make_float(std::string name, std::string code, std::function<T_FLOAT(T_FLOAT)> function);
67 };
68
73 class OpBinary : public Op {
74 public:
75 SPLA_API ~OpBinary() override = default;
78 SPLA_API static ref_ptr<OpBinary> make_int(std::string name, std::string code, std::function<T_INT(T_INT, T_INT)> function);
79 SPLA_API static ref_ptr<OpBinary> make_uint(std::string name, std::string code, std::function<T_UINT(T_UINT, T_UINT)> function);
80 SPLA_API static ref_ptr<OpBinary> make_float(std::string name, std::string code, std::function<T_FLOAT(T_FLOAT, T_FLOAT)> function);
81 };
82
87 class OpSelect : public Op {
88 public:
89 SPLA_API ~OpSelect() override = default;
91 SPLA_API static ref_ptr<OpSelect> make_int(std::string name, std::string code, std::function<bool(T_INT)> function);
92 SPLA_API static ref_ptr<OpSelect> make_uint(std::string name, std::string code, std::function<bool(T_UINT)> function);
93 SPLA_API static ref_ptr<OpSelect> make_float(std::string name, std::string code, std::function<bool(T_FLOAT)> function);
94 };
95
97
116
119
133
135
148
152
159
163
170
177
184
186
211
216}// namespace spla
217
218#endif//SPLA_OP_HPP
Base class for any library primitive.
Definition object.hpp:47
Binary operation with 2-arity.
Definition op.hpp:73
virtual ref_ptr< Type > get_type_arg_0()=0
static ref_ptr< OpBinary > make_uint(std::string name, std::string code, std::function< T_UINT(T_UINT, T_UINT)> function)
Definition op.cpp:302
virtual ref_ptr< Type > get_type_arg_1()=0
static ref_ptr< OpBinary > make_float(std::string name, std::string code, std::function< T_FLOAT(T_FLOAT, T_FLOAT)> function)
Definition op.cpp:310
~OpBinary() override=default
static ref_ptr< OpBinary > make_int(std::string name, std::string code, std::function< T_INT(T_INT, T_INT)> function)
Definition op.cpp:294
Select operation with 1-arity and bool return type.
Definition op.hpp:87
~OpSelect() override=default
virtual ref_ptr< Type > get_type_arg_0()=0
static ref_ptr< OpSelect > make_int(std::string name, std::string code, std::function< bool(T_INT)> function)
Definition op.cpp:319
static ref_ptr< OpSelect > make_uint(std::string name, std::string code, std::function< bool(T_UINT)> function)
Definition op.cpp:327
static ref_ptr< OpSelect > make_float(std::string name, std::string code, std::function< bool(T_FLOAT)> function)
Definition op.cpp:335
Unary operation with 1-arity.
Definition op.hpp:60
virtual ref_ptr< Type > get_type_arg_0()=0
static ref_ptr< OpUnary > make_int(std::string name, std::string code, std::function< T_INT(T_INT)> function)
Definition op.cpp:269
static ref_ptr< OpUnary > make_float(std::string name, std::string code, std::function< T_FLOAT(T_FLOAT)> function)
Definition op.cpp:285
~OpUnary() override=default
static ref_ptr< OpUnary > make_uint(std::string name, std::string code, std::function< T_UINT(T_UINT)> function)
Definition op.cpp:277
An callable operation to parametrize execution of math computations.
Definition op.hpp:47
virtual ref_ptr< Type > get_type_res()=0
~Op() override=default
virtual std::string get_source_cl()=0
virtual std::string get_key()=0
virtual std::string get_name()=0
Automates reference counting and behaves as shared smart pointer.
Definition ref.hpp:117
#define SPLA_API
Definition config.hpp:43
ref_ptr< OpBinary > LOR_FLOAT
Definition op.cpp:112
ref_ptr< OpBinary > MINUS_POW2_FLOAT
Definition op.cpp:90
ref_ptr< OpBinary > MAX_INT
Definition op.cpp:106
ref_ptr< OpSelect > GTZERO_UINT
Definition op.cpp:133
ref_ptr< OpUnary > IDENTITY_UINT
Definition op.cpp:38
ref_ptr< OpUnary > BNOT_UINT
Definition op.cpp:57
ref_ptr< OpBinary > MAX_UINT
Definition op.cpp:107
ref_ptr< OpUnary > FLOOR_FLOAT
Definition op.cpp:69
ref_ptr< OpBinary > MINUS_INT
Definition op.cpp:78
ref_ptr< OpBinary > BONE_FLOAT
Definition op.cpp:101
ref_ptr< OpUnary > ABS_UINT
Definition op.cpp:53
ref_ptr< OpBinary > PLUS_FLOAT
Definition op.cpp:77
ref_ptr< OpUnary > ACOS_FLOAT
Definition op.cpp:66
ref_ptr< OpBinary > FIRST_INT
Definition op.cpp:92
float T_FLOAT
Definition type.hpp:60
ref_ptr< OpSelect > EQZERO_FLOAT
Definition op.cpp:128
ref_ptr< OpSelect > ALWAYS_UINT
Definition op.cpp:145
ref_ptr< OpBinary > MULT_INT
Definition op.cpp:81
ref_ptr< OpSelect > NQZERO_INT
Definition op.cpp:129
ref_ptr< OpBinary > LOR_UINT
Definition op.cpp:111
ref_ptr< OpUnary > SIN_FLOAT
Definition op.cpp:62
ref_ptr< OpBinary > DIV_FLOAT
Definition op.cpp:86
ref_ptr< OpSelect > GEZERO_INT
Definition op.cpp:135
ref_ptr< OpBinary > LAND_FLOAT
Definition op.cpp:115
ref_ptr< OpBinary > BXOR_INT
Definition op.cpp:121
ref_ptr< OpBinary > PLUS_INT
Definition op.cpp:75
ref_ptr< OpSelect > GTZERO_FLOAT
Definition op.cpp:134
ref_ptr< OpSelect > LTZERO_INT
Definition op.cpp:138
ref_ptr< OpUnary > AINV_FLOAT
Definition op.cpp:42
ref_ptr< OpUnary > BNOT_INT
Definition op.cpp:56
ref_ptr< OpUnary > LNOT_FLOAT
Definition op.cpp:48
ref_ptr< OpBinary > PLUS_UINT
Definition op.cpp:76
ref_ptr< OpUnary > SQRT_FLOAT
Definition op.cpp:59
ref_ptr< OpUnary > LNOT_UINT
Definition op.cpp:47
ref_ptr< OpBinary > BOR_INT
Definition op.cpp:117
ref_ptr< OpBinary > BAND_UINT
Definition op.cpp:120
ref_ptr< OpUnary > ATAN_FLOAT
Definition op.cpp:67
ref_ptr< OpBinary > LAND_UINT
Definition op.cpp:114
ref_ptr< OpBinary > BAND_INT
Definition op.cpp:119
ref_ptr< OpSelect > EQZERO_UINT
Definition op.cpp:127
ref_ptr< OpUnary > ASIN_FLOAT
Definition op.cpp:65
ref_ptr< OpSelect > ALWAYS_FLOAT
Definition op.cpp:146
ref_ptr< OpSelect > NEVER_INT
Definition op.cpp:147
ref_ptr< OpBinary > BXOR_UINT
Definition op.cpp:122
ref_ptr< OpSelect > NQZERO_UINT
Definition op.cpp:130
ref_ptr< OpBinary > LOR_INT
Definition op.cpp:110
ref_ptr< OpBinary > MINUS_POW2_INT
Definition op.cpp:88
ref_ptr< OpUnary > MINV_INT
Definition op.cpp:43
ref_ptr< OpSelect > LTZERO_FLOAT
Definition op.cpp:140
ref_ptr< OpBinary > MULT_FLOAT
Definition op.cpp:83
ref_ptr< OpBinary > DIV_UINT
Definition op.cpp:85
ref_ptr< OpBinary > MULT_UINT
Definition op.cpp:82
ref_ptr< OpBinary > DIV_INT
Definition op.cpp:84
ref_ptr< OpSelect > LEZERO_UINT
Definition op.cpp:142
ref_ptr< OpUnary > UONE_UINT
Definition op.cpp:50
ref_ptr< OpUnary > MINV_UINT
Definition op.cpp:44
ref_ptr< OpBinary > FIRST_UINT
Definition op.cpp:93
ref_ptr< OpUnary > COS_FLOAT
Definition op.cpp:63
ref_ptr< OpUnary > ABS_INT
Definition op.cpp:52
ref_ptr< OpSelect > GTZERO_INT
Definition op.cpp:132
ref_ptr< OpUnary > UONE_INT
Definition op.cpp:49
std::int32_t T_INT
Definition type.hpp:58
ref_ptr< OpBinary > MINUS_UINT
Definition op.cpp:79
ref_ptr< OpUnary > EXP_FLOAT
Definition op.cpp:61
ref_ptr< OpBinary > MAX_FLOAT
Definition op.cpp:108
ref_ptr< OpBinary > BONE_UINT
Definition op.cpp:100
ref_ptr< OpSelect > LEZERO_INT
Definition op.cpp:141
ref_ptr< OpBinary > MINUS_FLOAT
Definition op.cpp:80
ref_ptr< OpBinary > MINUS_POW2_UINT
Definition op.cpp:89
ref_ptr< OpSelect > GEZERO_FLOAT
Definition op.cpp:137
ref_ptr< OpBinary > BONE_INT
Definition op.cpp:99
ref_ptr< OpSelect > NEVER_FLOAT
Definition op.cpp:149
ref_ptr< OpUnary > TRUNC_FLOAT
Definition op.cpp:71
ref_ptr< OpBinary > MIN_UINT
Definition op.cpp:104
ref_ptr< OpUnary > CEIL_FLOAT
Definition op.cpp:68
ref_ptr< OpUnary > TAN_FLOAT
Definition op.cpp:64
ref_ptr< OpUnary > IDENTITY_FLOAT
Definition op.cpp:39
ref_ptr< OpBinary > SECOND_INT
Definition op.cpp:95
ref_ptr< OpSelect > LEZERO_FLOAT
Definition op.cpp:143
ref_ptr< OpBinary > MIN_INT
Definition op.cpp:103
ref_ptr< OpSelect > ALWAYS_INT
Definition op.cpp:144
ref_ptr< OpBinary > FIRST_FLOAT
Definition op.cpp:94
ref_ptr< OpUnary > LOG_FLOAT
Definition op.cpp:60
ref_ptr< OpUnary > UONE_FLOAT
Definition op.cpp:51
ref_ptr< OpBinary > SECOND_FLOAT
Definition op.cpp:97
ref_ptr< OpUnary > AINV_INT
Definition op.cpp:40
ref_ptr< OpBinary > BOR_UINT
Definition op.cpp:118
ref_ptr< OpUnary > ABS_FLOAT
Definition op.cpp:54
ref_ptr< OpUnary > MINV_FLOAT
Definition op.cpp:45
std::uint32_t T_UINT
Definition type.hpp:59
ref_ptr< OpBinary > SECOND_UINT
Definition op.cpp:96
ref_ptr< OpUnary > ROUND_FLOAT
Definition op.cpp:70
ref_ptr< OpUnary > AINV_UINT
Definition op.cpp:41
ref_ptr< OpUnary > IDENTITY_INT
Definition op.cpp:37
ref_ptr< OpBinary > LAND_INT
Definition op.cpp:113
ref_ptr< OpSelect > EQZERO_INT
Definition op.cpp:126
ref_ptr< OpBinary > MIN_FLOAT
Definition op.cpp:105
ref_ptr< OpSelect > GEZERO_UINT
Definition op.cpp:136
ref_ptr< OpSelect > LTZERO_UINT
Definition op.cpp:139
ref_ptr< OpUnary > LNOT_INT
Definition op.cpp:46
ref_ptr< OpSelect > NQZERO_FLOAT
Definition op.cpp:131
ref_ptr< OpSelect > NEVER_UINT
Definition op.cpp:148
Definition algorithm.hpp:37