diff --git a/cpp/ppx_generated.h b/cpp/ppx_generated.h index 5a60d76..ebce161 100644 --- a/cpp/ppx_generated.h +++ b/cpp/ppx_generated.h @@ -74,6 +74,12 @@ struct GammaBuilder; struct LogNormal; struct LogNormalBuilder; +struct Binomial; +struct BinomialBuilder; + +struct Weibull; +struct WeibullBuilder; + enum MessageBody { MessageBody_NONE = 0, MessageBody_Handshake = 1, @@ -196,11 +202,13 @@ enum Distribution { Distribution_Exponential = 7, Distribution_Gamma = 8, Distribution_LogNormal = 9, + Distribution_Binomial = 10, + Distribution_Weibull = 11, Distribution_MIN = Distribution_NONE, - Distribution_MAX = Distribution_LogNormal + Distribution_MAX = Distribution_Weibull }; -inline const Distribution (&EnumValuesDistribution())[10] { +inline const Distribution (&EnumValuesDistribution())[12] { static const Distribution values[] = { Distribution_NONE, Distribution_Normal, @@ -211,13 +219,15 @@ inline const Distribution (&EnumValuesDistribution())[10] { Distribution_Beta, Distribution_Exponential, Distribution_Gamma, - Distribution_LogNormal + Distribution_LogNormal, + Distribution_Binomial, + Distribution_Weibull }; return values; } inline const char * const *EnumNamesDistribution() { - static const char * const names[11] = { + static const char * const names[13] = { "NONE", "Normal", "Uniform", @@ -228,13 +238,15 @@ inline const char * const *EnumNamesDistribution() { "Exponential", "Gamma", "LogNormal", + "Binomial", + "Weibull", nullptr }; return names; } inline const char *EnumNameDistribution(Distribution e) { - if (flatbuffers::IsOutRange(e, Distribution_NONE, Distribution_LogNormal)) return ""; + if (flatbuffers::IsOutRange(e, Distribution_NONE, Distribution_Weibull)) return ""; const size_t index = static_cast(e); return EnumNamesDistribution()[index]; } @@ -279,6 +291,14 @@ template<> struct DistributionTraits { static const Distribution enum_value = Distribution_LogNormal; }; +template<> struct DistributionTraits { + static const Distribution enum_value = Distribution_Binomial; +}; + +template<> struct DistributionTraits { + static const Distribution enum_value = Distribution_Weibull; +}; + bool VerifyDistribution(flatbuffers::Verifier &verifier, const void *obj, Distribution type); bool VerifyDistributionVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); @@ -720,6 +740,12 @@ struct Sample FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const ppx::LogNormal *distribution_as_LogNormal() const { return distribution_type() == ppx::Distribution_LogNormal ? static_cast(distribution()) : nullptr; } + const ppx::Binomial *distribution_as_Binomial() const { + return distribution_type() == ppx::Distribution_Binomial ? static_cast(distribution()) : nullptr; + } + const ppx::Weibull *distribution_as_Weibull() const { + return distribution_type() == ppx::Distribution_Weibull ? static_cast(distribution()) : nullptr; + } bool control() const { return GetField(VT_CONTROL, 1) != 0; } @@ -777,6 +803,14 @@ template<> inline const ppx::LogNormal *Sample::distribution_as( return distribution_as_LogNormal(); } +template<> inline const ppx::Binomial *Sample::distribution_as() const { + return distribution_as_Binomial(); +} + +template<> inline const ppx::Weibull *Sample::distribution_as() const { + return distribution_as_Weibull(); +} + struct SampleBuilder { typedef Sample Table; flatbuffers::FlatBufferBuilder &fbb_; @@ -941,6 +975,12 @@ struct Observe FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const ppx::LogNormal *distribution_as_LogNormal() const { return distribution_type() == ppx::Distribution_LogNormal ? static_cast(distribution()) : nullptr; } + const ppx::Binomial *distribution_as_Binomial() const { + return distribution_type() == ppx::Distribution_Binomial ? static_cast(distribution()) : nullptr; + } + const ppx::Weibull *distribution_as_Weibull() const { + return distribution_type() == ppx::Distribution_Weibull ? static_cast(distribution()) : nullptr; + } const ppx::Tensor *value() const { return GetPointer(VT_VALUE); } @@ -995,6 +1035,14 @@ template<> inline const ppx::LogNormal *Observe::distribution_as return distribution_as_LogNormal(); } +template<> inline const ppx::Binomial *Observe::distribution_as() const { + return distribution_as_Binomial(); +} + +template<> inline const ppx::Weibull *Observe::distribution_as() const { + return distribution_as_Weibull(); +} + struct ObserveBuilder { typedef Observe Table; flatbuffers::FlatBufferBuilder &fbb_; @@ -1671,6 +1719,114 @@ inline flatbuffers::Offset CreateLogNormal( return builder_.Finish(); } +struct Binomial FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BinomialBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TOTAL_COUNT = 4, + VT_PROBS = 6 + }; + const ppx::Tensor *total_count() const { + return GetPointer(VT_TOTAL_COUNT); + } + const ppx::Tensor *probs() const { + return GetPointer(VT_PROBS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_TOTAL_COUNT) && + verifier.VerifyTable(total_count()) && + VerifyOffset(verifier, VT_PROBS) && + verifier.VerifyTable(probs()) && + verifier.EndTable(); + } +}; + +struct BinomialBuilder { + typedef Binomial Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_total_count(flatbuffers::Offset total_count) { + fbb_.AddOffset(Binomial::VT_TOTAL_COUNT, total_count); + } + void add_probs(flatbuffers::Offset probs) { + fbb_.AddOffset(Binomial::VT_PROBS, probs); + } + explicit BinomialBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + BinomialBuilder &operator=(const BinomialBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBinomial( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset total_count = 0, + flatbuffers::Offset probs = 0) { + BinomialBuilder builder_(_fbb); + builder_.add_probs(probs); + builder_.add_total_count(total_count); + return builder_.Finish(); +} + +struct Weibull FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef WeibullBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_SCALE = 4, + VT_CONCENTRATION = 6 + }; + const ppx::Tensor *scale() const { + return GetPointer(VT_SCALE); + } + const ppx::Tensor *concentration() const { + return GetPointer(VT_CONCENTRATION); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_SCALE) && + verifier.VerifyTable(scale()) && + VerifyOffset(verifier, VT_CONCENTRATION) && + verifier.VerifyTable(concentration()) && + verifier.EndTable(); + } +}; + +struct WeibullBuilder { + typedef Weibull Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_scale(flatbuffers::Offset scale) { + fbb_.AddOffset(Weibull::VT_SCALE, scale); + } + void add_concentration(flatbuffers::Offset concentration) { + fbb_.AddOffset(Weibull::VT_CONCENTRATION, concentration); + } + explicit WeibullBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + WeibullBuilder &operator=(const WeibullBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateWeibull( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset scale = 0, + flatbuffers::Offset concentration = 0) { + WeibullBuilder builder_(_fbb); + builder_.add_concentration(concentration); + builder_.add_scale(scale); + return builder_.Finish(); +} + inline bool VerifyMessageBody(flatbuffers::Verifier &verifier, const void *obj, MessageBody type) { switch (type) { case MessageBody_NONE: { @@ -1777,6 +1933,14 @@ inline bool VerifyDistribution(flatbuffers::Verifier &verifier, const void *obj, auto ptr = reinterpret_cast(obj); return verifier.VerifyTable(ptr); } + case Distribution_Binomial: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Distribution_Weibull: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } default: return true; } } diff --git a/csharp/ppx/Binomial.cs b/csharp/ppx/Binomial.cs new file mode 100644 index 0000000..b4edc8e --- /dev/null +++ b/csharp/ppx/Binomial.cs @@ -0,0 +1,44 @@ +// +// automatically generated by the FlatBuffers compiler, do not modify +// + +namespace ppx +{ + +using global::System; +using global::System.Collections.Generic; +using global::FlatBuffers; + +public struct Binomial : IFlatbufferObject +{ + private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } + public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); } + public static Binomial GetRootAsBinomial(ByteBuffer _bb) { return GetRootAsBinomial(_bb, new Binomial()); } + public static Binomial GetRootAsBinomial(ByteBuffer _bb, Binomial obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } + public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } + public Binomial __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } + + public ppx.Tensor? TotalCount { get { int o = __p.__offset(4); return o != 0 ? (ppx.Tensor?)(new ppx.Tensor()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } + public ppx.Tensor? Probs { get { int o = __p.__offset(6); return o != 0 ? (ppx.Tensor?)(new ppx.Tensor()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } + + public static Offset CreateBinomial(FlatBufferBuilder builder, + Offset total_countOffset = default(Offset), + Offset probsOffset = default(Offset)) { + builder.StartTable(2); + Binomial.AddProbs(builder, probsOffset); + Binomial.AddTotalCount(builder, total_countOffset); + return Binomial.EndBinomial(builder); + } + + public static void StartBinomial(FlatBufferBuilder builder) { builder.StartTable(2); } + public static void AddTotalCount(FlatBufferBuilder builder, Offset totalCountOffset) { builder.AddOffset(0, totalCountOffset.Value, 0); } + public static void AddProbs(FlatBufferBuilder builder, Offset probsOffset) { builder.AddOffset(1, probsOffset.Value, 0); } + public static Offset EndBinomial(FlatBufferBuilder builder) { + int o = builder.EndTable(); + return new Offset(o); + } +}; + + +} diff --git a/csharp/ppx/Distribution.cs b/csharp/ppx/Distribution.cs index 91acc5c..d8f1b01 100644 --- a/csharp/ppx/Distribution.cs +++ b/csharp/ppx/Distribution.cs @@ -17,6 +17,8 @@ public enum Distribution : byte Exponential = 7, Gamma = 8, LogNormal = 9, + Binomial = 10, + Weibull = 11, }; diff --git a/csharp/ppx/Weibull.cs b/csharp/ppx/Weibull.cs new file mode 100644 index 0000000..c506f29 --- /dev/null +++ b/csharp/ppx/Weibull.cs @@ -0,0 +1,44 @@ +// +// automatically generated by the FlatBuffers compiler, do not modify +// + +namespace ppx +{ + +using global::System; +using global::System.Collections.Generic; +using global::FlatBuffers; + +public struct Weibull : IFlatbufferObject +{ + private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } + public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); } + public static Weibull GetRootAsWeibull(ByteBuffer _bb) { return GetRootAsWeibull(_bb, new Weibull()); } + public static Weibull GetRootAsWeibull(ByteBuffer _bb, Weibull obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } + public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); } + public Weibull __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } + + public ppx.Tensor? Scale { get { int o = __p.__offset(4); return o != 0 ? (ppx.Tensor?)(new ppx.Tensor()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } + public ppx.Tensor? Concentration { get { int o = __p.__offset(6); return o != 0 ? (ppx.Tensor?)(new ppx.Tensor()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } + + public static Offset CreateWeibull(FlatBufferBuilder builder, + Offset scaleOffset = default(Offset), + Offset concentrationOffset = default(Offset)) { + builder.StartTable(2); + Weibull.AddConcentration(builder, concentrationOffset); + Weibull.AddScale(builder, scaleOffset); + return Weibull.EndWeibull(builder); + } + + public static void StartWeibull(FlatBufferBuilder builder) { builder.StartTable(2); } + public static void AddScale(FlatBufferBuilder builder, Offset scaleOffset) { builder.AddOffset(0, scaleOffset.Value, 0); } + public static void AddConcentration(FlatBufferBuilder builder, Offset concentrationOffset) { builder.AddOffset(1, concentrationOffset.Value, 0); } + public static Offset EndWeibull(FlatBufferBuilder builder) { + int o = builder.EndTable(); + return new Offset(o); + } +}; + + +} diff --git a/dart/ppx_ppx_generated.dart b/dart/ppx_ppx_generated.dart index 57286f0..a60458e 100644 --- a/dart/ppx_ppx_generated.dart +++ b/dart/ppx_ppx_generated.dart @@ -69,7 +69,7 @@ class DistributionTypeId { } static const int minValue = 0; - static const int maxValue = 9; + static const int maxValue = 11; static bool containsValue(int value) => values.containsKey(value); static const DistributionTypeId NONE = const DistributionTypeId._(0); @@ -82,7 +82,9 @@ class DistributionTypeId { static const DistributionTypeId Exponential = const DistributionTypeId._(7); static const DistributionTypeId Gamma = const DistributionTypeId._(8); static const DistributionTypeId LogNormal = const DistributionTypeId._(9); - static get values => {0: NONE,1: Normal,2: Uniform,3: Categorical,4: Poisson,5: Bernoulli,6: Beta,7: Exponential,8: Gamma,9: LogNormal,}; + static const DistributionTypeId Binomial = const DistributionTypeId._(10); + static const DistributionTypeId Weibull = const DistributionTypeId._(11); + static get values => {0: NONE,1: Normal,2: Uniform,3: Categorical,4: Poisson,5: Bernoulli,6: Beta,7: Exponential,8: Gamma,9: LogNormal,10: Binomial,11: Weibull,}; static const fb.Reader reader = const _DistributionTypeIdReader(); @@ -625,6 +627,8 @@ class Sample { case 7: return Exponential.reader.vTableGet(_bc, _bcOffset, 10, null); case 8: return Gamma.reader.vTableGet(_bc, _bcOffset, 10, null); case 9: return LogNormal.reader.vTableGet(_bc, _bcOffset, 10, null); + case 10: return Binomial.reader.vTableGet(_bc, _bcOffset, 10, null); + case 11: return Weibull.reader.vTableGet(_bc, _bcOffset, 10, null); default: return null; } } @@ -847,6 +851,8 @@ class Observe { case 7: return Exponential.reader.vTableGet(_bc, _bcOffset, 10, null); case 8: return Gamma.reader.vTableGet(_bc, _bcOffset, 10, null); case 9: return LogNormal.reader.vTableGet(_bc, _bcOffset, 10, null); + case 10: return Binomial.reader.vTableGet(_bc, _bcOffset, 10, null); + case 11: return Weibull.reader.vTableGet(_bc, _bcOffset, 10, null); default: return null; } } @@ -1979,3 +1985,185 @@ class LogNormalObjectBuilder extends fb.ObjectBuilder { return fbBuilder.finish(offset, fileIdentifier); } } +class Binomial { + Binomial._(this._bc, this._bcOffset); + factory Binomial(List bytes) { + fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); + return reader.read(rootRef, 0); + } + + static const fb.Reader reader = const _BinomialReader(); + + final fb.BufferContext _bc; + final int _bcOffset; + + Tensor get totalCount => Tensor.reader.vTableGet(_bc, _bcOffset, 4, null); + Tensor get probs => Tensor.reader.vTableGet(_bc, _bcOffset, 6, null); + + @override + String toString() { + return 'Binomial{totalCount: $totalCount, probs: $probs}'; + } +} + +class _BinomialReader extends fb.TableReader { + const _BinomialReader(); + + @override + Binomial createObject(fb.BufferContext bc, int offset) => + new Binomial._(bc, offset); +} + +class BinomialBuilder { + BinomialBuilder(this.fbBuilder) { + assert(fbBuilder != null); + } + + final fb.Builder fbBuilder; + + void begin() { + fbBuilder.startTable(); + } + + int addTotalCountOffset(int offset) { + fbBuilder.addOffset(0, offset); + return fbBuilder.offset; + } + int addProbsOffset(int offset) { + fbBuilder.addOffset(1, offset); + return fbBuilder.offset; + } + + int finish() { + return fbBuilder.endTable(); + } +} + +class BinomialObjectBuilder extends fb.ObjectBuilder { + final TensorObjectBuilder _totalCount; + final TensorObjectBuilder _probs; + + BinomialObjectBuilder({ + TensorObjectBuilder totalCount, + TensorObjectBuilder probs, + }) + : _totalCount = totalCount, + _probs = probs; + + /// Finish building, and store into the [fbBuilder]. + @override + int finish( + fb.Builder fbBuilder) { + assert(fbBuilder != null); + final int totalCountOffset = _totalCount?.getOrCreateOffset(fbBuilder); + final int probsOffset = _probs?.getOrCreateOffset(fbBuilder); + + fbBuilder.startTable(); + if (totalCountOffset != null) { + fbBuilder.addOffset(0, totalCountOffset); + } + if (probsOffset != null) { + fbBuilder.addOffset(1, probsOffset); + } + return fbBuilder.endTable(); + } + + /// Convenience method to serialize to byte list. + @override + Uint8List toBytes([String fileIdentifier]) { + fb.Builder fbBuilder = new fb.Builder(); + int offset = finish(fbBuilder); + return fbBuilder.finish(offset, fileIdentifier); + } +} +class Weibull { + Weibull._(this._bc, this._bcOffset); + factory Weibull(List bytes) { + fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); + return reader.read(rootRef, 0); + } + + static const fb.Reader reader = const _WeibullReader(); + + final fb.BufferContext _bc; + final int _bcOffset; + + Tensor get scale => Tensor.reader.vTableGet(_bc, _bcOffset, 4, null); + Tensor get concentration => Tensor.reader.vTableGet(_bc, _bcOffset, 6, null); + + @override + String toString() { + return 'Weibull{scale: $scale, concentration: $concentration}'; + } +} + +class _WeibullReader extends fb.TableReader { + const _WeibullReader(); + + @override + Weibull createObject(fb.BufferContext bc, int offset) => + new Weibull._(bc, offset); +} + +class WeibullBuilder { + WeibullBuilder(this.fbBuilder) { + assert(fbBuilder != null); + } + + final fb.Builder fbBuilder; + + void begin() { + fbBuilder.startTable(); + } + + int addScaleOffset(int offset) { + fbBuilder.addOffset(0, offset); + return fbBuilder.offset; + } + int addConcentrationOffset(int offset) { + fbBuilder.addOffset(1, offset); + return fbBuilder.offset; + } + + int finish() { + return fbBuilder.endTable(); + } +} + +class WeibullObjectBuilder extends fb.ObjectBuilder { + final TensorObjectBuilder _scale; + final TensorObjectBuilder _concentration; + + WeibullObjectBuilder({ + TensorObjectBuilder scale, + TensorObjectBuilder concentration, + }) + : _scale = scale, + _concentration = concentration; + + /// Finish building, and store into the [fbBuilder]. + @override + int finish( + fb.Builder fbBuilder) { + assert(fbBuilder != null); + final int scaleOffset = _scale?.getOrCreateOffset(fbBuilder); + final int concentrationOffset = _concentration?.getOrCreateOffset(fbBuilder); + + fbBuilder.startTable(); + if (scaleOffset != null) { + fbBuilder.addOffset(0, scaleOffset); + } + if (concentrationOffset != null) { + fbBuilder.addOffset(1, concentrationOffset); + } + return fbBuilder.endTable(); + } + + /// Convenience method to serialize to byte list. + @override + Uint8List toBytes([String fileIdentifier]) { + fb.Builder fbBuilder = new fb.Builder(); + int offset = finish(fbBuilder); + return fbBuilder.finish(offset, fileIdentifier); + } +} diff --git a/go/ppx/Binomial.go b/go/ppx/Binomial.go new file mode 100644 index 0000000..c44d957 --- /dev/null +++ b/go/ppx/Binomial.go @@ -0,0 +1,66 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package ppx + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type Binomial struct { + _tab flatbuffers.Table +} + +func GetRootAsBinomial(buf []byte, offset flatbuffers.UOffsetT) *Binomial { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &Binomial{} + x.Init(buf, n+offset) + return x +} + +func (rcv *Binomial) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *Binomial) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *Binomial) TotalCount(obj *Tensor) *Tensor { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(Tensor) + } + obj.Init(rcv._tab.Bytes, x) + return obj + } + return nil +} + +func (rcv *Binomial) Probs(obj *Tensor) *Tensor { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(Tensor) + } + obj.Init(rcv._tab.Bytes, x) + return obj + } + return nil +} + +func BinomialStart(builder *flatbuffers.Builder) { + builder.StartObject(2) +} +func BinomialAddTotalCount(builder *flatbuffers.Builder, totalCount flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(totalCount), 0) +} +func BinomialAddProbs(builder *flatbuffers.Builder, probs flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(probs), 0) +} +func BinomialEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} diff --git a/go/ppx/Distribution.go b/go/ppx/Distribution.go index d392c40..c46c442 100644 --- a/go/ppx/Distribution.go +++ b/go/ppx/Distribution.go @@ -17,6 +17,8 @@ const ( DistributionExponential Distribution = 7 DistributionGamma Distribution = 8 DistributionLogNormal Distribution = 9 + DistributionBinomial Distribution = 10 + DistributionWeibull Distribution = 11 ) var EnumNamesDistribution = map[Distribution]string{ @@ -30,6 +32,8 @@ var EnumNamesDistribution = map[Distribution]string{ DistributionExponential: "Exponential", DistributionGamma: "Gamma", DistributionLogNormal: "LogNormal", + DistributionBinomial: "Binomial", + DistributionWeibull: "Weibull", } var EnumValuesDistribution = map[string]Distribution{ @@ -43,6 +47,8 @@ var EnumValuesDistribution = map[string]Distribution{ "Exponential": DistributionExponential, "Gamma": DistributionGamma, "LogNormal": DistributionLogNormal, + "Binomial": DistributionBinomial, + "Weibull": DistributionWeibull, } func (v Distribution) String() string { diff --git a/go/ppx/Weibull.go b/go/ppx/Weibull.go new file mode 100644 index 0000000..90caf83 --- /dev/null +++ b/go/ppx/Weibull.go @@ -0,0 +1,66 @@ +// Code generated by the FlatBuffers compiler. DO NOT EDIT. + +package ppx + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) + +type Weibull struct { + _tab flatbuffers.Table +} + +func GetRootAsWeibull(buf []byte, offset flatbuffers.UOffsetT) *Weibull { + n := flatbuffers.GetUOffsetT(buf[offset:]) + x := &Weibull{} + x.Init(buf, n+offset) + return x +} + +func (rcv *Weibull) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *Weibull) Table() flatbuffers.Table { + return rcv._tab +} + +func (rcv *Weibull) Scale(obj *Tensor) *Tensor { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(Tensor) + } + obj.Init(rcv._tab.Bytes, x) + return obj + } + return nil +} + +func (rcv *Weibull) Concentration(obj *Tensor) *Tensor { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + x := rcv._tab.Indirect(o + rcv._tab.Pos) + if obj == nil { + obj = new(Tensor) + } + obj.Init(rcv._tab.Bytes, x) + return obj + } + return nil +} + +func WeibullStart(builder *flatbuffers.Builder) { + builder.StartObject(2) +} +func WeibullAddScale(builder *flatbuffers.Builder, scale flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(scale), 0) +} +func WeibullAddConcentration(builder *flatbuffers.Builder, concentration flatbuffers.UOffsetT) { + builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(concentration), 0) +} +func WeibullEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { + return builder.EndObject() +} diff --git a/java/ppx/Binomial.java b/java/ppx/Binomial.java new file mode 100644 index 0000000..6f18ea4 --- /dev/null +++ b/java/ppx/Binomial.java @@ -0,0 +1,47 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +package ppx; + +import java.nio.*; +import java.lang.*; +import java.util.*; +import com.google.flatbuffers.*; + +@SuppressWarnings("unused") +public final class Binomial extends Table { + public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); } + public static Binomial getRootAsBinomial(ByteBuffer _bb) { return getRootAsBinomial(_bb, new Binomial()); } + public static Binomial getRootAsBinomial(ByteBuffer _bb, Binomial obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } + public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } + public Binomial __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } + + public ppx.Tensor totalCount() { return totalCount(new ppx.Tensor()); } + public ppx.Tensor totalCount(ppx.Tensor obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } + public ppx.Tensor probs() { return probs(new ppx.Tensor()); } + public ppx.Tensor probs(ppx.Tensor obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } + + public static int createBinomial(FlatBufferBuilder builder, + int total_countOffset, + int probsOffset) { + builder.startTable(2); + Binomial.addProbs(builder, probsOffset); + Binomial.addTotalCount(builder, total_countOffset); + return Binomial.endBinomial(builder); + } + + public static void startBinomial(FlatBufferBuilder builder) { builder.startTable(2); } + public static void addTotalCount(FlatBufferBuilder builder, int totalCountOffset) { builder.addOffset(0, totalCountOffset, 0); } + public static void addProbs(FlatBufferBuilder builder, int probsOffset) { builder.addOffset(1, probsOffset, 0); } + public static int endBinomial(FlatBufferBuilder builder) { + int o = builder.endTable(); + return o; + } + + public static final class Vector extends BaseVector { + public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } + + public Binomial get(int j) { return get(new Binomial(), j); } + public Binomial get(Binomial obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } + } +} + diff --git a/java/ppx/Distribution.java b/java/ppx/Distribution.java index bb445eb..0c899e9 100644 --- a/java/ppx/Distribution.java +++ b/java/ppx/Distribution.java @@ -14,8 +14,10 @@ private Distribution() { } public static final byte Exponential = 7; public static final byte Gamma = 8; public static final byte LogNormal = 9; + public static final byte Binomial = 10; + public static final byte Weibull = 11; - public static final String[] names = { "NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal", }; + public static final String[] names = { "NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal", "Binomial", "Weibull", }; public static String name(int e) { return names[e]; } } diff --git a/java/ppx/Weibull.java b/java/ppx/Weibull.java new file mode 100644 index 0000000..b09a41c --- /dev/null +++ b/java/ppx/Weibull.java @@ -0,0 +1,47 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +package ppx; + +import java.nio.*; +import java.lang.*; +import java.util.*; +import com.google.flatbuffers.*; + +@SuppressWarnings("unused") +public final class Weibull extends Table { + public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); } + public static Weibull getRootAsWeibull(ByteBuffer _bb) { return getRootAsWeibull(_bb, new Weibull()); } + public static Weibull getRootAsWeibull(ByteBuffer _bb, Weibull obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } + public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } + public Weibull __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } + + public ppx.Tensor scale() { return scale(new ppx.Tensor()); } + public ppx.Tensor scale(ppx.Tensor obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } + public ppx.Tensor concentration() { return concentration(new ppx.Tensor()); } + public ppx.Tensor concentration(ppx.Tensor obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } + + public static int createWeibull(FlatBufferBuilder builder, + int scaleOffset, + int concentrationOffset) { + builder.startTable(2); + Weibull.addConcentration(builder, concentrationOffset); + Weibull.addScale(builder, scaleOffset); + return Weibull.endWeibull(builder); + } + + public static void startWeibull(FlatBufferBuilder builder) { builder.startTable(2); } + public static void addScale(FlatBufferBuilder builder, int scaleOffset) { builder.addOffset(0, scaleOffset, 0); } + public static void addConcentration(FlatBufferBuilder builder, int concentrationOffset) { builder.addOffset(1, concentrationOffset, 0); } + public static int endWeibull(FlatBufferBuilder builder) { + int o = builder.endTable(); + return o; + } + + public static final class Vector extends BaseVector { + public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } + + public Weibull get(int j) { return get(new Weibull(), j); } + public Weibull get(Weibull obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } + } +} + diff --git a/js/ppx_generated.js b/js/ppx_generated.js index e6b70e7..d5c4d41 100644 --- a/js/ppx_generated.js +++ b/js/ppx_generated.js @@ -55,7 +55,9 @@ ppx.Distribution = { Beta: 6, Exponential: 7, Gamma: 8, - LogNormal: 9 + LogNormal: 9, + Binomial: 10, + Weibull: 11 }; /** @@ -71,7 +73,9 @@ ppx.DistributionName = { '6': 'Beta', '7': 'Exponential', '8': 'Gamma', - '9': 'LogNormal' + '9': 'LogNormal', + '10': 'Binomial', + '11': 'Weibull' }; /** @@ -2410,5 +2414,221 @@ ppx.LogNormal.createLogNormal = function(builder, locOffset, scaleOffset) { return ppx.LogNormal.endLogNormal(builder); } +/** + * @constructor + */ +ppx.Binomial = function() { + /** + * @type {flatbuffers.ByteBuffer} + */ + this.bb = null; + + /** + * @type {number} + */ + this.bb_pos = 0; +}; + +/** + * @param {number} i + * @param {flatbuffers.ByteBuffer} bb + * @returns {ppx.Binomial} + */ +ppx.Binomial.prototype.__init = function(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; +}; + +/** + * @param {flatbuffers.ByteBuffer} bb + * @param {ppx.Binomial=} obj + * @returns {ppx.Binomial} + */ +ppx.Binomial.getRootAsBinomial = function(bb, obj) { + return (obj || new ppx.Binomial).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param {flatbuffers.ByteBuffer} bb + * @param {ppx.Binomial=} obj + * @returns {ppx.Binomial} + */ +ppx.Binomial.getSizePrefixedRootAsBinomial = function(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ppx.Binomial).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param {ppx.Tensor=} obj + * @returns {ppx.Tensor|null} + */ +ppx.Binomial.prototype.totalCount = function(obj) { + var offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new ppx.Tensor).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; +}; + +/** + * @param {ppx.Tensor=} obj + * @returns {ppx.Tensor|null} + */ +ppx.Binomial.prototype.probs = function(obj) { + var offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new ppx.Tensor).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; +}; + +/** + * @param {flatbuffers.Builder} builder + */ +ppx.Binomial.startBinomial = function(builder) { + builder.startObject(2); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} totalCountOffset + */ +ppx.Binomial.addTotalCount = function(builder, totalCountOffset) { + builder.addFieldOffset(0, totalCountOffset, 0); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} probsOffset + */ +ppx.Binomial.addProbs = function(builder, probsOffset) { + builder.addFieldOffset(1, probsOffset, 0); +}; + +/** + * @param {flatbuffers.Builder} builder + * @returns {flatbuffers.Offset} + */ +ppx.Binomial.endBinomial = function(builder) { + var offset = builder.endObject(); + return offset; +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} totalCountOffset + * @param {flatbuffers.Offset} probsOffset + * @returns {flatbuffers.Offset} + */ +ppx.Binomial.createBinomial = function(builder, totalCountOffset, probsOffset) { + ppx.Binomial.startBinomial(builder); + ppx.Binomial.addTotalCount(builder, totalCountOffset); + ppx.Binomial.addProbs(builder, probsOffset); + return ppx.Binomial.endBinomial(builder); +} + +/** + * @constructor + */ +ppx.Weibull = function() { + /** + * @type {flatbuffers.ByteBuffer} + */ + this.bb = null; + + /** + * @type {number} + */ + this.bb_pos = 0; +}; + +/** + * @param {number} i + * @param {flatbuffers.ByteBuffer} bb + * @returns {ppx.Weibull} + */ +ppx.Weibull.prototype.__init = function(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; +}; + +/** + * @param {flatbuffers.ByteBuffer} bb + * @param {ppx.Weibull=} obj + * @returns {ppx.Weibull} + */ +ppx.Weibull.getRootAsWeibull = function(bb, obj) { + return (obj || new ppx.Weibull).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param {flatbuffers.ByteBuffer} bb + * @param {ppx.Weibull=} obj + * @returns {ppx.Weibull} + */ +ppx.Weibull.getSizePrefixedRootAsWeibull = function(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ppx.Weibull).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param {ppx.Tensor=} obj + * @returns {ppx.Tensor|null} + */ +ppx.Weibull.prototype.scale = function(obj) { + var offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new ppx.Tensor).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; +}; + +/** + * @param {ppx.Tensor=} obj + * @returns {ppx.Tensor|null} + */ +ppx.Weibull.prototype.concentration = function(obj) { + var offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new ppx.Tensor).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; +}; + +/** + * @param {flatbuffers.Builder} builder + */ +ppx.Weibull.startWeibull = function(builder) { + builder.startObject(2); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} scaleOffset + */ +ppx.Weibull.addScale = function(builder, scaleOffset) { + builder.addFieldOffset(0, scaleOffset, 0); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} concentrationOffset + */ +ppx.Weibull.addConcentration = function(builder, concentrationOffset) { + builder.addFieldOffset(1, concentrationOffset, 0); +}; + +/** + * @param {flatbuffers.Builder} builder + * @returns {flatbuffers.Offset} + */ +ppx.Weibull.endWeibull = function(builder) { + var offset = builder.endObject(); + return offset; +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} scaleOffset + * @param {flatbuffers.Offset} concentrationOffset + * @returns {flatbuffers.Offset} + */ +ppx.Weibull.createWeibull = function(builder, scaleOffset, concentrationOffset) { + ppx.Weibull.startWeibull(builder); + ppx.Weibull.addScale(builder, scaleOffset); + ppx.Weibull.addConcentration(builder, concentrationOffset); + return ppx.Weibull.endWeibull(builder); +} + // Exports for Node.js and RequireJS this.ppx = ppx; diff --git a/jsonschema/ppx.schema.json b/jsonschema/ppx.schema.json index 323e5f6..f8a9ad9 100644 --- a/jsonschema/ppx.schema.json +++ b/jsonschema/ppx.schema.json @@ -7,7 +7,7 @@ }, "ppx_Distribution" : { "type" : "string", - "enum": ["NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal"] + "enum": ["NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal", "Binomial", "Weibull"] }, "ppx_Message" : { "type" : "object", @@ -82,7 +82,7 @@ "$ref" : "#/definitions/ppx_Distribution" }, "distribution" : { - "anyOf": [{ "$ref" : "#/definitions/ppx_Normal" },{ "$ref" : "#/definitions/ppx_Uniform" },{ "$ref" : "#/definitions/ppx_Categorical" },{ "$ref" : "#/definitions/ppx_Poisson" },{ "$ref" : "#/definitions/ppx_Bernoulli" },{ "$ref" : "#/definitions/ppx_Beta" },{ "$ref" : "#/definitions/ppx_Exponential" },{ "$ref" : "#/definitions/ppx_Gamma" },{ "$ref" : "#/definitions/ppx_LogNormal" }] + "anyOf": [{ "$ref" : "#/definitions/ppx_Normal" },{ "$ref" : "#/definitions/ppx_Uniform" },{ "$ref" : "#/definitions/ppx_Categorical" },{ "$ref" : "#/definitions/ppx_Poisson" },{ "$ref" : "#/definitions/ppx_Bernoulli" },{ "$ref" : "#/definitions/ppx_Beta" },{ "$ref" : "#/definitions/ppx_Exponential" },{ "$ref" : "#/definitions/ppx_Gamma" },{ "$ref" : "#/definitions/ppx_LogNormal" },{ "$ref" : "#/definitions/ppx_Binomial" },{ "$ref" : "#/definitions/ppx_Weibull" }] }, "control" : { "type" : "boolean" @@ -115,7 +115,7 @@ "$ref" : "#/definitions/ppx_Distribution" }, "distribution" : { - "anyOf": [{ "$ref" : "#/definitions/ppx_Normal" },{ "$ref" : "#/definitions/ppx_Uniform" },{ "$ref" : "#/definitions/ppx_Categorical" },{ "$ref" : "#/definitions/ppx_Poisson" },{ "$ref" : "#/definitions/ppx_Bernoulli" },{ "$ref" : "#/definitions/ppx_Beta" },{ "$ref" : "#/definitions/ppx_Exponential" },{ "$ref" : "#/definitions/ppx_Gamma" },{ "$ref" : "#/definitions/ppx_LogNormal" }] + "anyOf": [{ "$ref" : "#/definitions/ppx_Normal" },{ "$ref" : "#/definitions/ppx_Uniform" },{ "$ref" : "#/definitions/ppx_Categorical" },{ "$ref" : "#/definitions/ppx_Poisson" },{ "$ref" : "#/definitions/ppx_Bernoulli" },{ "$ref" : "#/definitions/ppx_Beta" },{ "$ref" : "#/definitions/ppx_Exponential" },{ "$ref" : "#/definitions/ppx_Gamma" },{ "$ref" : "#/definitions/ppx_LogNormal" },{ "$ref" : "#/definitions/ppx_Binomial" },{ "$ref" : "#/definitions/ppx_Weibull" }] }, "value" : { "$ref" : "#/definitions/ppx_Tensor" @@ -251,6 +251,30 @@ } }, "additionalProperties" : false + }, + "ppx_Binomial" : { + "type" : "object", + "properties" : { + "total_count" : { + "$ref" : "#/definitions/ppx_Tensor" + }, + "probs" : { + "$ref" : "#/definitions/ppx_Tensor" + } + }, + "additionalProperties" : false + }, + "ppx_Weibull" : { + "type" : "object", + "properties" : { + "scale" : { + "$ref" : "#/definitions/ppx_Tensor" + }, + "concentration" : { + "$ref" : "#/definitions/ppx_Tensor" + } + }, + "additionalProperties" : false } }, "$ref" : "#/definitions/ppx_Message" diff --git a/kotlin/ppx/Binomial.kt b/kotlin/ppx/Binomial.kt new file mode 100644 index 0000000..f79cdbf --- /dev/null +++ b/kotlin/ppx/Binomial.kt @@ -0,0 +1,59 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +package ppx + +import java.nio.* +import kotlin.math.sign +import com.google.flatbuffers.* + +@Suppress("unused") +@ExperimentalUnsignedTypes +class Binomial : Table() { + + fun __init(_i: Int, _bb: ByteBuffer) { + __reset(_i, _bb) + } + fun __assign(_i: Int, _bb: ByteBuffer) : Binomial { + __init(_i, _bb) + return this + } + val totalCount : ppx.Tensor? get() = totalCount(ppx.Tensor()) + fun totalCount(obj: ppx.Tensor) : ppx.Tensor? { + val o = __offset(4) + return if (o != 0) { + obj.__assign(__indirect(o + bb_pos), bb) + } else { + null + } + } + val probs : ppx.Tensor? get() = probs(ppx.Tensor()) + fun probs(obj: ppx.Tensor) : ppx.Tensor? { + val o = __offset(6) + return if (o != 0) { + obj.__assign(__indirect(o + bb_pos), bb) + } else { + null + } + } + companion object { + fun validateVersion() = Constants.FLATBUFFERS_1_12_0() + fun getRootAsBinomial(_bb: ByteBuffer): Binomial = getRootAsBinomial(_bb, Binomial()) + fun getRootAsBinomial(_bb: ByteBuffer, obj: Binomial): Binomial { + _bb.order(ByteOrder.LITTLE_ENDIAN) + return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) + } + fun createBinomial(builder: FlatBufferBuilder, totalCountOffset: Int, probsOffset: Int) : Int { + builder.startTable(2) + addProbs(builder, probsOffset) + addTotalCount(builder, totalCountOffset) + return endBinomial(builder) + } + fun startBinomial(builder: FlatBufferBuilder) = builder.startTable(2) + fun addTotalCount(builder: FlatBufferBuilder, totalCount: Int) = builder.addOffset(0, totalCount, 0) + fun addProbs(builder: FlatBufferBuilder, probs: Int) = builder.addOffset(1, probs, 0) + fun endBinomial(builder: FlatBufferBuilder) : Int { + val o = builder.endTable() + return o + } + } +} diff --git a/kotlin/ppx/Distribution.kt b/kotlin/ppx/Distribution.kt index f8dbc3b..e6d8755 100644 --- a/kotlin/ppx/Distribution.kt +++ b/kotlin/ppx/Distribution.kt @@ -16,7 +16,9 @@ class Distribution private constructor() { const val Exponential: UByte = 7u const val Gamma: UByte = 8u const val LogNormal: UByte = 9u - val names : Array = arrayOf("NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal") + const val Binomial: UByte = 10u + const val Weibull: UByte = 11u + val names : Array = arrayOf("NONE", "Normal", "Uniform", "Categorical", "Poisson", "Bernoulli", "Beta", "Exponential", "Gamma", "LogNormal", "Binomial", "Weibull") fun name(e: Int) : String = names[e] } } diff --git a/kotlin/ppx/Weibull.kt b/kotlin/ppx/Weibull.kt new file mode 100644 index 0000000..ead3e4f --- /dev/null +++ b/kotlin/ppx/Weibull.kt @@ -0,0 +1,59 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +package ppx + +import java.nio.* +import kotlin.math.sign +import com.google.flatbuffers.* + +@Suppress("unused") +@ExperimentalUnsignedTypes +class Weibull : Table() { + + fun __init(_i: Int, _bb: ByteBuffer) { + __reset(_i, _bb) + } + fun __assign(_i: Int, _bb: ByteBuffer) : Weibull { + __init(_i, _bb) + return this + } + val scale : ppx.Tensor? get() = scale(ppx.Tensor()) + fun scale(obj: ppx.Tensor) : ppx.Tensor? { + val o = __offset(4) + return if (o != 0) { + obj.__assign(__indirect(o + bb_pos), bb) + } else { + null + } + } + val concentration : ppx.Tensor? get() = concentration(ppx.Tensor()) + fun concentration(obj: ppx.Tensor) : ppx.Tensor? { + val o = __offset(6) + return if (o != 0) { + obj.__assign(__indirect(o + bb_pos), bb) + } else { + null + } + } + companion object { + fun validateVersion() = Constants.FLATBUFFERS_1_12_0() + fun getRootAsWeibull(_bb: ByteBuffer): Weibull = getRootAsWeibull(_bb, Weibull()) + fun getRootAsWeibull(_bb: ByteBuffer, obj: Weibull): Weibull { + _bb.order(ByteOrder.LITTLE_ENDIAN) + return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) + } + fun createWeibull(builder: FlatBufferBuilder, scaleOffset: Int, concentrationOffset: Int) : Int { + builder.startTable(2) + addConcentration(builder, concentrationOffset) + addScale(builder, scaleOffset) + return endWeibull(builder) + } + fun startWeibull(builder: FlatBufferBuilder) = builder.startTable(2) + fun addScale(builder: FlatBufferBuilder, scale: Int) = builder.addOffset(0, scale, 0) + fun addConcentration(builder: FlatBufferBuilder, concentration: Int) = builder.addOffset(1, concentration, 0) + fun endWeibull(builder: FlatBufferBuilder) : Int { + val o = builder.endTable() + return o + } + } +} diff --git a/lobster/ppx_generated.lobster b/lobster/ppx_generated.lobster index f5be5c3..a0e6770 100644 --- a/lobster/ppx_generated.lobster +++ b/lobster/ppx_generated.lobster @@ -28,6 +28,8 @@ enum Distribution: Distribution_Exponential = 7 Distribution_Gamma = 8 Distribution_LogNormal = 9 + Distribution_Binomial = 10 + Distribution_Weibull = 11 class Message @@ -73,6 +75,10 @@ class Gamma class LogNormal +class Binomial + +class Weibull + class Message : flatbuffers_handle def body_type(): return MessageBody(buf_.flatbuffers_field_int8(pos_, 4, 0)) @@ -249,6 +255,10 @@ class Sample : flatbuffers_handle return ppx_Gamma { buf_, buf_.flatbuffers_field_table(pos_, 10) } def distribution_as_LogNormal(): return ppx_LogNormal { buf_, buf_.flatbuffers_field_table(pos_, 10) } + def distribution_as_Binomial(): + return ppx_Binomial { buf_, buf_.flatbuffers_field_table(pos_, 10) } + def distribution_as_Weibull(): + return ppx_Weibull { buf_, buf_.flatbuffers_field_table(pos_, 10) } def control(): return buf_.flatbuffers_field_int8(pos_, 12, 1) def replace(): @@ -325,6 +335,10 @@ class Observe : flatbuffers_handle return ppx_Gamma { buf_, buf_.flatbuffers_field_table(pos_, 10) } def distribution_as_LogNormal(): return ppx_LogNormal { buf_, buf_.flatbuffers_field_table(pos_, 10) } + def distribution_as_Binomial(): + return ppx_Binomial { buf_, buf_.flatbuffers_field_table(pos_, 10) } + def distribution_as_Weibull(): + return ppx_Weibull { buf_, buf_.flatbuffers_field_table(pos_, 10) } def value(): let o = buf_.flatbuffers_field_table(pos_, 12) return if o: ppx_Tensor { buf_, o } else: nil @@ -610,3 +624,51 @@ struct LogNormalBuilder: def end(): return b_.EndObject() +class Binomial : flatbuffers_handle + def total_count(): + let o = buf_.flatbuffers_field_table(pos_, 4) + return if o: ppx_Tensor { buf_, o } else: nil + def probs(): + let o = buf_.flatbuffers_field_table(pos_, 6) + return if o: ppx_Tensor { buf_, o } else: nil + +def GetRootAsBinomial(buf:string): return Binomial { buf, buf.flatbuffers_indirect(0) } + +struct BinomialBuilder: + b_:flatbuffers_builder + def start(): + b_.StartObject(2) + return this + def add_total_count(total_count:flatbuffers_offset): + b_.PrependUOffsetTRelativeSlot(0, total_count) + return this + def add_probs(probs:flatbuffers_offset): + b_.PrependUOffsetTRelativeSlot(1, probs) + return this + def end(): + return b_.EndObject() + +class Weibull : flatbuffers_handle + def scale(): + let o = buf_.flatbuffers_field_table(pos_, 4) + return if o: ppx_Tensor { buf_, o } else: nil + def concentration(): + let o = buf_.flatbuffers_field_table(pos_, 6) + return if o: ppx_Tensor { buf_, o } else: nil + +def GetRootAsWeibull(buf:string): return Weibull { buf, buf.flatbuffers_indirect(0) } + +struct WeibullBuilder: + b_:flatbuffers_builder + def start(): + b_.StartObject(2) + return this + def add_scale(scale:flatbuffers_offset): + b_.PrependUOffsetTRelativeSlot(0, scale) + return this + def add_concentration(concentration:flatbuffers_offset): + b_.PrependUOffsetTRelativeSlot(1, concentration) + return this + def end(): + return b_.EndObject() + diff --git a/lua/ppx/Binomial.lua b/lua/ppx/Binomial.lua new file mode 100644 index 0000000..6f7c0fc --- /dev/null +++ b/lua/ppx/Binomial.lua @@ -0,0 +1,47 @@ +-- automatically generated by the FlatBuffers compiler, do not modify + +-- namespace: ppx + +local flatbuffers = require('flatbuffers') + +local Binomial = {} -- the module +local Binomial_mt = {} -- the class metatable + +function Binomial.New() + local o = {} + setmetatable(o, {__index = Binomial_mt}) + return o +end +function Binomial.GetRootAsBinomial(buf, offset) + local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) + local o = Binomial.New() + o:Init(buf, n + offset) + return o +end +function Binomial_mt:Init(buf, pos) + self.view = flatbuffers.view.New(buf, pos) +end +function Binomial_mt:TotalCount() + local o = self.view:Offset(4) + if o ~= 0 then + local x = self.view:Indirect(o + self.view.pos) + local obj = require('ppx.Tensor').New() + obj:Init(self.view.bytes, x) + return obj + end +end +function Binomial_mt:Probs() + local o = self.view:Offset(6) + if o ~= 0 then + local x = self.view:Indirect(o + self.view.pos) + local obj = require('ppx.Tensor').New() + obj:Init(self.view.bytes, x) + return obj + end +end +function Binomial.Start(builder) builder:StartObject(2) end +function Binomial.AddTotalCount(builder, totalCount) builder:PrependUOffsetTRelativeSlot(0, totalCount, 0) end +function Binomial.AddProbs(builder, probs) builder:PrependUOffsetTRelativeSlot(1, probs, 0) end +function Binomial.End(builder) return builder:EndObject() end + +return Binomial -- return the module \ No newline at end of file diff --git a/lua/ppx/Distribution.lua b/lua/ppx/Distribution.lua index ec3003e..9b911a1 100644 --- a/lua/ppx/Distribution.lua +++ b/lua/ppx/Distribution.lua @@ -13,6 +13,8 @@ local Distribution = { Exponential = 7, Gamma = 8, LogNormal = 9, + Binomial = 10, + Weibull = 11, } return Distribution -- return the module \ No newline at end of file diff --git a/lua/ppx/Weibull.lua b/lua/ppx/Weibull.lua new file mode 100644 index 0000000..ca82e68 --- /dev/null +++ b/lua/ppx/Weibull.lua @@ -0,0 +1,47 @@ +-- automatically generated by the FlatBuffers compiler, do not modify + +-- namespace: ppx + +local flatbuffers = require('flatbuffers') + +local Weibull = {} -- the module +local Weibull_mt = {} -- the class metatable + +function Weibull.New() + local o = {} + setmetatable(o, {__index = Weibull_mt}) + return o +end +function Weibull.GetRootAsWeibull(buf, offset) + local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) + local o = Weibull.New() + o:Init(buf, n + offset) + return o +end +function Weibull_mt:Init(buf, pos) + self.view = flatbuffers.view.New(buf, pos) +end +function Weibull_mt:Scale() + local o = self.view:Offset(4) + if o ~= 0 then + local x = self.view:Indirect(o + self.view.pos) + local obj = require('ppx.Tensor').New() + obj:Init(self.view.bytes, x) + return obj + end +end +function Weibull_mt:Concentration() + local o = self.view:Offset(6) + if o ~= 0 then + local x = self.view:Indirect(o + self.view.pos) + local obj = require('ppx.Tensor').New() + obj:Init(self.view.bytes, x) + return obj + end +end +function Weibull.Start(builder) builder:StartObject(2) end +function Weibull.AddScale(builder, scale) builder:PrependUOffsetTRelativeSlot(0, scale, 0) end +function Weibull.AddConcentration(builder, concentration) builder:PrependUOffsetTRelativeSlot(1, concentration, 0) end +function Weibull.End(builder) return builder:EndObject() end + +return Weibull -- return the module \ No newline at end of file diff --git a/php/ppx/Binomial.php b/php/ppx/Binomial.php new file mode 100644 index 0000000..67d820e --- /dev/null +++ b/php/ppx/Binomial.php @@ -0,0 +1,110 @@ +init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb)); + } + + public static function BinomialIdentifier() + { + return "PPXF"; + } + + public static function BinomialBufferHasIdentifier(ByteBuffer $buf) + { + return self::__has_identifier($buf, self::BinomialIdentifier()); + } + + /** + * @param int $_i offset + * @param ByteBuffer $_bb + * @return Binomial + **/ + public function init($_i, ByteBuffer $_bb) + { + $this->bb_pos = $_i; + $this->bb = $_bb; + return $this; + } + + public function getTotalCount() + { + $obj = new Tensor(); + $o = $this->__offset(4); + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; + } + + public function getProbs() + { + $obj = new Tensor(); + $o = $this->__offset(6); + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; + } + + /** + * @param FlatBufferBuilder $builder + * @return void + */ + public static function startBinomial(FlatBufferBuilder $builder) + { + $builder->StartObject(2); + } + + /** + * @param FlatBufferBuilder $builder + * @return Binomial + */ + public static function createBinomial(FlatBufferBuilder $builder, $total_count, $probs) + { + $builder->startObject(2); + self::addTotalCount($builder, $total_count); + self::addProbs($builder, $probs); + $o = $builder->endObject(); + return $o; + } + + /** + * @param FlatBufferBuilder $builder + * @param int + * @return void + */ + public static function addTotalCount(FlatBufferBuilder $builder, $totalCount) + { + $builder->addOffsetX(0, $totalCount, 0); + } + + /** + * @param FlatBufferBuilder $builder + * @param int + * @return void + */ + public static function addProbs(FlatBufferBuilder $builder, $probs) + { + $builder->addOffsetX(1, $probs, 0); + } + + /** + * @param FlatBufferBuilder $builder + * @return int table offset + */ + public static function endBinomial(FlatBufferBuilder $builder) + { + $o = $builder->endObject(); + return $o; + } +} diff --git a/php/ppx/Distribution.php b/php/ppx/Distribution.php index ffb83f1..e246466 100644 --- a/php/ppx/Distribution.php +++ b/php/ppx/Distribution.php @@ -15,6 +15,8 @@ class Distribution const Exponential = 7; const Gamma = 8; const LogNormal = 9; + const Binomial = 10; + const Weibull = 11; private static $names = array( Distribution::NONE=>"NONE", @@ -27,6 +29,8 @@ class Distribution Distribution::Exponential=>"Exponential", Distribution::Gamma=>"Gamma", Distribution::LogNormal=>"LogNormal", + Distribution::Binomial=>"Binomial", + Distribution::Weibull=>"Weibull", ); public static function Name($e) diff --git a/php/ppx/Weibull.php b/php/ppx/Weibull.php new file mode 100644 index 0000000..dfb2817 --- /dev/null +++ b/php/ppx/Weibull.php @@ -0,0 +1,110 @@ +init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb)); + } + + public static function WeibullIdentifier() + { + return "PPXF"; + } + + public static function WeibullBufferHasIdentifier(ByteBuffer $buf) + { + return self::__has_identifier($buf, self::WeibullIdentifier()); + } + + /** + * @param int $_i offset + * @param ByteBuffer $_bb + * @return Weibull + **/ + public function init($_i, ByteBuffer $_bb) + { + $this->bb_pos = $_i; + $this->bb = $_bb; + return $this; + } + + public function getScale() + { + $obj = new Tensor(); + $o = $this->__offset(4); + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; + } + + public function getConcentration() + { + $obj = new Tensor(); + $o = $this->__offset(6); + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; + } + + /** + * @param FlatBufferBuilder $builder + * @return void + */ + public static function startWeibull(FlatBufferBuilder $builder) + { + $builder->StartObject(2); + } + + /** + * @param FlatBufferBuilder $builder + * @return Weibull + */ + public static function createWeibull(FlatBufferBuilder $builder, $scale, $concentration) + { + $builder->startObject(2); + self::addScale($builder, $scale); + self::addConcentration($builder, $concentration); + $o = $builder->endObject(); + return $o; + } + + /** + * @param FlatBufferBuilder $builder + * @param int + * @return void + */ + public static function addScale(FlatBufferBuilder $builder, $scale) + { + $builder->addOffsetX(0, $scale, 0); + } + + /** + * @param FlatBufferBuilder $builder + * @param int + * @return void + */ + public static function addConcentration(FlatBufferBuilder $builder, $concentration) + { + $builder->addOffsetX(1, $concentration, 0); + } + + /** + * @param FlatBufferBuilder $builder + * @return int table offset + */ + public static function endWeibull(FlatBufferBuilder $builder) + { + $o = $builder->endObject(); + return $o; + } +} diff --git a/ppx.fbs b/ppx.fbs index 25094af..c51267d 100644 --- a/ppx.fbs +++ b/ppx.fbs @@ -1,5 +1,5 @@ // ppx -// 0.1.4 +// 0.1.5 // // Probabilistic programming execution protocol // https://github.com/pyprob/ppx @@ -38,7 +38,9 @@ union Distribution { Beta, Exponential, Gamma, - LogNormal + LogNormal, + Binomial, + Weibull } table Handshake { @@ -128,5 +130,15 @@ table LogNormal { scale: Tensor; } +table Binomial { + total_count: Tensor; + probs: Tensor; +} + +table Weibull { + scale: Tensor; + concentration: Tensor; +} + root_type Message; file_identifier "PPXF"; diff --git a/python/ppx/Binomial.py b/python/ppx/Binomial.py new file mode 100644 index 0000000..24bb4cd --- /dev/null +++ b/python/ppx/Binomial.py @@ -0,0 +1,52 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: ppx + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Binomial(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsBinomial(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Binomial() + x.Init(buf, n + offset) + return x + + @classmethod + def BinomialBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x50\x50\x58\x46", size_prefixed=size_prefixed) + + # Binomial + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Binomial + def TotalCount(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from ppx.Tensor import Tensor + obj = Tensor() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Binomial + def Probs(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from ppx.Tensor import Tensor + obj = Tensor() + obj.Init(self._tab.Bytes, x) + return obj + return None + +def BinomialStart(builder): builder.StartObject(2) +def BinomialAddTotalCount(builder, totalCount): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(totalCount), 0) +def BinomialAddProbs(builder, probs): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(probs), 0) +def BinomialEnd(builder): return builder.EndObject() diff --git a/python/ppx/Distribution.py b/python/ppx/Distribution.py index a7a04a2..12f7704 100644 --- a/python/ppx/Distribution.py +++ b/python/ppx/Distribution.py @@ -13,4 +13,6 @@ class Distribution(object): Exponential = 7 Gamma = 8 LogNormal = 9 + Binomial = 10 + Weibull = 11 diff --git a/python/ppx/Weibull.py b/python/ppx/Weibull.py new file mode 100644 index 0000000..b84d1d3 --- /dev/null +++ b/python/ppx/Weibull.py @@ -0,0 +1,52 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: ppx + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Weibull(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsWeibull(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Weibull() + x.Init(buf, n + offset) + return x + + @classmethod + def WeibullBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x50\x50\x58\x46", size_prefixed=size_prefixed) + + # Weibull + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Weibull + def Scale(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from ppx.Tensor import Tensor + obj = Tensor() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Weibull + def Concentration(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from ppx.Tensor import Tensor + obj = Tensor() + obj.Init(self._tab.Bytes, x) + return obj + return None + +def WeibullStart(builder): builder.StartObject(2) +def WeibullAddScale(builder, scale): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(scale), 0) +def WeibullAddConcentration(builder, concentration): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(concentration), 0) +def WeibullEnd(builder): return builder.EndObject() diff --git a/rust/ppx_generated.rs b/rust/ppx_generated.rs index 59f9472..ce9f589 100644 --- a/rust/ppx_generated.rs +++ b/rust/ppx_generated.rs @@ -122,11 +122,13 @@ pub enum Distribution { Exponential = 7, Gamma = 8, LogNormal = 9, + Binomial = 10, + Weibull = 11, } pub const ENUM_MIN_DISTRIBUTION: u8 = 0; -pub const ENUM_MAX_DISTRIBUTION: u8 = 9; +pub const ENUM_MAX_DISTRIBUTION: u8 = 11; impl<'a> flatbuffers::Follow<'a> for Distribution { type Inner = Self; @@ -160,7 +162,7 @@ impl flatbuffers::Push for Distribution { } #[allow(non_camel_case_types)] -pub const ENUM_VALUES_DISTRIBUTION:[Distribution; 10] = [ +pub const ENUM_VALUES_DISTRIBUTION:[Distribution; 12] = [ Distribution::NONE, Distribution::Normal, Distribution::Uniform, @@ -170,11 +172,13 @@ pub const ENUM_VALUES_DISTRIBUTION:[Distribution; 10] = [ Distribution::Beta, Distribution::Exponential, Distribution::Gamma, - Distribution::LogNormal + Distribution::LogNormal, + Distribution::Binomial, + Distribution::Weibull ]; #[allow(non_camel_case_types)] -pub const ENUM_NAMES_DISTRIBUTION:[&'static str; 10] = [ +pub const ENUM_NAMES_DISTRIBUTION:[&'static str; 12] = [ "NONE", "Normal", "Uniform", @@ -184,7 +188,9 @@ pub const ENUM_NAMES_DISTRIBUTION:[&'static str; 10] = [ "Beta", "Exponential", "Gamma", - "LogNormal" + "LogNormal", + "Binomial", + "Weibull" ]; pub fn enum_name_distribution(e: Distribution) -> &'static str { @@ -941,6 +947,26 @@ impl<'a> Sample<'a> { } } + #[inline] + #[allow(non_snake_case)] + pub fn distribution_as_binomial(&self) -> Option> { + if self.distribution_type() == Distribution::Binomial { + self.distribution().map(|u| Binomial::init_from_table(u)) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn distribution_as_weibull(&self) -> Option> { + if self.distribution_type() == Distribution::Weibull { + self.distribution().map(|u| Weibull::init_from_table(u)) + } else { + None + } + } + } pub struct SampleArgs<'a> { @@ -1237,6 +1263,26 @@ impl<'a> Observe<'a> { } } + #[inline] + #[allow(non_snake_case)] + pub fn distribution_as_binomial(&self) -> Option> { + if self.distribution_type() == Distribution::Binomial { + self.distribution().map(|u| Binomial::init_from_table(u)) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn distribution_as_weibull(&self) -> Option> { + if self.distribution_type() == Distribution::Weibull { + self.distribution().map(|u| Weibull::init_from_table(u)) + } else { + None + } + } + } pub struct ObserveArgs<'a> { @@ -2331,6 +2377,182 @@ impl<'a: 'b, 'b> LogNormalBuilder<'a, 'b> { } } +pub enum BinomialOffset {} +#[derive(Copy, Clone, Debug, PartialEq)] + +pub struct Binomial<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Binomial<'a> { + type Inner = Binomial<'a>; + #[inline] + fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table { buf: buf, loc: loc }, + } + } +} + +impl<'a> Binomial<'a> { + #[inline] + pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Binomial { + _tab: table, + } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args BinomialArgs<'args>) -> flatbuffers::WIPOffset> { + let mut builder = BinomialBuilder::new(_fbb); + if let Some(x) = args.probs { builder.add_probs(x); } + if let Some(x) = args.total_count { builder.add_total_count(x); } + builder.finish() + } + + pub const VT_TOTAL_COUNT: flatbuffers::VOffsetT = 4; + pub const VT_PROBS: flatbuffers::VOffsetT = 6; + + #[inline] + pub fn total_count(&self) -> Option> { + self._tab.get::>>(Binomial::VT_TOTAL_COUNT, None) + } + #[inline] + pub fn probs(&self) -> Option> { + self._tab.get::>>(Binomial::VT_PROBS, None) + } +} + +pub struct BinomialArgs<'a> { + pub total_count: Option>>, + pub probs: Option>>, +} +impl<'a> Default for BinomialArgs<'a> { + #[inline] + fn default() -> Self { + BinomialArgs { + total_count: None, + probs: None, + } + } +} +pub struct BinomialBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> BinomialBuilder<'a, 'b> { + #[inline] + pub fn add_total_count(&mut self, total_count: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Binomial::VT_TOTAL_COUNT, total_count); + } + #[inline] + pub fn add_probs(&mut self, probs: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Binomial::VT_PROBS, probs); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> BinomialBuilder<'a, 'b> { + let start = _fbb.start_table(); + BinomialBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +pub enum WeibullOffset {} +#[derive(Copy, Clone, Debug, PartialEq)] + +pub struct Weibull<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Weibull<'a> { + type Inner = Weibull<'a>; + #[inline] + fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table { buf: buf, loc: loc }, + } + } +} + +impl<'a> Weibull<'a> { + #[inline] + pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Weibull { + _tab: table, + } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args WeibullArgs<'args>) -> flatbuffers::WIPOffset> { + let mut builder = WeibullBuilder::new(_fbb); + if let Some(x) = args.concentration { builder.add_concentration(x); } + if let Some(x) = args.scale { builder.add_scale(x); } + builder.finish() + } + + pub const VT_SCALE: flatbuffers::VOffsetT = 4; + pub const VT_CONCENTRATION: flatbuffers::VOffsetT = 6; + + #[inline] + pub fn scale(&self) -> Option> { + self._tab.get::>>(Weibull::VT_SCALE, None) + } + #[inline] + pub fn concentration(&self) -> Option> { + self._tab.get::>>(Weibull::VT_CONCENTRATION, None) + } +} + +pub struct WeibullArgs<'a> { + pub scale: Option>>, + pub concentration: Option>>, +} +impl<'a> Default for WeibullArgs<'a> { + #[inline] + fn default() -> Self { + WeibullArgs { + scale: None, + concentration: None, + } + } +} +pub struct WeibullBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> WeibullBuilder<'a, 'b> { + #[inline] + pub fn add_scale(&mut self, scale: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Weibull::VT_SCALE, scale); + } + #[inline] + pub fn add_concentration(&mut self, concentration: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Weibull::VT_CONCENTRATION, concentration); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeibullBuilder<'a, 'b> { + let start = _fbb.start_table(); + WeibullBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + #[inline] pub fn get_root_as_message<'a>(buf: &'a [u8]) -> Message<'a> { flatbuffers::get_root::>(buf) diff --git a/swift/ppx_generated.swift b/swift/ppx_generated.swift index 00a1a4e..5d5b2d5 100644 --- a/swift/ppx_generated.swift +++ b/swift/ppx_generated.swift @@ -40,9 +40,11 @@ public enum Distribution: UInt8, Enum { case exponential = 7 case gamma = 8 case lognormal = 9 + case binomial = 10 + case weibull = 11 - public static var max: Distribution { return .lognormal } + public static var max: Distribution { return .weibull } public static var min: Distribution { return .none } } @@ -647,6 +649,62 @@ public struct LogNormal: FlatBufferObject { } } +public struct Binomial: FlatBufferObject { + + static func validateVersion() { FlatBuffersVersion_1_12_0() } + public var __buffer: ByteBuffer! { return _accessor.bb } + + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: "PPXF", addPrefix: prefix) } + public static func getRootAsBinomial(bb: ByteBuffer) -> Binomial { return Binomial(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } + + private init(_ t: Table) { _accessor = t } + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } + + public var totalCount: ppx.Tensor? { let o = _accessor.offset(4); return o == 0 ? nil : ppx.Tensor(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public var probs: ppx.Tensor? { let o = _accessor.offset(6); return o == 0 ? nil : ppx.Tensor(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public static func startBinomial(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) } + public static func add(totalCount: Offset, _ fbb: FlatBufferBuilder) { fbb.add(offset: totalCount, at: 0) } + public static func add(probs: Offset, _ fbb: FlatBufferBuilder) { fbb.add(offset: probs, at: 1) } + public static func endBinomial(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end } + public static func createBinomial(_ fbb: FlatBufferBuilder, + offsetOfTotalCount totalCount: Offset = Offset(), + offsetOfProbs probs: Offset = Offset()) -> Offset { + let __start = Binomial.startBinomial(fbb) + Binomial.add(totalCount: totalCount, fbb) + Binomial.add(probs: probs, fbb) + return Binomial.endBinomial(fbb, start: __start) + } +} + +public struct Weibull: FlatBufferObject { + + static func validateVersion() { FlatBuffersVersion_1_12_0() } + public var __buffer: ByteBuffer! { return _accessor.bb } + + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: "PPXF", addPrefix: prefix) } + public static func getRootAsWeibull(bb: ByteBuffer) -> Weibull { return Weibull(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } + + private init(_ t: Table) { _accessor = t } + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } + + public var scale: ppx.Tensor? { let o = _accessor.offset(4); return o == 0 ? nil : ppx.Tensor(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public var concentration: ppx.Tensor? { let o = _accessor.offset(6); return o == 0 ? nil : ppx.Tensor(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public static func startWeibull(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) } + public static func add(scale: Offset, _ fbb: FlatBufferBuilder) { fbb.add(offset: scale, at: 0) } + public static func add(concentration: Offset, _ fbb: FlatBufferBuilder) { fbb.add(offset: concentration, at: 1) } + public static func endWeibull(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end } + public static func createWeibull(_ fbb: FlatBufferBuilder, + offsetOfScale scale: Offset = Offset(), + offsetOfConcentration concentration: Offset = Offset()) -> Offset { + let __start = Weibull.startWeibull(fbb) + Weibull.add(scale: scale, fbb) + Weibull.add(concentration: concentration, fbb) + return Weibull.endWeibull(fbb, start: __start) + } +} + } // MARK: - ppx diff --git a/ts/ppx_generated.ts b/ts/ppx_generated.ts index edae0ed..0729d29 100644 --- a/ts/ppx_generated.ts +++ b/ts/ppx_generated.ts @@ -34,7 +34,9 @@ export enum Distribution{ Beta= 6, Exponential= 7, Gamma= 8, - LogNormal= 9 + LogNormal= 9, + Binomial= 10, + Weibull= 11 }}; /** @@ -2134,3 +2136,195 @@ static createLogNormal(builder:flatbuffers.Builder, locOffset:flatbuffers.Offset } } } +/** + * @constructor + */ +export namespace ppx{ +export class Binomial { + bb: flatbuffers.ByteBuffer|null = null; + + bb_pos:number = 0; +/** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Binomial + */ +__init(i:number, bb:flatbuffers.ByteBuffer):Binomial { + this.bb_pos = i; + this.bb = bb; + return this; +}; + +/** + * @param flatbuffers.ByteBuffer bb + * @param Binomial= obj + * @returns Binomial + */ +static getRootAsBinomial(bb:flatbuffers.ByteBuffer, obj?:Binomial):Binomial { + return (obj || new Binomial()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param flatbuffers.ByteBuffer bb + * @param Binomial= obj + * @returns Binomial + */ +static getSizePrefixedRootAsBinomial(bb:flatbuffers.ByteBuffer, obj?:Binomial):Binomial { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Binomial()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param ppx.Tensor= obj + * @returns ppx.Tensor|null + */ +totalCount(obj?:ppx.Tensor):ppx.Tensor|null { + var offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new ppx.Tensor()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +}; + +/** + * @param ppx.Tensor= obj + * @returns ppx.Tensor|null + */ +probs(obj?:ppx.Tensor):ppx.Tensor|null { + var offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new ppx.Tensor()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +}; + +/** + * @param flatbuffers.Builder builder + */ +static startBinomial(builder:flatbuffers.Builder) { + builder.startObject(2); +}; + +/** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset totalCountOffset + */ +static addTotalCount(builder:flatbuffers.Builder, totalCountOffset:flatbuffers.Offset) { + builder.addFieldOffset(0, totalCountOffset, 0); +}; + +/** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset probsOffset + */ +static addProbs(builder:flatbuffers.Builder, probsOffset:flatbuffers.Offset) { + builder.addFieldOffset(1, probsOffset, 0); +}; + +/** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ +static endBinomial(builder:flatbuffers.Builder):flatbuffers.Offset { + var offset = builder.endObject(); + return offset; +}; + +static createBinomial(builder:flatbuffers.Builder, totalCountOffset:flatbuffers.Offset, probsOffset:flatbuffers.Offset):flatbuffers.Offset { + Binomial.startBinomial(builder); + Binomial.addTotalCount(builder, totalCountOffset); + Binomial.addProbs(builder, probsOffset); + return Binomial.endBinomial(builder); +} +} +} +/** + * @constructor + */ +export namespace ppx{ +export class Weibull { + bb: flatbuffers.ByteBuffer|null = null; + + bb_pos:number = 0; +/** + * @param number i + * @param flatbuffers.ByteBuffer bb + * @returns Weibull + */ +__init(i:number, bb:flatbuffers.ByteBuffer):Weibull { + this.bb_pos = i; + this.bb = bb; + return this; +}; + +/** + * @param flatbuffers.ByteBuffer bb + * @param Weibull= obj + * @returns Weibull + */ +static getRootAsWeibull(bb:flatbuffers.ByteBuffer, obj?:Weibull):Weibull { + return (obj || new Weibull()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param flatbuffers.ByteBuffer bb + * @param Weibull= obj + * @returns Weibull + */ +static getSizePrefixedRootAsWeibull(bb:flatbuffers.ByteBuffer, obj?:Weibull):Weibull { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Weibull()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +}; + +/** + * @param ppx.Tensor= obj + * @returns ppx.Tensor|null + */ +scale(obj?:ppx.Tensor):ppx.Tensor|null { + var offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new ppx.Tensor()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +}; + +/** + * @param ppx.Tensor= obj + * @returns ppx.Tensor|null + */ +concentration(obj?:ppx.Tensor):ppx.Tensor|null { + var offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new ppx.Tensor()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +}; + +/** + * @param flatbuffers.Builder builder + */ +static startWeibull(builder:flatbuffers.Builder) { + builder.startObject(2); +}; + +/** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset scaleOffset + */ +static addScale(builder:flatbuffers.Builder, scaleOffset:flatbuffers.Offset) { + builder.addFieldOffset(0, scaleOffset, 0); +}; + +/** + * @param flatbuffers.Builder builder + * @param flatbuffers.Offset concentrationOffset + */ +static addConcentration(builder:flatbuffers.Builder, concentrationOffset:flatbuffers.Offset) { + builder.addFieldOffset(1, concentrationOffset, 0); +}; + +/** + * @param flatbuffers.Builder builder + * @returns flatbuffers.Offset + */ +static endWeibull(builder:flatbuffers.Builder):flatbuffers.Offset { + var offset = builder.endObject(); + return offset; +}; + +static createWeibull(builder:flatbuffers.Builder, scaleOffset:flatbuffers.Offset, concentrationOffset:flatbuffers.Offset):flatbuffers.Offset { + Weibull.startWeibull(builder); + Weibull.addScale(builder, scaleOffset); + Weibull.addConcentration(builder, concentrationOffset); + return Weibull.endWeibull(builder); +} +} +}