Copies gradients from param_with_grad to params

        :param params: dst parameters
        :param params_with_grad: src parameters
425535
def set_grads(params, params_with_grad):
        
        for param, param_w_grad in zip(params, params_with_grad):
            if param.grad is None:
                param.grad = torch.nn.Parameter(torch.empty_like(param))
            param.grad.data.copy_(param_w_grad.grad.data)
196845
def grad(self, ctx=None):
        
        if self._data is not None and self._grad is None:
            raise RuntimeError(
                "Cannot get gradient array for Parameter '%s' " \
                "because grad_req='null'"%(self.name))
        return self._check_and_get(self._grad, ctx)
491374
def train_batch(self, batch_info, data, target):
        
        batch_info.optimizer.zero_grad()
        loss = self.feed_batch(batch_info, data, target)
        loss.backward()

        if self.max_grad_norm is not None:
            batch_info['grad_norm'] = torch.nn.utils.clip_grad_norm_(
                filter(lambda p: p.requires_grad, self.model.parameters()),
                max_norm=self.max_grad_norm
            )

        batch_info.optimizer.step()
1240731
def gradients_X(self, dL_dK, X, X2):
        """"""
        return self._comp_grads(dL_dK, X, X2)[3]
385180
def set_params(w, src):
    
    params = extract_source_params(src)
    # this is done because for characteristic sources geometry is in
    # 'surface' attribute
    params.update(extract_geometry_params(src))

    mfd_pars, rate_pars = extract_mfd_params(src)
    params.update(mfd_pars)
    params.update(rate_pars)

    strikes, dips, rakes, np_weights = extract_source_nodal_planes(src)
    params.update(strikes)
    params.update(dips)
    params.update(rakes)
    params.update(np_weights)

    hds, hdsw = extract_source_hypocentral_depths(src)
    params.update(hds)
    params.update(hdsw)

    pstrikes, pdips = extract_source_planes_strikes_dips(src)
    params.update(pstrikes)
    params.update(pdips)
    params['sourcetype'] = striptag(src.tag)
    w.record(**params)
275877
def first_order_gradient(arr, axis=0):
  '''
  
  '''
  grad_arr = difference(arr, n=1, axis=axis)
  return np.insert(grad_arr, grad_arr.shape[axis], 0, axis=axis)
709316
def filter_requires_grad(pgroups):
    
    warnings.warn(
        "For filtering gradients, please use skorch.callbacks.Freezer.",
        DeprecationWarning)

    for pgroup in pgroups:
        output = {k: v for k, v in pgroup.items() if k != 'params'}
        output['params'] = (p for p in pgroup['params'] if p.requires_grad)
        yield output
97397
def pack(self, grads):
        
        for i, g in enumerate(grads):
            assert g.shape == self._shapes[i]

        with cached_name_scope("GradientPacker", top_level=False):
            concat_grads = tf.concat([tf.reshape(g, [-1]) for g in grads], 0, name='concatenated_grads')
            # concat_grads = tf.cast(concat_grads, tf.float16)
            grad_packs = tf.split(concat_grads, self._split_sizes)
            return grad_packs
601687
def grad(self, params, epsilon=0.0001):
        """"""
        grad = []
        for x in range(len(params)):
            temp = np.copy(params)
            temp[x] += epsilon
            temp2 = np.copy(params)
            temp2[x] -= epsilon
            grad.append((self.__cost_function(temp)-self.__cost_function(temp2))/(2*epsilon))
        return np.array(grad)
405071
def on_epoch_end(self, **kwargs):
        ""
        for p in (self.learn.model.parameters()):
                if p.requires_grad: p.grad.div_(self.acc_samples)
        if not self.drop_last: self.learn.opt.step()
        self.learn.opt.zero_grad()
85822
def trace_grad(fn, args):
  """"""
  from tensorflow.python.eager.backprop import make_vjp
  result, vjp = make_vjp(fn)(*args)
  return result, vjp
