Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_core
Merge requests
!44
Binary operators
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Binary operators
hrouis/aidge_core:binary_operators
into
main
Overview
0
Commits
6
Pipelines
5
Changes
10
Merged
Houssem ROUIS
requested to merge
hrouis/aidge_core:binary_operators
into
main
1 year ago
Overview
0
Commits
6
Pipelines
5
Changes
10
Expand
Added Pow and Div operators
0
0
Merge request reports
Compare
main
version 3
62ef56c4
1 year ago
version 2
3dab8e7c
1 year ago
version 1
3a763bc4
1 year ago
main (base)
and
latest version
latest version
27b268ed
6 commits,
1 year ago
version 3
62ef56c4
5 commits,
1 year ago
version 2
3dab8e7c
4 commits,
1 year ago
version 1
3a763bc4
3 commits,
1 year ago
10 files
+
705
−
1
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
Search (e.g. *.vue) (Ctrl+P)
include/aidge/operator/Div.hpp
0 → 100644
+
146
−
0
Options
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_CORE_OPERATOR_DIV_H_
#define AIDGE_CORE_OPERATOR_DIV_H_
#include
<cassert>
#include
<memory>
#include
<vector>
#include
"aidge/utils/Registrar.hpp"
#include
"aidge/operator/Operator.hpp"
#include
"aidge/backend/OperatorImpl.hpp"
#include
"aidge/data/Tensor.hpp"
#include
"aidge/data/Data.hpp"
#include
"aidge/graph/Node.hpp"
#include
"aidge/utils/Types.h"
namespace
Aidge
{
class
Div_Op
:
public
Operator
,
public
Registrable
<
Div_Op
,
std
::
string
,
std
::
unique_ptr
<
OperatorImpl
>
(
const
Div_Op
&
)
>
{
public:
// FIXME: change accessibility
std
::
array
<
std
::
shared_ptr
<
Tensor
>
,
2
>
mInputs
=
{
std
::
make_shared
<
Tensor
>
(),
std
::
make_shared
<
Tensor
>
()};
const
std
::
shared_ptr
<
Tensor
>
mOutput
=
std
::
make_shared
<
Tensor
>
();
public
:
static
constexpr
const
char
*
Type
=
"Div"
;
Div_Op
()
:
Operator
(
Type
)
{
setDatatype
(
DataType
::
Float32
);
}
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s), but not its input tensors (the new operator has no input associated).
* @param op Operator to copy.
*/
Div_Op
(
const
Div_Op
&
op
)
:
Operator
(
Type
),
mOutput
(
std
::
make_shared
<
Tensor
>
(
*
op
.
mOutput
))
{
// cpy-ctor
setDatatype
(
op
.
mOutput
->
dataType
());
mImpl
=
op
.
mImpl
?
Registrar
<
Div_Op
>::
create
(
mOutput
->
getImpl
()
->
backend
())(
*
this
)
:
nullptr
;
}
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::Div_Op
*/
std
::
shared_ptr
<
Operator
>
clone
()
const
override
{
return
std
::
make_shared
<
Div_Op
>
(
*
this
);
}
void
associateInput
(
const
IOIndex_t
inputIdx
,
std
::
shared_ptr
<
Data
>
data
)
override
final
{
assert
(
inputIdx
<
2
&&
"operator supports only 2 inputs"
);
(
void
)
inputIdx
;
// avoid unused warning
assert
(
strcmp
(
data
->
type
(),
Tensor
::
Type
)
==
0
&&
"input data must be of Tensor type"
);
mInputs
[
inputIdx
]
=
std
::
dynamic_pointer_cast
<
Tensor
>
(
data
);
}
void
computeOutputDims
()
override
final
{
if
(
!
mInputs
[
0
]
->
empty
())
mOutput
->
resize
(
mInputs
[
0
]
->
dims
());
}
bool
outputDimsForwarded
()
const
override
final
{
return
!
(
mOutput
->
empty
());
}
inline
Tensor
&
input
(
const
IOIndex_t
inputIdx
)
const
override
final
{
assert
(
static_cast
<
std
::
size_t
>
(
inputIdx
)
<
2
&&
"wrong inputIdx for Add operator."
);
return
*
(
mInputs
[
inputIdx
].
get
());
}
inline
Tensor
&
output
(
const
IOIndex_t
/*outputIdx*/
)
const
override
final
{
return
*
(
mOutput
.
get
());
}
inline
std
::
shared_ptr
<
Tensor
>
getInput
(
const
IOIndex_t
inputIdx
)
const
override
final
{
assert
((
inputIdx
<
2
)
&&
"Div Operator has 2 inputs"
);
(
void
)
inputIdx
;
// avoid unused warning
return
mInputs
[
inputIdx
];
}
inline
std
::
shared_ptr
<
Tensor
>
getOutput
(
const
IOIndex_t
outputIdx
)
const
override
final
{
assert
((
outputIdx
==
0
)
&&
"Div Operator has only 1 output"
);
(
void
)
outputIdx
;
// avoid unused warning
return
mOutput
;
}
std
::
shared_ptr
<
Data
>
getRawInput
(
const
IOIndex_t
inputIdx
)
const
override
final
{
assert
(
inputIdx
<
2
&&
"operator supports only 2 inputs"
);
(
void
)
inputIdx
;
// avoid unused warning
return
std
::
static_pointer_cast
<
Data
>
(
mInputs
[
inputIdx
]);
}
std
::
shared_ptr
<
Data
>
getRawOutput
(
const
IOIndex_t
outputIdx
)
const
override
final
{
assert
(
outputIdx
==
0
&&
"operator supports only 1 output"
);
(
void
)
outputIdx
;
// avoid unused warning
return
std
::
static_pointer_cast
<
Data
>
(
mOutput
);
}
void
setBackend
(
const
std
::
string
&
name
)
override
{
mImpl
=
Registrar
<
Div_Op
>::
create
(
name
)(
*
this
);
mOutput
->
setBackend
(
name
);
// FIXME: temporary workaround
mInputs
[
0
]
->
setBackend
(
name
);
mInputs
[
1
]
->
setBackend
(
name
);
}
void
setDatatype
(
const
DataType
&
datatype
)
override
{
mOutput
->
setDatatype
(
datatype
);
// FIXME: temporary workaround
mInputs
[
0
]
->
setDatatype
(
datatype
);
mInputs
[
1
]
->
setDatatype
(
datatype
);
}
inline
IOIndex_t
nbInputs
()
const
noexcept
override
final
{
return
2
;
}
inline
IOIndex_t
nbDataInputs
()
const
noexcept
override
final
{
return
2
;
}
inline
IOIndex_t
nbOutputs
()
const
noexcept
override
final
{
return
1
;
}
static
const
std
::
vector
<
std
::
string
>
getInputsName
(){
return
{
"data_input"
};
}
static
const
std
::
vector
<
std
::
string
>
getOutputsName
(){
return
{
"data_output"
};
}
};
inline
std
::
shared_ptr
<
Node
>
Div
(
const
std
::
string
&
name
=
""
)
{
return
std
::
make_shared
<
Node
>
(
std
::
make_shared
<
Div_Op
>
(),
name
);
}
}
#endif
/* AIDGE_CORE_OPERATOR_DIV_H_ */
Loading