code: def conv1d_sd(
      input,
      filters,
      image_shape,
      filter_shape,
      border_mode="valid",
      subsample=(1,),
      filter_flip=True,
  ):
      """
      using a single dot product
      """
      if border_mode not in ("valid", 0, (0,)):
          raise RuntimeError(
              "Unsupported border_mode for conv1d_sd: "
              "%s" % border_mode
          )
  
      batch_size, num_input_channels, input_length = image_shape
      num_filters, num_input_channels_, filter_length = filter_shape
      stride = subsample[0]
  
      if filter_length % stride > 0:
          raise RuntimeError(
              "Filter length (%d) is not a multiple of the "
              "stride (%d)" % (filter_length, stride)
          )
  
      num_steps = filter_length // stride
      output_length = (input_length - filter_length + stride) // stride
  
      # pad the input so all the shifted dot products fit inside.
      # shape is (b, c, l)
      padded_length = (
          input_length // filter_length
      ) * filter_length + (num_steps - 1) * stride
  
      # at this point, it is possible that the padded_length is SMALLER than the
      # input size. so then we have to truncate first.
      truncated_length = min(input_length, padded_length)
      input_truncated = input[:, :, :truncated_length]
  
      input_padded_shape = (
          batch_size,
          num_input_channels,
          padded_length,
      )
      input_padded = T.zeros(input_padded_shape)
      input_padded = T.set_subtensor(
          input_padded[:, :, :truncated_length], input_truncated
      )
  
      inputs = []
      for num in range(num_steps):
          shift = num * stride
          length = (padded_length - shift) // filter_length
  
          r_input_shape = (
              batch_size,
              num_input_channels,
              length,
              filter_length,
          )
          r_input = input_padded[
              :, :, shift : length * filter_length + shift
          ].reshape(r_input_shape)
  
          inputs.append(r_input)
  
      inputs_stacked = T.stack(*inputs)  # shape is (n, b, c, w, f)
      filters_flipped = filters[:, :, ::-1] if filter_flip else filters
  
      r_conved = T.tensordot(
          inputs_stacked, filters_flipped, np.asarray([[2, 4], [1, 2]])
      )
      # resulting shape is (n, b, w, n_filters)
      # output needs to be (b, n_filters, w * n)
      r_conved = r_conved.dimshuffle(1, 3, 2, 0)  # (b, n_filters, w, n)
      conved = r_conved.reshape(
          (
              r_conved.shape[0],
              r_conved.shape[1],
              r_conved.shape[2] * r_conved.shape[3],
          )
      )
      # result is (b, n_f, l)
  
      # remove padding
      return conved[:, :, :output_length]
  
file_path: Lasagne/lasagne/theano_extensions/conv.py
imports: import numpy
  import theano.tensor
  from ..utils import int_types
label_desc: Use image node_id 5 for calling a global function with example usage: conv1d_sd(input, filters, image_shape, filter_shape, border_mode, subsample, filter_flip) and returns: conved