[Scilab-users] Generating a boolean vector or matrix

classic Classic list List threaded Threaded
22 messages Options
12
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Generating a boolean vector or matrix


Dear all,

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

However I've found a workaround:

a = ones(1,n) & %t

It shouldn't work because ones(1,n) is not boolean, but it does.

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Thank you.

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

Hello,

Le 04/09/2019 à 09:11, Federico Miyara a écrit :

Dear all,

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

However I've found a workaround:

a = ones(1,n) & %t

It shouldn't work because ones(1,n) is not boolean, but it does.

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Yes, there :

https://codereview.scilab.org/#/c/19964/

S.



Thank you.

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by fmiyara
Hello,

> De : Federico Miyara
> Envoyé : mercredi 4 septembre 2019 09:11
>
> I need to create a boolean vector, such as [%t, %t, %t, %t] […] I
> couldn't find a function similar to ones(1,n).
>
> However I've found a workaround:
>
> a = ones(1,n) & %t
> […]
> 1) Why does it work?

Because "A number is considered as %F (false) if it is 0 or 0+0i. Otherwise (including %nan), it is equivalent to %T (true)."

https://help.scilab.org/docs/6.0.2/en_US/and.html

> 2) Is there some native function to create bolean matrices

No, but you have several other ways, you may test to find the one that is the less greedy.

I propose this one:

a = (ones(1,n) == 1)

Apart from this, I think most (if not all) functions that require boolean also accept numbers In the same way as and() (but I may be mistaken).

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by mottelet


Le 04/09/2019 à 09:39, Stéphane Mottelet a écrit :

Hello,

Le 04/09/2019 à 09:11, Federico Miyara a écrit :

Dear all,

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

However I've found a workaround:

a = ones(1,n) & %t

It shouldn't work because ones(1,n) is not boolean, but it does.

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Yes, there :

https://codereview.scilab.org/#/c/19964/

S.

with the following syntax:

ones(n,m,"boolean")
zeros(n,m,"boolean")

The patch is ready since Apr 19, 2018. If you think that it should be included in the next Scilab version, just express you interest !



Thank you.

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Stéphane,

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Yes, there :

https://codereview.scilab.org/#/c/19964/

S.

with the following syntax:

ones(n,m,"boolean")
zeros(n,m,"boolean")

The patch is ready since Apr 19, 2018. If you think that it should be included in the next Scilab version, just express you interest !


Yes, I'm interested in this new feature!

I must express my interest elsewwhere? Because I entered there but as I'm not registered I cannot comment, and I don't find how to register, either.

Regards,

Federico



Thank you.

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Le 04/09/2019 à 20:19, Federico Miyara a écrit :

Stéphane,

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Yes, there :

https://codereview.scilab.org/#/c/19964/

S.

with the following syntax:

ones(n,m,"boolean")
zeros(n,m,"boolean")

The patch is ready since Apr 19, 2018. If you think that it should be included in the next Scilab version, just express you interest !


Yes, I'm interested in this new feature!

I must express my interest elsewwhere? Because I entered there but as I'm not registered I cannot comment, and I don't find how to register, either.

Its is OK to say it here as it will likely pop up this patch in the patchs-to-be-merged list !

S.


Regards,

Federico



Thank you.

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Alain LAMY Alain LAMY
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

Hi,

 

I’m not convinced the new syntax: ones(n, m, “boolean”) is a good idea or is necessary because it makes “integer” (“constant”) and “boolean” 2 identical types.

There is a simple way to do the same :

repmat(%t, n, m)

 

Alain

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

Le 05/09/2019 à 08:55, Lamy Alain a écrit :

Hi,

 

I’m not convinced the new syntax: ones(n, m, “boolean”) is a good idea or is necessary because it makes “integer” (“constant”) and “boolean” 2 identical types.

Sorry Alain can you explain it further ?

There is a simple way to do the same :

repmat(%t, n, m)

Yeah, there are many other (ineficient) ways, but the average user would appreciate to have one and only one function (here "zeros") to initialize a matrix regardless is type.

 

Alain

 


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by Christophe Dang Ngoc Chan

Christophe,

Thanks!

Two more questions (for anybody reading and willing to reply):

1) Is there an exclusive or function? I couldn't find it, a search leads to the XOR mode of combining graphic pixels. It would be most useful since it is one of the operations in the Galois field GF(2). Currently, as I needed it, I created a very simple implementtion of the xor using and, or and negation, but I wonder if a direct implementation would be more efficient.

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?

