public class Slice extends Object implements Cloneable, Serializable
Slice
class represents the set of indices (start, stop, step), that are used to extract specifics subsets of Dataset
.
final Dataset onedData = DatasetFactory.createFromObject(new int[]{1,2,3});
Dataset sliceData = onedData.getSlice(new Slice(1, null, null));
If Slice is specified with only one argument, this will be the stop index which is exclusive. In this case sliceData will be [1,2] :
final Dataset onedData = DatasetFactory.createFromObject(new int[]{1,2,3});
Dataset sliceData = onedData.getSlice(new Slice(2));
To create a 1D Slice, so sliceData is : [6, 5, 4], we will do :
final Dataset sliceData = DatasetFactory.createFromObject(new int[]{10,9,8,7,6,5,4,3,2,1,0});
Dataset newOnedData = sliceData.getSlice(new Slice(4, 7, 1));
Constructor and Description |
---|
Slice()
Constructs a Slice object with the start and the stop value representing
the entirety of the sliced dimension of the Dataset.
|
Slice(Integer stop)
Constructs a Slice object with, by default the start set to 0 and with a
step of 1.
|
Slice(Integer start,
Integer stop)
Constructs a Slice object with, by default a step of 1.
|
Slice(Integer start,
Integer stop,
Integer step)
Constructs a Slice object on which it is possible to chooe the start, the
stop and the step.
|
Modifier and Type | Method and Description |
---|---|
static void |
appendSliceToString(StringBuilder s,
int len,
int beg,
int end,
int del)
Appends a String representation of the Slice comparable to the python
representation.
|
Slice |
clone()
Creates a deep copy of the Slice.
|
static void |
convertFromSlice(Slice[] slice,
int[] shape,
int[] start,
int[] stop,
int[] step)
Populates given start, stop, step arrays from given slice array
|
static Slice[] |
convertFromString(String sliceString)
Converts string in a Slice array
|
static Slice[] |
convertToSlice(int[] start,
int[] stop,
int[] step)
Converts a set of integer arrays in a slice array
|
static String |
createString(int[] shape,
int[] start,
int[] stop,
int[] step)
Creates a string representing the slice taken from given shape
|
static String |
createString(Slice... slices)
Creates a string representation of slices.
|
Slice |
flip()
Flips the Slice direction, after this operation, the slice begins at
previous end point, steps in the opposite direction, and finishes at the
previous start point.
|
int |
getEnd()
Returns the last value inside of Slice.
|
int |
getLength()
Returns the maximum value of the slice.
|
int |
getNumSteps()
Returns the number of steps inside of the Slice
|
int |
getNumSteps(int beg,
int end)
Returns the number of steps inside of the Slice from a point to an other
point minus 1 because this is an exclusive index
|
int |
getPosition(int n)
Returns the index of the n-th step inside of the slice
|
Integer |
getStart()
Returns the starting index of the slice.
|
int |
getStep()
Returns the step of the slice.
|
Integer |
getStop()
Returns the stopping index of the slice.
|
boolean |
isSliceComplete()
Returns
true if the slice has a maximum size equal to the current
size, else false . |
Slice |
setLength(int length)
Sets the maximal dimensions length of the Slice.
|
boolean |
setPosition(int beg)
Move the start and end to an other index keeping the same step and the
same gap between the two values
|
void |
setStart(Integer start)
Set the starting index of the slice.
|
void |
setStep(int step)
Set the step size inside of the Slice.
|
void |
setStop(Integer stop)
Set the stopping index of the slice.
|
String |
toString()
Returns a string construction of the slice with the python form.
|
public Slice()
public Slice(Integer stop)
null
, it will be set
to the stop argument default to the end of the dimension that the slice
is applied to.stop
- the stop point of the Slicepublic Slice(Integer start, Integer stop)
null
, it will be set automatically to 0. If
the stop point of the Slice is null
, it will be set to the stop
argument default to the end of the dimension that the slice is applied
to.start
- the start point of the Slicestop
- the stop point of the Slicepublic Slice(Integer start, Integer stop, Integer step)
null
, it
will be set automatically to 0. If the stop point of the Slice is
null
, it will be set to the stop argument default to the end of
the dimension that the slice is applied to. If the the wanted step is set
to null
, it will be set by default to 1.start
- the start point of the Slice, may be null
stop
- the stop point of the Slice, may be null
step
- the step wanted to browse the Dataset, may be null
public Slice setLength(int length)
length
- Wanted size of dimensionspublic boolean isSliceComplete()
true
if the slice has a maximum size equal to the current
size, else false
.true
if slice represents complete dimension,
false
in the other case.public int getLength()
public Integer getStart()
public Integer getStop()
public int getStep()
public void setStart(Integer start)
null
, it will be set automatically to 0.start
- Starting index of the Slice, may be null
public void setStop(Integer stop)
null
, it will be set to the stop argument default to the end of
the dimension that the slice is applied to.stop
- Stopping index of the Slice, may be null
public boolean setPosition(int beg)
beg
- New starting pointtrue
if the end was reached, false
in the
other case.public int getPosition(int n)
n
- Wanted step index in the slicepublic void setStep(int step)
null
, it will be set by default to 1.step
- New wanted step, may be null
public static void appendSliceToString(StringBuilder s, int len, int beg, int end, int del)
s
- String builderlen
- Maximal length of the Slice, or -1 if not setbeg
- Start index of the Sliceend
- Stop index of the Slicedel
- Step of the Slicepublic int getNumSteps()
public int getNumSteps(int beg, int end)
beg
- Starting pointend
- (exclusive) Stopping pointpublic int getEnd()
public Slice flip()
Note : the stop value may not be preserved across two flips
public static void convertFromSlice(Slice[] slice, int[] shape, int[] start, int[] stop, int[] step)
slice
- Input array of Slices wanted to convertshape
- Input array of Slices shapesstart
- Output array of Slices startsstop
- Output array of Slices stopsstep
- Output array of Slices stepspublic static Slice[] convertToSlice(int[] start, int[] stop, int[] step)
start
- Array of Slices startsstop
- Array of Slices stopsstep
- Array of Slices stepspublic static Slice[] convertFromString(String sliceString)
sliceString
- String of the Slice arraypublic static String createString(int[] shape, int[] start, int[] stop, int[] step)
shape
- Array of Slices shapesstart
- Array of Slices startsstop
- Array of Slices stopsstep
- Array of Slices stepspublic static String createString(Slice... slices)
slices
- Wanted Slices to put inside of the string representationCopyright © 2014–2019 Eclipse Foundation. All rights reserved.