Skip to content

Commit

Permalink
Merge pull request #17 from quantumlib/protos
Browse files Browse the repository at this point in the history
Pack repeated proto fields and export the .proto file
  • Loading branch information
NoureldinYosri authored Nov 5, 2024
2 parents 95fa5a3 + cc20c43 commit 48bee12
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 41 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
recursive-include . *pyx
include requirements.txt
include _version.py
include tunits/proto/tunits.proto
4 changes: 2 additions & 2 deletions tunits/core/cython/with_unit_value_array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class ValueArray(WithUnit):
def __len__(WithUnit self):
return len(self.value)

def __array__(WithUnit self, dtype=None):
def __array__(WithUnit self, dtype=None, copy: bool=False):
if self.is_dimensionless:
return np.asarray(conversion_to_double(self.conv) * self.value,
dtype=dtype)
dtype=dtype, copy=copy)

unit_array = np.full_like(self.value, self.unit, dtype=object)
result = self.value * unit_array
Expand Down
65 changes: 36 additions & 29 deletions tunits/proto/tunits.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ option java_multiple_files = true;

// Units supported for serialization.
enum UnitEnum {
DECIBEL = 1; // Power unit (dB).
DECIBEL_MILLIWATTS = 2; // Decibel-milliwatts (dBm).
RADIANS = 3; // Radians (rad).
HERTZ = 4; // Frequency unit (Hz).
VOLT = 5; // Electric potential Unit (V).
SECOND = 6; // Time unit (s).
DECIBEL = 1; // Power unit (dB).
DECIBEL_MILLIWATTS = 2; // Decibel-milliwatts (dBm).
RADIANS = 3; // Radians (rad).
HERTZ = 4; // Frequency unit (Hz).
VOLT = 5; // Electric potential Unit (V).
SECOND = 6; // Time unit (s).
}

enum Scale {
// Enum value should be the associated exponent.
YOTTA = 24; // 10^24
ZETTA = 21; // 10^21
EXA = 18; // 10^18
PETA = 15; // 10^15
TERA = 12; // 10^12
GIGA = 9; // 10^9
MEGA = 6; // 10^6
KILO = 3; // 10^3
HECTO = 2; // 10^2
DECAD = 1; // 10^1
UNITY = 0; // 1
DECI = -1; // 10^-1
CENTI = -2; // 10^-2
MILLI = -3; // 10^-3
MICRO = -6; // 10^-6
NANO = -9; // 10^-9
PICO = -12; // 10^-12
FEMTO = -15; // 10^-15
ATTO = -18; // 10^-18
ZEPTO = -21; // 10^-21
YOCTO = -24; // 10^-24
YOTTA = 24; // 10^24
ZETTA = 21; // 10^21
EXA = 18; // 10^18
PETA = 15; // 10^15
TERA = 12; // 10^12
GIGA = 9; // 10^9
MEGA = 6; // 10^6
KILO = 3; // 10^3
HECTO = 2; // 10^2
DECAD = 1; // 10^1
UNITY = 0; // 1
DECI = -1; // 10^-1
CENTI = -2; // 10^-2
MILLI = -3; // 10^-3
MICRO = -6; // 10^-6
NANO = -9; // 10^-9
PICO = -12; // 10^-12
FEMTO = -15; // 10^-15
ATTO = -18; // 10^-18
ZEPTO = -21; // 10^-21
YOCTO = -24; // 10^-24
}

// The exponent of a unit e.g.
Expand Down Expand Up @@ -79,14 +79,17 @@ message Value {
// Units are repeated to represent combinations of units (e.g. V*s and mV/us).
// Units are combined through multiplication.
repeated Unit units = 1;

oneof value {
double real_value = 2;
Complex complex_value = 3;
}
}

message DoubleArray {
repeated double values = 1;
repeated double values = 1 [
packed = true
];
}

message ComplexArray {
Expand All @@ -99,10 +102,14 @@ message ValueArray {
// Units are repeated to represent combinations of units (e.g. V*s and mV/us).
// Units are combined through multiplication.
repeated Unit units = 1;

oneof values {
// The flattened array.
DoubleArray reals = 2;
ComplexArray complexes = 3;
}
repeated uint32 shape = 4; // The shape of the array.

repeated uint32 shape = 4 [
packed = true
]; // The shape of the array.
}
24 changes: 14 additions & 10 deletions tunits/proto/tunits_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48bee12

Please sign in to comment.