r68682 - in /branches/upstream/libmath-sparsematrix-perl: ./ current/ current/lib/ current/lib/Math/ current/t/
takaki at users.alioth.debian.org
takaki at users.alioth.debian.org
Tue Feb 15 04:53:10 UTC 2011
Author: takaki
Date: Tue Feb 15 04:53:03 2011
New Revision: 68682
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=68682
Log:
[svn-inject] Installing original source of libmath-sparsematrix-perl (0.03)
Added:
branches/upstream/libmath-sparsematrix-perl/
branches/upstream/libmath-sparsematrix-perl/current/
branches/upstream/libmath-sparsematrix-perl/current/CHANGES
branches/upstream/libmath-sparsematrix-perl/current/INSTALL.pod
branches/upstream/libmath-sparsematrix-perl/current/MANIFEST
branches/upstream/libmath-sparsematrix-perl/current/META.yml
branches/upstream/libmath-sparsematrix-perl/current/Makefile.PL
branches/upstream/libmath-sparsematrix-perl/current/README
branches/upstream/libmath-sparsematrix-perl/current/lib/
branches/upstream/libmath-sparsematrix-perl/current/lib/Math/
branches/upstream/libmath-sparsematrix-perl/current/lib/Math/SparseMatrix.pm
branches/upstream/libmath-sparsematrix-perl/current/t/
branches/upstream/libmath-sparsematrix-perl/current/t/Math-SparseMatrix.t
Added: branches/upstream/libmath-sparsematrix-perl/current/CHANGES
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/CHANGES?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/CHANGES (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/CHANGES Tue Feb 15 04:53:03 2011
@@ -1,0 +1,14 @@
+Revision history for Perl extension Math::SparseMatrix.
+
+0.03 Sun Apr 06, 2008
+ - remove garbage Math-SparseMatrix-0.02 directory
+
+0.02 Mon Mar 24, 2008
+ - relax Perl requirements to 5.6.2
+ - update Makefile.PL to better support META.yml
+ - modified SparseMatrix.pm so README can be generated from it
+
+0.01 Sun Jun 18 18:54:21 2006
+ - original version; created by h2xs 1.23 with options
+ -AXc -n Math::SparseMatrix
+
Added: branches/upstream/libmath-sparsematrix-perl/current/INSTALL.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/INSTALL.pod?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/INSTALL.pod (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/INSTALL.pod Tue Feb 15 04:53:03 2011
@@ -1,0 +1,69 @@
+=head1 NAME
+
+INSTALL Installation instructions for Math::SparseMatrix
+
+=head1 DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+ Math::SparseVector
+
+=head1 SYNOPSIS
+
+To install this module type the following:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+The exact location of where Math::SparseMatrix will be installed depends
+on your system configuration.
+
+If you do not have authority to write into system directories, you can
+install Math::SparseMatrix in a local directory that you own and have
+permissions to read and write into as follows:
+
+ perl Makefile.PL PREFIX=/YOUR/DIR
+ make
+ make test
+ make install
+
+This will install the module into
+
+ /YOUR/DIR/lib/perl5/site_perl/Math/SparseMatrix.pm
+
+If you install Math::SparseMatrix in a local directory, you will have to
+explicitly set your PERL5LIB environment variable to include:
+
+ /YOUR/DIR/lib/perl5/site_perl
+
+if this directory was not already included.
+
+=head1 Authors
+
+Ted Pedersen, University of Minnesota, Duluth.
+tpederse at d.umn.edu
+
+Mahesh Joshi, Carnegie Mellon University
+maheshj at cmu.edu
+
+=head1 COPYRIGHT
+
+Copyright (c) 2006-2008, Ted Pedersen and Mahesh Joshi
+
+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.
Added: branches/upstream/libmath-sparsematrix-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/MANIFEST?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/MANIFEST (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/MANIFEST Tue Feb 15 04:53:03 2011
@@ -1,0 +1,8 @@
+CHANGES
+INSTALL.pod
+lib/Math/SparseMatrix.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+README
+t/Math-SparseMatrix.t
Added: branches/upstream/libmath-sparsematrix-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/META.yml?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/META.yml (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/META.yml Tue Feb 15 04:53:03 2011
@@ -1,0 +1,14 @@
+--- #YAML:1.0
+name: Math-SparseMatrix
+version: 0.03
+abstract: Provides basic sparse matrix operations such as creation, reading from file, reading transpose from file and writing to file.
+license: gpl
+author:
+ - Ted Pedersen <tpederse at d.umn.edu>; Mahesh Joshi <maheshj at cmu.edu>
+generated_by: ExtUtils::MakeMaker version 6.44
+distribution_type: module
+requires:
+ Math::SparseVector: 0.01
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
Added: branches/upstream/libmath-sparsematrix-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/Makefile.PL?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/Makefile.PL (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/Makefile.PL Tue Feb 15 04:53:03 2011
@@ -1,0 +1,20 @@
+use 5.006;
+use ExtUtils::MakeMaker;
+
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+
+WriteMakefile(
+ NAME => 'Math::SparseMatrix',
+ VERSION_FROM => 'lib/Math/SparseMatrix.pm', # finds $VERSION
+ PREREQ_PM => {Math::SparseVector => 0.01}, # e.g., Module::Name => 1.1
+ ($] >= 5.005 ? ## Add these new keywords supported since 5.005
+ (ABSTRACT_FROM => 'lib/Math/SparseMatrix.pm', # retrieve abstract from module
+ AUTHOR => 'Ted Pedersen <tpederse at d.umn.edu>; Mahesh Joshi <maheshj at cmu.edu>') : ()),
+ # allows make dist to create .tar.gz with correct name/version
+ 'dist' => {'COMPRESS' => 'gzip -9f', 'SUFFIX' => 'gz'},
+ # allows for automatic creation of META.yml
+ ($ExtUtils::MakeMaker::VERSION ge '6.30_00'?
+ ('LICENSE' => 'gpl', ) : ()),
+
+);
Added: branches/upstream/libmath-sparsematrix-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/README?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/README (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/README Tue Feb 15 04:53:03 2011
@@ -1,0 +1,127 @@
+NAME
+ Math::SparseMatrix - Provides basic sparse matrix operations such as
+ creation, reading from file, reading transpose from file and writing to
+ file.
+
+DESCRIPTION
+ Math::SparseMatrix provides simple sparse matrix functionality such as
+ creation of sparse matrices, writing them out to a file, reading
+ matrices from files and reading transpose of a matrix stored in a file.
+
+SYNOPSIS
+ 1. To begin with, Math::SparseMatrix should be included in your Perl
+ program as follows:
+ # include this module for use in your program
+ use Math::SparseMatrix;
+
+ 2. To create an empty sparse matrix object with the required dimensions,
+ use the following constructor:
+ # create a new sparse matrix with 10 rows and 15 columns
+ my $spmatrix = Math::SparseMatrix->new(10, 15);
+
+ 3. To update the values in the sparse matrix, use the "set" function as
+ follows:
+ # set the value at row 5, column 3 to 10
+ $spmatrix->set(5, 3, 10);
+
+ 4. To retrieve a stored value, use the "get" function as follows:
+ # get the value at row 6, column 5 if present, or zero
+ $val = $spmatrix->get(6, 5);
+
+ 5. A sparse matrix can be written out to a file in the supported format
+ (explained below) as follows:
+ # write out the sparse matrix to the file "matrix.txt"
+ $spmatrix->writeToFile("matrix.txt");
+
+ 6. A new sparse matrix object can be created from a file in the
+ supported format as follows:
+ # create a matrix object by reading the file "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createFromFile("matrix.txt");
+
+ 7. A new sparse matrix that is the transpose of the matrix stored in the
+ given input file can be created as follows:
+ # create the transpose of the matrix stored in "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createTransposeFromFile("matrix.txt");
+
+ 8. Finally, to generate the transpose of a matrix stored in a file, read
+ the transpose as in #7 above and write out the read transpose to a new
+ file as in #5 above.
+ # create the transpose of the matrix stored in "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createTransposeFromFile("matrix.txt");
+
+ # write out the created transpose to another file "transpose.txt"
+ $spmatrix->writeToFile("transpose.txt");
+
+SPARSE DATA FORMAT
+ The sparse matrix file format that Math::SparseMatrix expects is
+ described below with an example.
+
+ The first line (or the header line) of the file should contain 3 number
+ separated by a single space. The first number is the number of rows in
+ the sparse matrix, the second number is the number of columns and the
+ third number is the number of non-zero elements present in the stored
+ matrix.
+
+ Each subsequent line represents one row of the sparse matrix, therefore
+ there should be as many number of lines after the header line as the
+ number of rows mentioned in the header line. In every line representing
+ a row, there should be as many pairs of numbers as the number of
+ non-zero elements in that row. The first number in the pair represents
+ the column number of the non-zero element (column numbers start with 1).
+ The row number is implicitly provided by the line number in the file.
+ The second number in the pair is the actual non-zero matrix element.
+ Numbers in a pair and multiple pairs should all be separated by single
+ spaces. If a row does not contain any non-zero element, then an empty
+ line should be present in the file.
+
+ NOTE: There should be no empty lines except those representing empty
+ rows, neither should there be any comment lines. Commenting is not
+ supported.
+
+ Consider the sparse matrix of 5 rows and 4 columns below:
+
+ 10 0 0 0
+ 0 0 6 8
+ 0 0 0 0
+ 0 21 0 0
+ 7 0 0 9
+
+ The sparse file representation for the same is:
+
+ 5 4 6
+ 1 10
+ 3 6 4 8
+
+ 2 21
+ 1 7 4 9
+
+ Notice the empty line in between for the third row.
+
+SEE ALSO
+ Math::SparseVector
+
+AUTHORS
+ Ted Pedersen, University of Minnesota, Duluth. tpederse at d.umn.edu
+
+ Mahesh Joshi, Carnegie-Mellon University maheshj @ cmu.edu
+
+COPYRIGHT
+ Copyright (c) 2006-2008, Ted Pedersen and Mahesh Joshi
+
+ 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.
+
Added: branches/upstream/libmath-sparsematrix-perl/current/lib/Math/SparseMatrix.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/lib/Math/SparseMatrix.pm?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/lib/Math/SparseMatrix.pm (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/lib/Math/SparseMatrix.pm Tue Feb 15 04:53:03 2011
@@ -1,0 +1,463 @@
+package Math::SparseMatrix;
+
+=head1 NAME
+
+Math::SparseMatrix - Provides basic sparse matrix operations such as creation, reading from file, reading transpose from file and writing to file.
+
+=cut
+
+use 5.006;
+use strict;
+use warnings;
+
+require Exporter;
+require Math::SparseVector;
+
+use Math::SparseVector;
+
+
+our @ISA = qw(Exporter);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration use Math::SparseMatrix ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+our %EXPORT_TAGS = ( 'all' => [ qw(
+
+) ] );
+
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+
+our @EXPORT = qw(
+
+);
+
+our $VERSION = '0.03';
+
+sub new {
+ my $class = shift;
+ my $rows = shift;
+ my $cols = shift;
+
+ if (!defined $rows || !defined $cols) {
+ die "Math::SparseMatrix->new error.\n" .
+ "USAGE: my \$spmatrix = Math::SparseMatrix->new(\$num_rows, \$num_cols);\n";
+ }
+
+ my $self = {
+ _rows => $rows,
+ _cols => $cols,
+ _nnz => 0,
+ _data => {}
+ };
+
+ bless $self, $class;
+ return $self;
+}
+
+sub set {
+ my $self = shift;
+ my ($row, $col, $val) = @_;
+
+ if (!defined $row || !defined $col || !defined $val) {
+ die "Math::SparseMatrix->set error.\n" .
+ "USAGE: \$spmatrix->set(\$row, \$col, \$val);\n";
+ }
+
+ if ($row < 1 || $row > $self->{_rows}) {
+ die "Math::SparseMatrix->set error.\n" .
+ "Row index out of bounds, must be between 1 and " .
+ $self->{_rows} . " inclusive.\n";
+ }
+
+ if ($col < 1 || $col > $self->{_cols}) {
+ die "Math::SparseMatrix->set error.\n" .
+ "Column index out of bounds, must be between 1 and " .
+ $self->{_cols} . " inclusive.\n";
+ }
+
+ if ($val == 0) {
+ die "Math::SparseMatrix->set error.\n" .
+ "Cannot store zero value in a sparse matrix.\n";
+ }
+
+ if (exists $self->{_data}->{$row}) {
+ # update the number of non-zero elements in the matrix
+ $self->{_nnz} -= scalar($self->{_data}->{$row}->keys);
+ $self->{_data}{$row}->set($col,$val);
+ $self->{_nnz} += scalar($self->{_data}->{$row}->keys);
+ } else {
+ $self->{_data}->{$row} = new Math::SparseVector();
+ $self->{_data}->{$row}->set($col,$val);
+ $self->{_nnz}++;
+ }
+}
+
+sub get {
+ my $self = shift;
+ my ($row, $col) = @_;
+
+ if (!defined $row || !defined $col) {
+ die "Math::SparseMatrix->get error.\n" .
+ "USAGE: \$val = \$spmatrix->get(\$row, \$col);\n";
+ }
+
+ if ($row < 1 || $row > $self->{_rows}) {
+ die "Math::SparseMatrix->get error.\n" .
+ "Row index out of bounds, must be between 1 and " .
+ $self->{_rows} . " inclusive.\n";
+ }
+
+ if ($col < 1 || $col > $self->{_cols}) {
+ die "Math::SparseMatrix->get error.\n" .
+ "Column index out of bounds, must be between 1 and " .
+ $self->{_cols} . " inclusive.\n";
+ }
+
+ if (exists $self->{_data}->{$row}) {
+ return $self->{_data}->{$row}->get($col);
+ } else {
+ return 0;
+ }
+}
+
+sub createFromFile {
+
+ my $class = shift;
+ my $infile = shift;
+
+ if (!defined $infile) {
+ die "Math::SparseMatrix->createFromFile error.\n" .
+ "USAGE: my \$spmatrix = Math::SparseMatrix->createFromFile(\$input_file);\n";
+ }
+
+ if (!-f $infile) {
+ die "Math::SparseMatrix->createFromFile error.\n" .
+ "Cannot find file $infile.\n";
+ }
+
+ my $self = {
+ _rows => 0,
+ _cols => 0,
+ _nnz => 0,
+ _data => {}
+ };
+
+ open(INPUT, "< $infile") or
+ die "Math::SparseMatrix->createFromFile error.\n" .
+ "Failed to open sparse matrix input file $infile.\n";
+
+ # read the number of rows, columns and the non-zero elements in the
+ # file
+ my $line = <INPUT>;
+ chomp $line;
+ my ($rows, $cols, $nnz) = split / +/, $line;
+ $self->{_rows} = $rows;
+ $self->{_cols} = $cols;
+ # DO NOT SET THE NUMBER OF NON-ZEROS, THAT IS MANAGED BY THE set(...)
+ # function, which is called below
+
+ # create a Math::SparseMatrix object
+ bless $self, $class;
+
+ # also do error checks on file integrity
+ my $lineNum = 0;
+ my $nnzFound = 0;
+ while ($line = <INPUT>) {
+ chomp $line;
+ $lineNum++;
+ if ($lineNum > $rows) {
+ die "Math::SparseMatrix->createFromFile error.\n".
+ "Number of rows in $infile is greater than that " .
+ "mentioned in the file header ($rows).";
+ }
+
+ my @tokens = split / +/, $line;
+ my $index;
+ # process the <column, value> pairs in each line
+ for ($index = 0; $index < @tokens; $index += 2) {
+ # the column number of the current pair is the column
+ # number, and the current line number is the row number
+ $self->set($lineNum, $tokens[$index], $tokens[$index + 1]);
+ $nnzFound++;
+ }
+ }
+
+ if ($nnzFound < $nnz) {
+ die "Math::SparseMatrix->createFromFile error.\n".
+ "Number of non-zero elements found in $infile is less than that " .
+ "mentioned in the file header -- $nnzFound < $nnz.\n";
+ }
+
+ if ($nnzFound > $nnz) {
+ die "Math::SparseMatrix->createFromFile error.\n".
+ "Number of non-zero elements found in $infile is greater than that " .
+ "mentioned in the file header -- $nnzFound > $nnz.\n";
+ }
+
+ # now the transposed matrix is loaded and ready to be returned
+ return $self;
+}
+
+sub createTransposeFromFile {
+
+ my $class = shift;
+ my $infile = shift;
+
+ if (!defined $infile) {
+ die "Math::SparseMatrix->createTransposeFromFile error.\n" .
+ "USAGE: \$my \$spmatrix = Math::SparseMatrix->createTransposeFromFile(\$input_file)\n";
+ }
+
+ if (!-f $infile) {
+ die "Math::SparseMatrix->createTransposeFromFile error.\n" .
+ "Cannot find file $infile.\n";
+ }
+
+ my $self = {
+ _rows => 0,
+ _cols => 0,
+ _nnz => 0,
+ _data => {}
+ };
+
+ open(INPUT, "< $infile") or
+ die "Math::SparseMatrix->createTransposeFromFile error.\n" .
+ "Failed to open sparse matrix input file $infile.\n";
+
+ # read the number of rows, columns and the non-zero elements in the
+ # file
+ my $line = <INPUT>;
+ chomp $line;
+ my ($rows, $cols, $nnz) = split / +/, $line;
+ # swap number of rows and columns
+ $self->{_rows} = $cols;
+ $self->{_cols} = $rows;
+ # DO NOT SET THE NUMBER OF NON-ZEROS, THAT IS MANAGED BY THE set(...)
+ # function, which is called below
+
+ # create a Math::SparseMatrix object
+ bless $self, $class;
+
+ # also do error checks on file integrity
+ my $lineNum = 0;
+ my $nnzFound = 0;
+ while ($line = <INPUT>) {
+ chomp $line;
+ $lineNum++;
+ if ($lineNum > $rows) {
+ die "Math::SparseMatrix->createTransposeFromFile error.\n".
+ "Number of columns in $infile is greater than that " .
+ "mentioned in the file header ($rows).";
+ }
+
+ my @tokens = split / +/, $line;
+ my $index;
+ # process the <column, value> pairs in each line
+ for ($index = 0; $index < @tokens; $index += 2) {
+ # the column number of the current pair is the row
+ # number in the transpose, the current line number is
+ # the column number in the transpose
+ $self->set($tokens[$index], $lineNum, $tokens[$index + 1]);
+ $nnzFound++;
+ }
+ }
+
+ if ($nnzFound < $nnz) {
+ die "Math::SparseMatrix->createTransposeFromFile error.\n".
+ "Number of non-zero elements found in $infile is less than that " .
+ "mentioned in the file header -- $nnzFound < $nnz.\n";
+ }
+
+ if ($nnzFound > $nnz) {
+ die "Math::SparseMatrix->createTransposeFromFile error.\n".
+ "Number of non-zero elements found in $infile is greater than that " .
+ "mentioned in the file header -- $nnzFound > $nnz.\n";
+ }
+
+
+ # now the transposed matrix is loaded and ready to be returned
+ return $self;
+}
+
+sub writeToFile {
+
+ my $self = shift;
+ my $outfile = shift;
+
+ if (!defined $outfile) {
+ die "Math::SparseMatrix->writeToFile error.\n" .
+ "USAGE: \$spmatrix->writeToFile (\$output_file);\n";
+ }
+
+ # write it to the output file
+ open(OUTPUT, "> $outfile") or
+ die "Math::SparseMatrix->writeToFile error.\n" .
+ "Failed to create output file $outfile.\n";
+ print OUTPUT $self->{_rows} . " " . $self->{_cols} . " " .
+ $self->{_nnz} . "\n";
+ my $row;
+ my $linecount = 1;
+ foreach $row (sort {$a <=> $b} keys %{$self->{_data}}) {
+ if ($row > $linecount) {
+ # add empty lines for empty rows
+ my $i = 0;
+ my $limit = $row - $linecount;
+ for ($i = 0; $i < $limit; $i++) {
+ print OUTPUT "\n";
+ $linecount++;
+ }
+ }
+ my $vec = $self->{_data}->{$row};
+ my $line = $vec->stringify();
+ print OUTPUT $line . "\n";
+ $linecount++;
+ }
+ close OUTPUT;
+}
+
+sub printDims {
+ my $self = shift;
+ print "Rows: " . $self->{_rows} . ". Cols: " . $self->{_cols} . ".\n";
+}
+
+1;
+__END__
+
+=head1 DESCRIPTION
+
+Math::SparseMatrix provides simple sparse matrix functionality such as
+creation of sparse matrices, writing them out to a file, reading matrices from
+files and reading transpose of a matrix stored in a file.
+
+=head1 SYNOPSIS
+
+=over
+
+=item 1. To begin with, Math::SparseMatrix should be included in your Perl program as follows:
+
+ # include this module for use in your program
+ use Math::SparseMatrix;
+
+=item 2. To create an empty sparse matrix object with the required dimensions, use the following constructor:
+
+ # create a new sparse matrix with 10 rows and 15 columns
+ my $spmatrix = Math::SparseMatrix->new(10, 15);
+
+=item 3. To update the values in the sparse matrix, use the "set" function as follows:
+
+ # set the value at row 5, column 3 to 10
+ $spmatrix->set(5, 3, 10);
+
+=item 4. To retrieve a stored value, use the "get" function as follows:
+
+ # get the value at row 6, column 5 if present, or zero
+ $val = $spmatrix->get(6, 5);
+
+=item 5. A sparse matrix can be written out to a file in the supported format (explained below) as follows:
+
+ # write out the sparse matrix to the file "matrix.txt"
+ $spmatrix->writeToFile("matrix.txt");
+
+=item 6. A new sparse matrix object can be created from a file in the supported format as follows:
+
+ # create a matrix object by reading the file "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createFromFile("matrix.txt");
+
+=item 7. A new sparse matrix that is the transpose of the matrix stored in the given input file can be created as follows:
+
+ # create the transpose of the matrix stored in "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createTransposeFromFile("matrix.txt");
+
+=item 8. Finally, to generate the transpose of a matrix stored in a file, read the transpose as in #7 above and write out the read transpose to a new file as in #5 above.
+
+ # create the transpose of the matrix stored in "matrix.txt"
+ my $spmatrix = Math::SparseMatrix->createTransposeFromFile("matrix.txt");
+
+ # write out the created transpose to another file "transpose.txt"
+ $spmatrix->writeToFile("transpose.txt");
+
+=back
+
+=head1 SPARSE DATA FORMAT
+
+The sparse matrix file format that Math::SparseMatrix expects is described
+below with an example.
+
+The first line (or the header line) of the file should contain 3 number
+separated by a single space.
+The first number is the number of rows in the sparse matrix, the second
+number is the number of columns and the third number is the number of non-zero
+elements present in the stored matrix.
+
+Each subsequent line represents one row of the sparse matrix, therefore there
+should be as many number of lines after the header line as the number of rows
+mentioned in the header line. In every line representing a row, there should
+be as many pairs of numbers as the number of non-zero elements in that row.
+The first number in the pair represents the column number of the non-zero
+element (column numbers start with 1). The row number is implicitly provided
+by the line
+number in the file. The second number in the pair is the actual non-zero
+matrix element. Numbers in a pair and multiple pairs should all be separated
+by single spaces. If a row does not contain any non-zero element, then an
+empty line should be present in the file.
+
+NOTE: There should be no empty lines except those representing empty rows,
+neither should there be any comment lines. Commenting is not supported.
+
+Consider the sparse matrix of 5 rows and 4 columns below:
+
+ 10 0 0 0
+ 0 0 6 8
+ 0 0 0 0
+ 0 21 0 0
+ 7 0 0 9
+
+The sparse file representation for the same is:
+
+ 5 4 6
+ 1 10
+ 3 6 4 8
+
+ 2 21
+ 1 7 4 9
+
+Notice the empty line in between for the third row.
+
+=head1 SEE ALSO
+
+Math::SparseVector
+
+=head1 AUTHORS
+
+Ted Pedersen, University of Minnesota, Duluth.
+tpederse at d.umn.edu
+
+Mahesh Joshi, Carnegie-Mellon University
+maheshj @ cmu.edu
+
+=head1 COPYRIGHT
+
+Copyright (c) 2006-2008, Ted Pedersen and Mahesh Joshi
+
+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.
+
+=cut
+
Added: branches/upstream/libmath-sparsematrix-perl/current/t/Math-SparseMatrix.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-sparsematrix-perl/current/t/Math-SparseMatrix.t?rev=68682&op=file
==============================================================================
--- branches/upstream/libmath-sparsematrix-perl/current/t/Math-SparseMatrix.t (added)
+++ branches/upstream/libmath-sparsematrix-perl/current/t/Math-SparseMatrix.t Tue Feb 15 04:53:03 2011
@@ -1,0 +1,60 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl Math-SparseMatrix.t'
+
+#########################
+
+use Test::More tests => 45;
+
+require_ok('Math::SparseVector');
+BEGIN { use_ok('Math::SparseMatrix') };
+require_ok('Math::SparseMatrix');
+
+#########################
+
+#########################
+# creation
+
+$spmatrix = Math::SparseMatrix->new(5, 10);
+isa_ok($spmatrix, 'Math::SparseMatrix');
+
+#########################
+# get / set
+
+$spmatrix->set(5, 4, 25);
+cmp_ok($spmatrix->get(5, 4), '==', 25, 'test get/set');
+
+#########################
+# saving to file / reading back
+
+$spmatrix1 = Math::SparseMatrix->new(5, 4);
+$spmatrix1->set(1,2,3);
+$spmatrix1->set(2,3,5);
+$spmatrix1->set(3,1,1);
+$spmatrix1->set(4,4,7);
+$spmatrix1->set(5,3,25);
+$spmatrix1->writeToFile("test.mat");
+$spmatrix2 = Math::SparseMatrix->createFromFile("test.mat");
+for ($i = 1; $i < 6; $i++) {
+ for ($j = 1; $j < 5; $j++) {
+ cmp_ok($spmatrix1->get($i,$j), '==',$spmatrix2->get($i,$j), 'test saving and reading back from file');
+ }
+}
+
+#########################
+# reading transpose
+
+$spmatrix3 = Math::SparseMatrix->new(4, 5);
+$spmatrix3->set(1,3,1);
+$spmatrix3->set(2,1,3);
+$spmatrix3->set(3,2,5);
+$spmatrix3->set(3,5,25);
+$spmatrix3->set(4,4,7);
+$spmatrix4 = Math::SparseMatrix->createTransposeFromFile("test.mat");
+for ($i = 1; $i < 5; $i++) {
+ for ($j = 1; $j < 6; $j++) {
+ cmp_ok($spmatrix3->get($i,$j), '==', $spmatrix4->get($i,$j), 'test saving and reading back from file');
+ }
+}
+
+unlink("test.mat");
+
More information about the Pkg-perl-cvs-commits
mailing list