Skip to content
Snippets Groups Projects

[UPD] Tensor formatting

Merged Maxence Naud requested to merge feat_precision-log into dev

Context

This MR:

  • adds a 'precision' parameter for floating-point elements Tensors
  • adds an 'offset' parameter for pretty printing
  • speeds-up Tensor formating (see barplot statistical graphic)
  • Change Tensor format to be more compact and similar to Numpy. Also, the __repr__() function now also shows Tensor data

Results

Performance comparison

A better performance while having more functionalities has been obtained.

Comparison_toString

User interface, examples

>>> import aidge_core as ai
>>> import numpy as np
>>> 
>>> A = np.random.rand(3,4)
>>> A
array([[0.6622091 , 0.5683254 , 0.93548552, 0.68983472],
       [0.52512011, 0.65322486, 0.82233094, 0.87423367],
       [0.59895995, 0.74877176, 0.21664187, 0.11510608]])
>>> T = ai.Tensor(A)
>>> T
Tensor({{ 0.66221, 0.56833, 0.93549, 0.68983},
        { 0.52512, 0.65322, 0.82233, 0.87423},
        { 0.59896, 0.74877, 0.21664, 0.11511}}, dims = [3, 4], dtype = Float64)
>>> ai.Log.set_precision(10) # set precision
>>> T
Tensor({{ 0.6622090965, 0.5683254030, 0.9354855227, 0.6898347185},
        { 0.5251201122, 0.6532248603, 0.8223309423, 0.8742336720},
        { 0.5989599518, 0.7487717633, 0.2166418691, 0.1151060795}}, dims = [3, 4], dtype = Float64)
>>> ai.Log.set_precision(0) # zero is a valid precision
>>> T
Tensor({{ 1, 1, 1, 1},
        { 1, 1, 1, 1},
        { 1, 1, 0, 0}}, dims = [3, 4], dtype = Float64)
>>> ai.Log.set_precision(-1) # does nothing and prints a notice log if `value < 0`
[NOTICE] - Impossible to set precision to -1. Must be a positive number.
>>> T
Tensor({{ 1, 1, 1, 1},
        { 1, 1, 1, 1},
        { 1, 1, 0, 0}}, dims = [3, 4], dtype = Float64)
>>>
>>> ai.Log.set_precision(30) # no maximum precision, print 0s when value is above actual floating-point representation precision
>>> U = ai.Tensor(1/3)
>>> U
Tensor(0.333333343267440795898437500000, dims = [], dtype = Float32)

Detailed major modifications

Edited by Maxence Naud

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading