Gillee

232 Reputation

8 Badges

7 years, 101 days

MaplePrimes Activity


These are replies submitted by Gillee

@acer The added the datatype declaration to local A in LArip showed some improvements. This line is amazing:

Grid:-Map(subs(rr = r, MM = M, eval(k -> LArip(k, rr, MM))), [$ (1 .. r)])

Thanks again.  

Thank you for your insightfulness and quick response.

Hi,

I noticed your additional conditions: g is not a square of an integer number and your limits for b, d, and f. I incorporate these new conditions to mloops.mw. Again there many solutions and the real time is less than 5 minutes to complete the search. Please see new script.

 

  mloops_mod_2.mw

 

@Carl Love This problem was prosed by a user a year ago on Mapleprime: looking for a fast way to find 6 integer roots. I suggested a solution at that time. I am revisting it to see if I can speedup my original solution. I enjoyed reviewing your script. It will take me much time to understand it.

You appear to have found more than 2 possible 6 integer root solutions. I may be wrong, but I substituted the values for the 7 coefficients from Sols into the equation: abs(a*x + b) + abs(c*x + d) - t*x^2 + m*x - n and calculated the equation for the various roots (x). The results were not always zero. Please see script.

Roots_with_map_cl.mw

I hope I understood your question correctly about the possibilities of 8 integer roots instead of 6. It never occurred to me that there will be 8 integer roots. I modified the script called Roots_with_map.mw found in my original question. I changed the statement if nops(X) = 6 to if nops(X) = 8 and added and frac(X[7]) = 0 and frac(X[8]) = 0 in Procedure 2. I was not able to come up solution with 8 roots. Please show me how to get 8.

Thanks again for your help, I throughly enjoyed it.

@Carl Love I would never have come up your three methods to handle multiple agruements. You are right they did required as much time to complete as my old method. Thanks.

@dharr I like the Profile function. I will implement your the seq method and see what happens.

Thanks again. 

@acer  thanks for your explanantion, very helpful.

I also have struggled with problem of properly declaring the datatype.


 

FFG := proc (xx::(Array(datatype = float[8])), yy::(Array(datatype = float[8])), zz::(Array(datatype = float[8])), maxx::integer) local T::float, ii::integer; option threadsafe; T := 0.; for ii to maxx do T := T+xx[ii]^2+yy[ii]^2+zz[ii]^2 end do; T end proc; cFFG := Compiler:-Compile(FFG)

dat := CodeTools:-Usage([seq([Array(1 .. 100, fill = 0), Array(1 .. 100, fill = 100), Array(1 .. 100, fill = 50)], ii = 1 .. 200)])

memory used=0.56MiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us, gc time=0ns

 

CodeTools:-Usage(Threads:-Map(proc (L) options operator, arrow; cFFG(op(L), 100) end proc, dat), iterations = 20)

Error, (in cFFG) invalid input: expecting a hardware float[8] rtable, but received 1

 

dat[1][1][1]; type(dat[1][1][1], 'integer')

0

 

true

(1)

dat := CodeTools:-Usage([seq([Array(1 .. 100, fill = 0, datatype = float[8]), Array(1 .. 100, fill = 100, datatype = float[8]), Array(1 .. 100, fill = 50, datatype = float[8])], ii = 1 .. 200)])

memory used=0.56MiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us, gc time=0ns

 

CodeTools:-Usage(Threads:-Map(proc (L) options operator, arrow; cFFG(op(L), 100) end proc, dat), iterations = 20)

memory used=26.26KiB, alloc change=0 bytes, cpu time=3.15ms, real time=2.60ms, gc time=0ns

 

# If you want to use integers, you have to change datatype = integer[4], everywhere. You will also find out that the proc only works with datatype = float[8] and datatype = integer[4], not datatype = integer.
 

X := Statistics:-RandomVariable(Uniform(0, 1)); SX := Statistics:-Sample(X)

dat := CodeTools:-Usage([seq([Array(1 .. 100, SX(100)), Array(1 .. 100, SX(100)), Array(1 .. 100, SX(100))], ii = 1 .. 100)])

memory used=0.94MiB, alloc change=0 bytes, cpu time=15.00ms, real time=8.00ms, gc time=0ns

 

dat[1][1][1]; type(dat[1][1][1], 'float[8]')

HFloat(0.26901318441369804)

 

true

(2)

CodeTools:-Usage(Threads:-Map(proc (L) options operator, arrow; cFFG(op(L), 100) end proc, dat), iterations = 20)

memory used=16.89KiB, alloc change=0 bytes, cpu time=750.00us, real time=2.00ms, gc time=0ns

 

 


 

