Skip to main content
Commonmark migration
Source Link

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

 
ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
  
(*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

 
ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
 (*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
 
(*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

edited tags
Link
Tweeted twitter.com/StackMma/status/806922171209629696
added 7 characters in body
Source Link
Emilio Pisanty
  • 10.3k
  • 1
  • 37
  • 71

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
(*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentationdocumentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
(*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

I've been using the combination

ConstantArray[0, {}]

(* 0 *)

in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers 
   expected at position 2 of ConstantArray[0, {}]
(*Out[]:= ConstantArray[0, {}]*)

The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

Source Link
Emilio Pisanty
  • 10.3k
  • 1
  • 37
  • 71
Loading