docstr: Generate a C++ function that mimics the im2col algorithm. This function works for 1D convolution.
  
  The HLS compiler produces suboptimal designs for a im2col algorithm implementation, so a trick we use is
  to generate a resulting a result of im2col transformation explicitly, instead of relying on loops. Since
  the result depends on the paraleters of the convolution layer (the input size, the kernel size, stride etc),
  we need to do this for every convolution layer.
  
  Args:
      layer_idx (int): Index of layer ('index' attribute).
      n_partitions (int): Number of partitions to divide the input into.
          The pixels in each partition will be processed in parallel.
      in_W (int): Width of input.
      in_C (int): Number of channels.
      kernel (int, optional): Size of the kernel. Defaults to 3.
      stride (int, optional): Stride length. Defaults to 1.
      pad (int or Iterable, optional): Padding to apply. Defaults to 0.
          Specified as either a number or a list [left_pad, right_pad].
      dilation (int, optional): Dilation rate. Defaults to 1.
  
  Returns:
      str: Generated C++ function
docstr_tok: ["Generate","a","C++","function","that","mimics","the","im2col","algorithm",".","This","function","works","for","1D","convolution",".","The","HLS","compiler","produces","suboptimal","designs","for","a","im2col","algorithm","implementation",",","so","a","trick","we","use","is","to","generate","a","resulting","a","result","of","im2col","transformation","explicitly",",","instead","of","relying","on","loops",".","Since","the","result","depends","on","the","paraleters","of","the","convolution","layer","(","the","input","size",",","the","kernel","size",",","stride","etc",")",",","we","need","to","do","this","for","every","convolution","layer",".","Args",":","layer_idx","(","int",")",":","Index","of","layer","(","'index","'","attribute",")",".","n_partitions","(","int",")",":","Number","of","partitions","to","divide","the","input","into",".","The","pixels","in","each","partition","will","be","processed","in","parallel",".","in_W","(","int",")",":","Width","of","input",".","in_C","(","int",")",":","Number","of","channels",".","kernel","(","int",",","optional",")",":","Size","of","the","kernel",".","Defaults","to","3.","stride","(","int",",","optional",")",":","Stride","length",".","Defaults","to","1.","pad","(","int","or","Iterable",",","optional",")",":","Padding","to","apply",".","Defaults","to","0",".","Specified","as","either","a","number","or","a","list","[","left_pad",",","right_pad","]",".","dilation","(","int",",","optional",")",":","Dilation","rate",".","Defaults","to","1",".","Returns",":","str",":","Generated","C++","function"]
code: def generate_conv1d_line_buffer_fn(
      self,
      layer_idx,
      n_partitions,
      in_W,
      in_C,
      kernel=3,
      stride=1,
      pad=0,
      dilation=1,
  ):
      """Generate a C++ function that mimics the im2col algorithm. This function works for 1D convolution.
  
      The HLS compiler produces suboptimal designs for a im2col algorithm implementation, so a trick we use is
      to generate a resulting a result of im2col transformation explicitly, instead of relying on loops. Since
      the result depends on the paraleters of the convolution layer (the input size, the kernel size, stride etc),
      we need to do this for every convolution layer.
  
      Args:
          layer_idx (int): Index of layer ('index' attribute).
          n_partitions (int): Number of partitions to divide the input into.
              The pixels in each partition will be processed in parallel.
          in_W (int): Width of input.
          in_C (int): Number of channels.
          kernel (int, optional): Size of the kernel. Defaults to 3.
          stride (int, optional): Stride length. Defaults to 1.
          pad (int or Iterable, optional): Padding to apply. Defaults to 0.
              Specified as either a number or a list [left_pad, right_pad].
          dilation (int, optional): Dilation rate. Defaults to 1.
  
      Returns:
          str: Generated C++ function
      """
      if isinstance(pad, Iterable):
          pad_left = pad[0]
          pad_right = pad[1]
      else:
          pad_left = pad
          pad_right = pad
  
      im2col_matrix = self._compute_conv1d_im2col(
          (in_W, in_C), kernel, stride, (pad_left, pad_right), dilation
      )
  
      generated_code = (
          "template<class data_T, typename CONFIG_T>\n"
          "class fill_buffer_{index} : public FillConv1DBuffer<data_T, CONFIG_T> {{\n"
          "    public:\n"
          "    static void fill_buffer(\n"
          "        data_T data[CONFIG_T::in_width * CONFIG_T::n_chan],\n"
          "        data_T buffer[CONFIG_T::n_pixels][CONFIG_T::filt_width * CONFIG_T::n_chan],\n"
          "        const unsigned partition\n"
          "    ) {{\n"
      ).format(index=layer_idx)
      indent = "    "
  
      for partition_idx, partition in enumerate(
          np.split(im2col_matrix, n_partitions)
      ):
          generated_code += (
              indent * 2 + f"if (partition == {partition_idx:>3}) {{\n"
          )
          for pixel_idx, arr in enumerate(partition):
              buffer_stmts = []
              for j, v in enumerate(arr):
                  if v == 0:
                      val = "0"
                  else:
                      val = f"data[{int(v - 1)}]"
                  buffer_stmts.append(
                      f"buffer[{pixel_idx}][{j}] = {val:>10};"
                  )
              generated_code += (
                  indent * 3 + " ".join(buffer_stmts) + "\n"
              )
          generated_code += "\n" + indent * 2 + "}\n"
  
      generated_code += indent + "}\n"
      generated_code += "};\n"
  
      return generated_code
  
imports: import math
  import os
  import re
  from bisect import bisect_left
  from collections.abc import Iterable
  import numpy
  from hls4ml.backends.backend import Backend
  from hls4ml.model.attributes import ChoiceAttribute, ConfigurableAttribute, TypeAttribute
  from hls4ml.model.layers import GRU, LSTM, Activation, BatchNormalization, Conv1D, Conv2D, Dense, Dot, Embedding, GarNet, GarNetStack, GlobalPooling1D, GlobalPooling2D, Pooling1D, Pooling2D, SeparableConv1D, SeparableConv2D, SimpleRNN, Softmax
  from hls4ml.model.optimizer import model_optimizer
  from hls4ml.model.types import ExponentPrecisionType, FixedPrecisionType, IntegerPrecisionType, RoundingMode, SaturationMode, XnorPrecisionType
  from hls4ml.writer import get_writer
label_desc: Use image node_id 20 for calling the FPGABackend obj's underlying member method code with example usage: obj.generate_conv1d_line_buffer_fn(layer_idx, n_partitions, in_W, in_C, kernel, stride, pad, dilation) and returns: generated_code