Download thread_gl.mw

 

Two lines of code were added in red font to @acer's tutorial. They appear show some speed improvements when using map versus Threads:-Map. Please explain. Is this possible? Thank you.

restart

ffgO := proc (xx, yy, zz) local maxx; maxx := (rhs-lhs+1)(op(2, xx)); return add(xx[ii]^2+yy[ii]^2+zz[ii]^2, ii = 1 .. maxx) end proc

ffg := proc (xx, yy, zz) local maxx; maxx := (rhs-lhs+1)(op(2, xx)); return evalhf(add(xx[ii]^2+yy[ii]^2+zz[ii]^2, ii = 1 .. maxx)) end proc

FFG := proc (xx::(Array(datatype = float[8])), yy::(Array(datatype = float[8])), zz::(Array(datatype = float[8])), maxx::integer) local T::float, ii::integer; option threadsafe; T := 0.; for ii to maxx do T := T+xx[ii]^2+yy[ii]^2+zz[ii]^2 end do; T end proc; cFFG := Compiler:-Compile(FFG)

X := Statistics:-RandomVariable(Uniform(0, 1)); SX := Statistics:-Sample(X)

n := 100; dat := CodeTools:-Usage([seq([Array(1 .. n, SX(n)), Array(1 .. n, SX(n)), Array(1 .. n, SX(n))], ii = 1 .. n)])

memory used=0.96MiB, alloc change=0 bytes, cpu time=0ns, real time=8.00ms, gc time=0ns

 

CodeTools:-Usage(map(`@`(ffgO, op), dat), iterations = 20)

memory used=4.42MiB, alloc change=8.00MiB, cpu time=39.05ms, real time=36.45ms, gc time=7.81ms

 

CodeTools:-Usage(map(`@`(ffg, op), dat), iterations = 20)

memory used=0.57MiB, alloc change=0 bytes, cpu time=4.70ms, real time=4.70ms, gc time=0ns

 

CodeTools:-Usage(Threads:-Map(`@`(ffg, op), dat), iterations = 20)

memory used=0.58MiB, alloc change=111.31MiB, cpu time=14.05ms, real time=7.25ms, gc time=0ns

 

CodeTools:-Usage(map(proc (L) options operator, arrow; cFFG(op(L), n) end proc, dat), iterations = 20)

memory used=14.21KiB, alloc change=0 bytes, cpu time=750.00us, real time=500.00us, gc time=0ns

 

CodeTools:-Usage(Threads:-Map(proc (L) options operator, arrow; cFFG(op(L), n) end proc, dat), iterations = 20)

memory used=16.89KiB, alloc change=0 bytes, cpu time=750.00us, real time=1.95ms, gc time=0ns

 

resO := CodeTools:-Usage(map(`@`(ffgO, op), dat), iterations = 20)

memory used=4.02MiB, alloc change=-4.00MiB, cpu time=50.00ms, real time=45.25ms, gc time=9.38ms

 

res1 := CodeTools:-Usage(Threads:-Map(`@`(ffg, op), dat), iterations = 20)

memory used=0.57MiB, alloc change=0 bytes, cpu time=6.25ms, real time=5.55ms, gc time=0ns

 

res2 := CodeTools:-Usage(Threads:-Map(proc (L) options operator, arrow; cFFG(op(L), n) end proc, dat), iterations = 20)

memory used=16.89KiB, alloc change=0 bytes, cpu time=0ns, real time=2.00ms, gc time=0ns

 

evalf[3](evalf[10](max(`~`[abs](resO-res2)))), max(`~`[abs](res1-res2))

0.472e-7, 0.

(1)

 


 

Download thread_map_acc_mod.mw

 

@mmcdara 

 

Your explanation is right on. This is a Bayesian problem that was first solved in R. I did not fully understand the solution in R. I thought if I tried to solve it in Maple then I would have a better understanding of Bayesian Analysis. I turned to Maple because I can ask questions, if I get stuck, and get some really good answers and help from very knowledgable people. Thanks so much for your help again.

@acer 

It is wonderful to see how you can get so much speed from your code. Thank you 

@mmcdara 

I am still stuck in the world of for loops. Thank you.

@Carl Love Thank you, you solved two problems for me: one in Maple and R.

@acer Thanks so much. I am learning to use Maple, off and on. I thought turning one of my procedure into C code would be something interesting to understand. I am always like to learn about simplifing or improving code/script. Could you offer some suggestions that I may try.

Thank you. 

@Carl Love 

 

Another variation. I am learning alot today. Thanks.

1 2 3 Page 2 of 3