26 #ifndef CASADI_SLICE_HPP
27 #define CASADI_SLICE_HPP
30 #include "exception.hpp"
31 #include "printable.hpp"
34 #include "generic_type.hpp"
37 class SerializingStream;
38 class DeserializingStream;
48 :
public SWIG_IF_ELSE(PrintableCommon, Printable<Slice>) {
60 explicit Slice(casadi_int i,
bool ind1=
false);
63 Slice(casadi_int start, casadi_int stop, casadi_int step=1);
64 Slice(
int start,
int stop,
int step=1);
65 Slice(
int start, casadi_int stop,
int step=1);
66 Slice(casadi_int start,
int stop,
int step=1);
69 std::vector<casadi_int>
all()
const;
72 std::vector<casadi_int>
all(casadi_int len,
bool ind1=
false)
const;
75 std::vector<casadi_int>
all(
const Slice& outer, casadi_int len)
const;
87 casadi_int
scalar(casadi_int len)
const;
91 return start==other.
start && stop==other.
stop && step==other.
step;
110 void disp(std::ostream& stream,
bool more=
false)
const;
114 std::stringstream ss;
121 return {{
"start", start}, {
"stop", stop}, {
"step", step}};
136 Slice CASADI_EXPORT
to_slice(
const std::vector<casadi_int>& v,
bool ind1=
false);
139 std::pair<Slice, Slice> CASADI_EXPORT
to_slice2(
const std::vector<casadi_int>& v);
142 bool CASADI_EXPORT
is_slice(
const std::vector<casadi_int>& v,
bool ind1=
false);
145 bool CASADI_EXPORT
is_slice2(
const std::vector<casadi_int>& v);
Helper class for Serialization.
Helper class for Serialization.
Class representing a Slice.
std::string type_name() const
Get name of the class.
void serialize(SerializingStream &s) const
Serialize an object.
Slice operator-(casadi_int i) const
Substract.
std::vector< casadi_int > all() const
Get a vector of indices.
size_t size() const
Get number of elements.
static Slice deserialize(DeserializingStream &s)
Deserialize without type information.
casadi_int scalar(casadi_int len) const
Get scalar (if is_scalar)
bool is_empty() const
Check if slice is empty.
Slice apply(casadi_int len, bool ind1=false) const
Apply concrete length.
Slice(casadi_int i, bool ind1=false)
A single element (explicit to avoid ambiguity with IM overload.
casadi_int stop
stop value: use std::numeric_limits<casadi_int>::max() to indicate unboundedness
bool operator==(const Slice &other) const
Check equality.
Slice()
Default constructor - all elements.
std::vector< casadi_int > all(casadi_int len, bool ind1=false) const
Get a vector of indices.
Slice(casadi_int start, int stop, int step=1)
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.
std::string get_str(bool more=false) const
Get string representation.
Slice operator*(casadi_int i) const
Slice(casadi_int start, casadi_int stop, casadi_int step=1)
A slice.
std::vector< casadi_int > all(const Slice &outer, casadi_int len) const
Get a vector of indices (nested slice)
Slice(int start, int stop, int step=1)
bool operator!=(const Slice &other) const
Check inequality.
bool is_scalar(casadi_int len) const
Is the slice a scalar.
casadi_int start
start value: negative values will get added to length
Slice(int start, casadi_int stop, int step=1)
bool CASADI_EXPORT is_slice(const IM &x, bool ind1=false)
Is the IM a Slice.
std::pair< Slice, Slice > CASADI_EXPORT to_slice2(const std::vector< casadi_int > &v)
Construct nested slices from an index vector (requires is_slice2(v) to be true)
bool CASADI_EXPORT is_slice2(const std::vector< casadi_int > &v)
Check if an index vector can be represented more efficiently as two nested slices.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
Slice CASADI_EXPORT to_slice(const IM &x, bool ind1=false)
Convert IM to Slice.