Class StringToStringCastingImpl
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The cast between two descriptors of ONE string class (S → S or U → U) — NumPy's
string_to_string_cast (convert_datatype.c, string_to_string_resolve_descriptors): a longer
destination is safe (zero padding, never a view), a shorter one same_kind (truncation; a view at
offset 0 when the byte order matches), an equal one a no-op view (no) or a U byte swap
(equiv).
public sealed class StringToStringCastingImpl : CastingImpl
- Inheritance
-
StringToStringCastingImpl
- Inherited Members
Remarks
The class-level minimal safety is unsafe ("must resolve"), so can_cast for any stricter rule always
asks resolve_descriptors(DType[], DType[], out long). Its strided loop (get_strided_loop(ArrayMethodContext, bool, long[], out NDArrayMethodFlags)) is NumPy's zero-pad copy
per element; a whole-array copy between two string storages keeps NumSharp's bulk route, the unit-view copy
(truncate or zero-pad over the uint8/uint32 lanes, NumSharp.Backends.Strings.NDStringCopy).
Methods
get_strided_loop(ArrayMethodContext, bool, long[], out NDArrayMethodFlags)
NumPy's string_to_string loop (PyArray_GetStridedZeroPadCopyFn): each element's first
min(src, dst) units copied and a wider destination NUL-padded
(TransferElements(byte*, long, int, bool, byte*, long, int, bool, long)). No unit is decoded: a unit that is not a valid
code point moves unchanged, so the loop cannot fail.
public override NDInnerLoopFunc get_strided_loop(ArrayMethodContext context, bool aligned, long[] strides, out NDArrayMethodFlags flags)
Parameters
contextArrayMethodContextThe resolved descriptors: [0] the source, [1] the destination (one class, any widths).
alignedboolUnused: the copy moves bytes.
strideslong[]Unused: the loop takes the strides of each call.
flagsNDArrayMethodFlagsReceives the method's flags.
Returns
- NDInnerLoopFunc
The loop: [0] the source run, [1] the destination run, byte strides.
resolve_descriptors(DType[], DType[], out long)
NumPy's string_to_string_resolve_descriptors: the input is used as given; a missing output is the
input made canonical (same length). The safety is decided by the two item sizes and byte orders.
public override NPY_CASTING resolve_descriptors(DType[] givenDescrs, DType[] loopDescrs, out long viewOffset)
Parameters
givenDescrsDType[]The source descriptor and the requested destination descriptor (null = "same length").
loopDescrsDType[]Receives the descriptors the copy runs on.
viewOffsetlong0 when the destination can be a view of the source (it fits and the byte order matches), else NoView.
Returns
- NPY_CASTING
safe(longer),same_kind(shorter),no(identical layout) orequiv(a byte swap).