From bb04adc703503630542379022aa5dd7d60ffd41d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 26 Oct 2011 20:14:54 -0400 Subject: [PATCH] allow min and max on anything. fixes issue #238. --- j/abstractarray.j | 5 ++++- j/complex.j | 2 +- j/number.j | 3 --- j/operators.j | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/j/abstractarray.j b/j/abstractarray.j index aed3ea1ccaa75..a8b905eacfcbc 100644 --- a/j/abstractarray.j +++ b/j/abstractarray.j @@ -32,7 +32,10 @@ strides{T}(a::AbstractArray{T,2}) = (1, size(a,1)) strides{T}(a::AbstractArray{T,3}) = (1, size(a,1), size(a,1)*size(a,2)) strides (a::AbstractArray) = ntuple(ndims(a), i->stride(a,i)) -iscomplex{T<:Complex}(x::AbstractArray{T}) = true +isreal{T<:Real}(::AbstractArray{T}) = true +isreal(::AbstractArray) = false +iscomplex{T<:Complex}(::AbstractArray{T}) = true +iscomplex(::AbstractArray) = false ## Constructors ## diff --git a/j/complex.j b/j/complex.j index daa3865746f8c..3a143615c9690 100644 --- a/j/complex.j +++ b/j/complex.j @@ -3,7 +3,7 @@ abstract Complex{T<:Real} <: Number iscomplex(x::Complex) = true -iscomplex(x) = false +iscomplex(x::Number) = false real_valued(z::Complex) = (imag(z) == 0) integer_valued(z::Complex) = (real_valued(z) && integer_valued(real(z))) diff --git a/j/number.j b/j/number.j index a2e4700bca66c..7bd6b688fdea8 100644 --- a/j/number.j +++ b/j/number.j @@ -25,9 +25,6 @@ transpose(x::Number) = x ctranspose(x::Number) = conj(transpose(x)) inv(x::Number) = one(x)/x -max(x::Real, y::Real) = x > y ? x : y -min(x::Real, y::Real) = x < y ? x : y - # TODO: should we really treat numbers as iterable? start(a::Real) = a next(a::Real, i) = (a, a+1) diff --git a/j/operators.j b/j/operators.j index 294bae79fef24..eb0fed0fe4097 100644 --- a/j/operators.j +++ b/j/operators.j @@ -19,6 +19,9 @@ isequal(x::Number, y::Number) = (x==y) <=(x,y) = x < y || x == y >=(x,y) = y <= x +max(x, y) = x > y ? x : y +min(x, y) = x < y ? x : y + ## definitions providing basic traits of arithmetic operators ## +() = 0 @@ -26,8 +29,6 @@ isequal(x::Number, y::Number) = (x==y) &() = error("zero-argument & is ambiguous") |() = error("zero-argument | is ambiguous") ($)() = error("zero-argument \$ is ambiguous") -max() = -Inf -min() = +Inf +(x::Number) = x *(x::Number) = x