예제 #1
0
        public override (NDArrayOrSymbol[], NDArrayOrSymbol[]) Unroll(int length, NDArrayOrSymbol[] inputs,
                                                                      NDArrayOrSymbol[] begin_state = null, string layout = "NTC", bool?merge_outputs = null,
                                                                      Symbol valid_length           = null)
        {
            Reset();
            BaseCell._modified   = false;
            var(outputs, states) = BaseCell.Unroll(length, inputs, begin_state, layout, merge_outputs, valid_length);
            BaseCell._modified   = true;

            if (!merge_outputs.HasValue)
            {
                merge_outputs = outputs.Length > 1;
            }

            if (merge_outputs.Value)
            {
                outputs = outputs.Zip(inputs, (i, j) =>
                {
                    if (i.IsNDArray)
                    {
                        return(new NDArrayOrSymbol(nd.ElemwiseAdd(i, j)));
                    }

                    return(new NDArrayOrSymbol(sym.ElemwiseAdd(i, j)));
                }).ToArray();
            }

            return(outputs, states);
        }