By the way, using booleans I very much improved speed in massive operations involving sequences of 0's and 1's respect to using decimal o's nd 1's and applying modulo 2 to the sum.

This is a sample code:


// Defining exclusive or, xor
function u=xor(v, w)
   // Probably some parenthesis are unnecessary
   u = ((~v)&w) | (v&(~w));
endfunction

After running this, 

n = 11;
tic
//A = ones(1,n);
A = ones(1,n) & %t;
no = n - 2;
for k=1:2^n -1
    y(k) = A(n);
    //A = [modulo(A(n)+ A(no), 2), A(1:n-1)];
    A = [(xor(A(n),A(no)), A(1:n-1)];
end
toc
It can be checked that using the commented lines for A instead of the uncommented ones the computing time is larger using the modulo 2 way of simulating a XOR than using boolean variables. For n larger the difference is even more noticeable.

This is part of a code I will post when ready for generating maximum length sequences.

Regards,

Federico Miyara 

On 04/09/2019 04:49, Dang Ngoc Chan, Christophe wrote:
Hello,

De : Federico Miyara
Envoyé : mercredi 4 septembre 2019 09:11

I need to create a boolean vector, such as [%t, %t, %t, %t] […] I
couldn't find a function similar to ones(1,n).

However I've found a workaround:

a = ones(1,n) & %t
[…]
1) Why does it work?
Because "A number is considered as %F (false) if it is 0 or 0+0i. Otherwise (including %nan), it is equivalent to %T (true)."

https://help.scilab.org/docs/6.0.2/en_US/and.html

2) Is there some native function to create bolean matrices
No, but you have several other ways, you may test to find the one that is the less greedy.

I propose this one:

a = (ones(1,n) == 1)

Apart from this, I think most (if not all) functions that require boolean also accept numbers In the same way as and() (but I may be mistaken).

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
David Chèze David Chèze
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by mottelet

+1 interested in this patch

 

De : users <[hidden email]> De la part de Stéphane Mottelet
Envoyé : jeudi 5 septembre 2019 08:46
À : [hidden email]
Objet : Re: [Scilab-users] Generating a boolean vector or matrix

 

 

Le 04/09/2019 à 20:19, Federico Miyara a écrit :


Stéphane,


Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?

Yes, there :

https://codereview.scilab.org/#/c/19964/

S.

with the following syntax:

ones(n,m,"boolean")
zeros(n,m,"boolean")

The patch is ready since Apr 19, 2018. If you think that it should be included in the next Scilab version, just express you interest !


Yes, I'm interested in this new feature!

I must express my interest elsewwhere? Because I entered there but as I'm not registered I cannot comment, and I don't find how to register, either.

Its is OK to say it here as it will likely pop up this patch in the patchs-to-be-merged list !

S.


Regards,

Federico


 


Thank you.

Federico Miyara

 

Image supprimée par l'expéditeur.

Libre de virus. www.avast.com



_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet



_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by mottelet


On 05/09/2019 04:13, Stéphane Mottelet wrote:

Le 05/09/2019 à 08:55, Lamy Alain a écrit :

Hi,

 

I’m not convinced the new syntax: ones(n, m, “boolean”) is a good idea or is necessary because it makes “integer” (“constant”) and “boolean” 2 identical types.

Sorry Alain can you explain it further ?

There is a simple way to do the same :

repmat(%t, n, m)

Yeah, there are many other (ineficient) ways, but the average user would appreciate to have one and only one function (here "zeros") to initialize a matrix regardless is type.



Yes, that is exactly the use case!

Federico Miyara



Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by mottelet

When I say ineficient, I mean that kind of behavior:

--> tic;repmat(uint8(0),10000,10000);toc
 ans  =

   1.622535

compared to proposed implementation:

--> tic;a=zeros(10000,10000,"uint8");toc
 ans  =

   0.063472

S.

Quoting Stéphane Mottelet <[hidden email]>:

Le 05/09/2019 à 08:55, Lamy Alain a écrit :

Hi,

 

 

 

 

I’m not convinced the new syntax: ones(n, m, “boolean”) is a good idea or is necessary because it makes “integer” (“constant”) and “boolean” 2 identical types.

Sorry Alain can you explain it further ?

 

 

There is a simple way to do the same :

 

repmat(%t, n, m)

Yeah, there are many other (ineficient) ways, but the average user would appreciate to have one and only one function (here "zeros") to initialize a matrix regardless is type.

 

 

 

 

 

Alain

 

 

 

 


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet




