7
$\begingroup$

Bug introduced in 10.3 and fixed in 10.4

--

Just checking whether anyone else can replicate this, or if it's a problem on my computer. The following refuses to execute on my machine, 10.3.1:

Take[{{1}}, All, {UpTo@3}]

It results in General::nomem and Throw::sysexc.

The behaviour seems to be for UpTo[anything bigger than 3], but not for 2.

The intended behaviour would be for it to output {{}}, analogously with

Take[{{1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1}, {1, 2, 3}}, All, {UpTo@2}]

which outputs {{2}, {2}, {}, {2}}.

$\endgroup$
9
  • $\begingroup$ Your syntax is incorrect. The last list demands an integer value and UpTo[3] does not have such a form. What are you trying to accomplish? This works: Take[{{1, 2, 3, 4, 5}}, All, {UpTo[3]}]. $\endgroup$ Jan 2, 2016 at 0:18
  • $\begingroup$ I'm using the fact that Take[{{1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1}, {1, 2, 3}}, All, {UpTo@2}] outputs {{2}, {2}, {}, {2}}, for instance. I could just use Take[{{1}}, All, UpTo@3] and trim down the lists as necessary, but this way was working for when I constructed my prototype using data that let me have 2 instead of 3. $\endgroup$ Jan 2, 2016 at 0:20
  • $\begingroup$ @DavidG.Stork Do you get the out-of-memory on my example? Since it works when {1} is Range[5], I'm very surprised it "runs out of memory" if you make the input smaller. $\endgroup$ Jan 2, 2016 at 0:22
  • 11
    $\begingroup$ This is a bug which has already been fixed in the development version (this example returns unevaluated with an error message). $\endgroup$
    – ilian
    Jan 2, 2016 at 0:40
  • 2
    $\begingroup$ @PatrickStevens {UpTo[n]} effectively means {UpTo[n], UpTo[n]} and in a sequence specification {m1, m2} only the second position allows UpTo. It would be confusing in the first position. $\endgroup$
    – ilian
    Jan 2, 2016 at 0:47

2 Answers 2

6
$\begingroup$

Turning my comment into an answer, this bug has been fixed as of Mathematica 10.4.0.

Take[{{1}}, All, {UpTo@3}]

During evaluation of Take::seqs: Sequence specification (+n, -n, {+n}, {-n}, {m, n}, 
or {m, n, s}) expected at position 3 in Take[{{1}},All,{UpTo[3]}]. >>

(* Take[{{1}}, All, {UpTo[3]}] *)
$\endgroup$
4
$\begingroup$

I indeed got the out-of-memory error in your original example.

This works:

Take[{{1}}, All, UpTo@3]

I think putting the last argument in braces makes Mathematica assume that its contents is an integer, but UpTo[3] is not an integer.

$\endgroup$
1
  • $\begingroup$ To make the output exactly what I wanted: If[Length[#] >= 3, Take[#, {3}], {}] & /@ Take[{{1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1}, {1, 2, 3}}, All, UpTo@3] doesn't have the error. $\endgroup$ Jan 2, 2016 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.