NumRu::VArray

VArray is Virtual Array class, in which a multi-dimensional array data is stored on memory (NArray, NArrayMiss) or in file (NetCDFVar etc). The in-file data handling is left to subclasses such as VArrayNetCDF, and this base class handles the following two cases:

  1. Data are stored on memory using NArray
  2. Subset of another VArray (possibly a subclass such as VArrayNetCDF).

Perhaps the latter case needs more explanation. Here, a VArray is defined as a subset of another VArray, so the current VArray has only the link and how the subset is mapped to the other VArray.

A VArray behaves just like a NArray, i.e., a numeric multi-dimensional array. The important difference is that a VArray has a name and can have "attributes" like a NetCDF variable. Therefore, VArray can perfectly represent a NetCDFVar, which is realized by a sub-class VArrayNetCDF.

NOMENCLATURE

Class Methods

VArray.new(narray=nil, attr=nil, name=nil)

A constructor

ARGUMENTS

attribute oject is created and stored.

RETURN VALUE

EXAMPLE

na = NArray.int(6,3).indgen!
va1 = VArray.new( na, nil, "test" )

VArray.new2(ntype, shape, attr=nil, name=nil)

Another constructor. Uses parameters to initialize a NArray to hold.

ARGUMENTS

RETURN VALUE

Instance Methods

val

Returns the values as a NArray.

This is the case even when the VArray is a mapping to another. Also, this method is to be redefined in subclasses to do the same thing.

ARGUMENTS -- none

RETURN VALUE

val=(narray)

Set values.

The whole values are set. If you want to set partly, use []=.

ARGUMENTS

[]

Get a subset. Its usage is the same as NArray#[]

[] =

Set a subset. Its usage is the same as NArray#[]=

attr

To be undefined.

ntype

Returns the numeric type.

ARGUMENTS -- none

RETURN VALUE

rank

Returns the rank (number of dimensions)

shape

Returns the shape

shape_current

aliased to shape.

length

Returns the length of the VArray

typecode

Returns the NArray typecode

name

Returns the name

RETURN VALUE

name=(nm)

Changes the name.

ARGUMENTS

RETURN VALUE

rename!(nm)

Changes the name (Same as name=, but returns self)

ARGUMENTS

RETURN VALUE

rename(nm)

Same as rename! but duplicate the VArray object and set its name.

This method may not be supported in sub-classes, since it is sometimes problematic not to change the original.

copy(to=nil)

Copy a VArray. If to is nil, works as the deep cloning (duplication of the entire object).

Both the values and the atribbutes are copied.

ARGUMENTS

reshape!( *shape )

Changes the shape without changing the total size. May not be available in subclasses.

ARGUMENTS

RETURN VALUE

EXAMPLE

vary = VArray.new2( "float", [10,2])
vary.reshape!(5,4)   # changes the vary directry
vary.copy.reshape!(2,2,5)  # make a deep clone and change it
      # This always works with a VArray subclass, since vary.copy
      # makes a deep clone to VArray with NArray.

coerce(other)

For Numeric operators. (If you don't know it, see a manual or book of Ruby)

Methods compatible with NArray

VArray is a numric multi-dimensional array, so it supports most of the methods and operators in NArray. Here, the name of those methods are just quoted. See the documentation of NArray for their usage.

Math functions

sqrt, exp, log, log10, log2, sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, csc, sec, cot, csch, sech, coth, acsc, asec, acot, acsch, asech, acoth

Binary operators

-, +, *, /, %, **, .add!, .sub!, .mul!, .div!, mod!, >, >=, <, <=, &, |, ^, .eq, .ne, .gt, .ge, .lt, .le, .and, .or, .xor, .not

Unary operators

~ - +

Other methods

These methods returns a NArray (not a VArray).

all?, any?, none?, where, where2, floor, ceil, round, to_f, to_i, to_a