jv.vecmath
Class PbVector
- java.lang.Object
-
- jv.vecmath.P_Vector
-
- jv.vecmath.PbVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class PbVector extends P_Vector implements java.lang.Cloneable
Linear algebra class for an array of booleans with variable length.- See Also:
- Serialized Form
- Author:
- Matthias Nieser
- Version:
- 06.02.08, 1.10 revised (kp) Moved to jv.vecmath from dev.number.
13.06.07, 1.00 created (mn) Created from PiVector.
00.00.97, 1.00 created (kp) Original class jv.vecmath.PiVector.
-
-
Field Summary
Fields Modifier and Type Field and Description boolean[]m_dataData array containing the components of the vector.
-
Constructor Summary
Constructors Constructor and Description PbVector()Construct vector with zero size.PbVector(boolean x)Constructs a vector of length 1 and given initial data.PbVector(boolean[] x)Constructs a vector having same length and given initial data as given array.PbVector(boolean x, boolean y)Constructs a vector of length 2 and given initial data.PbVector(boolean x, boolean y, boolean z)Constructs a vector of length 3 and given initial data.PbVector(boolean x, boolean y, boolean z, boolean w)Constructs a vector of length 4 and given initial data.PbVector(int aSize)Constructor creating a vector with given dimension.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description intaddEntry(boolean val)Add another entry at the end of the vector and increment size of vector.static PbVector[][]alloc(int sizeI, int sizeJ, int vectorSize)Allocate a new array of vectors, where all vectors have the same dimension.voidand(PbVector v)Apply the 'AND' operation component-wise to the entries ofthisandvand store the results inthis.voidblend(double a, PbVector v, double b, PbVector w)Interpolate between two vectors with given weights.static PbVectorblendNew(double a, PbVector v, double b, PbVector w)Create a new vectorthis = a*v + b*w.java.lang.Objectclone()Clone object and all instance variables.voidcopy(boolean[] anArray, int aSize)Copy a boolean array into a vector, and do not adjust size of dest vector.voidcopy(boolean[] anArray, int srcPos, int aSize)Copy part of a boolean array into a vector, and do not adjust size of dest vector.booleancopy(int destInd, PbVector dataSrc, int srcInd, int size)Copy part of the source vector into this vector, and adjust size of this vector only if it is too small.voidcopy(PbVector v)Copy a vector into a vector, and do not adjust size of dest vector.static booleancopy(PbVector[] dataDest, int destInd, PbVector[] dataSrc, int srcInd, int size)Copies some vectors of a given array of vectors into an existing destination array.voidcopyArray(PbVector v)Copy data array of source vector into this vector, and do not adjust size of dest vector.static PbVector[]copyNew(boolean[][] data)Create an new array with copies of all booleans of a given 2-dimensional array of numbers.static PbVectorcopyNew(PbVector v)Create a new vector as clone of argument vector.static PbVector[]copyNew(PbVector[] data)Create an new array with copies of all vectors of a given array of vectors.static PbVector[]copyNew(PbVector[] data, int size)Create an new array with copies of the first 'size' vectors of a given array of vectors.intcountTrueEntries()Count number of entries with state = true.intcountValue(boolean b)Count the entries that have the same value asb.booleanequals(boolean[] list)Compare vector with list of booleans and returnfalseif different array lengths or a different entry.booleanequals(java.lang.Object obj)Determines whether another vector or array of booleans is equal to this vector.booleanequals(PbVector v)Determines whether another vector is equal to this vector.boolean[]getEntries()Return a copy of the content of vector as array of booleans.static boolean[][]getEntries(PbVector[] vArr)Return content of array of vectors as matrix of boolean.booleangetEntry(int ind)Get the component of a vector.booleangetFirstEntry()Get the first component of a vector.booleangetLastEntry()Get the last component of a vector.static intgetSameSize(PbVector[] vecArray, int numUsed)Check of all vectors in array of vector have same length.intgetSize()Get dimension of vector, i.e. length of its data array.intindexOf(boolean value)Computes the index i of the first entry of vector withv[i]==value.voidinvert()Invert order of all entries, i.e. the first entry becomes the last entry.voidinvert(int usedSize)Invert order of the first 'usedSize' entries, i.e. the first entry becomes the 'usedSize-1' entry.voidinvertEntries()Set all entries e to (not e).voidor(PbVector v)Apply the 'OR' operation component-wise to the entries ofthisandvand store the results inthis.static PbVector[]realloc(PbVector[] data, int arraySize)Allocate an array of vectors.static PbVector[]realloc(PbVector[] data, int arraySize, int vectorSize)Allocate an array of vectors, where all vectors have the same dimension.voidset(boolean x)Assign value to vector, and increase size of vector if necessary.voidset(boolean[] x)Assign values of boolean array to vector, and adjust length of vector if different from length of array.voidset(boolean[] x, int len)Assign first values of boolean array to vector, and adjust length of vector if different from argument len.voidset(boolean[] x, int from, int len)Assign 'len' values of boolean array starting at 'from' to vector, and adjust length of vector if different from argument len.voidset(boolean x, boolean y)Assign value to vector, and increase size of vector if necessary.voidset(boolean x, boolean y, boolean z)Assign value to vector, and increase size of vector if necessary.voidset(boolean x, boolean y, boolean z, boolean w)Assign value to vector, and increase size of vector if necessary.voidset(PbVector x, int from, int len)Assign 'len' values of array starting at 'from' to vector, and adjust length of vector if different from argument len.voidsetConstant(boolean aValue)Set all entries to a constant value.static voidsetConstant(boolean[] v, boolean aValue)Set all entries to a constant value.static voidsetConstant(PbVector[] vecArr, boolean aValue)Set all components of all vectors of an array to a constant.static voidsetConstant(PbVector[] vecArr, boolean[] data)Set all vectors of an array equal to a given vector.static voidsetConstant(PbVector[] vecArr, PbVector aVector)Set all vectors of an array equal to a given vector.static voidsetConstant(PbVector v, boolean aValue)Set all entries to a constant value.voidsetEntry(int ind, boolean value)Assign value to component of vector, and possibly enlarge vector if too small.voidsetFirstEntry(boolean value)Set the first component of a vector.voidsetLastEntry(boolean value)Set the last component of a vector.intsetSize(int aSize)Set dimension of vector, i.e. length of its data array.java.lang.StringtoShortString()Create a single-line string representation of the vector components and attributes.java.lang.StringtoString()Create a multi-line string representation of the vector with detailed information about all instance variables.voidxor(PbVector v)Apply the 'XOR' operation component-wise to the entries ofthisandvand store the results inthis.
-
-
-
Field Detail
-
m_data
public boolean[] m_data
Data array containing the components of the vector. Array has public access for efficiency reasons in numerical computations, although method access should be preferred. Do not modify length of array directly.
-
-
Constructor Detail
-
PbVector
public PbVector()
Construct vector with zero size.
-
PbVector
public PbVector(int aSize)
Constructor creating a vector with given dimension.
-
PbVector
public PbVector(boolean x)
Constructs a vector of length 1 and given initial data.
-
PbVector
public PbVector(boolean x, boolean y)Constructs a vector of length 2 and given initial data.
-
PbVector
public PbVector(boolean x, boolean y, boolean z)Constructs a vector of length 3 and given initial data.
-
PbVector
public PbVector(boolean x, boolean y, boolean z, boolean w)Constructs a vector of length 4 and given initial data.
-
PbVector
public PbVector(boolean[] x)
Constructs a vector having same length and given initial data as given array.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Clone object and all instance variables. Similar likecopyNew(PbVector)but this clone() method is consistent with possible subclasses while copyNew() explicitly creates a new PbVector.- Overrides:
clonein classP_Vector- See Also:
copyNew(PbVector)
-
getEntries
public static boolean[][] getEntries(PbVector[] vArr)
Return content of array of vectors as matrix of boolean.- Parameters:
vArr- Array of vectors- Returns:
- 2-dimensional matrix of boolean
-
alloc
public static PbVector[][] alloc(int sizeI, int sizeJ, int vectorSize)
Allocate a new array of vectors, where all vectors have the same dimension.- Parameters:
sizeI- number of rows in new arraysizeJ- number of columns in row[i] in new arrayvectorSize- dimension of vectors in new array
-
realloc
public static PbVector[] realloc(PbVector[] data, int arraySize, int vectorSize)
Allocate an array of vectors, where all vectors have the same dimension. If argumentdata!=nullthen as most as possible of the content of existing vectors is copied into (possibly reused) vectors of the reallocated array.If requested array size is 0 then method returns an array of length 0.
- Parameters:
data- possibly empty array of vectorsarraySize- number of vectors in new arrayvectorSize- dimension of vectors in new array- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
realloc
public static PbVector[] realloc(PbVector[] data, int arraySize)
Allocate an array of vectors. If argumentdata!=nullthen as most as possible of the existing vectors are reused in the reallocated array. New vectors are allocated with dimension zero.If requested array size is 0 then method returns an array of length 0.
- Parameters:
data- possibly empty array of vectorsarraySize- number of vectors in new array- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
copyNew
public static PbVector[] copyNew(boolean[][] data)
Create an new array with copies of all booleans of a given 2-dimensional array of numbers. Each row of argument vector is stored in a vector. Rows may have different length. A row with length zero leads to a warning message, and allocates a vector with length zero.- Parameters:
data- 2-dimensional array of numbers- Returns:
- new array with same number of vectors as rows of argument array
-
copyNew
public static PbVector[] copyNew(PbVector[] data)
Create an new array with copies of all vectors of a given array of vectors. The new array contains new vectors containing the same data as the original vectors.- Parameters:
data- array of vectors- Returns:
- new array with same number of vectors as argument array
-
copyNew
public static PbVector[] copyNew(PbVector[] data, int size)
Create an new array with copies of the first 'size' vectors of a given array of vectors. The new array contains new vectors containing the same data as the original vectors.- Parameters:
data- array of vectorssize- number of copied vectors of array- Returns:
- new array with number of vectors equal to argument 'size'
- See Also:
copyNew(PbVector [])
-
copy
public static boolean copy(PbVector[] dataDest, int destInd, PbVector[] dataSrc, int srcInd, int size)
Copies some vectors of a given array of vectors into an existing destination array. All vectors in source and destination array must exist already.
Destination array must be large enough, i.e.for (int i=0; i<size; i++) dataDest[destInd+i].copy(dataSrc[srcInd+i]);dataDest.length >= destInd+size.- Parameters:
dataDest- destination array of vectorsdestInd- index of first destination vector in dataDestdataSrc- source array of vectorssrcInd- index of first source vector in dataSrc used for copyingsize- number of copied vectors of array- Returns:
trueif destination array is large enough- See Also:
copy(PbVector)
-
getSameSize
public static int getSameSize(PbVector[] vecArray, int numUsed)
Check of all vectors in array of vector have same length.- Returns:
- same length, or -1 if different or no entries.
-
setConstant
public static void setConstant(PbVector[] vecArr, boolean aValue)
Set all components of all vectors of an array to a constant.
-
setConstant
public static void setConstant(PbVector[] vecArr, boolean[] data)
Set all vectors of an array equal to a given vector. All vectors of argument array must have same length.
-
setConstant
public static void setConstant(PbVector[] vecArr, PbVector aVector)
Set all vectors of an array equal to a given vector. All vectors of argument array must have same length.
-
setConstant
public static void setConstant(PbVector v, boolean aValue)
Set all entries to a constant value.
-
setConstant
public static void setConstant(boolean[] v, boolean aValue)Set all entries to a constant value.
-
setConstant
public void setConstant(boolean aValue)
Set all entries to a constant value.
-
getSize
public int getSize()
Get dimension of vector, i.e. length of its data array.
-
setSize
public int setSize(int aSize)
Set dimension of vector, i.e. length of its data array.- Parameters:
aSize- new number of components of vector- Returns:
- new number of components of vector
-
getEntries
public boolean[] getEntries()
Return a copy of the content of vector as array of booleans.
-
getEntry
public boolean getEntry(int ind)
Get the component of a vector.
-
setEntry
public void setEntry(int ind, boolean value)Assign value to component of vector, and possibly enlarge vector if too small.- Parameters:
ind- index of component.value- new value of component.- Version:
- 29.09.99, 1.10 revised (kp) Check for m_data==null. 13.09.99, 1.10 revised (kp) setSize allocated one entry too few.
-
getFirstEntry
public boolean getFirstEntry()
Get the first component of a vector.- Returns:
- value of the first component.
-
setFirstEntry
public void setFirstEntry(boolean value)
Set the first component of a vector.- Parameters:
value- new value of first component- Version:
- 25.07.00 created (kp)
-
getLastEntry
public boolean getLastEntry()
Get the last component of a vector.- Returns:
- value of the last component.
-
setLastEntry
public void setLastEntry(boolean value)
Set the last component of a vector.- Parameters:
value- new value of last component- Version:
- 25.07.00 created (kp)
-
addEntry
public int addEntry(boolean val)
Add another entry at the end of the vector and increment size of vector.- Parameters:
val- value to be added- Returns:
- index of new last entry.
-
set
public void set(PbVector x, int from, int len)
Assign 'len' values of array starting at 'from' to vector, and adjust length of vector if different from argument len.
-
set
public void set(boolean[] x, int from, int len)Assign 'len' values of boolean array starting at 'from' to vector, and adjust length of vector if different from argument len.
-
set
public void set(boolean[] x, int len)Assign first values of boolean array to vector, and adjust length of vector if different from argument len.
-
set
public void set(boolean[] x)
Assign values of boolean array to vector, and adjust length of vector if different from length of array.
-
set
public void set(boolean x)
Assign value to vector, and increase size of vector if necessary.
-
set
public void set(boolean x, boolean y)Assign value to vector, and increase size of vector if necessary.
-
set
public void set(boolean x, boolean y, boolean z)Assign value to vector, and increase size of vector if necessary.
-
set
public void set(boolean x, boolean y, boolean z, boolean w)Assign value to vector, and increase size of vector if necessary.
-
invert
public void invert(int usedSize)
Invert order of the first 'usedSize' entries, i.e. the first entry becomes the 'usedSize-1' entry.- See Also:
invert()
-
invert
public void invert()
Invert order of all entries, i.e. the first entry becomes the last entry.- See Also:
invert(int)
-
invertEntries
public void invertEntries()
Set all entries e to (not e).
-
and
public void and(PbVector v)
Apply the 'AND' operation component-wise to the entries ofthisandvand store the results inthis.- Author:
- Felix Kaelberer
- Version:
- 06.02.2011, 1.00 created (fk)
-
or
public void or(PbVector v)
Apply the 'OR' operation component-wise to the entries ofthisandvand store the results inthis.- Author:
- Felix Kaelberer
- Version:
- 06.02.2011, 1.00 created (fk)
-
xor
public void xor(PbVector v)
Apply the 'XOR' operation component-wise to the entries ofthisandvand store the results inthis.- Author:
- Felix Kaelberer
- Version:
- 06.02.2011, 1.00 created (fk)
-
countValue
public int countValue(boolean b)
Count the entries that have the same value asb.- Author:
- Felix Kaelberer
- Version:
- 05.04.2011, 1.00 created (fk)
-
copyNew
public static PbVector copyNew(PbVector v)
Create a new vector as clone of argument vector.- Parameters:
v- source vector to clone
-
copy
public boolean copy(int destInd, PbVector dataSrc, int srcInd, int size)Copy part of the source vector into this vector, and adjust size of this vector only if it is too small.- See Also:
copy(PbVector)- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
copy
public void copy(PbVector v)
Copy a vector into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source vector. If source and destination vectors have different size then use the mininum of both sizes. If destination vector is bigger than source then reset the additional entries in destination vector with 0.- Parameters:
v- source vector to copy- See Also:
copy(int,PbVector,int,int)- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
25.08.99, 1.05 revised (ur) Set size if 'this' is empty.
-
copyArray
public void copyArray(PbVector v)
Copy data array of source vector into this vector, and do not adjust size of dest vector. In contrast tocopy(PbVector)this method does not invoke the copy method of the superclass. If destination vector is empty then allocated space of size of source vector. If source and destination vectors have different size then use the mininum of both sizes for copying. If destination vector is bigger than source then reset the additional entries in destination vector with 0.- Parameters:
v- source vector to copy- See Also:
copy(PbVector)- Version:
- 30.12.01, 1.10 revised (kp) Resize not only when m_data==null but also m_data.length==0.
01.01.01, 1.00 revised (kp)
-
copy
public void copy(boolean[] anArray, int aSize)Copy a boolean array into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source array. If source and destination vectors have different size then use the mininum of both sizes. If destination vector is bigger than source then reset the additional entries in destination vector with 0.- See Also:
copy(int,PbVector,int,int)- Version:
- 04.02.05, 1.20 revised (kp) Better sync with copy(PbVector).
26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
25.08.99, 1.05 revised (ur) Set size if 'this' is empty.
-
copy
public void copy(boolean[] anArray, int srcPos, int aSize)Copy part of a boolean array into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source array. If parameter size and length of destination vectors are different then use the minimum of both sizes. If destination vector is bigger than argument size then reset the additional entries in destination vector with 0.- Parameters:
anArray- array of booleanssrcPos- first position in array used for copyingaSize- number of entries to copy.- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
countTrueEntries
public int countTrueEntries()
Count number of entries with state = true.
-
blendNew
public static PbVector blendNew(double a, PbVector v, double b, PbVector w)
Create a new vectorthis = a*v + b*w.- Parameters:
a- weight of first vectorv- first vectorb- weight of second vectorw- second vector- See Also:
blend(double, PbVector, double, PbVector)
-
blend
public void blend(double a, PbVector v, double b, PbVector w)Interpolate between two vectors with given weights. Usesthis = v, if a>=b, or else this = w. If result vector 'this' is empty then its size is set to length of vector v, otherwise interpolation is done up to length of result vector.- Parameters:
a- weight of first vectorv- first vectorb- weight of second vectorw- second vector- See Also:
blendNew(double, PbVector, double, PbVector)
-
indexOf
public int indexOf(boolean value)
Computes the index i of the first entry of vector withv[i]==value.- Returns:
- Index of the first entry of vector with
v[i]==valueor -1 if value is smaller than minimum value of vector.
-
equals
public boolean equals(boolean[] list)
Compare vector with list of booleans and returnfalseif different array lengths or a different entry. Determines whether a list of booleans is equal to data of this vector. The result istrueif both arrays have same length and equal components. Result is alsotrueif argument vector is null and this vector has no entries.- Parameters:
list- the list of booleans to compare with- Returns:
trueif the objects are the same;falseotherwise.
-
equals
public boolean equals(java.lang.Object obj)
Determines whether another vector or array of booleans is equal to this vector.- Overrides:
equalsin classjava.lang.Object- Since:
- JavaView 3.62.012
- See Also:
equals(boolean[]),equals(PbVector),Object.equals(java.lang.Object)
-
equals
public boolean equals(PbVector v)
Determines whether another vector is equal to this vector. The result istrueif both vectors have same length and equal components. Result is alsotrueif argument vector is null and this vector has no entries.- Parameters:
v- the vector to compare with- Returns:
trueif the objects are the same;falseotherwise.
-
toString
public java.lang.String toString()
Create a multi-line string representation of the vector with detailed information about all instance variables.- Overrides:
toStringin classP_Vector- See Also:
toShortString()- Version:
- 03.06.06, 1.10 (kp) Print empty brackets instead of null if empty data array.
-
toShortString
public java.lang.String toShortString()
Create a single-line string representation of the vector components and attributes.- See Also:
toString()- Version:
- 03.06.06, 1.10 (kp) Print empty brackets instead of null if empty data array.
-
-
"