<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Le 04/09/2019 à 09:11, Federico Miyara
a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:b7587faa-5b7b-c402-abf6-291d6a80aa86@fceia.unr.edu.ar">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<br>
<font face="Courier New">Dear all, <br>
<br>
I need to create a boolean vector, such as [%t, %t, %t, %t] but
with a number of components given by a variable n. I couldn't
find a function similar to ones(1,n).<br>
<br>
However I've found a workaround:<br>
<br>
a = ones(1,n) & %t<br>
<br>
It shouldn't work because ones(1,n) is not boolean, but it does.<br>
<br>
Questions: <br>
1) Why does it work?<br>
2) Is there some native function to create bolean matrices<br>
3) If not, are there any plans to introduce functions such as
true(m,n) or false(m,n)?<br>
</font></blockquote>
<p><br>
</p>
<p>I hope no. These are typical -- IMO fake -- functions that i
would not expect in Scilab (and in any other language). There are
many trivial and fast ways to create a boolean array of given
dimensions.<br>
</p>
<p>To me, the only need is to document these trivial ways in the
help pages of %F and %T.<br>
Replacing a few lines of documentation with a lot of trivial
duplicated codes, separate pages, separate tests always look a
very bad idea to me.<br>
</p>
<p>But i can understand that, for some habit reason, former octavers
would appreciate their usual functions.<br>
This is why i don't clearly understand why this sub-community does
not build <i>and maintain</i> a "Matlabic" ATOMS package
gathering this kind of "aliases", or do not invest time to
contribute to the m2sci converter improvement.</p>
<p>Even when repmat() will be fastened by a factor 7 through its <a
moz-do-not-send="true"
href="https://codereview.scilab.org/#/c/19782">upgrade pending
for 7 months now</a>, it won't be the optimal way, noticeably
due to its overhead.</p>
<p>I am neither very convinced by the ones(m,n,.,"boolean") and
zeros(m,n,.. "boolean") proposal, for the same reason initially
exposed by Alain. But why not.<br>
In the same commit, Stéphane proposes to allow using the <b>"logical"</b>
keyword as an equivalent of the "boolean" one. On this side, i
definitively disagree with this. Indeed,</p>
<ol>
<li>it would be useless, adding strictly no value to scilab</li>
<li>it would introduce a confusion for everyone, including for
former octavers, since in Octave an array of logical type is
made of 0 and 1, not of %F and %T. While in Scilab we can also
have arrays of 0 and 1.<br>
</li>
</ol>
<p>About trivial ways, a preliminary note -- and answer to Federico
:</p>
<p>
<blockquote type="cite"><font face="Courier New">2) How much
memory does it take a boolean scalar? Does a boolean vector
eploit the fact that a byte could theoretically host up to 8
boolean components?<br>
</font></blockquote>
</p>
<p>4 bytes / boolean. This big memory waste is reported since a
while: <a class="moz-txt-link-freetext" href="http://bugzilla.scilab.org/12789">http://bugzilla.scilab.org/12789</a></p>
<p>This means that, using an array of decimal numbers to create a
boolean array uses an intermediate memory "only" ~twice bigger
than the final result.<br>
<br>
About some trivial efficient ways:</p>
<ul>
<li>Array of %F : <br>
</li>
<ul>
<li>zeros(m,n,..)==1 <br>
as Christophe does, the way i use when, for 99,5% of cases, a
factor 2 in intermediate memory is not critical<br>
</li>
<li>a(m,n,..) = %f;<br>
or safer:<br>
clear a, a(m,n,..) = %f;</li>
</ul>
<li>Array of %T :</li>
<ul>
<li>zeros(m,n,..)==0</li>
<li>a(m,n,..) = %f; ~a</li>
</ul>
<li>Random boolean array :</li>
<ul>
<li>rand(m,n,..) < 0.5</li>
</ul>
</ul>
<p>Personnaly, i don't need any option for getting all this. But
documenting it would be useful.<br>
In the same way, we can use<br>
</p>
<ul>
<li>clear c, c =(5,4,7) = %i*0 // to initiate an array of 0+0i
complex-encoded array</li>
<li>clear p, p(5,4,7) = %z*0 // to initiate an array of 0z
polynomials</li>
<li>etc</li>
</ul>
<p>.. still without any specific functions or option.<br>
</p>
<p>Best regards<br>
Samuel</p>
</body>
</html>