X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Ffunction.cppy;h=e1599f3d4d3244295ebcce665023b25a7a6841f3;hb=96be7a17790700998e2d071e00ad5c1ffb4a2d3e;hp=517f4566dff8799027cba532e24f9df6df39dd46;hpb=7d2c44606a17c76f6bec520c22eba96fa5875961;p=ginac.git diff --git a/ginac/function.cppy b/ginac/function.cppy index 517f4566..e1599f3d 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -7,7 +7,7 @@ * Please do not modify it directly, edit function.cppy instead! * function.py options: maxargs=@maxargs@ * - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2018 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,6 @@ #include "power.h" #include "archive.h" #include "inifcns.h" -#include "tostring.h" #include "utils.h" #include "hash_seed.h" #include "remember.h" @@ -76,11 +75,11 @@ function_options::~function_options() void function_options::initialize() { - set_name("unnamed_function", "\\\\mbox{unnamed}"); + set_name("unnamed_function", "\\mbox{unnamed}"); nparams = 0; eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = expand_f - = derivative_f = expl_derivative_f = power_f = series_f = 0; - info_f = 0; + = derivative_f = expl_derivative_f = power_f = series_f = nullptr; + info_f = nullptr; evalf_params_first = true; use_return_type = false; eval_use_exvector_args = false; @@ -105,7 +104,7 @@ function_options & function_options::set_name(std::string const & n, { name = n; if (tn==std::string()) - TeX_name = "\\\\mbox{"+name+"}"; + TeX_name = "\\mbox{"+name+"}"; else TeX_name = tn; return *this; @@ -143,7 +142,7 @@ function_options & function_options::set_return_type(unsigned rt, const return_t { use_return_type = true; return_type = rt; - if (rtt != 0) + if (rtt != nullptr) return_type_tinfo = *rtt; else return_type_tinfo = make_return_type_t(); @@ -229,7 +228,7 @@ function::function(unsigned ser) : serial(ser) // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): function::function(unsigned ser, @seq('const ex & param%(n)d', N)@) - : exprseq(@seq('param%(n)d', N)@), serial(ser) + : exprseq{@seq('param%(n)d', N)@}, serial(ser) { } --- @@ -242,8 +241,8 @@ function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser) clearflag(status_flags::evaluated); } -function::function(unsigned ser, const exvector & v, bool discardable) - : exprseq(v,discardable), serial(ser) +function::function(unsigned ser, const exvector & v) + : exprseq(v), serial(ser) { } @@ -264,13 +263,12 @@ void function::read_archive(const archive_node& n, lst& sym_lst) std::string s; if (n.find_string("name", s)) { unsigned int ser = 0; - std::vector::const_iterator i = registered_functions().begin(), iend = registered_functions().end(); - while (i != iend) { - if (s == i->name) { + for (auto & it : registered_functions()) { + if (s == it.name) { serial = ser; return; } - ++i; ++ser; + ++ser; } throw (std::runtime_error("unknown function '" + s + "' in archive")); } else @@ -304,7 +302,7 @@ void function::print(const print_context & c, unsigned level) const next_context: unsigned id = pc_info->options.get_id(); - if (id >= pdt.size() || pdt[id] == NULL) { + if (id >= pdt.size() || pdt[id] == nullptr) { // Method not found, try parent print_context class const print_context_class_info *parent_pc_info = pc_info->get_parent(); @@ -364,11 +362,10 @@ next_context: } } -ex function::eval(int level) const +ex function::eval() const { - if (level>1) { - // first evaluate children, then we will end up here again - return function(serial,evalchildren(level)); + if (flags & status_flags::evaluated) { + return *this; } GINAC_ASSERT(serialhold(); } @@ -417,28 +414,23 @@ ex function::eval(int level) const return eval_result; } -ex function::evalf(int level) const +ex function::evalf() const { GINAC_ASSERT(serialevalf(level)); - ++it; + for (auto & it : seq) { + eseq.push_back(it.evalf()); } } - if (opt.evalf_f==0) { + if (opt.evalf_f==nullptr) { return function(serial,eseq).hold(); } current_serial = serial; @@ -456,7 +448,7 @@ ex function::evalf(int level) const } /** - * This method is defined to be in line with behaviour of function::return_type() + * This method is defined to be in line with behavior of function::return_type() */ ex function::eval_ncmul(const exvector & v) const { @@ -497,7 +489,7 @@ ex function::series(const relational & r, int order, unsigned options) const GINAC_ASSERT(serialsetflag(status_flags::dynallocated | - status_flags::evaluated); - - current_serial = serial; - if (opt.power_use_exvector_args) - return ((power_funcp_exvector)(opt.power_f))(seq, power_param); - switch (opt.nparams) { - // the following lines have been generated for max. @maxargs@ parameters + if (opt.power_f) { + // Invoke the defined power function. + current_serial = serial; + if (opt.power_use_exvector_args) + return ((power_funcp_exvector)(opt.power_f))(seq, power_param); + switch (opt.nparams) { + // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): - case @N@: - return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); + case @N@: + return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); --- - // end of generated lines + // end of generated lines + } } - throw(std::logic_error("function::power(): no power function defined")); + // No power function defined? Fall back to returning a power object. + return dynallocate(*this, power_param).setflag(status_flags::evaluated); } ex function::expand(unsigned options) const @@ -803,27 +796,25 @@ ex function::expand(unsigned options) const GINAC_ASSERT(serial & function::registered_functions() @@ -847,8 +838,8 @@ void function::store_remember_table(ex const & result) const unsigned function::register_new(function_options const & opt) { size_t same_name = 0; - for (size_t i=0; i::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end(); unsigned serial = 0; - while (i != end) { - if (i->get_name() == name && i->get_nparams() == nparams) + for (auto & it : function::registered_functions()) { + if (it.get_name() == name && it.get_nparams() == nparams) return serial; - ++i; ++serial; } - throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined")); + throw (std::runtime_error("no function '" + name + "' with " + std::to_string(nparams) + " parameters defined")); } /** Return the print name of the function. */