_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Alain LAMY Alain LAMY
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by David Chèze

What I didn’t like at first is to use “ones” for a boolean type.

(although I know the 2 types are almost interchangeable in Scilab).

The existing function bool2s changes %t into 1.

So thinking about it a little more, OK for the proposed extensions of “ones” and “zeros”.

 

Alain

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Le 05/09/2019 à 11:28, Lamy Alain a écrit :

What I didn’t like at first is to use “ones” for a boolean type.

That was also my first reaction.
When comparing the learning curve and overall ease of use of scilab with other options (matlab, julia, python), I always come to the conclusion that the biggest problem with scilab is the use of non-intuitive function names.
For example 'horner' for polynom evaluation as compared to 'polyval' is far from obvious unless you are already quite versed in polynom theory.
If you couple non-intuitive function names (at least for non-specialist and casual users) with a documentation that is far from perfect, this scares a lot of possible users.

Antoine

(although I know the 2 types are almost interchangeable in Scilab).

The existing function bool2s changes %t into 1.

So thinking about it a little more, OK for the proposed extensions of “ones” and “zeros”.

 

Alain

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Le 05/09/2019 à 12:44, Antoine Monmayrant a écrit :


Le 05/09/2019 à 11:28, Lamy Alain a écrit :

What I didn’t like at first is to use “ones” for a boolean type.

That was also my first reaction.
When comparing the learning curve and overall ease of use of scilab with other options (matlab, julia, python), I always come to the conclusion that the biggest problem with scilab is the use of non-intuitive function names.

Concerning "ones" for initializing booleans, Matlab also allows the unintuitive ones(n,m,'logical'), but also has true(n,m) and false(n,m). The two latter could be easily added as macros

function out = true(varargin)
    out = ones(varargin(:),"boolean")
end

function out = false(varargin)
    out = zeros(varargin(:),"boolean")
end

once the patch has been merged

For example 'horner' for polynom evaluation as compared to 'polyval' is far from obvious unless you are already quite versed in polynom theory.
If you couple non-intuitive function names (at least for non-specialist and casual users) with a documentation that is far from perfect, this scares a lot of possible users.

Antoine

(although I know the 2 types are almost interchangeable in Scilab).

The existing function bool2s changes %t into 1.

So thinking about it a little more, OK for the proposed extensions of “ones” and “zeros”.

 

Alain

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by fmiyara
Le 04/09/2019 à 09:11, Federico Miyara a écrit :

Dear all,

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

However I've found a workaround:

a = ones(1,n) & %t

It shouldn't work because ones(1,n) is not boolean, but it does.

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?


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.

To me, the only need is to document these trivial ways in the help pages of %F and %T.
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.

But i can understand that, for some habit reason, former octavers would appreciate their usual functions.
This is why i don't clearly understand why this sub-community does not build and maintain a "Matlabic" ATOMS package gathering this kind of "aliases", or do not invest time to contribute to the m2sci converter improvement.

Even when repmat() will be fastened by a factor 7 through its upgrade pending for 7 months now, it won't be the optimal way, noticeably due to its overhead.

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.
In the same commit, Stéphane proposes to allow using the "logical" keyword as an equivalent of the "boolean" one. On this side, i definitively disagree with this. Indeed,

  1. it would be useless, adding strictly no value to scilab
  2. 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.

About trivial ways, a preliminary note -- and answer to Federico :

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?

4 bytes / boolean. This big memory waste is reported since a while: http://bugzilla.scilab.org/12789

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.

About some trivial efficient ways:

  • Array of %F :
    • zeros(m,n,..)==1
      as Christophe does, the way i use when, for 99,5% of cases, a factor 2 in intermediate memory is not critical
    • a(m,n,..) = %f;
      or safer:
      clear a, a(m,n,..) = %f;
  • Array of %T :
    • zeros(m,n,..)==0
    • a(m,n,..) = %f; ~a
  • Random boolean array :
    • rand(m,n,..) < 0.5

Personnaly, i don't need any option for getting all this. But documenting it would be useful.
In the same way, we can use

  • clear c, c =(5,4,7) = %i*0 // to initiate an array of 0+0i complex-encoded array
  • clear p, p(5,4,7) = %z*0  // to initiate an array of 0z polynomials
  • etc

.. still without any specific functions or option.

Best regards
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Le 13/09/2019 à 15:04, Samuel Gougeon a écrit :
Le 04/09/2019 à 09:11, Federico Miyara a écrit :

Dear all,

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

However I've found a workaround:

