Math::SparseVector - Implements Sparse Vector Operations. The code is


Math-SparseVector documentation  | view source Contained in the Math-SparseVector distribution.

Index


NAME

Top

Math::SparseVector - Implements Sparse Vector Operations. The code is entirely borrowed from the existing Sparse::Vector v0.03 module on CPAN, and re-cast into a new namespace in order to introduce another module Math::SparseMatrix, which makes use of this module.

USAGE

Top

  use Math::SparseVector;

  # creating an empty sparse vector object
  $spvec=Math::SparseVector->new;

  # sets the value at index 12 to 5
  $spvec->set(12,5);

  # returns value at index 12
  $value = $spvec->get(12);

  # returns the indices of non-zero values in sorted order
  @indices = $spvec->keys;

  # returns 1 if the vector is empty and has no keys
  if($spvec->isnull)
  {
    print "vector is null.\n";
  }
  else
  {
    print "vector is not null.\n";
  }

  # print sparse vector to stdout
  $spvec->print;

  # returns the string form of sparse vector
  # same as print except the string is returned
  # rather than displaying on stdout
  $spvec->stringify;

  # adds sparse vectors v1, v2 and stores 
  # result into v1
  $v1->add($v2);

  # adds binary equivalent of v2 to v1
  $v1->binadd($v2);
  # binary equivalnet treats all non-zero values 
  # as 1s

  # increments the value at index 12
  $spvec->incr(12);

  # divides each vector entry by a given divisor 4
  $spvec->div(4);

  # returns norm of the vector
  $spvec_norm = $spvec->norm;

  # normalizes a sparse vector
  $spvec->normalize;

  # returns dot product of the 2 vectors
  $dotprod = $v1->dot($v2);

  # deallocates all entries
  $spvec->free;

ABSTRACT

Top

Math::SparseVector is a Perl module that implements basic vector operations on sparse vectors. The code is entirely borrowed from the existing Sparse::Vector v0.03 module on CPAN, and re-cast into a new namespace in order to introduce another module Math::SparseMatrix, which makes use of this module.

AUTHOR

Top

Amruta Purandare, <amruta@cs.pitt.edu>

Ted Pedersen, <tpederse@d.umn.edu>

Mahesh Joshi, <joshi031@d.umn.edu>

COPYRIGHT AND LICENSE

Top


Math-SparseVector documentation  | view source Contained in the Math-SparseVector distribution.