Skip to main content

arrow_schema/extension/canonical/
fixed_shape_tensor.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! FixedShapeTensor
6//!
7//! <https://arrow.apache.org/docs/format/CanonicalExtensions.html#fixed-shape-tensor>
8
9use serde_core::de::{self, MapAccess, Visitor};
10use serde_core::ser::SerializeStruct;
11use serde_core::{Deserialize, Deserializer, Serialize, Serializer};
12use std::fmt;
13
14use crate::{ArrowError, DataType, extension::ExtensionType};
15
16/// The extension type for fixed shape tensor.
17///
18/// Extension name: `arrow.fixed_shape_tensor`.
19///
20/// The storage type of the extension: `FixedSizeList` where:
21/// - `value_type` is the data type of individual tensor elements.
22/// - `list_size` is the product of all the elements in tensor shape.
23///
24/// Extension type parameters:
25/// - `value_type`: the Arrow data type of individual tensor elements.
26/// - `shape`: the physical shape of the contained tensors as an array.
27///
28/// Optional parameters describing the logical layout:
29/// - `dim_names`: explicit names to tensor dimensions as an array. The
30///   length of it should be equal to the shape length and equal to the
31///   number of dimensions.
32///   `dim_names` can be used if the dimensions have
33///   well-known names and they map to the physical layout (row-major).
34/// - `permutation`: indices of the desired ordering of the original
35///   dimensions, defined as an array.
36///   The indices contain a permutation of the values `[0, 1, .., N-1]`
37///   where `N` is the number of dimensions. The permutation indicates
38///   which dimension of the logical layout corresponds to which dimension
39///   of the physical tensor (the i-th dimension of the logical view
40///   corresponds to the dimension with number `permutations[i]` of the
41///   physical tensor).
42///   Permutation can be useful in case the logical order of the tensor is
43///   a permutation of the physical order (row-major).
44///   When logical and physical layout are equal, the permutation will
45///   always be `([0, 1, .., N-1])` and can therefore be left out.
46///
47/// Description of the serialization:
48/// The metadata must be a valid JSON object including shape of the
49/// contained tensors as an array with key `shape` plus optional
50/// dimension names with keys `dim_names` and ordering of the
51/// dimensions with key `permutation`.
52/// Example: `{ "shape": [2, 5]}`
53/// Example with `dim_names` metadata for NCHW ordered data:
54/// `{ "shape": [100, 200, 500], "dim_names": ["C", "H", "W"]}`
55/// Example of permuted 3-dimensional tensor:
56/// `{ "shape": [100, 200, 500], "permutation": [2, 0, 1]}`
57///
58/// This is the physical layout shape and the shape of the logical layout
59/// would in this case be `[500, 100, 200]`.
60///
61/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#fixed-shape-tensor>
62#[derive(Debug, Clone, PartialEq)]
63pub struct FixedShapeTensor {
64    /// The data type of individual tensor elements.
65    value_type: DataType,
66
67    /// The metadata of this extension type.
68    metadata: FixedShapeTensorMetadata,
69}
70
71impl FixedShapeTensor {
72    /// Returns a new fixed shape tensor extension type.
73    ///
74    /// # Error
75    ///
76    /// Return an error if the provided dimension names or permutations are
77    /// invalid.
78    pub fn try_new(
79        value_type: DataType,
80        shape: impl IntoIterator<Item = usize>,
81        dimension_names: Option<Vec<String>>,
82        permutations: Option<Vec<usize>>,
83    ) -> Result<Self, ArrowError> {
84        // TODO: are all data types are suitable as value type?
85        FixedShapeTensorMetadata::try_new(shape, dimension_names, permutations).map(|metadata| {
86            Self {
87                value_type,
88                metadata,
89            }
90        })
91    }
92
93    // Unlike `supports_data_type`, this needs no tensor instance. Borrowing metadata
94    // and returning the element type lets `try_new` reuse validation without cloning
95    // metadata, while `validate` can check it without constructing a tensor.
96    fn validate_impl<'a>(
97        data_type: &'a DataType,
98        metadata: &FixedShapeTensorMetadata,
99    ) -> Result<&'a DataType, ArrowError> {
100        match data_type {
101            DataType::FixedSizeList(field, list_size) if !field.is_nullable() => {
102                metadata.validate()?;
103                let expected_size = i32::try_from(metadata.list_size()).expect("overflow");
104                if *list_size != expected_size {
105                    Err(ArrowError::InvalidArgumentError(format!(
106                        "FixedShapeTensor list size mismatch, expected {expected_size} (metadata), found {list_size} (data type)"
107                    )))
108                } else {
109                    Ok(field.data_type())
110                }
111            }
112            data_type => Err(ArrowError::InvalidArgumentError(format!(
113                "FixedShapeTensor data type mismatch, expected FixedSizeList with non-nullable field, found {data_type}"
114            ))),
115        }
116    }
117
118    /// Returns the value type of the individual tensor elements.
119    pub fn value_type(&self) -> &DataType {
120        &self.value_type
121    }
122
123    /// Returns the product of all the elements in tensor shape.
124    pub fn list_size(&self) -> usize {
125        self.metadata.list_size()
126    }
127
128    /// Returns the physical shape of the contained tensors.
129    ///
130    /// [`Self::dimensions`] and [`Self::list_size`] do not identify this
131    /// shape. `[2, 6]` and `[3, 4]` are both 2-dimensional and both have
132    /// 12 elements.
133    ///
134    /// ```
135    /// # use arrow_schema::extension::FixedShapeTensor;
136    /// # use arrow_schema::DataType;
137    /// let tensor = FixedShapeTensor::try_new(DataType::Float32, [2, 6], None, None).unwrap();
138    /// assert_eq!(tensor.shape(), &[2, 6]);
139    /// assert_eq!(tensor.list_size(), 12);
140    /// ```
141    pub fn shape(&self) -> &[usize] {
142        self.metadata.shape()
143    }
144
145    /// Returns the number of dimensions in this fixed shape tensor.
146    pub fn dimensions(&self) -> usize {
147        self.metadata.dimensions()
148    }
149
150    /// Returns the names of the dimensions in this fixed shape tensor, if
151    /// set.
152    pub fn dimension_names(&self) -> Option<&[String]> {
153        self.metadata.dimension_names()
154    }
155
156    /// Returns the indices of the desired ordering of the original
157    /// dimensions, if set.
158    pub fn permutations(&self) -> Option<&[usize]> {
159        self.metadata.permutations()
160    }
161
162    /// Returns the logical shape.
163    ///
164    /// Logical dimension `i` has the size of physical dimension
165    /// `permutations[i]`. Without a permutation, this is the physical shape.
166    ///
167    /// Physical shape `[100, 200, 500]` and permutation `[2, 0, 1]` have
168    /// logical shape `[500, 100, 200]`.
169    ///
170    /// ```
171    /// # use arrow_schema::extension::FixedShapeTensor;
172    /// # use arrow_schema::DataType;
173    /// let tensor = FixedShapeTensor::try_new(
174    ///     DataType::Float32,
175    ///     [100, 200, 500],
176    ///     None,
177    ///     Some(vec![2, 0, 1]),
178    /// )
179    /// .unwrap();
180    /// assert_eq!(tensor.logical_shape(), vec![500, 100, 200]);
181    /// ```
182    pub fn logical_shape(&self) -> Vec<usize> {
183        self.metadata.logical_shape()
184    }
185}
186
187/// Extension type metadata for [`FixedShapeTensor`].
188#[derive(Debug, Clone, PartialEq)]
189pub struct FixedShapeTensorMetadata {
190    /// The physical shape of the contained tensors.
191    shape: Vec<usize>,
192
193    /// Explicit names to tensor dimensions.
194    dim_names: Option<Vec<String>>,
195
196    /// Indices of the desired ordering of the original dimensions.
197    permutations: Option<Vec<usize>>,
198}
199
200impl Serialize for FixedShapeTensorMetadata {
201    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
202    where
203        S: Serializer,
204    {
205        let mut state = serializer.serialize_struct("FixedShapeTensorMetadata", 3)?;
206        state.serialize_field("shape", &self.shape)?;
207        state.serialize_field("dim_names", &self.dim_names)?;
208        state.serialize_field("permutations", &self.permutations)?;
209        state.end()
210    }
211}
212
213#[derive(Debug)]
214enum MetadataField {
215    Shape,
216    DimNames,
217    Permutations,
218}
219
220struct MetadataFieldVisitor;
221
222impl Visitor<'_> for MetadataFieldVisitor {
223    type Value = MetadataField;
224
225    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
226        formatter.write_str("`shape`, `dim_names`, or `permutations`")
227    }
228
229    fn visit_str<E>(self, value: &str) -> Result<MetadataField, E>
230    where
231        E: de::Error,
232    {
233        match value {
234            "shape" => Ok(MetadataField::Shape),
235            "dim_names" => Ok(MetadataField::DimNames),
236            "permutations" => Ok(MetadataField::Permutations),
237            _ => Err(de::Error::unknown_field(
238                value,
239                &["shape", "dim_names", "permutations"],
240            )),
241        }
242    }
243}
244
245impl<'de> Deserialize<'de> for MetadataField {
246    fn deserialize<D>(deserializer: D) -> Result<MetadataField, D::Error>
247    where
248        D: Deserializer<'de>,
249    {
250        deserializer.deserialize_identifier(MetadataFieldVisitor)
251    }
252}
253
254struct FixedShapeTensorMetadataVisitor;
255
256impl<'de> Visitor<'de> for FixedShapeTensorMetadataVisitor {
257    type Value = FixedShapeTensorMetadata;
258
259    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
260        formatter.write_str("struct FixedShapeTensorMetadata")
261    }
262
263    fn visit_seq<V>(self, mut seq: V) -> Result<FixedShapeTensorMetadata, V::Error>
264    where
265        V: de::SeqAccess<'de>,
266    {
267        let shape = seq
268            .next_element()?
269            .ok_or_else(|| de::Error::invalid_length(0, &self))?;
270        let dim_names = seq
271            .next_element()?
272            .ok_or_else(|| de::Error::invalid_length(1, &self))?;
273        let permutations = seq
274            .next_element()?
275            .ok_or_else(|| de::Error::invalid_length(2, &self))?;
276        Ok(FixedShapeTensorMetadata {
277            shape,
278            dim_names,
279            permutations,
280        })
281    }
282
283    fn visit_map<V>(self, mut map: V) -> Result<FixedShapeTensorMetadata, V::Error>
284    where
285        V: MapAccess<'de>,
286    {
287        let mut shape = None;
288        let mut dim_names = None;
289        let mut permutations = None;
290
291        while let Some(key) = map.next_key()? {
292            match key {
293                MetadataField::Shape => {
294                    if shape.is_some() {
295                        return Err(de::Error::duplicate_field("shape"));
296                    }
297                    shape = Some(map.next_value()?);
298                }
299                MetadataField::DimNames => {
300                    if dim_names.is_some() {
301                        return Err(de::Error::duplicate_field("dim_names"));
302                    }
303                    dim_names = Some(map.next_value()?);
304                }
305                MetadataField::Permutations => {
306                    if permutations.is_some() {
307                        return Err(de::Error::duplicate_field("permutations"));
308                    }
309                    permutations = Some(map.next_value()?);
310                }
311            }
312        }
313
314        let shape = shape.ok_or_else(|| de::Error::missing_field("shape"))?;
315
316        Ok(FixedShapeTensorMetadata {
317            shape,
318            dim_names,
319            permutations,
320        })
321    }
322}
323
324impl<'de> Deserialize<'de> for FixedShapeTensorMetadata {
325    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
326    where
327        D: Deserializer<'de>,
328    {
329        deserializer.deserialize_struct(
330            "FixedShapeTensorMetadata",
331            &["shape", "dim_names", "permutations"],
332            FixedShapeTensorMetadataVisitor,
333        )
334    }
335}
336
337impl FixedShapeTensorMetadata {
338    /// Returns metadata for a fixed shape tensor extension type.
339    ///
340    /// # Error
341    ///
342    /// Return an error if the provided dimension names or permutations are
343    /// invalid.
344    pub fn try_new(
345        shape: impl IntoIterator<Item = usize>,
346        dimension_names: Option<Vec<String>>,
347        permutations: Option<Vec<usize>>,
348    ) -> Result<Self, ArrowError> {
349        let metadata = Self {
350            shape: shape.into_iter().collect(),
351            dim_names: dimension_names,
352            permutations,
353        };
354        metadata.validate()?;
355        Ok(metadata)
356    }
357
358    fn validate(&self) -> Result<(), ArrowError> {
359        let dimensions = self.dimensions();
360
361        if let Some(dimension_names) = &self.dim_names
362            && dimension_names.len() != dimensions
363        {
364            return Err(ArrowError::InvalidArgumentError(format!(
365                "FixedShapeTensor dimension names size mismatch, expected {dimensions}, found {}",
366                dimension_names.len()
367            )));
368        }
369
370        if let Some(permutations) = &self.permutations {
371            if permutations.len() != dimensions {
372                return Err(ArrowError::InvalidArgumentError(format!(
373                    "FixedShapeTensor permutations size mismatch, expected {dimensions}, found {}",
374                    permutations.len()
375                )));
376            }
377            let mut sorted_permutations = permutations.clone();
378            sorted_permutations.sort_unstable();
379            if (0..dimensions)
380                .zip(sorted_permutations)
381                .any(|(a, b)| a != b)
382            {
383                return Err(ArrowError::InvalidArgumentError(format!(
384                    "FixedShapeTensor permutations invalid, expected a permutation of [0, 1, .., N-1], where N is the number of dimensions: {dimensions}"
385                )));
386            }
387        }
388
389        Ok(())
390    }
391
392    /// Returns the physical shape of the contained tensors.
393    pub fn shape(&self) -> &[usize] {
394        &self.shape
395    }
396
397    /// Returns the product of all the elements in tensor shape.
398    pub fn list_size(&self) -> usize {
399        self.shape.iter().product()
400    }
401
402    /// Returns the number of dimensions in this fixed shape tensor.
403    pub fn dimensions(&self) -> usize {
404        self.shape.len()
405    }
406
407    /// Returns the names of the dimensions in this fixed shape tensor, if
408    /// set.
409    pub fn dimension_names(&self) -> Option<&[String]> {
410        self.dim_names.as_ref().map(AsRef::as_ref)
411    }
412
413    /// Returns the indices of the desired ordering of the original
414    /// dimensions, if set.
415    pub fn permutations(&self) -> Option<&[usize]> {
416        self.permutations.as_ref().map(AsRef::as_ref)
417    }
418
419    /// Returns the logical shape.
420    ///
421    /// See [`FixedShapeTensor::logical_shape`].
422    pub fn logical_shape(&self) -> Vec<usize> {
423        match &self.permutations {
424            Some(permutation) => permutation.iter().map(|&index| self.shape[index]).collect(),
425            None => self.shape.clone(),
426        }
427    }
428}
429
430impl ExtensionType for FixedShapeTensor {
431    const NAME: &'static str = "arrow.fixed_shape_tensor";
432
433    type Metadata = FixedShapeTensorMetadata;
434
435    fn metadata(&self) -> &Self::Metadata {
436        &self.metadata
437    }
438
439    fn serialize_metadata(&self) -> Option<String> {
440        Some(serde_json::to_string(&self.metadata).expect("metadata serialization"))
441    }
442
443    fn deserialize_metadata(metadata: Option<&str>) -> Result<Self::Metadata, ArrowError> {
444        metadata.map_or_else(
445            || {
446                Err(ArrowError::InvalidArgumentError(
447                    "FixedShapeTensor extension types requires metadata".to_owned(),
448                ))
449            },
450            |value| {
451                serde_json::from_str(value).map_err(|e| {
452                    ArrowError::InvalidArgumentError(format!(
453                        "FixedShapeTensor metadata deserialization failed: {e}"
454                    ))
455                })
456            },
457        )
458    }
459
460    fn supports_data_type(&self, data_type: &DataType) -> Result<(), ArrowError> {
461        let expected = DataType::new_fixed_size_list(
462            self.value_type.clone(),
463            i32::try_from(self.list_size()).expect("overflow"),
464            false,
465        );
466        data_type
467            .equals_datatype(&expected)
468            .then_some(())
469            .ok_or_else(|| {
470                ArrowError::InvalidArgumentError(format!(
471                    "FixedShapeTensor data type mismatch, expected {expected}, found {data_type}"
472                ))
473            })
474    }
475
476    fn try_new(data_type: &DataType, metadata: Self::Metadata) -> Result<Self, ArrowError> {
477        let value_type = Self::validate_impl(data_type, &metadata)?;
478        Ok(Self {
479            value_type: value_type.clone(),
480            metadata,
481        })
482    }
483
484    fn validate(data_type: &DataType, metadata: Self::Metadata) -> Result<(), ArrowError> {
485        Self::validate_impl(data_type, &metadata).map(|_| ())
486    }
487}
488
489#[cfg(test)]
490mod tests {
491    #[cfg(feature = "canonical_extension_types")]
492    use crate::extension::CanonicalExtensionType;
493    use crate::{
494        Field,
495        extension::{EXTENSION_TYPE_METADATA_KEY, EXTENSION_TYPE_NAME_KEY, ExtensionType},
496    };
497
498    use super::*;
499
500    #[test]
501    fn valid() -> Result<(), ArrowError> {
502        let fixed_shape_tensor = FixedShapeTensor::try_new(
503            DataType::Float32,
504            [100, 200, 500],
505            Some(vec!["C".to_owned(), "H".to_owned(), "W".to_owned()]),
506            Some(vec![2, 0, 1]),
507        )?;
508        let mut field = Field::new_fixed_size_list(
509            "",
510            Field::new("", DataType::Float32, false),
511            i32::try_from(fixed_shape_tensor.list_size()).expect("overflow"),
512            false,
513        );
514        field.try_with_extension_type(fixed_shape_tensor.clone())?;
515        assert!(field.has_valid_extension_type::<FixedShapeTensor>());
516        assert_eq!(
517            field.try_extension_type::<FixedShapeTensor>()?,
518            fixed_shape_tensor
519        );
520        assert_eq!(fixed_shape_tensor.shape(), &[100, 200, 500]);
521        assert_eq!(fixed_shape_tensor.metadata().shape(), &[100, 200, 500]);
522        #[cfg(feature = "canonical_extension_types")]
523        assert_eq!(
524            field.try_canonical_extension_type()?,
525            CanonicalExtensionType::FixedShapeTensor(fixed_shape_tensor)
526        );
527        Ok(())
528    }
529
530    #[test]
531    fn logical_shape_follows_permutation() -> Result<(), ArrowError> {
532        let physical = FixedShapeTensor::try_new(DataType::Float32, [100, 200, 500], None, None)?;
533        assert_eq!(physical.logical_shape(), vec![100, 200, 500]);
534        assert_eq!(physical.metadata().logical_shape(), vec![100, 200, 500]);
535
536        let permuted = FixedShapeTensor::try_new(
537            DataType::Float32,
538            [100, 200, 500],
539            Some(vec!["C".to_owned(), "H".to_owned(), "W".to_owned()]),
540            Some(vec![2, 0, 1]),
541        )?;
542        assert_eq!(permuted.logical_shape(), vec![500, 100, 200]);
543        assert_eq!(permuted.metadata().logical_shape(), vec![500, 100, 200]);
544
545        let identity =
546            FixedShapeTensor::try_new(DataType::Float32, [2, 6], None, Some(vec![0, 1]))?;
547        assert_eq!(identity.logical_shape(), vec![2, 6]);
548        Ok(())
549    }
550
551    #[test]
552    fn shape_distinguishes_equal_sizes() -> Result<(), ArrowError> {
553        let wide = FixedShapeTensor::try_new(DataType::Float32, [2, 6], None, None)?;
554        let tall = FixedShapeTensor::try_new(DataType::Float32, [3, 4], None, None)?;
555        assert_eq!(wide.dimensions(), tall.dimensions());
556        assert_eq!(wide.list_size(), tall.list_size());
557        assert_eq!(wide.shape(), &[2, 6]);
558        assert_eq!(tall.shape(), &[3, 4]);
559        assert_ne!(wide.shape(), tall.shape());
560        Ok(())
561    }
562
563    #[test]
564    #[should_panic(expected = "Extension type name missing")]
565    fn missing_name() {
566        let field =
567            Field::new_fixed_size_list("", Field::new("", DataType::Float32, false), 3, false)
568                .with_metadata([(
569                    EXTENSION_TYPE_METADATA_KEY,
570                    r#"{ "shape": [100, 200, 500], }"#,
571                )]);
572        field.extension_type::<FixedShapeTensor>();
573    }
574
575    #[test]
576    #[should_panic(expected = "FixedShapeTensor data type mismatch, expected FixedSizeList")]
577    fn invalid_type() {
578        let fixed_shape_tensor =
579            FixedShapeTensor::try_new(DataType::Int32, [100, 200, 500], None, None).unwrap();
580        let field = Field::new_fixed_size_list(
581            "",
582            Field::new("", DataType::Float32, false),
583            i32::try_from(fixed_shape_tensor.list_size()).expect("overflow"),
584            false,
585        );
586        field.with_extension_type(fixed_shape_tensor);
587    }
588
589    #[test]
590    #[should_panic(expected = "FixedShapeTensor extension types requires metadata")]
591    fn missing_metadata() {
592        let field =
593            Field::new_fixed_size_list("", Field::new("", DataType::Float32, false), 3, false)
594                .with_metadata([(EXTENSION_TYPE_NAME_KEY, FixedShapeTensor::NAME)]);
595        field.extension_type::<FixedShapeTensor>();
596    }
597
598    #[test]
599    #[should_panic(expected = "FixedShapeTensor metadata deserialization failed: \
600        unknown field `not-shape`, expected one of `shape`, `dim_names`, `permutations`")]
601    fn invalid_metadata() {
602        let fixed_shape_tensor =
603            FixedShapeTensor::try_new(DataType::Float32, [100, 200, 500], None, None).unwrap();
604        let field = Field::new_fixed_size_list(
605            "",
606            Field::new("", DataType::Float32, false),
607            i32::try_from(fixed_shape_tensor.list_size()).expect("overflow"),
608            false,
609        )
610        .with_metadata([
611            (EXTENSION_TYPE_NAME_KEY, FixedShapeTensor::NAME),
612            (EXTENSION_TYPE_METADATA_KEY, r#"{ "not-shape": [] }"#),
613        ]);
614        field.extension_type::<FixedShapeTensor>();
615    }
616
617    #[test]
618    fn invalid_deserialized_metadata() -> Result<(), ArrowError> {
619        let data_type = DataType::new_fixed_size_list(DataType::Float32, 6, false);
620        let metadata = FixedShapeTensor::deserialize_metadata(Some(
621            r#"{"shape":[2,3],"dim_names":["height"]}"#,
622        ))?;
623        for result in [
624            FixedShapeTensor::validate(&data_type, metadata.clone()),
625            <FixedShapeTensor as ExtensionType>::try_new(&data_type, metadata).map(|_| ()),
626        ] {
627            assert!(
628                matches!(&result, Err(ArrowError::InvalidArgumentError(message)) if message.contains("dimension names size mismatch")),
629                "expected dimension names size mismatch, got {result:?}"
630            );
631        }
632        Ok(())
633    }
634
635    #[test]
636    #[should_panic(
637        expected = "FixedShapeTensor dimension names size mismatch, expected 3, found 2"
638    )]
639    fn invalid_metadata_dimension_names() {
640        FixedShapeTensor::try_new(
641            DataType::Float32,
642            [100, 200, 500],
643            Some(vec!["a".to_owned(), "b".to_owned()]),
644            None,
645        )
646        .unwrap();
647    }
648
649    #[test]
650    #[should_panic(expected = "FixedShapeTensor permutations size mismatch, expected 3, found 2")]
651    fn invalid_metadata_permutations_len() {
652        FixedShapeTensor::try_new(DataType::Float32, [100, 200, 500], None, Some(vec![1, 0]))
653            .unwrap();
654    }
655
656    #[test]
657    #[should_panic(
658        expected = "FixedShapeTensor permutations invalid, expected a permutation of [0, 1, .., N-1], where N is the number of dimensions: 3"
659    )]
660    fn invalid_metadata_permutations_values() {
661        FixedShapeTensor::try_new(
662            DataType::Float32,
663            [100, 200, 500],
664            None,
665            Some(vec![4, 3, 2]),
666        )
667        .unwrap();
668    }
669}