Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
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
Model registry
Operate
Environments
Terraform modules
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
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
32de636e
Commit
32de636e
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
822d640b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
binaryc_python_utils/example_perl.pm
+95
-0
95 additions, 0 deletions
binaryc_python_utils/example_perl.pm
binaryc_python_utils/logging_functions.py
+7
-97
7 additions, 97 deletions
binaryc_python_utils/logging_functions.py
with
102 additions
and
97 deletions
binaryc_python_utils/example_perl.pm
0 → 100644
+
95
−
0
View file @
32de636e
# Autologging
# Perl code for autogeneration
# sub autogen_C_logging_code
# {
# # given a hash of arrays of variable names, where the hash
# # key is the header, autogenerate PRINTF statements
# my ($self) = @_;
# my $code = undef;
# if(defined $self->{_grid_options}->{C_auto_logging} &&
# ref $self->{_grid_options}->{C_auto_logging} eq 'HASH'
# )
# {
# $code = '';
# foreach my $header (keys %{$self->{_grid_options}->{C_auto_logging}})
# {
# if(ref $self->{_grid_options}->{C_auto_logging}->{$header} eq 'ARRAY')
# {
# $code .= 'PRINTF("'.$header.' ';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# {
# $code .= '%g ';
# }
# $code .= '\n"';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# {
# $code .= ',((double)stardata->'.$x.')';
# }
# $code .= ');'
# }
# }
# }
# print "MADE AUTO CODE \n\n************************************************************\n\n$code\n\n************************************************************\n";
# return $code;
# }
# Which is used in flexi-grid via this:
# $population->set( C_auto_logging => {
# 'MY_STELLAR_DATA' =>
# [
# 'model.time',
# 'star[0].mass',
# 'model.probability',
# 'model.dt'
# ]
# });
# binary_c_log_code
# sub binary_c_log_code
# {
# my ($code) = @_;
# return "
# #pragma push_macro(\"MAX\")
# #pragma push_macro(\"MIN\")
# #undef MAX
# #undef MIN
# #include \"binary_c.h\"
# void custom_output_function(SV * x);
# SV * custom_output_function_pointer(void);
# SV * custom_output_function_pointer()
# {
# /*
# * use PTR2UV to convert the function pointer
# * &custom_output_function to an unsigned int,
# * which is then converted to a Perl SV
# */
# return (SV*)newSVuv(PTR2UV(&custom_output_function));
# }
# void custom_output_function(SV * x)
# {
# struct stardata_t * stardata = (struct stardata_t *)x;
# $code;
# }
# #undef MAX
# #undef MIN
# #pragma pop_macro(\"MIN\")
# #pragma pop_macro(\"MAX\")
# ";
# }
# And then to use it via
# $population->set(
# C_logging_code => '
# PRINTF("MY_STELLAR_DATA %g %g %g %g\n",
# stardata->model.time,
# stardata->star[0].mass,
# stardata->model.probability,
# stardata->model.dt);
# '
# );
This diff is collapsed.
Click to expand it.
binaryc_python_utils/logging_functions.py
+
7
−
97
View file @
32de636e
...
...
@@ -5,58 +5,14 @@ import textwrap
# https://stackoverflow.com/questions/49941617/runtime-generation-and-compilation-of-cython-functions
# https://realpython.com/cpython-source-code-guide/
# https://docs.python.org/3.6/c-api/index.html
# https://stackoverflow.com/questions/6626167/build-a-pyobject-from-a-c-function
# https://docs.python.org/3.6/extending/newtypes_tutorial.html?highlight=pointer
# https://realpython.com/cpython-source-code-guide/
# https://diseraluca.github.io/blog/2019/03/21/wetting-feet-with-python-c-api
# https://docs.python.org/3/c-api/function.html
# Perl code for autogeneration
# sub autogen_C_logging_code
# {
# # given a hash of arrays of variable names, where the hash
# # key is the header, autogenerate PRINTF statements
# my ($self) = @_;
# my $code = undef;
# if(defined $self->{_grid_options}->{C_auto_logging} &&
# ref $self->{_grid_options}->{C_auto_logging} eq 'HASH'
# )
# {
# $code = '';
# foreach my $header (keys %{$self->{_grid_options}->{C_auto_logging}})
# {
# if(ref $self->{_grid_options}->{C_auto_logging}->{$header} eq 'ARRAY')
# {
# $code .= 'PRINTF("'.$header.' ';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# {
# $code .= '%g ';
# }
# $code .= '\n"';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# {
# $code .= ',((double)stardata->'.$x.')';
# }
# $code .= ');'
# }
# }
# }
# print "MADE AUTO CODE \n\n************************************************************\n\n$code\n\n************************************************************\n";
# return $code;
# }
# Which is used in flexi-grid via this:
# $population->set( C_auto_logging => {
# 'MY_STELLAR_DATA' =>
# [
# 'model.time',
# 'star[0].mass',
# 'model.probability',
# 'model.dt'
# ]
# });
# See example_perl.pm autologging
def
autogen_C_logging_code
(
logging_dict
):
"""
Function that autogenerates PRINTF statements for binaryc
...
...
@@ -114,53 +70,7 @@ autogen_C_logging_code(
####################################################################################
# sub binary_c_log_code
# {
# my ($code) = @_;
# return "
# #pragma push_macro(\"MAX\")
# #pragma push_macro(\"MIN\")
# #undef MAX
# #undef MIN
# #include \"binary_c.h\"
# void custom_output_function(SV * x);
# SV * custom_output_function_pointer(void);
# SV * custom_output_function_pointer()
# {
# /*
# * use PTR2UV to convert the function pointer
# * &custom_output_function to an unsigned int,
# * which is then converted to a Perl SV
# */
# return (SV*)newSVuv(PTR2UV(&custom_output_function));
# }
# void custom_output_function(SV * x)
# {
# struct stardata_t * stardata = (struct stardata_t *)x;
# $code;
# }
# #undef MAX
# #undef MIN
# #pragma pop_macro(\"MIN\")
# #pragma pop_macro(\"MAX\")
# ";
# }
# And then to use it via
# $population->set(
# C_logging_code => '
# PRINTF("MY_STELLAR_DATA %g %g %g %g\n",
# stardata->model.time,
# stardata->star[0].mass,
# stardata->model.probability,
# stardata->model.dt);
# '
# );
# see example_perl.pm binary_c_log_code
def
binary_c_log_code
(
code
):
"""
...
...
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