1041607
function toGradientData(v1, v2, v3, v4, v5) {
    var startColor, endColor, type, rotation, spread, d;
    var data = {};

    if (arguments.length === 1) { // The argument is a dictionary or undefined.
        d = v1 || {};
        startColor = d.startColor;
        endColor = d.endColor;
        type = d.type;
        rotation = d.rotation;
        spread = d.spread;
    } else if (arguments.length >= 2) { // The first two arguments are a start color and an end color.
        startColor = v1;
        endColor = v2;
        type = 'linear';
        rotation = 0;
        spread = 0;
        if (arguments.length === 3) {
            if (typeof v3 === 'string') { // The type can be either linear or radial.
                type = v3;
            } else if (typeof v3 === 'number') { // The type is implicitly linear and the third argument is the rotation angle.
                rotation = v3;
            }
        } else if (arguments.length === 4) {
            if (typeof v3 === 'number') { // The type is implicitly linear and the third/forth arguments are the rotation angle and gradient spread.
                rotation = v3;
                spread = v4;
            } else if (v3 === 'linear') { // The type is explicitly linear and the forth argument is the rotation angle.
                rotation = v4;
            } else if (v3 === 'radial') { // The type is explicitly radial and the forth argument is the gradient spread.
                type = v3;
                spread = v4;
            } else {
                throw new Error('Wrong argument provided: ' + v3);
            }
        } else if (arguments.length === 5) { // Type, rotation (unused in case of radial type gradient), and gradient spread.
            type = v3;
            rotation = v4;
            spread = v5;
        }
    }

    if (!startColor && startColor !== 0) {
        throw new Error('No startColor was given.');
    }
    if (!endColor && endColor !== 0) {
        throw new Error('No endColor was given.');
    }

    try {
        data.startColor = toColor(startColor);
    } catch (e1) {
        throw new Error('startColor is not a valid color: ' + startColor);
    }

    try {
        data.endColor = toColor(endColor);
    } catch (e2) {
        throw new Error('endColor is not a valid color: ' + endColor);
    }

    if (type === undefined) {
        type = 'linear';
    }
    if (type !== 'linear' && type !== 'radial') {
        throw new Error('Unknown gradient type: ' + type);
    }

    data.type = type;

    if (spread === undefined) {
        spread = 0;
    }
    if (typeof spread !== 'number') {
        throw new Error('Spread value is not a number: ' + spread);
    }

    if (type === 'linear') {
        if (rotation === undefined) {
            rotation = 0;
        }
        if (typeof rotation !== 'number') {
            throw new Error('Rotation value is not a number: ' + rotation);
        }
        data.rotation = rotation;
    }

    data.spread = clamp(spread, 0, 0.99);

    return data;
}
94993
def sde_update_gradient_full(self, gradients):
        
    
        self.variance.gradient = gradients[0]
        self.lengthscale.gradient = gradients[1]
1052848
def trainable_params_(m):
    
    if isinstance(m, collections.Sequence):
        return [p for p in m if p.requires_grad]
    else:
        return [p for p in m.parameters() if p.requires_grad]
13964
def trainable_params(m:nn.Module)->ParamList:
    ""
    res = filter(lambda p: p.requires_grad, m.parameters())
    return res
792572
def write_a_grad_fill(gradient)
      attributes = [
        ['flip',        'none'],
        ['rotWithShape', 1]
      ]
      attributes = [] if gradient[:type] == 'linear'

      @writer.tag_elements('a:gradFill', attributes) do

        # Write the a:gsLst element.
        write_a_gs_lst(gradient)

        if gradient[:type] == 'linear'
          # Write the a:lin element.
          write_a_lin(gradient[:angle])
        else
          # Write the a:path element.
          write_a_path(gradient[:type])

          # Write the a:tileRect element.
          write_a_tile_rect(gradient[:type])
        end
      end
    end
709987
def get_gradients(self) -> Dict[str, List[mx.nd.NDArray]]:
        
        # We may have None if not all parameters are optimized
        return {"dev_%d_%s" % (i, name): exe.grad_arrays[j] for i, exe in enumerate(self.executors) for j, name in
                enumerate(self.executor_group.arg_names)
                if name in self.executor_group.param_names and self.executors[0].grad_arrays[j] is not None}