7

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}}.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Patrick Stevens
  • 6,107
  • 1
  • 16
  • 42
  • 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]}]. – David G. Stork Jan 02 '16 at 00:18
  • 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. – Patrick Stevens Jan 02 '16 at 00:20
  • @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. – Patrick Stevens Jan 02 '16 at 00:22
  • It's by analogy with Take[{1,2,3}, {n}] returning the nth element of Take[{1,2,3}, n]; hence Take[{1,2,3}, {UpTo@n}] should return the nth element of Take[{1,2,3}, UpTo@n], or something standard if the list isn't long enough. Experimenting, when n=2 the "something standard" turns out to be {}. – Patrick Stevens Jan 02 '16 at 00:32
  • 11
    This is a bug which has already been fixed in the development version (this example returns unevaluated with an error message). – ilian Jan 02 '16 at 00:40
  • @ilian That's not the direction I'd have liked it fixed in :P but thanks! Given that the behaviour I wanted was not documented, it's perfectly reasonable not to have implemented it. – Patrick Stevens Jan 02 '16 at 00:41
  • 2
    @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. – ilian Jan 02 '16 at 00:47
  • @ilian I am encountering a similar problem with 10.3 when running FindRoot under ParallelTable. When will the development version that you mentioned above be released? Thanks. – bbgodfrey Feb 12 '16 at 06:04
  • @bbgodfrey 10.4 should be coming soon (source) but you may be seeing a different problem (this one was specific to UpTo). Please consider sending the example to support@wolfram.com. – ilian Feb 12 '16 at 16:53

2 Answers2

6

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]}] *)
ilian
  • 25,474
  • 4
  • 117
  • 186
4

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.

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • 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. – Patrick Stevens Jan 02 '16 at 00:30