Clair::Utils

LinearAlgebra


SummaryPackage variablesSynopsisGeneral documentationMethods

SummaryTop


verifyCount
verifyLength

Package variablesTop
Privates (from "my" definitions)
$countError = -1
$error = "e"
$lengthError = -1

SynopsisTop
No synopsis!
DescriptionTop
No description!
MethodsTop
addNo descriptionCode
averageNo descriptionCode
innerProductNo descriptionCode
subtractNo descriptionCode
verifyCountNo descriptionCode
verifyLengthNo descriptionCode

Methods description


None available.

Methods code


adddescriptionprevnextTop
sub add {
	my $count = verifyCount (@_);
    	my $length = verifyLength (@_);

    	if (($count == $countError) || ($length == $lengthError)) {
		return $error;
	}
	else {
		my @input = @_;
		my $result = shift(@input);
		my @result = @{$result};

		while (scalar @input > 0) { 
			my $v1 = shift(@input);
	    		my @v1vals = @{$v1};

	    		foreach $i (0..($length-1))  {
				$result[$i] = ($result[$i]+$v1vals[$i]);
	    		}
		}
		return @result;
    	}
}

averagedescriptionprevnextTop
sub average {
	my $count = verifyCount (@_);
    	my $length = verifyLength (@_);

    	if (($count == $countError) || ($length == $lengthError)) {
		return $error;
	}
	else {
		my @input = @_;
		my $interim = shift(@input);
		my @interim = @{$interim};

		while (scalar @input > 0) { 
			my $v1 = shift(@input);
	    		my @v1vals = @{$v1};

	    		foreach $i (0..($length-1))  {
				$interim[$i] = ($interim[$i]+$v1vals[$i]);
	    		}
		}
		
		my @result;
		foreach $ii (0..($length-1)) {
			$result[$ii] = ($interim[$ii]/$count);
} return @result; }
}

innerProductdescriptionprevnextTop
sub innerProduct {
	my $count = verifyCount (@_);
   	my $length = verifyLength(@_);
	if ($count == $countError || $count > 2) {
#		print "Error - Unable to perform an Inner Product on more than two vectors.\n";
return $error; } else { if ($length == $lengthError) { return $error; } else { my ($v1,$v2) = @_; my @v1vals = @{$v1}; my @v2vals = @{$v2}; my $sum = 0.0; my $l = scalar @v1vals; foreach $i (0..($l-1)) { $sum += $v1vals[$i]*$v2vals[$i]; } return $sum; } }
}

subtractdescriptionprevnextTop
sub subtract {
	my $count = verifyCount (@_);
    	my $length = verifyLength (@_);

    	if (($count == $countError) || ($length == $lengthError)) {
		return $error;
	}
	else {
		my @input = @_;
		my $result = shift(@input);
		my @result = @{$result};

		while (scalar @input > 0) { 
			my $v1 = shift(@input);
	    		my @v1vals = @{$v1};

	    		foreach $i (0..($length-1))  {
				$result[$i] = ($result[$i]-$v1vals[$i]);
	    		}
		}
		return @result;
    	}
}

verifyCountdescriptionprevnextTop
sub verifyCount {
	$count = scalar @_;
    	if ($count < 2)  {
		return -1;
    	}
    	else {
		return $count;
    	}
}

verifyLengthdescriptionprevnextTop
sub verifyLength {
    	my @array = @_;
    	$v = pop(@array);
    	my $length = (scalar @{$v});
    	my $index = (scalar @array);
    
    	for $i (0..$index) {
		$vt = $_[$i];
		if ( scalar @{$vt} != $length ) {
	    		return -1;
		}
		else {
	    		return $length;
		}
    	}
}

General documentation


NAME (1)Top
LinearAlgebra::InnerProduct

SYNOPSIS(1)Top
@a = (1,4,2,3,6); @b = (4,1,2,2,3);
$result = innerProduct(\@a,\@b);

DESCRIPTION (1)Top
Computes inner product of two arrays of numbers.

ERRORS (1)Top
Returns "e" if arrays are not the same length.
Returns "e" if only one array is given as input.
Returns "e" if more than one array is given as input.

AUTHOR(1)Top
Mark Thomas Joseph

NAME (2)Top
LinearAlgebra::Subtract

SYNOPSIS(2)Top
@a = (1,4,2,3,6); @b = (4,1,2,2,3);
$result = subtract(\@a,\@b);

DESCRIPTION (2)Top
Subtracts arrays of numbers.

ERRORS (2)Top
Returns "e" if arrays are not the same length.
Returns "e" if only one array is given as input.

AUTHOR(2)Top
Mark Thomas Joseph

NAME (3)Top
LinearAlgebra::Add

SYNOPSIS(3)Top
@a = (1,4,2,3,6); @b = (4,1,2,2,3);
$result = add(\@a,\@b);

DESCRIPTION (3)Top
Adds arrays of numbers.

ERRORS (3)Top
Returns "e" if arrays are not the same length.
Returns "e" if only one array is given as input.

AUTHOR(3)Top
Mark Thomas Joseph

NAME (4)Top
LinearAlgebra::Average

SYNOPSIS(4)Top
@a = (1,4,2,3,6); @b = (4,1,2,2,3);
$result = average(\@a,\@b);

DESCRIPTION (4)Top
Computes average of arrays of numbers.

ERRORS (4)Top
Returns "e" if arrays are not the same length.
Returns "e" if only one array is given as input.

AUTHOR(4)Top
Mark Thomas Joseph

NAME(1)Top
verifyCount

SYNOPSIS(5)Top
Counts the number of lists/arrays passed into LinearAlgebra in the @_ array

NAME(2)Top
verifyLength

SYNOPSIS(6)Top
Verifies matching lengths between all lists/arrays passed into LinearAlgebra in the @_ array