bugGNU Octave - Bugs: bug #57870, mod doesn't accept char or logical...

 
 

bug #57870: mod doesn't accept char or logical inputs (Matlab compatibility)

Submitter:  None
Submitted:  Fri 21 Feb 2020 04:10:23 AM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  1 - Later Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 5.2.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 14 Mar 2020 11:59:12 AM UTC, comment #6: 

1. Checking for bool and char arguments
2. type casting them to double
3. Issue a warning about typecasting.

I am planning this approach to solve the bug. Please correct me if I am going wrong.

Also, forgive me for spoiling the discussion page. comment #5 was done by mistake. I am new here, and don't know how to delete comments

vishnu parammal <vishnuparammal>
Sat 14 Mar 2020 11:50:40 AM UTC, comment #5: 

comment #1:

> Yes, this is true.  But, I'm not sure it's all that useful.
>
> A logical matrix can only take the values of 0 and 1.  Hence, there is never any need to check for non-integers.  And using isbool() or islogical() is a much faster test then mod() because it only checks the matrix type, rather than performing any floating point math.
>
> If you really want to use mod with booleans there are workarounds.  You can cast your input to double as you demonstrated.
>
> The same thing holds for char matrices.
>


> mod ('A', 1)
> error: mod: wrong type argument 'sq_string'


>
> I re-titled the bug report to mention that both char and logical inputs are not accepted by mod.  However, because there is an easy workaround, and a better choice not to use mod at all, I've lowered the priority.
>


comment #1:

> Yes, this is true.  But, I'm not sure it's all that useful.
>
> A logical matrix can only take the values of 0 and 1.  Hence, there is never any need to check for non-integers.  And using isbool() or islogical() is a much faster test then mod() because it only checks the matrix type, rather than performing any floating point math.
>
> If you really want to use mod with booleans there are workarounds.  You can cast your input to double as you demonstrated.
>
> The same thing holds for char matrices.
>


> mod ('A', 1)
> error: mod: wrong type argument 'sq_string'


>
> I re-titled the bug report to mention that both char and logical inputs are not accepted by mod.  However, because there is an easy workaround, and a better choice not to use mod at all, I've lowered the priority.
>

vishnu parammal <vishnuparammal>
Tue 03 Mar 2020 01:54:33 AM UTC, comment #4: 

Regarding comment #3: Please ask such questions at -email is unavailable- or the IRC.  The discussion of a bug report is not the right place to explain Octave development.

Kai Torben Ohlhus <siko1056>
Group Member
Mon 02 Mar 2020 11:57:58 PM UTC, comment #3: 

As I just start contributing in octave so I don't understand now what will be the goal or the target when I try to solve this bug?

Ahmed ElShreif <shikoz>
Sat 22 Feb 2020 09:26:36 PM UTC, comment #2: 

OK perfect. Error is the answer.

Anonymous
Fri 21 Feb 2020 04:02:52 PM UTC, comment #1: 

Yes, this is true.  But, I'm not sure it's all that useful.

A logical matrix can only take the values of 0 and 1.  Hence, there is never any need to check for non-integers.  And using isbool() or islogical() is a much faster test then mod() because it only checks the matrix type, rather than performing any floating point math.

If you really want to use mod with booleans there are workarounds.  You can cast your input to double as you demonstrated.

The same thing holds for char matrices.


mod ('A', 1)
error: mod: wrong type argument 'sq_string'


I re-titled the bug report to mention that both char and logical inputs are not accepted by mod.  However, because there is an easy workaround, and a better choice not to use mod at all, I've lowered the priority.

Rik <rik5>
Group administrator
Fri 21 Feb 2020 04:10:23 AM UTC, original submission:  

I have some code that uses mod(arg,1) to check for non-integers. When arg is a bool it errors out rather than just do it. MATLAB's mod accepts bool without problem.


>> q=true(4)
q =

  1  1  1  1
  1  1  1  1
  1  1  1  1
  1  1  1  1

>> mod(q,1)
error: mod: wrong type argument 'bool matrix'
>> mod(double(q),1)
ans =

   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by vishnuparammal (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by shikoz (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-03-14 vishnuparammal Carbon-CopyRemoved 184871 -
    2020-02-21 rik5 CategoryNone Octave Function
        Severity3 - Normal 1 - Wish
        Priority5 - Normal 1 - Later
        Item GroupNone Feature Request
        StatusNone Confirmed
        Summarymod won't accept bools mod doesn't accept char or logical inputs (Matlab compatibility)

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code