Can we make a faster Boole implementation?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I just learned about Mr. Wizard's very efficient code here.
list=RandomChoice[True,False,10^6];
AbsoluteTiming[l2=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];]
(*0.066533,Null*)
Compare that to Boole.
AbsoluteTiming[l3=Boole[list];]
l2===l3
(*0.262770,Null*)
(* True *)
It seems we can make a faster Boole. I tried to use the code above to do that, but it doesn't work.
boole[list_]:=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];
list=True,True,False,True,False;
boole[list]
(*True,True,False,True,False*)
Why doesn't boole above work, and how can it be fixed?
performance-tuning function-construction core-language
add a comment |Â
up vote
2
down vote
favorite
I just learned about Mr. Wizard's very efficient code here.
list=RandomChoice[True,False,10^6];
AbsoluteTiming[l2=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];]
(*0.066533,Null*)
Compare that to Boole.
AbsoluteTiming[l3=Boole[list];]
l2===l3
(*0.262770,Null*)
(* True *)
It seems we can make a faster Boole. I tried to use the code above to do that, but it doesn't work.
boole[list_]:=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];
list=True,True,False,True,False;
boole[list]
(*True,True,False,True,False*)
Why doesn't boole above work, and how can it be fixed?
performance-tuning function-construction core-language
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I just learned about Mr. Wizard's very efficient code here.
list=RandomChoice[True,False,10^6];
AbsoluteTiming[l2=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];]
(*0.066533,Null*)
Compare that to Boole.
AbsoluteTiming[l3=Boole[list];]
l2===l3
(*0.262770,Null*)
(* True *)
It seems we can make a faster Boole. I tried to use the code above to do that, but it doesn't work.
boole[list_]:=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];
list=True,True,False,True,False;
boole[list]
(*True,True,False,True,False*)
Why doesn't boole above work, and how can it be fixed?
performance-tuning function-construction core-language
I just learned about Mr. Wizard's very efficient code here.
list=RandomChoice[True,False,10^6];
AbsoluteTiming[l2=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];]
(*0.066533,Null*)
Compare that to Boole.
AbsoluteTiming[l3=Boole[list];]
l2===l3
(*0.262770,Null*)
(* True *)
It seems we can make a faster Boole. I tried to use the code above to do that, but it doesn't work.
boole[list_]:=Developer`ToPackedArray@With[True=1,False=0,Evaluate@list];
list=True,True,False,True,False;
boole[list]
(*True,True,False,True,False*)
Why doesn't boole above work, and how can it be fixed?
performance-tuning function-construction core-language
performance-tuning function-construction core-language
edited 1 hour ago
Chris K
5,99221739
5,99221739
asked 2 hours ago
Ted Ersek
2,8441230
2,8441230
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[True$=1,False$=0,True,True,False,True,False]
True, True, False, True, False
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[True = 1, False = 0, #]];
Then:
boole[list]
1, 1, 0, 1, 0
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
add a comment |Â
up vote
1
down vote
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[True = 1, False = 0, list] // Developer`ToPackedArray
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[True$=1,False$=0,True,True,False,True,False]
True, True, False, True, False
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[True = 1, False = 0, #]];
Then:
boole[list]
1, 1, 0, 1, 0
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
add a comment |Â
up vote
1
down vote
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[True$=1,False$=0,True,True,False,True,False]
True, True, False, True, False
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[True = 1, False = 0, #]];
Then:
boole[list]
1, 1, 0, 1, 0
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[True$=1,False$=0,True,True,False,True,False]
True, True, False, True, False
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[True = 1, False = 0, #]];
Then:
boole[list]
1, 1, 0, 1, 0
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[True$=1,False$=0,True,True,False,True,False]
True, True, False, True, False
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[True = 1, False = 0, #]];
Then:
boole[list]
1, 1, 0, 1, 0
answered 2 hours ago
Carl Woll
62.7k281161
62.7k281161
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
add a comment |Â
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
Thank you. Wizard and Carl are both WL experts. I am using version 10. Is the With[True=1,False-0 ,...] trick faster than Boole in version 11.3 ?
â Ted Ersek
1 hour ago
add a comment |Â
up vote
1
down vote
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[True = 1, False = 0, list] // Developer`ToPackedArray
add a comment |Â
up vote
1
down vote
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[True = 1, False = 0, list] // Developer`ToPackedArray
add a comment |Â
up vote
1
down vote
up vote
1
down vote
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[True = 1, False = 0, list] // Developer`ToPackedArray
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[True = 1, False = 0, list] // Developer`ToPackedArray
answered 10 mins ago
Mr.Wizardâ¦
228k294671023
228k294671023
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184765%2fcan-we-make-a-faster-boole-implementation%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password