|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | + |
| 5 | +namespace Tensorflow.Common.Types |
| 6 | +{ |
| 7 | + public static class Nest |
| 8 | + { |
| 9 | + /// <summary> |
| 10 | + /// Pack the flat items to a nested sequence by the template. |
| 11 | + /// </summary> |
| 12 | + /// <typeparam name="T"></typeparam> |
| 13 | + /// <param name="template"></param> |
| 14 | + /// <param name="flatItems"></param> |
| 15 | + /// <returns></returns> |
| 16 | + public static Nest<T> PackSequenceAs<T>(INestable<T> template, T[] flatItems) |
| 17 | + { |
| 18 | + return template.AsNest().PackSequence(flatItems); |
| 19 | + } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Pack the flat items to a nested sequence by the template. |
| 23 | + /// </summary> |
| 24 | + /// <typeparam name="T"></typeparam> |
| 25 | + /// <param name="template"></param> |
| 26 | + /// <param name="flatItems"></param> |
| 27 | + /// <returns></returns> |
| 28 | + public static Nest<T> PackSequenceAs<T>(INestable<T> template, List<T> flatItems) |
| 29 | + { |
| 30 | + return template.AsNest().PackSequence(flatItems.ToArray()); |
| 31 | + } |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Flatten the nested object. |
| 35 | + /// </summary> |
| 36 | + /// <typeparam name="T"></typeparam> |
| 37 | + /// <param name="nestedObject"></param> |
| 38 | + /// <returns></returns> |
| 39 | + public static IEnumerable<T> Flatten<T>(INestable<T> nestedObject) |
| 40 | + { |
| 41 | + return nestedObject.AsNest().Flatten(); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Map the structure with specified function. |
| 46 | + /// </summary> |
| 47 | + /// <typeparam name="TIn"></typeparam> |
| 48 | + /// <typeparam name="TOut"></typeparam> |
| 49 | + /// <param name="func"></param> |
| 50 | + /// <param name="nestedObject"></param> |
| 51 | + /// <returns></returns> |
| 52 | + public static INestStructure<TOut> MapStructure<TIn, TOut>(Func<TIn, TOut> func, INestable<TIn> nestedObject) |
| 53 | + { |
| 54 | + return nestedObject.AsNest().MapStructure(func); |
| 55 | + } |
| 56 | + |
| 57 | + public static bool IsNested<T>(INestable<T> obj) |
| 58 | + { |
| 59 | + return obj.AsNest().IsNested(); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments