[Changeset] isa function with float and numeric arguments

View: New views
6 Messages — Rating Filter:   Alert me  

[Changeset] isa function with float and numeric arguments

by David Bateman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The isa function should allow the "float" and "numeric" arguments. The
attached patch adds this.

D.

# HG changeset patch
# User David Bateman <dbateman@...>
# Date 1210622234 -7200
# Node ID 66f4246ff15c7258328c916663857d0fbbdd5e96
# Parent  b3ba72dfbb1bcce79fe839d70cb0c73e97c57fda
Treat numeric and float argument in the isa function.

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@ 2008-05-09  David Bateman  <dbateman@fre
+2008-05-12  David Bateman  <dbateman@...>
+
+ * general/isa.m: Also treat "float: and "numeric" as the class
+ argument.
+
 2008-05-09  David Bateman  <dbateman@...>
 
  * testfun/assert.m: Allow assert(cond, errmsg, ...) and
diff --git a/scripts/general/isa.m b/scripts/general/isa.m
--- a/scripts/general/isa.m
+++ b/scripts/general/isa.m
@@ -30,6 +30,15 @@ function retval = isa (x, cname)
     print_usage ();
   endif
 
-  retval = strcmp (class (x), cname);
-
+  if (strcmp (cname, "float"))
+    retval = strcmp (class (x), "double") || strcmp (class (x), "single");
+  elseif (strcmp (cname, "fnumeric"))
+    retval = strcmp (class (x), "double") || strcmp (class (x), "single") ||
+    strcmp (class (x), "uint8") || strcmp (class (x), "uint16") ||
+    strcmp (class (x), "uint32") || strcmp (class (x), "uint64") ||
+    strcmp (class (x), "int8") || strcmp (class (x), "int16") ||
+    strcmp (class (x), "int32") || strcmp (class (x), "int64");
+  else
+    retval = strcmp (class (x), cname);
+  endif
 endfunction

Re: [Changeset] isa function with float and numeric arguments

by David Bateman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Bateman wrote:
> The isa function should allow the "float" and "numeric" arguments. The
> attached patch adds this.
>
> D.
>

Please use this version instead.

D.

# HG changeset patch
# User David Bateman <dbateman@...>
# Date 1210624773 -7200
# Node ID 8b7f2a4ca30f061937492672e7f98c90ada831fc
# Parent  b3ba72dfbb1bcce79fe839d70cb0c73e97c57fda
Treat numeric and float argument in the isa function.

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@ 2008-05-09  David Bateman  <dbateman@fre
+2008-05-12  David Bateman  <dbateman@...>
+
+ * general/isa.m: Also treat "float: and "numeric" as the class
+ argument.
+
 2008-05-09  David Bateman  <dbateman@...>
 
  * testfun/assert.m: Allow assert(cond, errmsg, ...) and
diff --git a/scripts/general/isa.m b/scripts/general/isa.m
--- a/scripts/general/isa.m
+++ b/scripts/general/isa.m
@@ -30,6 +30,15 @@ function retval = isa (x, cname)
     print_usage ();
   endif
 
-  retval = strcmp (class (x), cname);
-
+  if (strcmp (cname, "float"))
+    retval = (strcmp (class (x), "double") || strcmp (class (x), "single"));
+  elseif (strcmp (cname, "fnumeric"))
+    retval = (strcmp (class (x), "double") || strcmp (class (x), "single") ||
+    strcmp (class (x), "uint8") || strcmp (class (x), "uint16") ||
+    strcmp (class (x), "uint32") || strcmp (class (x), "uint64") ||
+    strcmp (class (x), "int8") || strcmp (class (x), "int16") ||
+    strcmp (class (x), "int32") || strcmp (class (x), "int64"));
+  else
+    retval = strcmp (class (x), cname);
+  endif
 endfunction

Re: [Changeset] isa function with float and numeric arguments

by Bill Denney-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Bateman wrote:

> David Bateman wrote:
>  
>> The isa function should allow the "float" and "numeric" arguments. The
>> attached patch adds this.
>>
>> D.
> Please use this version instead.
>
> D.
>  
Wouldn't this be easier to read (and marginally faster) if written as:

if (strcmp (cname, "float"))
  retval = any (strcmp (class (x), {"double" "single"}));
elseif (strcmp (cname, "fnumeric"))
  classes = {"double" "single" "uint8" "uint16" "uint32" "uint64" "int8" "int16" "int32" "int64"};
  retval = any (strcmp (class (x), classes));
else
  retval = strcmp (class (x), cname);
endif


Have a good day,

Bill

Re: [Changeset] isa function with float and numeric arguments

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 12-May-2008, Bill Denney wrote:

| David Bateman wrote:
| > David Bateman wrote:
| >  
| >> The isa function should allow the "float" and "numeric" arguments. The
| >> attached patch adds this.
| >>
| >> D.
| > Please use this version instead.
| >
| > D.
| >  
| Wouldn't this be easier to read (and marginally faster) if written as:
|
| if (strcmp (cname, "float"))
|   retval = any (strcmp (class (x), {"double" "single"}));
| elseif (strcmp (cname, "fnumeric"))
|   classes = {"double" "single" "uint8" "uint16" "uint32" "uint64" "int8" "int16" "int32" "int64"};
|   retval = any (strcmp (class (x), classes));
| else
|   retval = strcmp (class (x), cname);
| endif

I made this change, and used persistent variables for the cell arrays
to avoid the need for reinitializing them on each call.

Thanks,

jwe

Re: [Changeset] isa function with float and numeric arguments

by David Bateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John W. Eaton wrote:

> On 12-May-2008, Bill Denney wrote:
>
> | David Bateman wrote:
> | > David Bateman wrote:
> | >  
> | >> The isa function should allow the "float" and "numeric" arguments. The
> | >> attached patch adds this.
> | >>
> | >> D.
> | > Please use this version instead.
> | >
> | > D.
> | >  
> | Wouldn't this be easier to read (and marginally faster) if written as:
> |
> | if (strcmp (cname, "float"))
> |   retval = any (strcmp (class (x), {"double" "single"}));
> | elseif (strcmp (cname, "fnumeric"))
> |   classes = {"double" "single" "uint8" "uint16" "uint32" "uint64" "int8" "int16" "int32" "int64"};
> |   retval = any (strcmp (class (x), classes));
> | else
> |   retval = strcmp (class (x), cname);
> | endif
>
> I made this change, and used persistent variables for the cell arrays
> to avoid the need for reinitializing them on each call.
>  
The version in the repository seems to be mine.. You don't seem to have
committed the changes that make the classes variable persisent..

D.

--
David Bateman                                David.Bateman@...
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Re: [Changeset] isa function with float and numeric arguments

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 13-May-2008, David Bateman wrote:

| The version in the repository seems to be mine.. You don't seem to have
| committed the changes that make the classes variable persisent..

It should be in the public archive now.

jwe