Bumpity bump. Another version another request for the like keyword ;)

Hi there as per comment #12 I worked on this a long time ago. I was discouraged by the speed for which I got feedback on my patch so I did not continue.
I don't currently have a Octave dev environment so if anyone wants to take my patch and replay it thats fine or they could start from scratch.

I tried to test the patch from comment #9 but it would need to be adjusted for current dev. Brad, do you think you would have time to update your patch? I can try to have a look otherwise.
It would be great to have it for Octave 5.0.

Just a little bump for the 'like' keyword which is still unsupported (release 4.4.1).

Another function that should support 'like' functionality
cast

I added the functionality 'like' functionality to the following functions:
 NaN
 Inf
 ones
 zeros
 false
 true
Which were all listed in Matlab 2017a documentation as accepting the 'like' argument. (and existed in the data.cc file)
I also added tests to this effect.
Patch should be attached. I think we should separate this from rand, randi, randn which localize this patch.
(file #41183)

Inf and NaN both use this call model too.
I have some of this done and will submit patches for this.

Matlab also uses 'like' for rand, randi, randn,
to get a result which has the same object type as the given parameter.

It looks like "like" only copies the following properties:
 data type (class)
 complexity
 sparsity
Sorry I have no ability to implement this properly. It's not that it's a musthave thing, it just not having it breaks Matlab code. This is a horrible hackaround.
function x = zeros(varargin)
for k = 1:nargin
if isequal(varargin{k},'like')
if k+1 > nargin
error('''like'' must be followed by a variable.');
end
varargin{k} = class(varargin{k+1});
varargin(k+1) = [];
break;
end
end
x = builtin('zeros',varargin{:});

Okay, so they are inconsistent. If you're very interested in this feature you could work out the exact logic they are using and submit a changeset.

Looks like not.

I see. Yes, I suppose it would be interesting to have a function that copies all attributes. Does Matlab, for example, also copy the global attribute?

You're right Rik, class is a nice workaround.
Unfortunately I've got myself addicted to using the gpuArray class in Matlab and 'like' is useful for copying that attribute over. It's still a hack in Matlab if you just want to copy the GPU part but not the complexity... they haven't really ironed out bugs in pcg, lsqr, etc. which use 'like' to declare arrays like resvec. My data is complex so these come back as complex arrays. Matlabs support could not care less, just cut&paste replies describing memory management on the gpu side.
So you still end up with if/else statements all over the place. Annoying.

Yeah. Matlab has been this way for a while. I happen to think it clutters the interface to the matrixproducing functions like zeros, ones, etc., but maybe it will get implemented.
A pretty easy hack, if one really needs this functionality, is to use class().
The complex attribute isn't really necessary to copy because Octave adjusts matrices automatically as necessary to save memory. If a matrix has all zero imaginary parts t is automatically reduced to real to save memory. Conversely, if you assign a complex variable to a real matrix Octave will conver the matrix to complex. Using the example above.
Now B is taking up 8 bytes just as the Matlab variable does.
And now it is back to requiring only 4 bytes.

MATLAB introduced the 'like' keyword for zeros, ones, cast.
