Parent

Included Modules

Class/Module Index [+]

Quicksearch

NArrayMiss

Constants

BYTE

Class Constants

— NArrayMiss::BYTE

type code for 1 byte unsigned integer.

— NArrayMiss::SINT

type code for 2 byte signed integer.

— NArrayMiss::INT

type code for 4 byte signed integer.

— NArrayMiss::SFLOAT

type code for single precision float.

— NArrayMiss::FLOAT

type code for double precision float.

— NArrayMiss::SCOMPLEX

type code for single precision complex.

— NArrayMiss::COMPLEX

type code for double precision complex.

— NArrayMiss::OBJECT

type code for Ruby object.

go back to ((<Index>))

COMPLEX
FLOAT
INT
OBJECT
SCOMPLEX
SFLOAT
SINT
VERSION

Public Class Methods

[](*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 147
def self.[](*arg)
  NArrayMiss.to_nam(NArray[*arg])
end
__new__(*arg) click to toggle source
Alias for: new
_load(o) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1250
def self._load(o)
  ary, mask = Marshal::load(o)
  ary = NArray._load(ary)
  mask = NArray._load(mask)
  NArrayMiss.to_nam_no_dup(ary,mask)
end
byte(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 123
def self.byte(*arg)
  NArrayMiss.new(BYTE,*arg)
end
complex(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 141
def self.complex(*arg)
  NArrayMiss.new(COMPLEX,*arg)
end
float(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 135
def self.float(*arg)
  NArrayMiss.new(FLOAT,*arg)
end
int(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 129
def self.int(*arg)
  NArrayMiss.new(INT,*arg)
end
new(*arg) click to toggle source

Class Methods

NArrayMiss.new(typecode, size, …)

create (({NArrayMiss})) of ((|typecode|)).
All elements are initialized with 0.

NArrayMiss.byte(size, …)

same as NArrayMiss.new(NArrayMiss::BYTE, ((|size|)), ...).

NArrayMiss.sint(size, …)

same as NArrayMiss.new(NArrayMiss::SINT, ((|size|)), ...).

NArrayMiss.int(size, …)

same as NArrayMiss.new(NArrayMiss::INT, ((|size|)), ...).

NArrayMiss.sfloat(size, …)

same as NArrayMiss.new(NArrayMiss::SFLOAT, ((|size|)), ...).

NArrayMiss.float(size, …)

same as NArrayMiss.new(NArrayMiss::FLOAT, ((|size|)), ...).

NArrayMiss.scomplex(size, …)

same as NArrayMiss.new(NArrayMiss::SCOMPLEX, ((|size|)), ...).

NArrayMiss.complex(size, …)

same as NArrayMiss.new(NArrayMiss::COMPLEX, ((|size|)), ...).

NArrayMiss.object(size, …)

same as NArrayMiss.new(NArrayMiss::OBJECT, ((|size|)), ...).

— NArrayMiss[](value, …)

create (({NArrayMiss})) form [((|value|)), ...].

NArrayMiss.to_nam(array [,mask])

create (({NArrayMiss})) from ((|array|)).
((|array|)) must be (({Numeric})) (({Array})) or (({NArray})).

NArrayMiss.to_nam_no_dup(array [,mask])

convert from ((|array|)) to (({NArrayMiss})).

go back to ((<Index>))

# File lib/narray_miss/narray_miss.rb, line 118
def self.new(*arg)
  array = NArray.new(*arg)
  mask = NArray.byte(*arg[1..-1])
  __new__(array, mask)
end
Also aliased as: __new__
new(array, mask) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 77
def initialize(array, mask)
  if array.shape!=mask.shape
    raise "array and mask must have the same shape"
  end
  @array = array
  @mask = mask
end
object(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 144
def self.object(*arg)
  NArrayMiss.new(OBJECT,*arg)
end
scomplex(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 138
def self.scomplex(*arg)
  NArrayMiss.new(SCOMPLEX,*arg)
end
sfloat(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 132
def self.sfloat(*arg)
  NArrayMiss.new(SFLOAT,*arg)
end
sint(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 126
def self.sint(*arg)
  NArrayMiss.new(SINT,*arg)
end
to_nam(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 185
def self.to_nam(*arg)
  if !(Numeric===arg[0]) && !(Array===arg[0]) && !arg[0].is_a?(NArray)
    raise "first argument must be Numeric, NArray or Array"
  end
  arg[0] = arg[0].dup if !(Numeric===arg[0])
  if arg.length==2 && !(Numeric===arg[1]) && arg[1].class!=TrueClass && arg[1].class!=FalseClass then
    arg[1] = arg[1].dup
  end
  NArrayMiss.to_nam_no_dup(*arg)
end
to_nam_no_dup(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 150
def self.to_nam_no_dup(*arg)
  if arg.length > 2 || arg.length==0 then
    raise("NArrayMiss.to_nar( array [,mask]] )")
  end

  array = arg[0]
  if Numeric===array then array = NArray[array] end
  if Array===array then array = NArray.to_na(array) end
  if !array.is_a?(NArray) then
    raise("argument must be Numeric, NArray or Array")
  end

  if arg.length==2 then
    mask = arg[1]
    if Numeric===mask then mask = array.ne(mask) end
    if Array===mask then
      mask = NArray.to_na(mask).ne(0)
    end
    if mask.class == FalseClass then
      mask = NArray.byte(*array.shape)
    end
    if mask.class == TrueClass then
      mask = NArray.byte(*array.shape).fill(1)
    end
    if !(NArray===mask && mask.typecode==BYTE) then
        raise("mask must be Numeric, Array, true, false or NArray(byte)")
    end
    if mask.length!=array.length
      raise "mask.length must be same as array.length"
    end
  else
    mask = NArray.byte(*array.shape).fill(1)
  end
  __new__(array,mask)
end

Public Instance Methods

%(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 396
def %(arg)
  binary_operation(arg, 1){|t1, t2| t1 % t2}
end
&(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 445
def &(arg)
  binary_operation(arg, 1){|t1, t2| t1 & t2}
end
*(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 390
def *(arg)
  binary_operation(arg, 1){|t1, t2| t1 * t2}
end
**(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 399
def **(arg)
  binary_operation(arg, 1){|t1, t2| t1 ** t2}
end
+(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 384
def +(arg)
  binary_operation(arg, 0){|t1, t2| t1 + t2}
end
-(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 387
def -(arg)
  binary_operation(arg, 0){|t1, t2| t1 - t2}
end
-@() click to toggle source

Arithmetic operator

— NArrayMiss#-@ — NArrayMiss#+(other) — NArrayMiss#-(other) — NArrayMiss#*(other) — NArrayMiss#/(other) — NArrayMiss#%(other) — NArrayMiss#**(other) — NArrayMiss#absNArrayMiss#add!(other)NArrayMiss#sbt!(other)NArrayMiss#mul!(other)NArrayMiss#div!(other)NArrayMiss#mod!(other)NArrayMiss#mul_add(other, dim, …)

# File lib/narray_miss/narray_miss.rb, line 379
def -@
  array = @array.dup
  array[@mask] = -@array[@mask]
  NArrayMiss.to_nam_no_dup(array, @mask.dup)
end
/(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 393
def /(arg)
  binary_operation(arg, 1){|t1, t2| t1 / t2}
end
==(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 507
def ==(arg)
  if arg.kind_of?(NArrayMiss) then
    @mask==arg.get_mask! && @array[@mask]==arg.get_array![@mask]
  else
    false
  end
end
[](*arg) click to toggle source

Slicing Array

— NArrayMiss#[](index)

return the value at [((|index|))].
((|index|)) must be (({Integer, Range, Array, true})).
Index order is FORTRAN type.

NArrayMiss#slice(index)

same as (({NArrayMiss#[]})) but keeps the rank of original array by not elimiting dimensions whose length became equal to 1 (which (({NArrayMiss#[]})) dose).
This is not the case with the 1-dimensional indexing and masking.

NArrayMiss#set_without_validation(index,value)

replace elements at ((|index|)) by ((|value|)).

— NArrayMiss#[]=(index, value)

replace elements at ((|index|)) by ((|value|)) and
make replaced elements valid.
# File lib/narray_miss/narray_miss.rb, line 262
def [](*arg)
  if arg[0].class == NArrayMiss && arg[0].typecode == BYTE
    obj = @array[arg[0].to_na(0)]
    if Numeric===obj
      return obj
    else
      return NArrayMiss.to_nam_no_dup(obj)
    end
  else
    obj = @array[*arg]
    if Numeric===obj
      return obj
    else
      return NArrayMiss.to_nam_no_dup(obj,@mask[*arg])
    end
  end
end
[]=(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 306
def []=(*arg)
  if arg.length == 2 && arg[0].class == NArrayMiss && arg[0].typecode == BYTE
    idx = arg[0].to_na(0)
    self.set_without_validation(idx,arg[-1])
    if arg[-1].class != NArrayMiss && arg[-1] then
      @mask[idx] = 1
    end
  else
    self.set_without_validation(*arg)
    if arg[-1].class != NArrayMiss && arg[-1] then
      if arg.length==1 then
        @mask=1
      else
        @mask[*arg[0..-2]] = 1
      end
    end
  end
  return self
end
^(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 451
def ^(arg)
  binary_operation(arg, 1){|t1, t2| t1 ^ t2}
end
__clone__() click to toggle source
Alias for: clone
_dump(limit) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1247
def _dump(limit)
  Marshal::dump([@array._dump(nil),@mask._dump(nil)])
end
abs() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 403
def abs
  array = @array.dup
  array[@mask] = @array[@mask].abs
  NArrayMiss.to_nam_no_dup(array, @mask.dup)
end
accum(*arg) click to toggle source

Statistics

NArrayMiss#sum(dim, … [“min_count”=>i])

return summation of elements in specified dimensions.
Elements at which the number of elements for summation is less than ((|i|)) is invalid.

NArrayMiss#accum(dim, …)

same as (({NArrayMiss#sum})) but not elimiting dimensions whose length became equal to 1.

NArrayMiss#min(dim, …)

return minimum in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.

NArrayMiss#max(dim, …)

return maximum in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.

NArrayMiss#median(dim, …)

return median in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.

NArrayMiss#mean(dim, …)

return mean of elements in specified dimensions.
Elements at which the number of elements for then mean is less than ((|i|)) is invalid.

NArrayMiss#stddev(dim, …)

return standard deviation of elements in specified dimensions.
Elements at which the number of elements for calculation the standard deviation is less than ((|i|)) is invalid.

NArrayMiss#rms(dim, …)

return root mean square of elements in specified dimensions.
Elements at which the number of elements for calculation the RMS is less than ((|i|)) is invalid.

NArrayMiss#rmsdev(dim, …)

return root mean square deviation of elements in specified dimensions.
Elements at which the number of elements for calculation the RMS deviation is less than ((|i|)) is invalid.
# File lib/narray_miss/narray_miss.rb, line 546
def accum(*arg)
  if @mask.count_true == 0 then
    return nil
  else
    array = @array.dup
    array[@mask.not] = 0
    return NArrayMiss.to_nam_no_dup(array.accum(*arg),
                             @mask.to_type(NArray::INT).accum(*arg).ne(0))
  end
end
add!(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 409
def add!(arg)
  binary_operation(arg, 0){|t1, t2| t1.add!(t2)}
end
all?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 904
def all?
  @array[@mask].all?
end
all_invalid() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1044
def all_invalid
  @mask[true]=0
  self
end
all_invalid?() click to toggle source
Alias for: none_valid?
all_valid() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1040
def all_valid
  @mask[true]=1
  self
end
all_valid?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1111
def all_valid?
  @mask.all?
end
and(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 493
def and(arg)
  binary_operation(arg, 1){|t1, t2| t1.and t2}
end
angle() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 943
def angle
  NArrayMiss.to_nam_no_dup(@array.angle,@mask)
end
any?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 907
def any?
  @array[@mask].any?
end
any_valid?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1118
def any_valid?
  @mask.any?
end
ceil() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 783
def ceil
  NArrayMiss.to_nam_no_dup(@array.ceil, @mask.dup)
end
clone() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1165
def clone
  obj = __clone__
  obj.set_array(@array.clone)
  obj.set_mask(@mask.clone)
  return obj
end
Also aliased as: __clone__
coerce(x) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1172
def coerce(x)
  if Numeric===x then
    return [NArrayMiss.new(NArray[x].typecode,*self.shape).fill(x),self]
  elsif x.class==Array || x.class==NArray then
    return [NArrayMiss.to_nam(x), self]
  else
    raise("donnot know how to cange #{x.class} to NArrayMiss")
  end
end
collect(&blk) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 856
def collect(&blk)
  self.dup.collect!(&blk)
end
collect!() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 850
def collect!
  for i in 0..self.total-1
    self[i] = yield(self[i])
  end
  self
end
complex?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1155
def complex?
  @array.complex?
end
conj() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 940
def conj
  NArrayMiss.to_nam_no_dup(@array.conj,@mask)
end
count_false() click to toggle source

Boolean and mask related (only for byte, sint and int)

NArrayMiss#count_false

return the number of elements whose value==0 and valid.

NArrayMiss#count_true

return the number of elements whose value!=0 and valid.

NArrayMiss#mask(mask)

return (({NArrayMiss#get_mask!&((|mask|))})).

NArrayMiss#all?

return true if all the valid elements are not 0, else false.

NArrayMiss#any?

return true if any valid element is not 0, else false.

NArrayMiss#none?

return true if none of the valid elements is not 0, else false.

NArrayMiss#where

return (({NArray})) of indices where valid elements are not 0.

NArrayMiss#where2

return (({Array})) including two (({NArray}))s of indices,
where valid elements are not 0, and 0, respectively.
# File lib/narray_miss/narray_miss.rb, line 882
def count_false
  if @array.typecode==BYTE then
    return @array.count_false-@mask.count_false
  else
    raise("cannot count_true NArrayMiss except BYTE type")
  end
end
count_invalid(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1129
def count_invalid(*arg)
  if arg.length==0 then
    return @mask.count_false
  else
    return NArray.int(*@mask.shape).fill(1).sum(*arg)-
           @mask.to_type(NArray::INT).sum(*arg)
  end
end
count_true() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 889
def count_true
  if @array.typecode==BYTE then
    return (@array&@mask).count_true
  else
    raise("cannot count_true NArrayMiss except BYTE type")
  end
end
count_valid(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1122
def count_valid(*arg)
  if arg.length==0 then
    return @mask.count_true
  else
    return @mask.to_type(NArray::INT).sum(*arg)
  end    
end
dim() click to toggle source

NArrayMiss information

NArrayMiss#dim

return the dimension which is the number of indices.

NArrayMiss#rank

same as (({NArrayMiss#dim})).

NArrayMiss#shape

return the (({Array})) of sizes of each index.

NArrayMiss#size

return the number of total elements.

NArrayMiss#total

alias to size

NArrayMiss#length

alias to size

NArrayMiss#rank_total

return the number of total of the shape.

NArrayMiss#typecode

return the typecode.
# File lib/narray_miss/narray_miss.rb, line 222
def dim
  @array.dim
end
div!(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 418
def div!(arg)
  binary_operation(arg, 1){|t1, t2| t1.div!(t2)}
end
dup() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1160
def dup
  NArrayMiss.to_nam(@array,@mask)
end
each() click to toggle source

Iteration

NArrayMiss#each{|x| …} — NArrayMiss#each_valid{|x| …} — NArrayMiss#each_valid_with_index{|x,i| …} — NArrayMiss#collect{|x| …} — NArrayMiss#collect!{|x| …}

# File lib/narray_miss/narray_miss.rb, line 835
def each
  for i in 0..self.total-1
    yield(@array[i])
  end
end
each_valid() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 840
def each_valid
  for i in 0..self.total-1
    yield(@array[i]) if @mask[i]
  end
end
each_valid_with_index() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 845
def each_valid_with_index
  for i in 0..self.total-1
    yield(@array[i],i) if @mask[i]
  end
end
eq(arg) click to toggle source

Comparison

NArrayMiss#eq(other)NArrayMiss#ne(other)NArrayMiss#gt(other)NArrayMiss#ge(other)NArrayMiss#lt(other)NArrayMiss#le(other) — NArrayMiss#>(other) — NArrayMiss#>=(other) — NArrayMiss#<(other) — NArrayMiss#<=(other) — NArrayMiss#and(other)NArrayMiss#or(other)NArrayMiss#xor(other)NArrayMiss#not(other)

# File lib/narray_miss/narray_miss.rb, line 474
def eq(arg)
  binary_operation(arg, 0){|t1, t2| t1.eq t2}
end
floor() click to toggle source

Type conversion

NArrayMiss#floor

return (({NArrayMiss})) of integer whose elements processed (({floor})).

NArrayMiss#ceil

return (({NArrayMiss})) of integer whose elements processed (({ceil})).

NArrayMiss#round

return (({NArrayMiss})) of integer whose elements processed (({round})).

NArrayMiss#to_i

return (({NArrayMiss})) of integer whose elements processed (({to_i})).

NArrayMiss#to_f

return (({NArrayMiss})) of float whose elements processed (({to_f})).

NArrayMiss#to_type(typecode)

return (({NArrayMiss})) of ((|typecode|)).

NArrayMiss#to_a

convert (({NArrayMiss})) to (({Array})).

NArrayMiss#to_na!()

convert (({NArrayMiss})) to (({NArray})).
if there is argument, set missing_value for invalid elements.

NArrayMiss#to_na()

convert (({NArrayMiss})) to (({NArray})).
if there is argument, set missing_value for invalid elements.

NArrayMiss#to_s

convert (({NArrayMiss})) to (({String})) as a binary data.

NArrayMiss#to_string

create (({NArrayMiss})) of object whose elements are processed (({to_s}))
# File lib/narray_miss/narray_miss.rb, line 780
def floor
  NArrayMiss.to_nam_no_dup(@array.floor, @mask.dup)
end
ge(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 483
def ge(arg)
  binary_operation(arg, 0){|t1, t2| t1.ge t2}
end
get_array() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1089
def get_array
  @array.dup
end
get_array!() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1086
def get_array!
  @array
end
get_mask() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1083
def get_mask
  @mask.dup
end
get_mask!() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1080
def get_mask!
  @mask
end
gt(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 480
def gt(arg)
  binary_operation(arg, 0){|t1, t2| t1.gt t2}
end
hton() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 974
def hton
  NArrayMiss.to_nam(@array.hton,@mask.hton)
end
Also aliased as: ntoh
htov() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 978
def htov
  NArrayMiss.to_nam(@array.htov,@mask.htov)
end
Also aliased as: vtoh
im() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 950
def im
  NArrayMiss.to_nam_no_dup(@array.im,@mask)
end
imag() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 937
def imag
  NArrayMiss.to_nam_no_dup(@array.imag,@mask)
end
imag=(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 946
def imag=(arg)
  @array.image=(arg)
  self
end
inspect() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1183
  def inspect
#    "array -> " + @array.inspect + "\nmask  -> " + @mask.inspect
    count_line = 0
    max_line = 10
    max_col = 80
    sep = ", "
    const = Hash.new
    NArray.constants.each{|c| const[NArray.const_get(c)] = c}
    str_ret = "NArrayMiss."+const[typecode].to_s.downcase+"("+shape.join(",")+"):"
    if rank == 0 then
      str_ret << " []"
      return str_ret
    else
       str_ret << "\n"
    end
    str = ""
    index = Array.new(rank,0)
    index[0] = true
    i = 1
    (rank-1).times{ str_ret << "[ " }
    while(true)
      i.times{ str_ret << "[ " }

      str = @array[*index].inspect
      ary = str[str.index("[")+1..str.index("]")-1].strip.split(/\s*,\s*/)
      miss = @mask[*index].where2[1]
      miss = miss[miss<ary.length].to_a
      if ary[-1]=="..." && miss[-1]==ary.length-1 then miss.pop end
      for j in miss
        ary[j] = "-"
      end
      while ( rank*4+ary.join(", ").length > max_col )
        ary.pop
        ary[-1] = "..."
      end
      str_ret << ary.join(", ")
      i = 1
      while (i<rank)
        if index[i]<shape[i]-1 then
          str_ret << " ]" << sep << "\n"
          count_line += 1
          index[i] += 1
          break
        else
          str_ret << " ]"
          index[i] = 0
          i += 1
        end
      end

      if i>=rank then
        str_ret << " ]"
        return str_ret
      elsif count_line>=max_line then
        str_ret << " ..."
        return str_ret
      end

      (rank-i).times{ str_ret << "  " }
    end
    return str_ret
  end
integer?() click to toggle source

Others

NArrayMiss#integer?

return true if (({NArrayMiss})) is byte, sint or int, else false.

NArrayMiss#complex?

return true if (({NArrayMiss})) is scomplex or complex, else false.

NArrayMiss#dupNArrayMiss#coerce(object)NArrayMiss#inspect

go back to ((<Index>))

# File lib/narray_miss/narray_miss.rb, line 1152
def integer?
  @array.integer?
end
invalidation(*pos) click to toggle source
Alias for: set_invalid
le(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 489
def le(arg)
  binary_operation(arg, 0){|t1, t2| t1.le t2}
end
length() click to toggle source
Alias for: size
lt(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 486
def lt(arg)
  binary_operation(arg, 0){|t1, t2| t1.lt t2}
end
mask(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 896
def mask(arg)
  obj = self.dup
  if arg.class==NArrayMiss then
    arg = arg.get_array!&arg.get_mask!
  end
  obj.set_mask(@mask&arg)
end
max(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 576
def max(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 欠損値に最小値を入れて普通に max する
  # byte,sint,int,sfloat,float の MIN の値を入れるように変更すべき
  ary0 = @array.dup
  ary0[@mask.not] = @array.min
  NArrayMiss.reduction(@mask, rank, min_count, dims, false, typecode) do
    ary0.max(*dims)
  end
end
mean(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 587
def mean(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 整数型の場合は浮動小数型へ変換
  ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
  NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
    ary0.sum(*dims)/count_sum
  end
end
median(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 628
def median(*arg)
  if arg.length==0 then
    return @array[@mask].median
  else
    nshape = NArray.to_na(@array.shape)
    nshape[arg]=1
    nslice = nshape[nshape.ne(1).where]
    index = NArray.object(@mask.rank)
    index[nshape.eq(1).where] = true
    obj = NArrayMiss.new(@array.typecode,*nslice.to_a)
    total = 1
    nslice.each{|n| total *= n}
    for i in 0...total
      index[nshape.ne(1).where] = pos(i,nslice)
      mask = NArray.byte(*@array.shape).fill(0)
      mask[*index] = 1
      mask = @mask&mask
      if mask.count_true != 0 then
        obj[*pos(i,nslice)] = @array[mask].median
      end
    end
    return obj
  end
end
min(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 566
def min(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 欠損値に最大値を入れて普通に min する
  # byte,sint,int,sfloat,float の MAX の値を入れるように変更すべき
  ary0 = @array.dup
  ary0[@mask.not] = @array.max
  NArrayMiss.reduction(@mask, rank, min_count, dims, false, typecode) do
    ary0.min(*dims)
  end
end
mod!(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 421
def mod!(arg)
  binary_operation(arg, 1){|t1, t2| t1.mod!(t2)}
end
mul!(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 415
def mul!(arg)
  binary_operation(arg, 1){|t1, t2| t1.mul!(t2)}
end
mul_add(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 425
def mul_add(*arg)
  if arg.length==1 then
    return (self*arg[0]).sum
  else
    return (self*arg[0]).sum(*arg[1..-1])
  end
end
ne(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 477
def ne(arg)
  binary_operation(arg, 0){|t1, t2| t1.ne t2}
end
newdim(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 745
def newdim(*arg)
  obj = self.dup
  obj.newdim!(*arg)
end
Also aliased as: rewrank
newdim!(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 738
def newdim!(*arg)
  @array = @array.newdim!(*arg)
  @mask = @mask.newdim!(*arg)
  self
end
Also aliased as: rewrank!, rewrank=
none?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 910
def none?
  @array[@mask].none?
end
none_valid?() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1114
def none_valid?
  @mask.none?
end
Also aliased as: all_invalid?
not() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 503
def not
  NArrayMiss.to_nam_no_dup(@array.not, @mask.dup)
end
ntoh() click to toggle source
Alias for: hton
or(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 496
def or(arg)
  binary_operation(arg, 0){|t1, t2| t1.or t2}
end
rank() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 225
def rank
  @array.rank
end
rank_total(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 237
def rank_total(*arg)
  @array.rank_total(*arg)
end
real() click to toggle source

Complex compound number (only for scomplex and complex)

NArrayMiss#realNArrayMiss#imagNArrayMiss#conjNArrayMiss#angleNArrayMiss#imag=(other)NArrayMiss#im

# File lib/narray_miss/narray_miss.rb, line 934
def real
  NArrayMiss.to_nam_no_dup(@array.real,@mask)
end
reshape(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 733
def reshape(*arg)
  obj = self.dup
  obj.reshape!(*arg)
end
reshape!(*arg) click to toggle source

Changing Shapes of indices

NArrayMiss#reshape!(size, …)

change shape of array.

NArrayMiss#reshape(size, …)

same as (({NArrayMiss#reshape!})) but create new object.

NArrayMiss#shape=(size, …)

same as (({NArrayMiss#reshape!})).

NArrayMiss#newdim!(dim)

insert new dimension with size=1

NArrayMiss#newdim(dim)

same as (({NArrayMiss#newdim!})) but create new object.

NArrayMiss#rewrank!(dim)

same as (({NArrayMiss#newdim!})).

NArrayMiss#rewrank=(dim)

same as (({NArrayMiss#newdim!})).
# File lib/narray_miss/narray_miss.rb, line 728
def reshape!(*arg)
  @array = @array.reshape!(*arg)
  @mask = @mask.reshape!(*arg)
  self
end
Also aliased as: shape=
rewrank(*arg) click to toggle source
Alias for: newdim
rewrank!(*arg) click to toggle source
Alias for: newdim!
rewrank=(*arg) click to toggle source
Alias for: newdim!
rms(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 606
def rms(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 整数型の場合は浮動小数型へ変換
  ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
  NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
    ary0 = ary0.abs if ary0.complex?
    ary0 = (ary0**2).sum(*dims) / count_sum
    NMMath.sqrt(ary0)
  end
end
rmsdev(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 616
def rmsdev(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 整数型の場合は浮動小数型へ変換
  ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
  NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
    ary0 = ary0 - ary0.accum(*dims)/count_accum
    ary0 = ary0.abs if ary0.complex?
    ary0 = (ary0**2).sum(*dims) / count_sum
    NMMath.sqrt(ary0)
  end
end
round() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 786
def round
  NArrayMiss.to_nam_no_dup(@array.round, @mask.dup)
end
sbt!(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 412
def sbt!(arg)
  binary_operation(arg, 0){|t1, t2| t1.sbt!(t2)}
end
set_invalid(*pos) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1035
def set_invalid(*pos)
  @mask[*pos] = 0
  self
end
Also aliased as: invalidation
set_mask(mask) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1048
def set_mask(mask)
  if mask.class == Array then
    tmp = NArray.byte(*@mask.shape)
    tmp[true] = mask
    mask = tmp
  end
  if mask.class == NArrayMiss then
    mask = mask.to_na(0)
  end
  if mask.class == NArray then
    if mask.typecode != BYTE then
      raise("mask must be NArrayMiss.byte, NArray.byte or Array")
    end
    if @array.shape != mask.shape then
      raise("mask.shape must be same as array")
    end
    @mask = mask.dup
    return self
  else
    raise("mask must be NArray.byte or Array")
  end
end
set_missing_value(val) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1075
def set_missing_value(val)
  obj = self.dup
  obj.set_missing_value!(val)
end
set_missing_value!(val) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1071
def set_missing_value!(val)
  @array[@mask.not] = val
  self
end
set_valid(*pos) click to toggle source

Mask and missing value

NArrayMiss#set_valid(index)

validate element at ((|index|)).
((|index|)) must be (({Integer, Range, Array, or ture})).

NArrayMiss#validation(index)

alias to set_valid

NArrayMiss#set_invalid(index)

invaliadate element at ((|index|)).
((|index|)) must be (({Integer, Range, Array, or ture})).

NArrayMiss#invalidation(index)

alias to set_invalid

NArrayMiss#all_valid

set all elements valid

NArrayMiss#all_invalid

set all elements invalid

NArrayMiss#set_mask(mask)

masking by ((|mask|))

NArrayMiss#set_missing_value(value)

replace invalid elements by ((|value|)).

NArrayMiss#get_mask!

return (({NArray})) of byte as mask.

NArrayMiss#get_mask

return (({NArray})) of byte as mask.

NArrayMiss#get_array!

return (({NArray})) as data.

NArrayMiss#get_array

return (({NArray})) as data.

NArrayMiss#valid?(index)

return (({Array})) whose elements are true or false, 
or (({True}))/(({False})) corresponding to validity of the specified element(s) by the ((|index|))

NArrayMiss#all_valid?

return true if all elements are valid, else false.

NArrayMiss#none_valid?

return true if all elements are invalid, else false.

NArrayMiss#all_invalid?

alias to none_valid?

NArrayMiss#any_valid?

return true if any elements are valid, else false.

NArrayMiss#count_valid

return the number of valid elements.

NArrayMiss#count_invalid

return the number of invalid elements.
# File lib/narray_miss/narray_miss.rb, line 1030
def set_valid(*pos)
  @mask[*pos] = 1
  self
end
Also aliased as: validation
set_without_validation(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 283
def set_without_validation(*arg)
  if arg.length==1 then
    if !arg[0] then
      @mask[] = 0
    elsif arg[0].class == NArrayMiss then
      @array[] = arg[0].get_array!
      @mask[] = arg[0].get_mask!
    else
      @array[] = arg[0]
    end
  else
    if !arg[-1] then
      @mask[*arg[0..-2]] = 0
    elsif arg[-1].class == NArrayMiss then
      @array[*arg[0..-2]] = arg[-1].get_array!
      @mask[*arg[0..-2]] = arg[-1].get_mask!
    else
      @array[*arg[0..-2]] = arg[-1]
    end
  end
  return self
end
shape() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 228
def shape
  @array.shape
end
shape=(*arg) click to toggle source
Alias for: reshape!
size() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 231
def size
  @array.size
end
Also aliased as: total, length
slice(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 279
def slice(*arg)
  NArrayMiss.to_nam_no_dup(@array.slice(*arg),@mask.slice(*arg))
end
stddev(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 595
def stddev(*dims)
  min_count = NArrayMiss.check_options(dims, 2)
  # 整数型の場合は浮動小数型へ変換
  ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
  NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
    ary0 = ary0 - ary0.accum(*dims)/count_accum
    ary0 = ary0.abs if ary0.complex?
    ary0 = (ary0**2).sum(*dims) / (count_sum-1)
    NMMath.sqrt(ary0)
  end
end
sum(*dims) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 557
def sum(*dims)
  min_count = NArrayMiss.check_options(dims, 1)
  # 欠損値に 0 を入れて普通に sum する
  ary0 = @array.dup
  ary0[@mask.not] = 0
  NArrayMiss.reduction(@mask, rank, min_count, dims, false, typecode) do
    ary0.sum(*dims)
  end
end
swap_byte() click to toggle source

Byte swap

NArrayMiss#swap_byte

swap byte order.

NArrayMiss#hton

convert to network byte order.

NArrayMiss#ntoh

convert from network byte order.

NArrayMiss#htov

convert to VAX byte order.

NArrayMiss#vtoh

convert from VAX byte order.
# File lib/narray_miss/narray_miss.rb, line 969
def swap_byte
  obj = self.dup
  obj.set_without_validation(@array.swap_byte)
  obj
end
to_a() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 799
def to_a
  @array.to_a
end
to_f() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 792
def to_f
  NArrayMiss.to_nam_no_dup(@array.to_f, @mask.dup)
end
to_i() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 789
def to_i
  NArrayMiss.to_nam_no_dup(@array.to_i, @mask.dup)
end
to_na(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 812
def to_na(*arg)
  return self.dup.to_na!(*arg)
end
to_na!(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 802
def to_na!(*arg)
  if arg.length==0
    return @array
  elsif arg.length==1 then
    self.set_missing_value!(arg[0])
    return @array
  else
    raise(ArgumentError, "Usage: NArray#to_na([missing_value])")
  end
end
to_s() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 815
def to_s
  @array.to_s
end
to_string() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 818
def to_string
  obj = NArrayMiss.obj(*@array.shape)
  obj.set_without_validation( @array.to_string )
  obh.set_mask(@mask)
  obj
end
to_type(typecode) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 796
def to_type(typecode)
  NArrayMiss.to_nam_no_dup(@array.to_type(typecode), @mask.dup)
end
total() click to toggle source
Alias for: size
transpose(*arg) click to toggle source

Transpose

NArrayMiss#transpose(dim0, dim1, …)

transpose array. The 0-th dimension goes to the ((|dim0|))-th dimension of new array.
# File lib/narray_miss/narray_miss.rb, line 700
def transpose(*arg)
  obj = self.dup
  shape = arg.collect{|i| obj.shape[i]}
  obj.reshape!(*shape)
  obj.set_without_validation( @array.transpose(*arg) )
  obj.set_mask(@mask.transpose(*arg))
  obj
end
typecode() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 241
def typecode
  @array.typecode
end
valid?(*arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 1093
def valid?(*arg)
  if arg.any?
    # For the subset specified by the argument(s) (in the same way as for []).
    # Returns true or false if a single value is specified.
    # Otherwise, returns an Array of true of false
    mask = @mask[*arg]
    if mask.is_a?(Numeric)
      return mask == 1  # true if mask (==1); false if not
    end
  else
    # no argument
    mask = @mask
  end
  ary = mask.to_a
  ary.flatten!
  ary.map!{|i| i==1}  # true if element == 1; false if not
  return ary
end
validation(*pos) click to toggle source
Alias for: set_valid
vtoh() click to toggle source
Alias for: htov
where() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 914
def where
  (@array&@mask).where
end
where2() click to toggle source
# File lib/narray_miss/narray_miss.rb, line 917
def where2
  self.where-@mask.where
end
xor(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 499
def xor(arg)
  binary_operation(arg, 1){|t1, t2| t1.xor t2}
end
|(arg) click to toggle source
# File lib/narray_miss/narray_miss.rb, line 448
def |(arg)
  binary_operation(arg, 0){|t1, t2| t1 | t2}
end
~() click to toggle source

Bitwise operator (only for byte, sint and int)

— NArrayMiss#~@ — NArrayMiss#&(other) — NArrayMiss#|(other) — NArrayMiss#^(other)

# File lib/narray_miss/narray_miss.rb, line 442
def ~
  NArrayMiss.to_nam_to_dup(~@array, @mask.dup)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.