|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.matrix.VectorNi
public class VectorNi
Implements a general vector of integers. We have provided integer implementations of all methods of VectorNd for which it makes sense to do so.
These vectors can be resized, either explicitly through a call to setSize
, or implicitly through operations that require the vector
size to be modified.
Constructor Summary | |
---|---|
VectorNi()
Creates a vector with an initial size of zero. |
|
VectorNi(int size)
Creates a vector of a specific size, and initializes its elements to 0. |
|
VectorNi(int[] values)
Creates a vector from an array of ints. |
|
VectorNi(int size,
int[] values)
Creates a vector of a specific size, and initializes its elements from an array of values. |
|
VectorNi(VectorNi vec)
Creates a new VectorNi from an existing one. |
Method Summary | |
---|---|
void |
absolute()
Sets the elements of this vector to their absolute values. |
void |
absolute(VectorNi v1)
Sets the elements of this vector to the absolute value of v1. |
void |
add(int i,
int value)
Adds a value to the i-th element of this vector. |
void |
add(VectorNi v1)
Adds this vector to v1 and places the result in this vector. |
void |
add(VectorNi v1,
VectorNi v2)
Adds vector v1 to v2 and places the result in this vector. |
int |
adjustSize(int inc)
|
void |
append(int value)
Appends a value to the end of this vector, increasing its size by one. |
VectorNi |
clone()
|
boolean |
equals(VectorNi v1)
Returns true if the elements of this vector exactly equal those of vector v1 . |
int |
get(int i)
Gets a single element of this vector. |
void |
get(int[] values)
Copies the elements of this vector into an array of ints. |
int[] |
getBuffer()
Returns the internal buffer used to store the elements in this vector. |
int |
getCapacity()
|
static java.lang.String |
getDefaultFormat()
Returns the default format string used in toString . |
int |
infinityNorm()
Returns the infinity norm of this vector. |
boolean |
isFixedSize()
Returns true if this vector is of fixed size. |
void |
max(VectorNi v)
Computes the element-wise maximum of this vector and vector v and places the result in this vector. |
int |
maxElement()
Returns the maximum element value of this vector. |
void |
min(VectorNi v)
Computes the element-wise minimum of this vector and vector v and places the result in this vector. |
int |
minElement()
Returns the minimum element value of this vector. |
void |
negate()
Negates this vector in place. |
void |
negate(VectorNi v1)
Sets this vector to the negative of v1. |
int |
oneNorm()
Returns the 1 norm of this vector. |
void |
permute(int[] permutation)
Rearrange the elements of this vector according to the specified permutation, such that each element i is replaced by element permutation[i]. |
void |
scale(double s)
Scales the elements of this vector by s . |
void |
scale(double s,
VectorNi v1)
Scales the elements of vector v1 by s and places the
results in this vector. |
void |
scaledAdd(double s,
VectorNi v1)
Computes s v1 and adds the result to this vector. |
void |
scaledAdd(double s,
VectorNi v1,
VectorNi v2)
|
void |
scan(ReaderTokenizer rtok)
Sets the contents of this vector to values read from a ReaderTokenizer. |
void |
set(int[] values)
Sets the elements of this vector from an array of ints. |
void |
set(int i,
int value)
Sets a single element of this vector. |
void |
set(VectorNi v1)
Sets the size and values of this vector to those of v1. |
void |
setBuffer(int size,
int[] buffer)
Explicitly sets the size and internal buffer associated with this vector. |
void |
setCapacity(int newcap)
|
static void |
setDefaultFormat(java.lang.String fmtStr)
Sets the default format string used in toString . |
void |
setRandom()
Sets the elements of this vector to uniformly distributed random values in the range -1000 (inclusive) to 1000 (exclusive). |
void |
setRandom(int lower,
int upper)
Sets the elements of this vector to uniformly distributed random values in a specified range. |
void |
setRandom(int lower,
int upper,
java.util.Random generator)
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator. |
void |
setSize(int newSize)
Sets the size of this vector. |
void |
setSubVector(int off,
VectorNi v1)
Sets a subset of the values of this vector, beginning at a specified offset, to the values of v1. |
void |
setZero()
Sets the elements of this vector to zero. |
int |
size()
Returns the size of this vector. |
void |
sort()
Sorts the contents of this vector by element value, from largest to smallest value. |
void |
sort(VectorNi v1)
Sorts the contents of vector v1 by element value, from largest to smallest value, and places the result into this vector. |
void |
sub(VectorNi v1)
Subtracts v1 from this vector and places the result in this vector. |
void |
sub(VectorNi v1,
VectorNi v2)
Subtracts vector v1 from v2 and places the result in this vector. |
int |
sum()
Returns the sum of all the elements in this vector. |
java.lang.String |
toString()
Returns a String representation of this vector, using the default format returned by getDefaultFormat . |
java.lang.String |
toString(NumberFormat fmt)
Returns a String representation of this vector, in which each element is formatted using a C printf style format as decribed by the
parameter NumberFormat . |
java.lang.String |
toString(java.lang.String fmtStr)
Returns a String representation of this vector, in which each element is formatted using a C printf style format string. |
void |
unsetBuffer()
Removes an explicit buffer provided for this vector and replaces it with a default implicit buffer. |
void |
write(java.io.PrintWriter pw,
NumberFormat fmt)
Writes the contents of this vector to a PrintWriter. |
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
boolean withBrackets)
Writes the contents of this vector to a PrintWriter. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public VectorNi()
public VectorNi(int size) throws ImproperSizeException
size
- size of the vector
ImproperSizeException
- if size is negativepublic VectorNi(int size, int[] values) throws ImproperSizeException
size
- size of the vectorvalues
- element values for the new vector
ImproperSizeException
- if size is negativepublic VectorNi(int[] values)
values
- element values for the new vectorpublic VectorNi(VectorNi vec)
vec
- Vector to be copiedMethod Detail |
---|
public static void setDefaultFormat(java.lang.String fmtStr)
toString
. For
a description of the format string syntax, see NumberFormat
.
fmtStr
- new format string
java.lang.IllegalArgumentException
- if the format string is invalidgetDefaultFormat()
public static java.lang.String getDefaultFormat()
toString
. If
unset, this string is "%d". For a description of the format string syntax,
see NumberFormat
.
public int[] getBuffer()
Note that the buffer may be larger than the vector. The i-th element in the vector corresponds to the i-th entry in the buffer.
If this vector is resized, then the internal buffer may change and the buffer previously returned by this routine may no longer be valid.
setBuffer(int, int[])
public int size()
public boolean isFixedSize()
setSize(int)
public void setSize(int newSize) throws ImproperSizeException
getBuffer
.
If a vector is resized, then previous element values which are still within the new vector dimension are preserved. Other (new) element values are undefined.
newSize
- new vector size
ImproperSizeException
- if this vector has an explicit internal buffer and that buffer is too
small for the requested sizepublic int adjustSize(int inc) throws ImproperSizeException
ImproperSizeException
public int getCapacity()
public void setCapacity(int newcap)
public void setBuffer(int size, int[] buffer)
buffer
must equal or exceed the specified size. The vector
can continue to be resized as long as the requested sizes do not exceed
the buffer size.
size
- new vector sizebuffer
- explicit buffer for this vector
ImproperSizeException
- if the specified buffer is too small for the requested sizeunsetBuffer()
public void unsetBuffer()
java.lang.IllegalStateException
- if this vector does not have an explicit buffer given by
setBuffer
setBuffer(int, int[])
public int get(int i)
i
- element index
public void get(int[] values)
values
- array into which values are copiedpublic void set(int i, int value)
i
- element indexvalue
- element valuepublic void append(int value)
append
calls.
value
- value to append to the end of this vector
ImproperSizeException
- if the capacity needs to be increased but
the internal buffer is explicit and so cannot be increased.public void set(int[] values)
values
- array from which values are copiedpublic void set(VectorNi v1)
v1
- vector whose size and values are copied
ImproperSizeException
- if this vector needs resizing but is of fixed sizepublic void setSubVector(int off, VectorNi v1)
off
- offset where copying should begin in this vectorv1
- vector whose values are copied
ImproperSizeException
- if this vector is not large enough to accomodate the specified subvectorpublic void add(VectorNi v1, VectorNi v2) throws ImproperSizeException
v1
- left-hand vectorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different sizes, or if this vector needs resizing but is
of fixed sizepublic void add(VectorNi v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different sizespublic void add(int i, int value)
i
- index of the elementvalue
- value to be addedpublic void sub(VectorNi v1, VectorNi v2) throws ImproperSizeException
v1
- left-hand vectorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different sizes, or if this vector needs resizing but is
of fixed sizepublic void sub(VectorNi v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different sizespublic void negate(VectorNi v1)
v1
- vector to negate
ImproperSizeException
- if this vector needs resizing but is of fixed sizepublic void negate()
public void scale(double s)
s
.
s
- scaling factorpublic void scale(double s, VectorNi v1)
s
and places the
results in this vector. This vector is resized if necessary.
s
- scaling factorv1
- vector to be scaled
ImproperSizeException
- if this vector needs resizing but is of fixed sizepublic void scaledAdd(double s, VectorNi v1, VectorNi v2) throws ImproperSizeException
ImproperSizeException
public void scaledAdd(double s, VectorNi v1) throws ImproperSizeException
s v1
and adds the result to this vector.
s
- scaling factorv1
- vector to be scaled and added
ImproperSizeException
- if this vector and v1 have different sizespublic int maxElement()
public int minElement()
public int infinityNorm()
public int oneNorm()
public boolean equals(VectorNi v1) throws ImproperSizeException
v1
.
v1
- vector to compare with
ImproperSizeException
public int sum()
public void setZero()
public void absolute()
public void absolute(VectorNi v1)
v1
- vector to take the absolute value of
ImproperSizeException
- if this vector needs resizing but is of fixed sizepublic void sort()
public void sort(VectorNi v1)
v1
- vector to sortpublic void setRandom()
public void setRandom(int lower, int upper)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)public void setRandom(int lower, int upper, java.util.Random generator)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generatorpublic void max(VectorNi v) throws ImproperSizeException
v
- vector to compare with
ImproperSizeException
- if this vector and v have different sizespublic void min(VectorNi v) throws ImproperSizeException
v
- vector to compare with
ImproperSizeException
- if this vector and v have different sizespublic VectorNi clone()
clone
in interface Clonable
clone
in class java.lang.Object
public void permute(int[] permutation)
permutation
- describes the element exchanges
ImproperSizeException
- if the length of permutation
is less than the size of this
vector.public java.lang.String toString()
getDefaultFormat
.
toString
in class java.lang.Object
toString(String)
public java.lang.String toString(java.lang.String fmtStr)
printf
style format string. For a
description of the format string syntax, see NumberFormat
. Note that when called numerous
times, toString(NumberFormat)
will be more
efficient because the NumberFormat
will
not need to be recreated each time from a specification string.
fmtStr
- numeric format specification
public java.lang.String toString(NumberFormat fmt)
printf
style format as decribed by the
parameter NumberFormat
.
fmt
- numeric format
public void write(java.io.PrintWriter pw, NumberFormat fmt) throws java.io.IOException
printf
style as decribed by the parameter
NumberFormat
.
pw
- PrintWriter to write this vector tofmt
- numeric format
java.io.IOException
public void write(java.io.PrintWriter pw, NumberFormat fmt, boolean withBrackets) throws java.io.IOException
[ ]
if withBrackets
is set true. Each
element is formatted using a C printf
style as decribed by
the parameter NumberFormat
.
pw
- PrintWriter to write this vector tofmt
- numeric formatwithBrackets
- if true, causes the output to be surrounded by square brackets.
java.io.IOException
public void scan(ReaderTokenizer rtok) throws java.io.IOException
[ ]
.
If the input is not surrounded by square brackets, then the number of
values should equal the current size
of this vector.
If the input is surrounded by square brackets, then all values up to the
closing bracket are read, and the resulting number of values should either
equal the current size
of this vector, or this vector should
be resizeable to fit the input. For example,
[ 1 4 5 3 ]defines a vector of size 4.
rtok
- Tokenizer from which vector values are read. Number parsing should be
enabled.
ImproperSizeException
- if this vector has a fixed size which is incompatible with the input
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |