[GiNaC-list] [patch] Allow exprseq in the arguments to lsolve()
Vitaly Magerya
vmagerya at gmail.com
Tue May 29 20:35:23 CEST 2018
Hi, folks. Currently lsolve(eqns, vars) takes two lists as
arguments, but then only accesses them via op(), so essentially
any other container should work equally well. Here's a small patch
to make it support exprseq in addition to lst. The motivation is
that std::vector<ex>, upon which exprseq is based, can be more
convenient to work with than std::list<ex>.
Note that there's one additional places where lst is required,
but exprseq would work too: ex::subs(). It would make sense to
support exprseq there too.
Also note that testing for lst is done via two different patterns
in the source code: sometimes it is 'info(info_flags::list)',
other times it is 'is_a<lst>'. It's not clear to me why this
difference exists, or what should be the preferred way.
-------------- next part --------------
From f16fde8871d94580bfd790684380ffe22f56969f Mon Sep 17 00:00:00 2001
From: Vitaly Magerya <magv at tx97.net>
Date: Tue, 15 May 2018 17:36:29 +0200
Subject: [PATCH] Allow exprseq in the arguments to lsolve()
---
ginac/inifcns.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp
index 4e426f4c..8b5fed41 100644
--- a/ginac/inifcns.cpp
+++ b/ginac/inifcns.cpp
@@ -1053,20 +1053,20 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options)
}
// syntax checks
- if (!eqns.info(info_flags::list)) {
- throw(std::invalid_argument("lsolve(): 1st argument must be a list or an equation"));
+ if (!(eqns.info(info_flags::list) || eqns.info(info_flags::exprseq))) {
+ throw(std::invalid_argument("lsolve(): 1st argument must be a list, a sequence, or an equation"));
}
for (size_t i=0; i<eqns.nops(); i++) {
if (!eqns.op(i).info(info_flags::relation_equal)) {
throw(std::invalid_argument("lsolve(): 1st argument must be a list of equations"));
}
}
- if (!symbols.info(info_flags::list)) {
- throw(std::invalid_argument("lsolve(): 2nd argument must be a list or a symbol"));
+ if (!(symbols.info(info_flags::list) || symbols.info(info_flags::exprseq))) {
+ throw(std::invalid_argument("lsolve(): 2nd argument must be a list, a sequence, or a symbol"));
}
for (size_t i=0; i<symbols.nops(); i++) {
if (!symbols.op(i).info(info_flags::symbol)) {
- throw(std::invalid_argument("lsolve(): 2nd argument must be a list of symbols"));
+ throw(std::invalid_argument("lsolve(): 2nd argument must be a list or a sequence of symbols"));
}
}
--
2.13.6
More information about the GiNaC-list
mailing list