2 added 517 characters in body
source | link

Posting ilian's comment as an answer,

That is intended behavior. When operating on a packed array, Clip returns a packed array of the same type. – ilian

Checking:

lst = RandomReal[{-1, 1}, {10}];

lst2 = RandomInteger[2, 20];

Clip[lst, {0, 0}, {0, 1}]

Clip[lst2, {0, 0}, {0, 1}]

Clip[Developer`FromPackedArray@lst, {0, 0}, {0, 1}]    
{1., 0., 0., 1., 1., 1., 0., 1., 1., 0.}

{1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1}

{1, 0, 0, 1, 1, 1, 0, 1, 1, 0}
 

But Clip[RandomInteger[2, 10], {0., 0.}, {0., 1.}] returns a packed array of reals:

Clip[lst2, {0., 0.}, {0., 1.}]
% // Developer`PackedArrayQ    
{1., 0., 0., 0., 1., 0., 1., 1., 0., 1., 1., 0., 0., 1., 0., 1., 1., 0., 0., 1.}

True

ilian's responce:

Yes, my previous comment was not precise enough. It also matters whether the ranges can be packed and into what type. For example, Clip[RandomInteger[2, 10], {0., 0.}, {0., 1}] and Clip[RandomReal[2, 10], {0., 0.}, {0., Infinity}] do not return a packed result.

Posting ilian's comment as an answer,

That is intended behavior. When operating on a packed array, Clip returns a packed array of the same type. – ilian

Checking:

lst = RandomReal[{-1, 1}, {10}];

lst2 = RandomInteger[2, 20];

Clip[lst, {0, 0}, {0, 1}]

Clip[lst2, {0, 0}, {0, 1}]

Clip[Developer`FromPackedArray@lst, {0, 0}, {0, 1}]    
{1., 0., 0., 1., 1., 1., 0., 1., 1., 0.}

{1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1}

{1, 0, 0, 1, 1, 1, 0, 1, 1, 0}

But

Clip[lst2, {0., 0.}, {0., 1.}]
% // Developer`PackedArrayQ    
{1., 0., 0., 0., 1., 0., 1., 1., 0., 1., 1., 0., 0., 1., 0., 1., 1., 0., 0., 1.}

True

Posting ilian's comment as an answer,

That is intended behavior. When operating on a packed array, Clip returns a packed array of the same type.

Checking:

lst = RandomReal[{-1, 1}, {10}];

lst2 = RandomInteger[2, 20];

Clip[lst, {0, 0}, {0, 1}]

Clip[lst2, {0, 0}, {0, 1}]

Clip[Developer`FromPackedArray@lst, {0, 0}, {0, 1}]    
{1., 0., 0., 1., 1., 1., 0., 1., 1., 0.}

{1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1}

{1, 0, 0, 1, 1, 1, 0, 1, 1, 0}
 

But Clip[RandomInteger[2, 10], {0., 0.}, {0., 1.}] returns a packed array of reals:

Clip[lst2, {0., 0.}, {0., 1.}]
% // Developer`PackedArrayQ    
{1., 0., 0., 0., 1., 0., 1., 1., 0., 1., 1., 0., 0., 1., 0., 1., 1., 0., 0., 1.}

True

ilian's responce:

Yes, my previous comment was not precise enough. It also matters whether the ranges can be packed and into what type. For example, Clip[RandomInteger[2, 10], {0., 0.}, {0., 1}] and Clip[RandomReal[2, 10], {0., 0.}, {0., Infinity}] do not return a packed result.

1
source | link

Posting ilian's comment as an answer,

That is intended behavior. When operating on a packed array, Clip returns a packed array of the same type. – ilian

Checking:

lst = RandomReal[{-1, 1}, {10}];

lst2 = RandomInteger[2, 20];

Clip[lst, {0, 0}, {0, 1}]

Clip[lst2, {0, 0}, {0, 1}]

Clip[Developer`FromPackedArray@lst, {0, 0}, {0, 1}]    
{1., 0., 0., 1., 1., 1., 0., 1., 1., 0.}

{1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1}

{1, 0, 0, 1, 1, 1, 0, 1, 1, 0}

But

Clip[lst2, {0., 0.}, {0., 1.}]
% // Developer`PackedArrayQ    
{1., 0., 0., 0., 1., 0., 1., 1., 0., 1., 1., 0., 0., 1., 0., 1., 1., 0., 0., 1.}

True