|
AlgART Home | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Matrix<T extends Array> extends java.lang.Cloneable
AlgART matrix: multidimensional array.
Unlike AlgART array, AlgART matrix is a very simple thing.
The matrix is just a pair:
The product of all dimensions must be equal to the array length. Moreover,
the array must be unresizable: so, the array length
cannot be changed after creating the matrix.
It is supposed that all matrix elements are stored in the built-in AlgART array. The storing scheme is traditional. For 2D matrix, the matrix element (x,y) is stored at the position y*dim[0]+x of the array (dim[0] is the first matrix dimension: the "width"). For 3D matrix, the matrix element (x,y,z) is stored at the position z*dim[1]*dim[0]+y*dim[0]+x (dim[0] is the x-dimension, dim[1] is the y-dimension). In the common case, the element of n-dimensional matrix with coordinates i0,i1,...,in-1 is stored in the built-in array at the position
in-1dn-2...d1d0 + ... + i2d1d0 + i1d0 + i0,
where dk=dim[k] (k=0,1,...,n-1) is the dimension #k.
There are 3 basic ways to create a new matrix.
MemoryModel.newMatrix(Class, Class, long...)
method or one of more concrete methods MemoryModel.newByteMatrix(long...),
MemoryModel.newShortMatrix(long...), etc.Matrices.matrix(Array, long...) method.matrix(Array) method of the matrix instance;
the new matrix instance will be created.
It is the basic way to change some properties of the built-in array,
for example, to convert it to immutable
or copy-on-next-write form.We do not provide special tools for accessing matrix elements by several indexes,
as "getByte(x,y)" or similar methods. But there is the index
method, that transforms a set of multidimensional indexes
i0, i2, ..., in-1
into the position in the corresponded array, as described above.
Also you can get a reference to the built-in array by the array() method.
The typical example of access to matrix elements is the following:
Matrix<UpdatableFloatArray> m = ...; m.array().setFloat(m.index(x, y, z), myValue);
There are two important notes concerning usage of matrices.
First, the matrix indexes in all methods (index,
dim(n), dim argument in MemoryModel.newMatrix, etc.) are ordered from the lowest index to the highest.
Please compare: for numeric matrix m,
Second, the number of indexes in the index method
may differ from the number of dimensions (dimCount()).
In any case, the returned position in calculated by the formula listed above
(dimCount().
The matrix object is immutable, that means that there are no ways to change
any dimension or the reference to the built-in AlgART array.
But the matrix elements can be modified, if the AlgART array is not
immutable.
So, the matrix object is thread-safe or thread-compatible
in the same situations as the built-in AlgART array: see comments to Array interface.
The generic argument T specifies the type of the built-in AlgART array.
Any array type can be declared here, but the contract of this interface
requires that the array must be unresizable.
So, there are no ways to create a matrix with MutableArray (or its subinterface)
as the type argument, alike Matrix<MutableByteArray>:
all creation methods throw IllegalArgumentException in this case.
AlgART Laboratory 2007-2013
Array,
UpdatableArray,
MutableArray| Modifier and Type | Interface and Description |
|---|---|
static class |
Matrix.ContinuationMode
Continuation mode for submatrices, created by subMatrix(long[], long[], ContinuationMode continuationMode),
subMatr(long[], long[], ContinuationMode continuationMode) and similar methods. |
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_DIM_COUNT_FOR_SOME_ALGORITHMS
Maximal number of dimensions for some complex algorithms or service classes: 9. |
| Modifier and Type | Method and Description | |
|---|---|---|
T |
array()
Returns a reference to the built-in AlgART array. |
|
|
cast(java.lang.Class<U> arrayClass)
Returns this matrix, cast to the specified generic array type, or throws ClassCastException if the built-in AlgART array cannot be cast to the required type (because the array type is not its subclass). |
|
long[] |
coordinates(long index,
long[] result)
Returns the coordinates in the matrix, corresponding to the given linear index in the built-in AlgART array. |
|
long |
cyclicIndex(long... coordinates)
An analog of index(long...) method, that, before all calculations,
replaces the passed coordinates with the positive remainders
from division of them by the corresponding matrix dimensions. |
|
long |
dim(int n)
Returns the dimension #n of this matrix or 1 if n>= dimCount(). |
|
int |
dimCount()
Returns the number of dimensions of this matrix. |
|
long[] |
dimensions()
Returns an array containing all dimensions of this matrix. |
|
boolean |
dimEquals(long... dimensions)
Indicates whether the passed dimensions are equal to the dimension array of this matrix. |
|
boolean |
dimEquals(Matrix<?> m)
Indicates whether the other matrix has the same dimension array. |
|
long |
dimX()
Equivalent to dim(0). |
|
long |
dimY()
Equivalent to dim(1). |
|
long |
dimZ()
Equivalent to dim(2). |
|
java.lang.Class<?> |
elementType()
Returns the type of matrix elements. |
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other matrix is equal to this one. |
|
void |
flushResources(ArrayContext context)
Equivalent to array().flushResources(context). |
|
void |
freeResources()
Equivalent to array().freeResources(null). |
|
void |
freeResources(ArrayContext context)
Equivalent to array().freeResources(context). |
|
int |
hashCode()
Returns the hash code of this matrix. |
|
long |
index(long... coordinates)
Returns the linear index in the built-in AlgART array of the matrix element with specified coordinates. |
|
long |
index(long x,
long y)
The simplified version of the full index method for the case
of 2-dimensional matrix. |
|
long |
index(long x,
long y,
long z)
The simplified version of the full index method for the case
of 3-dimensional matrix. |
|
boolean |
inside(long... coordinates)
Returns true if all specified coordinates ik are inside the ranges 0..dk-1, where dk= dim(k). |
|
boolean |
inside(long x,
long y)
The simplified version of the full inside method for the case
of 2-dimensional matrix. |
|
boolean |
inside(long x,
long y,
long z)
The simplified version of the full inside method for the case
of 3-dimensional matrix. |
|
boolean |
isCopyOnNextWrite()
Equivalent to array().isCopyOnNextWrite(). |
|
boolean |
isDirectAccessible()
Returns true if and only if the built-in AlgART array implements DirectAccessible
interface and ((DirectAccessible)array()).hasJavaArray() method returns true. |
|
boolean |
isImmutable()
Equivalent to array().isImmutable(). |
|
boolean |
isStructuredLike(Matrix<?> m)
Returns true if the elements of this matrix is ordered "alike" the elements of the specified matrix m, in terms of structureLike(Matrix) method. |
|
boolean |
isSubMatrix()
Returns true if and only if this matrix is a submatrix of
some parent matrix, created by one of calls parent.subMatrix(...),
parent.subMatr(...) or equivalent. |
|
boolean |
isTiled()
Not ready yet! |
|
|
matrix(U anotherArray)
Returns the new matrix backed by the specified AlgART array with the same dimensions as this one. |
|
long |
mirrorCyclicIndex(long... coordinates)
An analog of index(long...) method, that, before all calculations,
replaces the passed coordinates with the positive remainders
from division of them by the corresponding matrix dimensions
or with complement of these remainders on the dimensions,
as if the matrix would be reflected in each its bound as in a mirror. |
|
long |
pseudoCyclicIndex(long... coordinates)
An analog of index(long...) method, that does not check,
whether the passed coordinates are in the required ranges,
but replaces the resulting index with the positive remainder
from division of it by the length of the built-in array. |
|
long |
size()
Returns the total number of matrix elements. |
|
Matrix<T> |
structureLike(Matrix<?> m)
Returns a view ot this matrix, where the elements are reordered in some order "like" in the specified matrix m. |
|
Matrix<T> |
subMatr(long[] position,
long[] dimensions)
Equivalent to subMatrix(long[] from, long[] to) method, where
from[k]=position[k] and to[k]=position[k]+dimensions[k] for all k. |
|
Matrix<T> |
subMatr(long[] position,
long[] dimensions,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatrix(long[] from, long[] to, ContinuationMode continuationMode) method, where
from[k]=position[k] and to[k]=position[k]+dimensions[k] for all k. |
|
Matrix<T> |
subMatr(long x,
long y,
long dimX,
long dimY)
Equivalent to subMatr(new long[]{x,y}, new long[]{dimX,dimY}) |
|
Matrix<T> |
subMatr(long x,
long y,
long z,
long dimX,
long dimY,
long dimZ)
Equivalent to subMatr(new long[]{x,y,z}, new long[]{dimX,dimY,dimZ}) |
|
Matrix<T> |
subMatr(long x,
long y,
long z,
long dimX,
long dimY,
long dimZ,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatr(new long[]{x,y,z}, new long[]{dimX,dimY,dimZ}, continuationMode) |
|
Matrix<T> |
subMatr(long x,
long y,
long dimX,
long dimY,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatr(new long[]{x,y}, new long[]{dimX,dimY}, continuationMode) |
|
Matrix<T> |
subMatrix(IRectangularArea area)
Equivalent to subMatrix(long[] from, long[] to) method, where
from.length=to.length=area.coordCount(),
from[k]=area.min(k),
to[k]=area.max(k)+1. |
|
Matrix<T> |
subMatrix(IRectangularArea area,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatrix(long[] from, long[] to, ContinuationMode continuationMode) method, where
from.length=to.length=area.coordCount(),
from[k]=area.min(k),
to[k]=area.max(k)+1. |
|
Matrix<T> |
subMatrix(long[] from,
long[] to)
Returns a view of the rectangular fragment of this matrix between from, inclusive, and to, exclusive. |
|
Matrix<T> |
subMatrix(long[] from,
long[] to,
Matrix.ContinuationMode continuationMode)
An extended analog of subMatrix(long[], long[]) method, allowing to get a rectangular fragment
which is not fully inside this matrix. |
|
Matrix<T> |
subMatrix(long fromX,
long fromY,
long toX,
long toY)
Equivalent to subMatrix(new long[]{fromX,fromY}, new long[]{toX,toY}) |
|
Matrix<T> |
subMatrix(long fromX,
long fromY,
long fromZ,
long toX,
long toY,
long toZ)
Equivalent to subMatrix(new long[]{fromX,fromY,fromZ}, new long[]{toX,toY,toZ}) |
|
Matrix<T> |
subMatrix(long fromX,
long fromY,
long fromZ,
long toX,
long toY,
long toZ,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatrix(new long[]{fromX,fromY,fromZ}, new long[]{toX,toY,toZ}, continuationMode) |
|
Matrix<T> |
subMatrix(long fromX,
long fromY,
long toX,
long toY,
Matrix.ContinuationMode continuationMode)
Equivalent to subMatrix(new long[]{fromX,fromY}, new long[]{toX,toY}, continuationMode) |
|
Matrix.ContinuationMode |
subMatrixContinuationMode()
If this matrix is a submatrix
of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
returns the continuation mode, used by this submatrix. |
|
long[] |
subMatrixFrom()
If this matrix is a submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
creates and returns a new Java array containing the starting position of this submatrix
in the parent one. |
|
Matrix<T> |
subMatrixParent()
If this matrix is a submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
returns a reference to the parent matrix instance. |
|
long[] |
subMatrixTo()
If this matrix is a submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
creates and returns a new Java array containing the ending position (exclusive) of this submatrix
in the parent one. |
|
Matrix<T> |
tile()
Returns a tiled view ot this matrix with some default dimensions of the tiles. |
|
Matrix<T> |
tile(long... tileDim)
Returns a view ot this matrix, where the elements are reordered by tiles: a grid of rectangular regions (tiles), the sizes of which are specified by tileDim argument. |
|
long[] |
tileDimensions()
Not ready yet! |
|
Matrix<T> |
tileParent()
Not ready yet! |
|
java.lang.String |
toString()
Returns a brief string description of this object. |
|
java.lang.Class<? extends Array> |
type()
Returns array().type(). |
|
|
type(java.lang.Class<U> arraySupertype)
Returns array().type(),
if it is subtype of (or same type as) the passed arraySupertype,
or throws ClassCastException in other case. |
|
long |
uncheckedIndex(long... coordinates)
An analog of index(long...) method, that does not check,
whether the passed coordinates are in the required ranges. |
|
java.lang.Class<? extends UpdatableArray> |
updatableType()
Returns array().updatableType(). |
|
|
updatableType(java.lang.Class<U> arraySupertype)
Returns array().updatableType(),
if it is subtype of (or same type as) the passed arraySupertype,
or throws ClassCastException in other case. |
| Field Detail |
|---|
static final int MAX_DIM_COUNT_FOR_SOME_ALGORITHMS
MAX_DIM_COUNT_FOR_SOME_ALGORITHMS.
In this package and all known subpackages of net.algart package,
the following classes require that the number of dimensions must not be greater
than MAX_DIM_COUNT_FOR_SOME_ALGORITHMS:
MatrixInfo.Note: the value of this constant (9) is the maximal n so that 3n<32768=215 (39=19683). It can be useful while storing indexes of elements of little 3x3x3x... submatrix (aperture): signed short type is enough in this case.
| Method Detail |
|---|
T array()
There is a guarantee that this method works very quickly (usually it just returns a value of some private field).
java.lang.Class<?> elementType()
array().elementType().
long size()
array().length().
java.lang.Class<? extends Array> type()
array().type().
java.lang.NullPointerException - if the passed argument is null.java.lang.Class<? extends UpdatableArray> updatableType()
array().updatableType().
java.lang.NullPointerException - if the passed argument is null.<U extends Array> java.lang.Class<? extends U> type(java.lang.Class<U> arraySupertype)
array().type(),
if it is subtype of (or same type as) the passed arraySupertype,
or throws ClassCastException in other case.
(If the passed argument is a class of UpdatableArray or some its
subinterfaces or subclasses, IllegalArgumentException is thrown instead:
updatable array classes cannot be specified in this method.)
arraySupertype - the required supertype of the built-in AlgART array.java.lang.NullPointerException - if the passed argument is null.java.lang.IllegalArgumentException - if the passed argument is a class of UpdatableArray or some its
subinterfaces or subclasses (updatable classes cannot be supertypes of
for Array.type()).java.lang.ClassCastException - if arraySupertype does not allow storing
the immutable version of the built-in AlgART array.<U extends Array> java.lang.Class<? extends U> updatableType(java.lang.Class<U> arraySupertype)
array().updatableType(),
if it is subtype of (or same type as) the passed arraySupertype,
or throws ClassCastException in other case.
arraySupertype - the required supertype of the built-in AlgART array.java.lang.NullPointerException - if the passed argument is null.java.lang.ClassCastException - if arraySupertype does not allow storing
the built-in AlgART array.long[] dimensions()
The returned array is a clone of the internal dimension array, stored in this object. The returned array is never empty (its length cannot be zero). The elements of the returned array are never negative.
int dimCount()
dimensions().length, but works faster.
There is a guarantee that this method works very quickly (usually it just returns a value of some private field).
long dim(int n)
dimCount().
Equivalent to n<dimCount()?dimensions()[n]:1, but works faster.
There is a guarantee that this method works very quickly.
n - the index of dimension.java.lang.IndexOutOfBoundsException - if n<0 (but not if n is too large).long dimX()
dim(0).
long dimY()
dim(1).
long dimZ()
dim(2).
boolean dimEquals(Matrix<?> m)
dimCount())
and the corresponding dimensions (dim(k)) are equal.
m - the matrix to be compared for equal dimensions with this matrix.java.lang.NullPointerException - if the passed argument is null.dimEquals(long...)boolean dimEquals(long... dimensions)
dimCount()
and the corresponding dimensions dim(k)==dimension[k] for all k.
Note: this method does not check, whether all passed dimensions are correct (in particular, non-negative). If some elements of the passed array are incorrect, this method just returns false. But it the passed array is null, this method throws NullPointerException.
dimensions - the dimension array.java.lang.NullPointerException - if the passed argument is null.dimEquals(Matrix)long index(long... coordinates)
More precisely, index(i0,i1,...,in-1) returns the following value:
in-1dn-2...d1d0 + ... + i2d1d0 + i1d0 + i0,where dk=
dim(k).
All passed indexes ik must be in ranges 0..dk-1.
All elements of coordinates array are always used, regardless of the number of matrix dimensions.
But the extra elements of coordinates array must be zero,
because dk=1 for k>=dimCount().
Good algorithms processing the matrix should use this method rarely: usually there are more optimal ways to calculate necessary linear index. For example, if you just need to calculate something for all matrix elements, the best way is the following:
Array a = m.array();
for (long disp = 0, n = a.length(); disp < n; disp++)
// process the element #k of the array
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).java.lang.IndexOutOfBoundsException - if some coordinate ik is out of range
0..dk-1.uncheckedIndex(long...),
cyclicIndex(long...),
pseudoCyclicIndex(long...),
mirrorCyclicIndex(long...),
coordinates(long, long[]),
IPoint.toOneDimensional(long[], boolean)
long index(long x,
long y)
index method for the case
of 2-dimensional matrix.
x - the first coordinate.y - the second coordinate.dimX() + x.java.lang.IndexOutOfBoundsException - if x<0, x>=dimX(),
y<0 or y>=dimX().
long index(long x,
long y,
long z)
index method for the case
of 3-dimensional matrix.
x - the first coordinate.y - the second coordinate.z - the third coordinate.dimY() * dimX() + y * dimX() + x.java.lang.IndexOutOfBoundsException - if x<0, x>=dimX(),
y<0, y>=dimX(),
z<0 or z>=dimZ().
long[] coordinates(long index,
long[] result)
index(long...): for any index,
index(coordinates(index, null)) == indexThe result argument may be null or some array, containing at least dimCount()
elements. If the first case, this method allocates new Java array long[dimCount()]
for storing coordinates and returns it.
In the second case, this method stores the found coordinates in result array and returns it.
The returned coordinates are always in ranges
0 ≤ result[k] < dim(k)
index - the linear index in the built-in AlgART array.result - the array where you want to store results; may be null.java.lang.IllegalArgumentException - if result!=null, but result.length<dimCount().java.lang.IndexOutOfBoundsException - if index<0 or index>=dim(0)*dim(1)*...=array().length().long uncheckedIndex(long... coordinates)
index(long...) method, that does not check,
whether the passed coordinates are in the required ranges.
More precisely, uncheckedIndex(i0,i1,...,in-1) always returns the following value:
in-1dn-2...d1d0 + ... + i2d1d0 + i1d0 + i0,where dk=
dim(k).
All calculations are performed with long type without any overflow checks.
All elements of coordinates array are always used, regardless of the number of matrix dimensions.
Please remember that dk=dim(k)=1
for k>=dimCount()
(extra elements of coordinates array)..
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).long cyclicIndex(long... coordinates)
index(long...) method, that, before all calculations,
replaces the passed coordinates with the positive remainders
from division of them by the corresponding matrix dimensions.
More precisely, let i0,i1,...,in-1
are the arguments of the method. Let
dim(k)
i'k = dk == 0 ? 0 : ik % dk >= 0 ? ik % dk : ik % dk + dkThis method returns the following value:
i'n-1dn-2...d1d0 + ... + i'2d1d0 + i'1d0 + i'0,In other words, the resulting index is "cyclical".
All elements of coordinates array are always used, regardless of the number of matrix dimensions. (You can note that extra elements of coordinates array are ignored in fact: the reminders ik%dk=ik%1 will be zero for them.)
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).Matrix.ContinuationMode.CYCLIClong pseudoCyclicIndex(long... coordinates)
index(long...) method, that does not check,
whether the passed coordinates are in the required ranges,
but replaces the resulting index with the positive remainder
from division of it by the length of the built-in array.
More precisely, let i0,i1,...,in-1
are the arguments of the method, and index is the following value
(as in index(long...) method):
index = in-1dn-2...d1d0 + ... + i2d1d0 + i1d0 + i0,where dk=
dim(k).
Here we do no require that the passed indexes ik
are in ranges 0..dk-1.
Then, let len=array().length()=dn-1...d1d0.
The result of this method is the following:
len == 0 ? 0 : index % len >= 0 ? index % len : index % len + len(It is in the 0..len-1 range always, excepting the generated case len==0.) In other words, the resulting index is "pseudo-cyclical", as the resulting shift in
Matrices.asShifted(Matrix, long...) method.
All elements of coordinates array are always used, regardless of the number of matrix dimensions. (You can note that extra elements of coordinates array are ignored in fact: they add k*len summand, where k is an integer.)
Note that all calculations are performed absolutely precisely, even in a case when the direct calculation according the formulas above leads to overflow (because some of values in these formulas are out of Long.MIN_VALUE..Long.MAX_VALUE range).
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).IPoint.toOneDimensional(long[], boolean),
Matrix.ContinuationMode.PSEUDO_CYCLIClong mirrorCyclicIndex(long... coordinates)
index(long...) method, that, before all calculations,
replaces the passed coordinates with the positive remainders
from division of them by the corresponding matrix dimensions
or with complement of these remainders on the dimensions,
as if the matrix would be reflected in each its bound as in a mirror.
More precisely, let i0,i1,...,in-1
are the arguments of the method. Let
dim(k)
i'k = dk == 0 ? 0 : ik % dk >= 0 ? ik % dk : ik % dk + dk(as in
cyclicIndex(long...) and
i''k = dk == 0 ? 0 : ⌊ik / dk⌋ % 2 == 0 ? i'k : dk − 1 − i'k(here ⌊x⌋ means the integer part of x, i.e. Math.floor(x)).
This method returns the following value:
i''n-1dn-2...d1d0 + ... + i''2d1d0 + i''1d0 + i''0,
In other words, the resulting index is "mirroring-cyclical".
All elements of coordinates array are always used, regardless of the number of matrix dimensions. (You can note that extra elements of coordinates array are ignored in fact: the reminders ik%dk=ik%1 will be zero for them.)
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).Matrix.ContinuationMode.MIRROR_CYCLICboolean inside(long... coordinates)
dim(k).
This method allows simply check that the arguments of
the index method are correct and will not lead to
IndexOutOfBoundsException:
if (matrix.inside(i1, i2, ...)) {
long index = matrix.index(i1, i2, ...);
// processing an element at this index
} else {
// special branch for positions outside the matrix
}
coordinates - all coordinates.java.lang.NullPointerException - if the passed array is null.java.lang.IllegalArgumentException - if the passed array is empty (no coordinates are passed).
boolean inside(long x,
long y)
inside method for the case
of 2-dimensional matrix.
x - the first coordinate.y - the second coordinate.
boolean inside(long x,
long y,
long z)
inside method for the case
of 3-dimensional matrix.
x - the first coordinate.y - the second coordinate.z - the third coordinate.<U extends Array> Matrix<U> matrix(U anotherArray)
Matrices.matrix(anotherArray, dimensions()).
The array anotherArray must be unresizable,
and its length must be equal to the length of the array built-in this matrix.
anotherArray - some another AlgART array with the same length as array().java.lang.NullPointerException - if anotherArray argument is null.java.lang.IllegalArgumentException - if the passed array is resizable
(for example, implements MutableArray).SizeMismatchException - if the product of all dimensions is not equal to the passed array length.<U extends Array> Matrix<U> cast(java.lang.Class<U> arrayClass)
matrix((U)array), but returns
the reference to this instance and is compiled without "unchecked cast" warning.
This method is useful when you need to cast the type of AlgART array, built in this matrix, to to its sub- or superinterface.
arrayClass - the type of built-in array in the new matrix.java.lang.NullPointerException - if the argument is null.java.lang.ClassCastException - if the built-in AlgART array cannot be cast to the required type.
Matrix<T> subMatrix(long[] from,
long[] to)
More precisely, the returned matrix consists of all elements of this one with coordinates
i0, i1, ..., in−1,
n=dimCount(),
matching the following conditions:
from[0] <= i0 < to[0],
from[1] <= i1 < to[1],
. . .
from[n-1] <= in-1 < to[n-1]
So, every dimension dim(k) in the returned matrix will be equal to to[k]-from[k].
The following condition must be fulfilled for all k:
0<=from[k]<=to[k]<=thisMatrix.dim(k).
The element type of the returned matrix is identical to the element type
of this matrix.
This method is equivalent to the call
subMatrix(from,to,Matrix.ContinuationMode.NONE)
The built-in AlgART array of the returned matrix is backed by the built-in array of this matrix,
so — if this matrix is not immutable
— any changes of the elements of the returned matrix are reflected in this matrix, and vice-versa.
The returned matrix is immutable if, and only if,
the built-in array of this matrix does not implement UpdatableArray.
The Array.asTrustedImmutable() method
in the built-in array of the returned matrix is equivalent to Array.asImmutable(),
and Array.asCopyOnNextWrite() method just returns the full copy of the array.
from - low endpoints (inclusive) of all coordinates.to - high endpoints (exclusive) of all coordinates.java.lang.NullPointerException - if from or to argument is null.java.lang.IllegalArgumentException - if from.length or to.length
is not equal to dimCount().java.lang.IndexOutOfBoundsException - if, for some k,
from[k]<0 || to[k]>dim(k) ||
from[k]>to[k].subMatrix(long[], long[], ContinuationMode),
subMatrix(IRectangularArea),
subMatr(long[], long[], ContinuationMode),
subMatr(long[], long[]),
isSubMatrix()Matrix<T> subMatrix(IRectangularArea area)
subMatrix(long[] from, long[] to) method, where
from.length=to.length=area.coordCount(),
from[k]=area.min(k),
to[k]=area.max(k)+1.
area - rectangular area within this matrix.java.lang.NullPointerException - if the argument is null.java.lang.IllegalArgumentException - if area.coordCount()
is not equal to dimCount().java.lang.IndexOutOfBoundsException - if, for some k,
min[k]<0 || max[k]>=dim(k), where
min=area.min().coordinates() and,
max=area.max().coordinates().
Matrix<T> subMatrix(long fromX,
long fromY,
long toX,
long toY)
subMatrix(new long[]{fromX,fromY}, new long[]{toX,toY})
fromX - low endpoints (inclusive) of the first coordinate.fromY - low endpoints (inclusive) of the second coordinate.toX - high endpoints (exclusive) of the first coordinate.toY - high endpoints (exclusive) of the second coordinate.java.lang.IllegalArgumentException - if dimCount()!=2.java.lang.IndexOutOfBoundsException - in the same situations as in subMatrix(long[], long[]).
Matrix<T> subMatrix(long fromX,
long fromY,
long fromZ,
long toX,
long toY,
long toZ)
subMatrix(new long[]{fromX,fromY,fromZ}, new long[]{toX,toY,toZ})
fromX - low endpoints (inclusive) of the first coordinate.fromY - low endpoints (inclusive) of the second coordinate.fromZ - low endpoints (inclusive) of the third coordinate.toX - high endpoints (exclusive) of the first coordinate.toY - high endpoints (exclusive) of the second coordinate.toZ - high endpoints (exclusive) of the third coordinate.java.lang.IllegalArgumentException - if dimCount()!=3.java.lang.IndexOutOfBoundsException - in the same situations as in subMatrix(long[], long[]).
Matrix<T> subMatrix(long[] from,
long[] to,
Matrix.ContinuationMode continuationMode)
subMatrix(long[], long[]) method, allowing to get a rectangular fragment
which is not fully inside this matrix.
More precisely, unlike subMatrix(long[], long[]), here
the only requirement for the from and to coordinate boundaries is from[k]<=to[k],
but from[k] may be negative and to[k] may be greater than dim(k).
(And there is also a trivial obvious requirement
The elements of the returned matrix, that do not correspond to any elements of this one,
i.e. "lie outside" of the source matrix, are considered to be equal to some values, according to
some continuation model, described by continuationMode argument.
Such "outside" elements can correspond (according some rules) to actual elements of the source elements —
then attempts to read them return the values of the corresponding source elements
and attempts to write into them modify the corresponding source elements
(it is so for Matrix.ContinuationMode.CYCLIC, Matrix.ContinuationMode.PSEUDO_CYCLIC,
Matrix.ContinuationMode.MIRROR_CYCLIC modes),
— or can be calculated "virtually" (according some rules) —
then attempts to read them return the calculated values
and attempts to modify them are ignored
(it is so for the constant continuation mode).
See Matrix.ContinuationMode class for more details.
Important note: there are two cases, when requirements to the from and to coordinate boundaries are more strong, than described above.
Matrix.ContinuationMode.NONE, this method is strictly
equivalent to more simple subMatrix(long[], long[]) method,
so all requirements are the same as for that method.Matrix.ContinuationMode.CYCLIC,
Matrix.ContinuationMode.PSEUDO_CYCLIC or Matrix.ContinuationMode.MIRROR_CYCLIC
(but it is not a constant continuation mode) and some dimension #k
of this matrix is zero — dim(k)==0 —
then both corresponding coordinate boundaries from[k] and to[k]
must be zero (as in subMatrix(long[], long[]) method).
from - low endpoints (inclusive) of all coordinates.to - high endpoints (exclusive) of all coordinates.continuationMode - the mode of continuation outside this matrix.java.lang.NullPointerException - if from, to or continuationMode
argument is null.java.lang.IllegalArgumentException - if from.length or to.length
is not equal to dimCount().java.lang.IndexOutOfBoundsException - for continuationMode==Matrix.ContinuationMode.NONE —
see subMatrix(long[], long[]) method;
for other cases — if, for some k,
from[k]>to[k] or
dim(k)==0 and
java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.subMatr(long[], long[], ContinuationMode),
subMatrix(long[], long[]),
subMatr(long[], long[]),
isSubMatrix()
Matrix<T> subMatrix(IRectangularArea area,
Matrix.ContinuationMode continuationMode)
subMatrix(long[] from, long[] to, ContinuationMode continuationMode) method, where
from.length=to.length=area.coordCount(),
from[k]=area.min(k),
to[k]=area.max(k)+1.
area - rectangular area within this matrix.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if one of the arguments is null.java.lang.IllegalArgumentException - if area.coordCount()
is not equal to dimCount().java.lang.IndexOutOfBoundsException - if the product of all area.IRectangularArea.sizes()
(i.e. desired total size of the new matrix)
is greater than Long.MAX_VALUE.java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.
Matrix<T> subMatrix(long fromX,
long fromY,
long toX,
long toY,
Matrix.ContinuationMode continuationMode)
subMatrix(new long[]{fromX,fromY}, new long[]{toX,toY}, continuationMode)
fromX - low endpoints (inclusive) of the first coordinate.fromY - low endpoints (inclusive) of the second coordinate.toX - high endpoints (exclusive) of the first coordinate.toY - high endpoints (exclusive) of the second coordinate.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if continuationMode argument is null.java.lang.IllegalArgumentException - if dimCount()!=2.java.lang.IndexOutOfBoundsException - if fromX>toX or toX-fromX>Long.MAX_VALUE,
or if fromY>toY or toY-fromY>Long.MAX_VALUE,
or if the product (toX-fromX)*(toY-fromY)
(i.e. desired total size of the new matrix)
is greater than java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.
Matrix<T> subMatrix(long fromX,
long fromY,
long fromZ,
long toX,
long toY,
long toZ,
Matrix.ContinuationMode continuationMode)
subMatrix(new long[]{fromX,fromY,fromZ}, new long[]{toX,toY,toZ}, continuationMode)
fromX - low endpoints (inclusive) of the first coordinate.fromY - low endpoints (inclusive) of the second coordinate.fromZ - low endpoints (inclusive) of the third coordinate.toX - high endpoints (exclusive) of the first coordinate.toY - high endpoints (exclusive) of the second coordinate.toZ - high endpoints (exclusive) of the third coordinate.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if continuationMode argument is null.java.lang.IllegalArgumentException - if dimCount()!=3.java.lang.IndexOutOfBoundsException - if fromX>toX or toX-fromX>Long.MAX_VALUE,
or if fromY>toY or toY-fromY>Long.MAX_VALUE,
or if fromZ>toZ or toZ-fromZ>Long.MAX_VALUE,
or if the product (toX-fromX)*(toY-fromY)*(toZ-fromZ)
(i.e. desired total size of the new matrix)
is greater than java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.
Matrix<T> subMatr(long[] position,
long[] dimensions)
subMatrix(long[] from, long[] to) method, where
from[k]=position[k] and to[k]=position[k]+dimensions[k] for all k.
position - low endpoints (inclusive) of all coordinates.dimensions - dimensions of the returned submatrix.java.lang.NullPointerException - if position or dimensions argument is null.java.lang.IllegalArgumentException - if position.length or dimensions.length
is not equal to dimCount().java.lang.IndexOutOfBoundsException - if, for some k,
position[k]<0 || dimensions[k]<0 ||
position[k]+dimensions[k]>dim(k).subMatr(long[], long[], ContinuationMode)
Matrix<T> subMatr(long x,
long y,
long dimX,
long dimY)
subMatr(new long[]{x,y}, new long[]{dimX,dimY})
x - low endpoint (inclusive) of the first coordinate.y - low endpoint (inclusive) of the second coordinate.dimX - th first dimension of the returned submatrix.dimY - the second dimension of the returned submatrix.java.lang.IllegalArgumentException - if dimCount()!=2.java.lang.IndexOutOfBoundsException - in the same situations as in subMatr(long[], long[]).
Matrix<T> subMatr(long x,
long y,
long z,
long dimX,
long dimY,
long dimZ)
subMatr(new long[]{x,y,z}, new long[]{dimX,dimY,dimZ})
x - low endpoint (inclusive) of the first coordinate.y - low endpoint (inclusive) of the second coordinate.z - low endpoint (inclusive) of the third coordinate.dimX - th first dimension of the returned submatrix.dimY - the second dimension of the returned submatrix.dimZ - the third dimension of the returned submatrix.java.lang.IllegalArgumentException - if dimCount()!=2.java.lang.IndexOutOfBoundsException - in the same situations as in subMatr(long[], long[]).
Matrix<T> subMatr(long[] position,
long[] dimensions,
Matrix.ContinuationMode continuationMode)
subMatrix(long[] from, long[] to, ContinuationMode continuationMode) method, where
from[k]=position[k] and to[k]=position[k]+dimensions[k] for all k.
position - low endpoints (inclusive) of all coordinates.dimensions - dimensions of the returned submatrix.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if position, dimensions or continuationMode
argument is null.java.lang.IllegalArgumentException - if position.length or dimensions.length
is not equal to dimCount()/java.lang.IndexOutOfBoundsException - if, for some k, dimensions[k]<0
or position[k]+dimensions[k]>Long.MAX_VALUE,
or if the product of all dimensions[k]
(i.e. desired total size of the new matrix)
is greater than java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.subMatr(long[], long[])
Matrix<T> subMatr(long x,
long y,
long dimX,
long dimY,
Matrix.ContinuationMode continuationMode)
subMatr(new long[]{x,y}, new long[]{dimX,dimY}, continuationMode)
x - low endpoint (inclusive) of the first coordinate.y - low endpoint (inclusive) of the second coordinate.dimX - th first dimension of the returned submatrix.dimY - the second dimension of the returned submatrix.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if continuationMode argument is null.java.lang.IllegalArgumentException - if dimCount()!=2.java.lang.IndexOutOfBoundsException - if dimX<0, dimY<0, x+dimX>Long.MAX_VALUE
or y+dimY>Long.MAX_VALUE,
or if the product dimX*dimY
(i.e. desired total size of the new matrix)
is greater than java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.
Matrix<T> subMatr(long x,
long y,
long z,
long dimX,
long dimY,
long dimZ,
Matrix.ContinuationMode continuationMode)
subMatr(new long[]{x,y,z}, new long[]{dimX,dimY,dimZ}, continuationMode)
x - low endpoint (inclusive) of the first coordinate.y - low endpoint (inclusive) of the second coordinate.z - low endpoint (inclusive) of the third coordinate.dimX - th first dimension of the returned submatrix.dimY - the second dimension of the returned submatrix.dimZ - the third dimension of the returned submatrix.continuationMode - the value returned while reading elements, lying outside this matrix.java.lang.NullPointerException - if continuationMode argument is null.java.lang.IllegalArgumentException - if dimCount()!=3.java.lang.IndexOutOfBoundsException - if dimX<0, dimY<0, dimZ<0,
x+dimX>Long.MAX_VALUE, y+dimY>Long.MAX_VALUE
or z+dimZ>Long.MAX_VALUE,
or if the product dimX*dimY*dimZ
(i.e. desired total size of the new matrix)
is greater than java.lang.ClassCastException - if continuationMode is a constant mode,
the continuation constant is not null and the class of this
constant is illegal, i.e.
cannot be casted to the necessary type according the rules, specified
for the constant continuation mode.boolean isSubMatrix()
submatrix of
some parent matrix, created by one of calls parent.subMatrix(...),
parent.subMatr(...) or equivalent.
The subMatrixParent() method throws NotSubMatrixException
if and only if this method returns false.
subMatrix(long[], long[]),
subMatrix(long[], long[], ContinuationMode),
subMatr(long[], long[]),
subMatr(long[], long[], ContinuationMode),
subMatrixParent()Matrix<T> subMatrixParent()
submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
returns a reference to the parent matrix instance.
If this matrix is not a submatrix, throws NotSubMatrixException.
NotSubMatrixException - if this object is not created by subMatrix(...),
subMatr(...) or equivalent call.isSubMatrix()long[] subMatrixFrom()
submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
creates and returns a new Java array containing the starting position of this submatrix
in the parent one. The result will be equal to "from" argument of
subMatrix(long[], long[]) and subMatrix(long[], long[], ContinuationMode) methods.
If this matrix is not a submatrix, throws NotSubMatrixException.
NotSubMatrixException - if this object is not created by subMatrix(...),
subMatr(...) or equivalent call.isSubMatrix()long[] subMatrixTo()
submatrix of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
creates and returns a new Java array containing the ending position (exclusive) of this submatrix
in the parent one. The result will be equal to "to" argument of
subMatrix(long[], long[]) and subMatrix(long[], long[], ContinuationMode) methods.
If this matrix is not a submatrix, throws NotSubMatrixException.
NotSubMatrixException - if this object is not created by subMatrix(...),
subMatr(...) or equivalent call.isSubMatrix()Matrix.ContinuationMode subMatrixContinuationMode()
submatrix
of some parent matrix,
created by one of calls parent.subMatrix(...) or parent.subMatr(...),
returns the continuation mode, used by this submatrix.
If this matrix is not a submatrix, throws NotSubMatrixException.
If the submatrix was created by
subMatrix(long[], long[], net.algart.arrays.Matrix.ContinuationMode) or equivalent method,
the continuationMode argument, passed to that method, is returned.
If the submatrix was created by
subMatrix(long[], long[]) or equivalent method,
Matrix.ContinuationMode.NONE constant is returned.
NotSubMatrixException - if this object is not created by subMatrix(...),
subMatr(...) or equivalent call.isSubMatrix()Matrix<T> structureLike(Matrix<?> m)
built-in array of the returned matrix are
the same as the elements of the built-in array of this one
(any changes of the elements of the returned matrix are reflected in this matrix, and vice-versa),
but the order of the elements can differ. The precise algorithm of reordering is not specified
and depends of the matrix m: this method tries to help algorithms, processing the same
or similar areas in both matrices, to provide maximal performance.
This method returns non-trivial results only if the matrix m is already a view of some other
matrix with some form of reordering elements, for example, if m is a tiled matrix.
In other case, this method just returns this instance.
In the current version of this package (if this instance was created by means of methods of this package), this method is equivalent to the following:
m.isTiled()? thisInstance.tile(m.tileDimensions()) : thisInstance;
In future versions, it is possible that this method will recognize other forms of reordering matrix elements and return non-trivial results for such m matrices.
Because the precise order of elements of the returning matrix is not specified, we recommend to use this method generally for newly created matrices, for example:
memoryModel.or, more briefly,newMatrix(UpdatablePArray.class, m).structureLike(m);
memoryModel.newStructuredMatrix(UpdatablePArray.class, m);
m - some matrix, probably a view of another matrix with reordered elements
(for example, tiled).java.lang.NullPointerException - if m argument is null.isStructuredLike(Matrix)boolean isStructuredLike(Matrix<?> m)
structureLike(Matrix) method.
"Ordered alike" does not mean that the dimensions of both matrices are equal, or that
the details of the structure are the same; it means only that both matrices use similar
reordering algorithms.
More precisely, structureLike(Matrix) method returns this instance if and only if
this method returns true.
In the current version of this package (if this instance was created by means of methods of this package),
this method is equivalent to: thisInstance.isTiled()==m.isTiled().
m - some matrix, probably a view of another matrix with reordered elements
(for example, tiled).java.lang.NullPointerException - if m argument is null.Matrix<T> tile(long... tileDim)
dimensions
of the returned matrix are the same as the dimensions of this one.
The element type of the returned matrix is identical to the element type
of this matrix.
More precisely, let this matrix be M and the tiled matrix, returned by this method, be T.
Let i0, i1, ..., in−1
(n=dimCount()) be coordinates of some element it the tiled matrix T,
that is located in T.array()
at the index i=T.index(i0,i1,...,in−1).
This element is located in the original array M.array() at another index
j, which is calculated by the following algorithm.
dim(k),
k=0,1,...,n−1: dimensions of this and returned matrix.array() before the given element.
In 2-dimensional case, the formula is more simple:
previousVolume = dxsy
+ sxty.
array()
is Tiled matrices are necessary to provide good performance of many algorithms, if this matrix is very large (much greater than amount of RAM) and is located on disk or other external devices. For example, extracting a rectangular area 1000x1000 from a byte matrix 1000000x1000000 (1 terabyte) will probably work much faster if it is tiled, than if it is a usual matrix, where every line occupies 1 MB of continuous disk space.
In the degenerated case of 1-dimensional matrix (dimCount()=1)
the tiled matrix is absolutely useless, though still works correctly.
Recommended tile dimensions are from several hundreds to several thousands, but it depends on the number of dimensions. If tile dimensions are degrees of two (2k), the tiled matrix will probably work faster.
The built-in AlgART array of the returned matrix is backed by the built-in array of this matrix,
so — if this matrix is not immutable
— any changes of the elements of the returned matrix are reflected in this matrix, and vice-versa.
The returned matrix is immutable if, and only if,
the built-in array of this matrix does not implement UpdatableArray.
The Array.asTrustedImmutable() method
in the built-in array of the returned matrix is equivalent to Array.asImmutable(),
and Array.asCopyOnNextWrite() method just returns the full copy of the array.
tileDim - dimensions of the tiles in the returned matrix (excepting the boundary tiles,
which can be less).java.lang.NullPointerException - if tileDim argument is null.java.lang.IllegalArgumentException - if tileDim.lengthdimCount(),
or if some tileDim[k]<=0,
or if the product of all tile dimensions tileDim[k]
is greater than tile(),
isTiled(),
tileDimensions()Matrix<T> tile()
tile(tileDim), where all elements of tileDim
are equal to the default integer value, retrieved from the system property
"net.algart.arrays.matrixTile2D",
"net.algart.arrays.matrixTile3D"
"net.algart.arrays.matrixTile4D"
"net.algart.arrays.matrixTile5D" or
"net.algart.arrays.matrixTileND",
if the number of dimensions of this matrix is correspondingly 2, 3, 4, 5 or greater.
If there is no such property, or if it contains not a number,
or if some exception occurred while calling Long.getLong,
this method uses the following tile dimensions:
4096x4096 in 2-dimensional case,
256x256x256 in 3-dimensional case,
64x64x64x64 in 4-dimensional case,
32x32x32x32x32 in 5-dimensional case,
16x16x... if the number of dimensions is greater than 5.
If the corresponding property exists and contains a valid integer number,
but it is too small, in particular, zero or negative, then it is replaced with some minimal positive value.
The values of all these system property is loaded and checked only once
while initializing Arrays class.
If the number of dimensions is 1 (degenerated case), this method always uses 65536 as the tile size.
(Warning! These defaults can be changed in future versions!)
java.lang.IllegalArgumentException - if the product of all tile dimensions tileDim[k]
is greater than tile(long...),
isTiled(),
tileDimensions()Matrix<T> tileParent()
long[] tileDimensions()
boolean isTiled()
boolean isImmutable()
array().isImmutable().
There is a guarantee that this method works very quickly.
boolean isCopyOnNextWrite()
array().isCopyOnNextWrite().
There is a guarantee that this method works very quickly.
boolean isDirectAccessible()
DirectAccessible
interface and ((DirectAccessible)array()).hasJavaArray() method returns true.
There is a guarantee that this method works very quickly.
void flushResources(ArrayContext context)
array().flushResources(context).
context - the context of execution; may be null, then it will be ignored.void freeResources(ArrayContext context)
array().freeResources(context).
context - the context of execution; may be null, then it will be ignored.void freeResources()
array().freeResources(null).
java.lang.String toString()
The result of this method may depend on implementation and usually contains a short description of the built-in AlgART array and all matrix dimensions.
toString in class java.lang.Objectint hashCode()
Array.hashCode() and all matrix dimensions.
hashCode in class java.lang.Objectboolean equals(java.lang.Object obj)
Matrix),dimCount())
and the same corresponding dimensions;array()) are equal (see Array.equals(Object)).
equals in class java.lang.Objectobj - the object to be compared for equality with this matrix.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||