Amruta Purandare > Sparse > Sparse::Vector



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


Sparse::Vector - Implements Sparse Vector Operations


  use Sparse::Vector;

  # creating an empty sparse vector object

  # sets the value at index 12 to 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
        print "vector is null.\n";
        print "vector is not null.\n";

  # print sparse vector to stdout

  # returns the string form of sparse vector
  # same as print except the string is returned
  # rather than displaying on stdout

  # adds sparse vectors v1, v2 and stores 
  # result into v1

  # adds binary equivalent of v2 to v1
  # binary equivalnet treats all non-zero values 
  # as 1s

  # increments the value at index 12

  # divides each vector entry by a given divisor 4

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

  # normalizes a sparse vector

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

  # deallocates all entries


Sparse::Vector is a Perl module that implements basic vector operations on sparse vectors.


Amruta D Purandare, <>

Ted Pederse, <>


Copyright (c) 2004,

Amruta Purandare, University of Minnesota, Duluth.

Ted Pedersen, University of Minnesota, Duluth.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to

The Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

syntax highlighting: