Optimizations for is_vector(), is_matrix(). Added is_finite().

This commit is contained in:
Garth Minette
2020-07-06 18:28:35 -07:00
parent efa76fe9f5
commit feba482396
5 changed files with 16 additions and 16 deletions

View File

@@ -13,13 +13,12 @@
// Function: is_vector()
// Usage:
// is_vector(v, [length], [fast]);
// is_vector(v, [length]);
// Description:
// Returns true if v is a list of finite numbers.
// Arguments:
// v = The value to test to see if it is a vector.
// length = If given, make sure the vector is `length` items long.
// fast = If true, do a shallow test that is faster.
// Example:
// is_vector(4); // Returns false
// is_vector([4,true,false]); // Returns false
@@ -29,10 +28,8 @@
// is_vector([3,4,5],3); // Returns true
// is_vector([3,4,5],4); // Returns true
// is_vector([]); // Returns false
// is_vector([3,undef,undef,true], fast=true); // Returns true
function is_vector(v,length,fast=false) =
(fast? (is_list(v) && is_num(v[0])) : is_list_of(v,0)) &&
len(v) && (is_undef(length) || length==len(v));
function is_vector(v,length) =
is_list(v) && is_num(0*(v*v)) && (is_undef(length)||len(v)==length);
// Function: add_scalar()