I have some sequence: (a)(1)(b)(2)(c)(3) and I want to expand it in: a_b_c, what solutions? I tried BOOST_PP_SEQ_FOLD_LEFT vs BOOST_PP_SEQ_FILTER but unsuccessfully, it's was: a1b2c3 ...
Help)
You could do something like this (I can't guarantee it's the best approach):
#define DO_CONCAT_WITH_UNDERSCORE(__,STATE,ELEM) BOOST_PP_CAT(STATE,BOOST_PP_CAT(_,ELEM))
#define DO_FILTER_POSITION(_,__,INDEX,ELEM) BOOST_PP_IF(BOOST_PP_MOD(INDEX,2),BOOST_PP_EMPTY(),(ELEM)) //IF IT'S ODD ADD NOTHING, IF IT'S EVEN ADD THE CURRENT ELEM IN PARENS
#define TAKE_EVEN_POSITIONS(SEQ) BOOST_PP_SEQ_FOR_EACH_I(DO_FILTER_POSITION,_,SEQ)
#define TAKE_EVEN_POSITIONS_AND_CONCAT_HELPER(FILTERED_SEQ) BOOST_PP_SEQ_FOLD_LEFT(DO_CONCAT_WITH_UNDERSCORE,BOOST_PP_SEQ_HEAD(FILTERED_SEQ),BOOST_PP_SEQ_TAIL(FILTERED_SEQ))
#define TAKE_EVEN_POSITIONS_AND_CONCAT(SEQ) TAKE_EVEN_POSITIONS_AND_CONCAT_HELPER(TAKE_EVEN_POSITIONS(SEQ))
Running on Wandbox
Related
I have an error for the following code in Julia for solving NLP problem.
using JuMP
using Ipopt
using DataFrames,ConditionalJuMP
m = Model(solver=IpoptSolver())
#importing data
xi=[-1.016713795 0.804447648 0.932137661 1.064136698 -0.963217531
-1.048396778 1.076371484 1.099027177 1.061556926 -0.95185481
-0.980261302 0.271253807 0.184946729 1.062838197 -0.958794505
-0.980703191 0.278820569 0.231132677 1.062967459 -0.959302488
-0.953074503 -0.00768112 0.128808175 1.067743779 -0.978524489
-1.014866259 0.815325963 1.065956208 1.067059122 -0.974682291
-0.995088119 0.550359991 0.845087207 1.066556784 -0.973154887]
xj=xi
pii=[-300
-259.6530828
-284.3708955
-291.3387625
-342.4479859
-356.5031603
-351.0154738]
sample_size=7
bus_num=5
tempsum=0
#define variables
#variable(m,aij[1:2*bus_num,1:2*bus_num]) # define matrix by
2bus_num*2bus_num
for n=1:sample_size
for i=1:bus_num
for j=1:bus_num
tempsum=(aij[i,j]*xi[n,i]*xj[n,j]-pii[n,2])^2+tempsum
end
end
end
#define constraints
#constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,j]==aij[j,i])
#constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,j]*aij[i,j]<=aij
[i,i]*aij[j,j])
#constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,i]*aij[j,j]<=0.25*
(aij[i,i]+aij[j,j])*(aij[i,i]+aij[j,j]))
#define NLP objective function
#NLobjective(m, Min, tempsum)
solve(m)
println("m = ",getobjectivevalue(m))
println("Aij = ", getvalue(aij))
but after operation, an error was shown as below.
MethodError: no method matching parseNLExpr_runtime(::JuMP.Model,
::JuMP.GenericQuadExpr{Float64,JuMP.Variable},
::Array{ReverseDiffSparse.NodeData,1}, ::Int64, ::Array{Float64,1})
The error occurs on #NLobjective(m, Min, tempsum), but I dont know how to modify the code. May you please anyone help me ?
Besides, I am also confused by how to add positive definite contraints here for the solution Matrix aij, as I want to get a positive definite matrix aij.
#NLobjective(m, Min, tempsum) the tempsum in this code must be a function which is registered by Jump.register(***).
I have a postscript file when i try to convert it into pdf or open it with postscript it gives the following error
undefined in execform
I am trying to fix this error. But there is no solution i found. Kindly Help me understand the issue.
This is postscript file
OK so a few observations to start;
The file is 8 pages long, uses many forms, and the first form it uses has nested forms. This really isn't suitable as an example file, you are expecting other programmers to dig through a lot of extraneous cruft to help you out. When you post an example, please try and reduce it to just the minimum required to reproduce the problem.
Have you actually tried to debug this problem yourself ? If so what did you do ? (and why didn't you start by reducing the file complexity ?)
I don't want to be offensive, but this is the third rather naive posting you've made recently, do you have much experience of PostScript programming ? Has anyone offered you any training in the language ? It appears you are working on behalf of a commercial organisation, you should talk to your line manager and try and arrange some training if you haven't already been given some.
The PostScript program does not give the error you stated
undefined in execform
In fact the error is a Ghostscript-specific error message:
Error: /undefined in --.execform1--
So that's the .execform1 operator (note the leading '.' to indicate a Ghostscript internal operator). That's only important because firstly its important to accurately quote error messages, and secondly because, for someone familiar with Ghostscript, it tells you that the error occurs while executing the form PaintProc, not while executing the execform operator.
After considerably reducing of the complexity of the file, the problem is absolutely nothing to do with the use of Forms. The offending Form executes code like this:
2 RM
0.459396 w
[(\0\1\0\2)]435.529999 -791.02002 T
(That's the first occurrence, and its where the error occurs)
That executes the procedure named T which is defined as:
/T{neg _LY add /_y ed _LX add /_x ed/_BLSY _y _BLY sub D/_BLX _x D/_BLY _y D _x _y TT}bd
Obviously that's using a number of other functions defined in the prolog, but the important point is that it executes TT which is defined as :
/TT{/_y ed/_x ed/_SX _x _LX sub D/_SY _y _LY sub D/_LX _x D/_LY _y D _x _y m 0 _rm eq{ dup type/stringtype eq{show}{{ dup type /stringtype eq{show}{ 0 rmoveto}?}forall}?} if
1 _rm eq {gsave 0 _scs eq { _sr setgray}if 1 _scs eq { _sr _sg _sb setrgbcolor}if 2 _scs eq { _sr _sg _sb _sk setcmykcolor} if dup type/stringtype eq{true charpath }{{dup type /stringtype eq{true charpath } { 0 rmoveto}?}forall}? S grestore} if
2 _rm eq {gsave 0 _fcs eq { _fr setgray}if 1 _fcs eq { _fr _fg _fb setrgbcolor}if 2 _fcs eq { _fr _fg _fb _fk setcmykcolor} if dup type/stringtype eq{true charpath }{{dup type /stringtype eq{true charpath } { 0 rmoveto}?}
forall}? gsave fill grestore 0 _scs eq { _sr setgray}if 1 _scs eq { _sr _sg _sb setrgbcolor}if 2 _scs eq { _sr _sg _sb _sk setcmykcolor}if S grestore} if
Under the conditions holding at the time TT is executed (RM sets _rm to 2), we go through this piece of code:
gsave 0 _fcs eq
However, _fcs is initially undefined, and only defined when the /fcs function is executed. Your program never executes /fcs so _fcs is undefined, leading to the error.
Is there a reason why you are defining each page in a PostScript Form ? This is not optimal, if the interpreter actually supports Forms then you are using up VM for no useful purpose (since you only execute each Form once).
If its because the original PDF input uses PDF Form XObjects I would recommend that you don't try and reproduce those in PostScript. Reuse of Form XObjects in PDF is rather rare (it does happen but non-reuse is much more common). The loss of efficiency due to describing PostScript Forms for each PDF Form XObject for all the files where the form isn't reused exceeds the benefit for the rare cases where it would actually be valuable.
I'm a newbie of Linux, currently I read some code of Linux, and I see a macro current_pt_regs in arch/arm/include/asm/ptrace.h defined as below:
#define current_pt_regs(void) ({ (struct pt_regs *) \
((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1; \
})
In my opinion current_stack_pointer | (THREAD_SIZE - 1) can get the top address of stack. But what confused me is that, why it has -7?
Can someone tell me something about that?
Thanks and regards,
kan.
I'm having a problem with __sync_fetch_and_and incorrectly performing. I wrote the following code to illustrate it:
bool equal;
int64_t mask = 0x01234567BEEFDEAD;
int64_t orig = 0xDEADBEEF01234567;
int64_t test1, test2;
test1 = test2 = orig;
equal = (test1 == test2);
printf("Before anding\n");
printf("test1:\t0x%016llX\n", test1);
printf("test2:\t0x%016llX\n", test2);
printf("equal:\t%d\n", equal);
// Try anding
test1 &= mask;
__sync_fetch_and_and(&test2, mask);
equal = (test1 == test2);
printf("After anding\n");
printf("test1:\t0x%016llX\n", test1);
printf("test2:\t0x%016llX\n", test2);
printf("equal:\t%d\n", equal);
The output from this is:
Before anding
test1: 0xDEADBEEF01234567
test2: 0xDEADBEEF01234567
equal: 1
After anding
test1: 0x0021046700234425
test2: 0xDFAFFFEFBFEFDFEF
equal: 0
...which is obviously not correct. I've tried replacing __sync_and_and_fetch but that doesn't fix it. Or-ing with ``__sync_fetch_and_or` works correctly. I'm using Xcode 4.2.1 and compiling with the default compiler Apple LLVM Compiler 3.0 (Clang). When I switch to using GCC 4.2, it works correctly.
This certainly seems like a compiler bug, but I'm not sure if I'm somehow doing this wrong on Clang. Are there some differences in Clang that I'm not accounting for, or is this indeed a bug?
EDIT: I haven't tried the latest release of Clang (3.0) because I'm stuck using Xcode for now.
Yes, it's a bug; it's been fixed in newer versions of clang. As a workaround, you can add "-no-integrated-as" to your compiler flags.
I am looking for a fast implementation of the "arrangement" algorithm (permutation with duplicates).
Given N objects (A in quantity a, B in quantity b, ...), generate all the possible combinations.
Exemple:
Arrangement("AAA", "B", "CC") would return :
"AAABCC" "AABACC" "AABCAC" "AABCCA" "ABAACC" "ABACAC" "ABACCA" "ABCAAC"
"ABCACA" "ABCCAA" "BAAACC" "BAACAC" "BAACCA" "BACAAC" "BACACA" "BACCAA"
"BCAAAC" "BCAACA" "BCACAA" "BCCAAA" "AAACBC" "AACABC" "AACBAC" "AACBCA"
"ACAABC" "ACABAC" "ACABCA" "ACBAAC" "ACBACA" "ACBCAA" "CAAABC" "CAABAC"
"CAABCA" "CABAAC" "CABACA" "CABCAA" "CBAAAC" "CBAACA" "CBACAA" "CBCAAA"
"AAACCB" "AACACB" "AACCAB" "AACCBA" "ACAACB" "ACACAB" "ACACBA" "ACCAAB"
"ACCABA" "ACCBAA" "CAAACB" "CAACAB" "CAACBA" "CACAAB" "CACABA" "CACBAA"
"CCAAAB" "CCAABA" "CCABAA" "CCBAAA"
(Code in C, C# or Pascal if possible)
Thanks in advance
Philippe
If you can use C++, it's already provided in the standard library:
#include <algorithm>
#include <string>
#include <iostream>
int main() {
std::string a("AAABCC");
do {
std::cout << a << "\t";
} while (std::next_permutation(a.begin(), a.end()));
return 0;
}
Edit: the output from this is:
AAABCC AAACBC AAACCB AABACC AABCAC AABCCA AACABC AACACB AACBAC AACBCA
AACCAB AACCBA ABAACC ABACAC ABACCA ABCAAC ABCACA ABCCAA ACAABC ACAACB
ACABAC ACABCA ACACAB ACACBA ACBAAC ACBACA ACBCAA ACCAAB ACCABA ACCBAA
BAAACC BAACAC BAACCA BACAAC BACACA BACCAA BCAAAC BCAACA BCACAA BCCAAA
CAAABC CAAACB CAABAC CAABCA CAACAB CAACBA CABAAC CABACA CABCAA CACAAB
CACABA CACBAA CBAAAC CBAACA CBACAA CBCAAA CCAAAB CCAABA CCABAA CCBAAA
For anybody who can't use C++, Mark Nelson wrote an article in the C/C++ User's Journal a few years ago that might be helpful.