a = ones(1,n) & %t

It shouldn't work because ones(1,n) is not boolean, but it does.

Questions:
1) Why does it work?
2) Is there some native function to create bolean matrices
3) If not, are there any plans to introduce functions such as true(m,n) or false(m,n)?


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.

To me, the only need is to document these trivial ways in the help pages of %F and %T.
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.

But i can understand that, for some habit reason, former octavers would appreciate their usual functions.
This is why i don't clearly understand why this sub-community does not build and maintain a "Matlabic" ATOMS package gathering this kind of "aliases", or do not invest time to contribute to the m2sci converter improvement.

Even when repmat() will be fastened by a factor 7 through its upgrade pending for 7 months now, it won't be the optimal way, noticeably due to its overhead.

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.
In the same commit, Stéphane proposes to allow using the "logical" keyword as an equivalent of the "boolean" one. On this side, i definitively disagree with this. Indeed,

  1. it would be useless, adding strictly no value to scilab
  2. 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.
OK Samuel, I can forget this one. However, "double" should be kept as an equivalent of "constant", even if not the name of a scilab type returned by typeof(). We already have the macro "double()" (instead of "constant()") and the keyword "double" used everywhere in the API.

About trivial ways, a preliminary note -- and answer to Federico :

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?

4 bytes / boolean. This big memory waste is reported since a while: http://bugzilla.scilab.org/12789

I think it was stored as 4 bytes for historical reasons (in Visual Studio up to version 4.2 C++ int was 4 bytes)

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.

About some trivial efficient ways:

  • Array of %F :
    • zeros(m,n,..)==1
      as Christophe does, the way i use when, for 99,5% of cases, a factor 2 in intermediate memory is not critical
    • a(m,n,..) = %f;
      or safer:
      clear a, a(m,n,..) = %f;
  • Array of %T :
    • zeros(m,n,..)==0
    • a(m,n,..) = %f; ~a
  • Random boolean array :
    • rand(m,n,..) < 0.5

Personnaly, i don't need any option for getting all this. But documenting it would be useful.
In the same way, we can use

  • clear c, c =(5,4,7) = %i*0 // to initiate an array of 0+0i complex-encoded array
  • clear p, p(5,4,7) = %z*0  // to initiate an array of 0z polynomials
  • etc

.. still without any specific functions or option.

Best regards
Samuel


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

Le 13/09/2019 à 15:32, Stéphane Mottelet a écrit :
.../...

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.
In the same commit, Stéphane proposes to allow using the "logical" keyword as an equivalent of the "boolean" one. On this side, i definitively disagree with this. Indeed,

  1. it would be useless, adding strictly no value to scilab
  2. 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.
OK Samuel, I can forget this one. However, "double" should be kept as an equivalent of "constant", even if not the name of a scilab type returned by typeof(). We already have the macro "double()" (instead of "constant()") and the keyword "double" used everywhere in the API.

Glad to see that we converge about the "logical" keyword exclusion.

About "constant": You will never have any pain to convince me that it is even worse than "double".
"constant" can't be more misleading than it already is.
But just that the "double" keyword is useful, since it is the default returned datatype.
Now, if in some particular occasions it can avoid a specific shortened syntax, why not.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix

In reply to this post by mottelet
Le 13/09/2019 à 15:32, Stéphane Mottelet a écrit :
.../...
OK Samuel, I can forget this one. However, "double" should be kept as an equivalent of "constant", even if not the name of a scilab type returned by typeof(). We already have the macro "double()" (instead of "constant()") and the keyword "double" used everywhere in the API.


AFAIR, in the commit, i was arguing against "constant", not against "double".
IMO both can be implemented (to be able to automate the option out of typeof()).
But documenting "constant" as acceptable keyword would make me ill.
It's not an issue. Anyone else will be able to do it :-)



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Generating a boolean vector or matrix


Le 13/09/2019 à 16:17, Samuel Gougeon a écrit :
Le 13/09/2019 à 15:32, Stéphane Mottelet a écrit :
.../...
OK Samuel, I can forget this one. However, "double" should be kept as an equivalent of "constant", even if not the name of a scilab type returned by typeof(). We already have the macro "double()" (instead of "constant()") and the keyword "double" used everywhere in the API.


AFAIR, in the commit, i was arguing against "constant", not against "double".
IMO both can be implemented (to be able to automate the option out of typeof()).
But documenting "constant" as acceptable keyword would make me ill.
It's not an issue. Anyone else will be able to do it :-)

+1


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
12