Writes single scalar value to Tensorboard.
5039
def _write_scalar(self, name:str, scalar_value, iteration:int)->None:
        ""
        tag = self.metrics_root + name
        self.tbwriter.add_scalar(tag=tag, scalar_value=scalar_value, global_step=iteration)
803814
def write_numeric(fmt, value, buff, byteorder='big'):
    """"""
    try:
        buff.write(fmt[byteorder].pack(value))
    except KeyError as exc:
        raise ValueError('Invalid byte order') from exc
140950
def write(self)->None:
        ""
        if len(self.gradients) == 0: return
        norms = [x.data.norm() for x in self.gradients]
        self._write_avg_norm(norms=norms)
        self._write_median_norm(norms=norms)
        self._write_max_norm(norms=norms)
        self._write_min_norm(norms=norms)
        self._write_num_zeros()
        self._write_avg_gradient()
        self._write_median_gradient()
        self._write_max_gradient()
        self._write_min_gradient()
1163098
def write_val_axis(x_axis, y_axis, axis_ids, position = nil)
      return unless axis_ids && !axis_ids.empty?

      write_val_axis_base(
        x_axis, y_axis,
        axis_ids[0],
        axis_ids[1],
        y_axis.position || position || @val_axis_position
      )
    end
9071
def sub(x1, x2, output_shape=None, name=None):
  
  output_shape = convert_to_shape(output_shape)
  if not isinstance(x2, Tensor):
    return ScalarAddOperation(x1, -x2).outputs[0]
  with tf.name_scope(name, default_name="sub"):
    x1, x2 = binary_arguments_to_tensors(x1, x2)
    return add(x1, negative(x2), output_shape=output_shape)
71980
public void writeFloat(float value) throws UnsupportedEncodingException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "writeFloat", new Float(value));
    getBodyList().add(new Float(value));
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "writeFloat");
  }
1363837
def scalar_term(self, st):
        """"""
        if isinstance(st, binary_type):
            return _ScalarTermS(st, self._jinja_sub)
        elif isinstance(st, text_type):
            return _ScalarTermU(st, self._jinja_sub)
        elif st is None:
            return _ScalarTermU(u(''), self._jinja_sub)
        else:
            return st
481945
def _write_median_gradient(self)->None:
        ""
        median_gradient = statistics.median(x.data.median() for x in self.gradients)
        self._add_gradient_scalar('median_gradient', scalar_value=median_gradient)
874591
@Override
    public INDArray scalar(Number value, long offset) {
        if (Nd4j.dataType() == DataType.DOUBLE)
            return scalar(value.doubleValue(), offset);
        if (Nd4j.dataType() == DataType.FLOAT || Nd4j.dataType() == DataType.HALF)
            return scalar(value.floatValue(), offset);
        if (Nd4j.dataType() == DataType.INT)
            return scalar(value.intValue(), offset);
        throw new IllegalStateException("Illegal data opType " + Nd4j.dataType());
    }
1340898
private void generateMTFValues() {
        final int lastShadow = this.last;
        final Data dataShadow = this.data;
        final boolean[] inUse = dataShadow.inUse;
        final byte[] block = dataShadow.block;
        final int[] fmap = dataShadow.fmap;
        final char[] sfmap = dataShadow.sfmap;
        final int[] mtfFreq = dataShadow.mtfFreq;
        final byte[] unseqToSeq = dataShadow.unseqToSeq;
        final byte[] yy = dataShadow.generateMTFValues_yy;

        // make maps
        int nInUseShadow = 0;
        for (int i = 0; i < 256; i++) {
            if (inUse[i]) {
                unseqToSeq[i] = (byte) nInUseShadow;
                nInUseShadow++;
            }
        }
        this.nInUse = nInUseShadow;

        final int eob = nInUseShadow + 1;

        for (int i = eob; i >= 0; i--) {
            mtfFreq[i] = 0;
        }

        for (int i = nInUseShadow; --i >= 0;) {
            yy[i] = (byte) i;
        }

        int wr = 0;
        int zPend = 0;

        for (int i = 0; i <= lastShadow; i++) {
            final byte ll_i = unseqToSeq[block[fmap[i]] & 0xff];
            byte tmp = yy[0];
            int j = 0;

            while (ll_i != tmp) {
                j++;
                byte tmp2 = tmp;
                tmp = yy[j];
                yy[j] = tmp2;
            }
            yy[0] = tmp;

            if (j == 0) {
                zPend++;
            } else {
                if (zPend > 0) {
                    zPend--;
                    while (true) {
                        if ((zPend & 1) == 0) {
                            sfmap[wr] = RUNA;
                            wr++;
                            mtfFreq[RUNA]++;
                        } else {
                            sfmap[wr] = RUNB;
                            wr++;
                            mtfFreq[RUNB]++;
                        }

                        if (zPend >= 2) {
                            zPend = (zPend - 2) >> 1;
                        } else {
                            break;
                        }
                    }
                    zPend = 0;
                }
                sfmap[wr] = (char) (j + 1);
                wr++;
                mtfFreq[j + 1]++;
            }
        }

        if (zPend > 0) {
            zPend--;
            while (true) {
                if ((zPend & 1) == 0) {
                    sfmap[wr] = RUNA;
                    wr++;
                    mtfFreq[RUNA]++;
                } else {
                    sfmap[wr] = RUNB;
                    wr++;
                    mtfFreq[RUNB]++;
                }

                if (zPend >= 2) {
                    zPend = (zPend - 2) >> 1;
                } else {
                    break;
                }
            }
        }

        sfmap[wr] = (char) eob;
        mtfFreq[eob]++;
        this.nMTF = wr + 1;
    }
