Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuhao Liu
ogs
Commits
0f3a09f3
Commit
0f3a09f3
authored
8 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[NL] moved max fct args; renamed argument info -> ~names
parent
bb81230e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NumLib/NamedFunction.cpp
+12
-12
12 additions, 12 deletions
NumLib/NamedFunction.cpp
NumLib/NamedFunction.h
+18
-25
18 additions, 25 deletions
NumLib/NamedFunction.h
NumLib/NamedFunctionCaller.cpp
+4
-3
4 additions, 3 deletions
NumLib/NamedFunctionCaller.cpp
with
34 additions
and
40 deletions
NumLib/NamedFunction.cpp
+
12
−
12
View file @
0f3a09f3
...
...
@@ -64,9 +64,9 @@ static const CallerFunction callers[] = {
generateCaller
<
21
>
(),
generateCaller
<
22
>
(),
generateCaller
<
23
>
(),
generateCaller
<
24
>
(),
generateCaller
<
25
>
(),
generateCaller
<
26
>
(),
generateCaller
<
27
>
(),
generateCaller
<
28
>
(),
generateCaller
<
29
>
(),
generateCaller
<
30
>
(),
generateCaller
<
31
>
()};
generateCaller
<
30
>
(),
generateCaller
<
31
>
()
,
generateCaller
<
32
>
()
};
static_assert
(
sizeof
(
callers
)
/
sizeof
(
CallerFunction
)
==
NumLib
::
MAX_FUNCTION_ARGS
,
NumLib
::
NamedFunction
::
MAX_FUNCTION_ARGS
+
1
,
"You did not instantiate the right number of callers."
);
/*! Deletes the given \c function.
...
...
@@ -113,9 +113,9 @@ static const DeleterFunction deleters[] = {
generateDeleter
<
21
>
(),
generateDeleter
<
22
>
(),
generateDeleter
<
23
>
(),
generateDeleter
<
24
>
(),
generateDeleter
<
25
>
(),
generateDeleter
<
26
>
(),
generateDeleter
<
27
>
(),
generateDeleter
<
28
>
(),
generateDeleter
<
29
>
(),
generateDeleter
<
30
>
(),
generateDeleter
<
31
>
()};
generateDeleter
<
30
>
(),
generateDeleter
<
31
>
()
,
generateDeleter
<
32
>
()
};
static_assert
(
sizeof
(
deleters
)
/
sizeof
(
DeleterFunction
)
==
NumLib
::
MAX_FUNCTION_ARGS
,
NumLib
::
NamedFunction
::
MAX_FUNCTION_ARGS
+
1
,
"You did not instantiate the right number of deleters."
);
/*! Copies the given \c function.
...
...
@@ -162,16 +162,16 @@ static const CopierFunction copiers[] = {
generateCopier
<
21
>
(),
generateCopier
<
22
>
(),
generateCopier
<
23
>
(),
generateCopier
<
24
>
(),
generateCopier
<
25
>
(),
generateCopier
<
26
>
(),
generateCopier
<
27
>
(),
generateCopier
<
28
>
(),
generateCopier
<
29
>
(),
generateCopier
<
30
>
(),
generateCopier
<
31
>
()};
generateCopier
<
30
>
(),
generateCopier
<
31
>
()
,
generateCopier
<
32
>
()
};
static_assert
(
sizeof
(
copiers
)
/
sizeof
(
CopierFunction
)
==
NumLib
::
MAX_FUNCTION_ARGS
,
NumLib
::
NamedFunction
::
MAX_FUNCTION_ARGS
+
1
,
"You did not instantiate the right number of deleters."
);
namespace
NumLib
{
NamedFunction
::
NamedFunction
(
NamedFunction
&&
other
)
:
_name
(
std
::
move
(
other
.
_name
)),
_argument_
info
(
std
::
move
(
other
.
_argument_
info
)),
_argument_
names
(
std
::
move
(
other
.
_argument_
names
)),
_function
(
other
.
_function
)
{
other
.
_function
=
nullptr
;
...
...
@@ -179,20 +179,20 @@ NamedFunction::NamedFunction(NamedFunction&& other)
NamedFunction
::
NamedFunction
(
NamedFunction
const
&
other
)
:
_name
(
other
.
_name
),
_argument_
info
(
other
.
_argument_
info
),
_function
(
copiers
[
_argument_
info
.
size
()](
other
.
_function
))
_argument_
names
(
other
.
_argument_
names
),
_function
(
copiers
[
_argument_
names
.
size
()](
other
.
_function
))
{
}
NamedFunction
::~
NamedFunction
()
{
deleters
[
_argument_
info
.
size
()](
_function
);
deleters
[
_argument_
names
.
size
()](
_function
);
}
double
NamedFunction
::
call
(
const
std
::
vector
<
double
>&
arguments
)
const
{
assert
(
arguments
.
size
()
==
_argument_
info
.
size
());
return
callers
[
_argument_
info
.
size
()](
_function
,
arguments
);
assert
(
arguments
.
size
()
==
_argument_
names
.
size
());
return
callers
[
_argument_
names
.
size
()](
_function
,
arguments
);
}
}
// namespace NumLib
This diff is collapsed.
Click to expand it.
NumLib/NamedFunction.h
+
18
−
25
View file @
0f3a09f3
...
...
@@ -10,12 +10,12 @@
#ifndef NUMLIB_NAMED_FUNCTION
#define NUMLIB_NAMED_FUNCTION
#include
<string>
#include
<vector>
#include
<cassert>
#include
<functional>
#include
<memory>
#include
<
cassert
>
#include
<
string
>
#include
<type_traits>
#include
<vector>
namespace
detail
{
...
...
@@ -44,31 +44,23 @@ const bool AllTypesSameAs<TRef>::value;
}
// namespace detail
namespace
NumLib
{
//! Maximum number of function arguments supported by NamedFunction.
const
int
MAX_FUNCTION_ARGS
=
32
;
//! Stores a function object along with a name for it and information about its
//! arguments.
class
NamedFunction
final
{
public:
using
ArgumentInfo
=
std
::
string
;
/*! Constructs a new named function.
*
* \param name the function's name
* \param arguments names of arguments of the function
* \param argument
_name
s names of arguments of the function
* \param function the actual function object
*/
template
<
typename
ReturnType
,
typename
...
Arguments
>
NamedFunction
(
std
::
string
const
&
name
,
std
::
vector
<
ArgumentInfo
>&&
arguments
,
std
::
function
<
ReturnType
(
Arguments
...)
>&&
function
);
NamedFunction
(
std
::
string
const
&
name
,
std
::
vector
<
std
::
string
>&&
argument_names
,
std
::
function
<
ReturnType
(
Arguments
...)
>&&
function
);
NamedFunction
(
NamedFunction
&&
other
);
NamedFunction
(
NamedFunction
const
&
);
...
...
@@ -77,22 +69,24 @@ public:
//! Returns the function's name.
std
::
string
const
&
getName
()
const
{
return
_name
;
}
//! Returns information about the function's arguments.
std
::
vector
<
ArgumentInfo
>
const
&
getArgumentInfo
()
const
//! Returns the names of the function's arguments.
std
::
vector
<
std
::
string
>
const
&
getArgumentNames
()
const
{
return
_argument_
info
;
return
_argument_
names
;
}
//! Call the function with the supplied arguments.
double
call
(
std
::
vector
<
double
>
const
&
arguments
)
const
;
//! Maximum number of function arguments supported by NamedFunction.
static
const
int
MAX_FUNCTION_ARGS
=
32
;
private
:
//! The function's name.
std
::
string
_name
;
//! Information about the function's arguments.
std
::
vector
<
ArgumentInfo
>
_argument_
info
;
std
::
vector
<
std
::
string
>
_argument_
names
;
//! The function handle.
void
*
_function
;
...
...
@@ -100,10 +94,10 @@ private:
template
<
typename
ReturnType
,
typename
...
Arguments
>
NamedFunction
::
NamedFunction
(
std
::
string
const
&
name
,
std
::
vector
<
ArgumentInfo
>&&
argument_
info
,
std
::
vector
<
std
::
string
>&&
argument_
names
,
std
::
function
<
ReturnType
(
Arguments
...)
>&&
function
)
:
_name
(
name
),
_argument_
info
(
std
::
move
(
argument_
info
)),
_argument_
names
(
std
::
move
(
argument_
names
)),
_function
(
new
std
::
function
<
ReturnType
(
Arguments
...)
>
(
std
::
move
(
function
)))
{
...
...
@@ -114,10 +108,9 @@ NamedFunction::NamedFunction(std::string const& name,
static_assert
(
sizeof
...(
Arguments
)
<=
MAX_FUNCTION_ARGS
,
"The function you passed has too many arguments."
);
assert
(
sizeof
...(
Arguments
)
==
_argument_
info
.
size
());
assert
(
sizeof
...(
Arguments
)
==
_argument_
names
.
size
());
}
}
// namespace NumLib
}
// namespace NumLib
#endif // NUMLIB_NAMED_FUNCTION
This diff is collapsed.
Click to expand it.
NumLib/NamedFunctionCaller.cpp
+
4
−
3
View file @
0f3a09f3
...
...
@@ -120,7 +120,8 @@ void NamedFunctionCaller::addNamedFunction(NamedFunction&& fct)
_map_name_idx
,
fct
.
getName
(),
_named_functions
.
size
(),
"The name of the function is not unique."
);
_map_sink_source
.
emplace_back
(
fct
.
getArgumentInfo
().
size
(),
_uninitialized
);
_map_sink_source
.
emplace_back
(
fct
.
getArgumentNames
().
size
(),
_uninitialized
);
_named_functions
.
push_back
(
std
::
move
(
fct
));
}
...
...
@@ -157,7 +158,7 @@ void NamedFunctionCaller::applyPlugs()
auto
const
sink_fct_idx
=
sink_it
->
second
;
auto
const
&
sink_args
=
_named_functions
[
sink_it
->
second
].
getArgument
Info
();
_named_functions
[
sink_it
->
second
].
getArgument
Names
();
auto
const
sink_arg_it
=
std
::
find
(
sink_args
.
begin
(),
sink_args
.
end
(),
sink_arg
);
if
(
sink_arg_it
==
sink_args
.
end
())
...
...
@@ -216,7 +217,7 @@ double NamedFunctionCaller::call(
_named_functions
[
function_idx
].
getName
().
c_str
());
auto
const
&
sis_sos
=
_map_sink_source
[
function_idx
];
assert
(
sis_sos
.
size
()
==
_named_functions
[
function_idx
].
getArgument
Info
().
size
());
_named_functions
[
function_idx
].
getArgument
Names
().
size
());
std
::
vector
<
double
>
fct_args
(
sis_sos
.
size
());
for
(
std
::
size_t
sink
=
0
;
sink
<
sis_sos
.
size
();
++
sink
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment