Class FieldView

Inheritance Relationships

Derived Type

Class Documentation

class FieldView

Non-owning wrapper over a memory pointer that allows for type safe conversion to typed pointer, eigen array or ArrayView.

Subclassed by ouster::sdk::core::Field

Public Functions

FieldView() noexcept

Default constructor for empty FieldView.

FieldView(void *ptr, const FieldDescriptor &desc)

Initialize FieldView with a pointer and a descriptor.

Parameters:
  • ptr[in] – Memory pointer.

  • desc[in]Field descriptor.

template<typename T = void>
inline T *get()

Returns arbitrary pointer type.

Throws:

std::invalid_argument – on type mismatch unless FieldView was constructed typeless (with type void) or dereference type is void*

Template Parameters:

T – pointer type

Returns:

typed pointer to the memory

template<typename T = void>
inline const T *get() const

Returns arbitrary pointer type.

Throws:

std::invalid_argument – on type mismatch unless FieldView was constructed typeless (with type void) or dereference type is void*

Template Parameters:

T – pointer type

Returns:

typed pointer to the memory

template<typename T>
inline operator T*()

Arbitrary type ptr conversion.

Throws:

std::invalid_argument – on type mismatch unless FieldView was constructed with void ptr or the requested ptr type is void*

template<typename T>
inline operator const T*() const

Arbitrary type const ptr conversion.

Throws:

std::invalid_argument – on type mismatch unless FieldView was constructed with void ptr or the requested ptr type is void*

template<typename T, size_t Dim>
inline operator ArrayView<T, Dim>()

Arbitrary type ArrayView conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T, size_t Dim>
inline operator ConstArrayView<T, Dim>() const

Arbitrary type const ArrayView conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<img_t<T>>()

Arbitrary type Eigen 2D array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<const img_t<T>>() const

Arbitrary type const Eigen 2D array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<Eigen::Array<T, Eigen::Dynamic, 1>>()

Arbitrary type const Eigen 1D array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<const Eigen::Array<T, Eigen::Dynamic, 1>>() const

Arbitrary type const Eigen 1D array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<Eigen::Array<T, Eigen::Dynamic, 3, Eigen::RowMajor>>()

Arbitrary type const Eigen Nx3 array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

template<typename T>
inline operator Eigen::Ref<const Eigen::Array<T, Eigen::Dynamic, 3, Eigen::RowMajor>>() const

Arbitrary type const Eigen Nx3 array conversion.

Throws:
  • std::invalid_argument – on type mismatch

  • std::invalid_argument – on dimensional shape mismatch

explicit operator bool() const noexcept

Bool conversion.

Returns:

true if FieldView is owning a resource

template<typename ...Args>
inline FieldView subview(Args... idx) const

Get a subview.

Operates similarly to numpy ndarray bracket operator, returning a sliced, potentially sparse subview

The following two snippets are functionally equivalent

std::vector<int> data(100*100*100);
FieldView view(data.data(), fd_array<int>(100, 100, 100));
// get a slice of all elements in the first dimension with second
// and third pinned to 10 and 20 respectively
FieldView subview = view.subview(keep(), 10, 20);

import numpy as np
arr = np.ndarray(shape=(100,100,100), dtype=np.int32)
subview = arr[:,10,20]
Throws:

std::invalid_argument – If FieldView ran out of dimensions to subview or if FieldView cannot subview over the shape limits

Parameters:

idx[in] parameter pack of int indices or idx_range (keep())

Returns:

FieldView subview

template<typename ...Args>
inline FieldView reshape(Args... dims) const

Reshape field view to a different set of dimensions.

Throws:
  • std::invalid_argument – on trying to reshape a sparse FieldView

  • std::invalid_argument – on flattened dimension size not matching the original view size

Parameters:

dims[in] new dimensions

Returns:

reshaped FieldView with new dimensions

size_t bytes() const noexcept

Returns the number of allocated bytes in memory.

Returns:

size in bytes

size_t size() const

Returns size in elements, or 1 if field is not an array.

Returns:

size in elements

bool matches(const FieldDescriptor &d) const noexcept

returns true if FieldView matches descriptor

Parameters:

d[in] – descriptor to check

Returns:

true if matched, otherwise false

const FieldDescriptor &desc() const

Get descriptor of the underlying memory.

Returns:

FieldDescriptor

const std::vector<size_t> &shape() const

Get shape of the stored array, if present.

shorthand for desc().shape

Returns:

vector of dimensions

ChanFieldType tag() const

Get type tag, if applicable.

Returns:

ChanFieldType

bool sparse() const

Check if the FieldView is not contiguous.

Returns:

true if sparse