302472
def write_tensorboard_text(self, key, input_dict):
        
        try:
            with tf.Session() as sess:
                s_op = tf.summary.text(key, tf.convert_to_tensor(
                    ([[str(x), str(input_dict[x])] for x in input_dict])))
                s = sess.run(s_op)
                self.summary_writer.add_summary(s, self.get_step)
        except:
            LOGGER.info(
                "Cannot write text summary for Tensorboard. Tensorflow version must be r1.2 or above.")
            pass
918134
void writeFloat(float value) throws IOException {
        if (Float.isNaN(value) || Float.isInfinite(value)) {
            output.append('"').append(Float.toString(value)).append('"');
        } else {
            output.append(Float.toString(value));
        }
    }
821454
private void writeSimple(Class<?> declaredType, Object value) throws IOException {
        Class<?> realType = value.getClass();
        if (realType == Integer.class) {
            output.writeInt(((Integer) value).intValue());
        } else if (realType == Long.class) {
            output.writeLong(((Long) value).longValue());
        } else if (realType == Short.class) {
            output.writeInt(((Short) value).shortValue());
        } else if (realType == Byte.class) {
            output.writeInt(((Byte) value).byteValue());
        } else if (realType == Float.class) {
            float flt = ((Float) value).floatValue();
            if (Float.isNaN(flt)) {
                // write as string
                output.writeNull();
            } else if (Float.isInfinite(flt)) {
                // write as string
                output.writeString(Float.toString(flt));
            } else {
                output.writeFloat(flt);
            }
        } else if (realType == Double.class) {
            double dbl = ((Double) value).doubleValue();
            if (Double.isNaN(dbl)) {
                // write as string
                output.writeNull();
            } else if (Double.isInfinite(dbl)) {
                // write as string
                output.writeString(Double.toString(dbl));
            } else {
                output.writeDouble(dbl);
            }
        } else if (realType == Boolean.class) {
            output.writeBoolean(((Boolean) value).booleanValue());
        } else {
            // write as a string
            try {
                String converted = settings.getConverter().convertToString(realType, value);
                if (converted == null) {
                    throw new IllegalArgumentException("Unable to write because converter returned a null string: " + value);
                }
                output.writeString(converted);
            } catch (RuntimeException ex) {
                throw new IllegalArgumentException(
                        "Unable to convert type " + declaredType.getName() + " for real type: " + realType.getName(), ex);
            }
        }
    }
140683
def write(self, b):
        """"""

        if not isinstance(b, _BINARY_TYPES):
            raise TypeError(
                "input must be one of %r, got: %r" % (_BINARY_TYPES, type(b)))

        self._buf.write(b)
        self._total_bytes += len(b)

        if self._buf.tell() >= self._min_part_size:
            self._upload_next_part()

        return len(b)
1268567
def write_float(self, number):
        
        buf = pack(self.byte_order + "f", number)
        self.write(buf)
565774
def _write_training_loss(self, iteration:int, last_loss:Tensor)->None:
        ""
        scalar_value = to_np(last_loss)
        tag = self.metrics_root + 'train_loss'
        self.tbwriter.add_scalar(tag=tag, scalar_value=scalar_value, global_step=iteration)
50537
def to_data(value):
    """"""
    # TODO: Use get_framework() for better detection.
    if value.__class__.__module__.startswith("torch"):
        import torch
        if isinstance(value, torch.nn.parameter.Parameter):
            value = value.data
        if isinstance(value, torch.Tensor):
            if value.requires_grad:
                value = value.detach()
            value = value.cpu().numpy().copy()
        # If 0-dim array, convert to scalar
        if not value.shape:
            value = value.item()
    # Convert Numpy scalar types to Python types
    if value.__class__.__module__ == "numpy" and value.__class__.__name__ != "ndarray":
        value = value.item()
    return value