From 869922120cdf891e458f86ad0db7d1f8616e4ddb Mon Sep 17 00:00:00 2001 From: Joe Naegele Date: Fri, 13 Dec 2024 13:36:10 -0500 Subject: [PATCH] Fix NamedType generation in MATLAB codegen (#193) --- cpp/test/generated/binary/protocols.cc | 45 ++++++ cpp/test/generated/binary/protocols.h | 2 + cpp/test/generated/hdf5/protocols.cc | 40 +++++ cpp/test/generated/hdf5/protocols.h | 4 + cpp/test/generated/mocks.cc | 24 +++ cpp/test/generated/model.json | 64 ++++++++ cpp/test/generated/ndjson/protocols.cc | 42 +++++ cpp/test/generated/ndjson/protocols.h | 2 + cpp/test/generated/protocols.cc | 36 ++++- cpp/test/generated/protocols.h | 8 + cpp/test/generated/types.h | 18 +++ cpp/test/roundtrip_test.cc | 17 +++ matlab/generated/+basic_types/AliasedMap.m | 3 +- .../+basic_types/GenericNullableUnion2.m | 2 +- .../GenericRecordWithComputedFields.m | 20 ++- matlab/generated/+basic_types/GenericUnion2.m | 2 +- matlab/generated/+basic_types/GenericVector.m | 5 - matlab/generated/+basic_types/Int32OrString.m | 2 +- matlab/generated/+basic_types/MyTuple.m | 3 +- .../generated/+basic_types/RecordWithString.m | 6 +- .../+basic_types/RecordWithStringOrInt32.m | 2 +- .../generated/+basic_types/RecordWithUnions.m | 12 +- matlab/generated/+basic_types/T0OrT1.m | 2 +- .../generated/+basic_types/TimeOrDatetime.m | 2 +- matlab/generated/+image/FloatImage.m | 8 - matlab/generated/+image/Image.m | 5 - matlab/generated/+image/IntImage.m | 8 - .../+test_model/+binary/AliasesReader.m | 6 + .../+test_model/+binary/AliasesWriter.m | 6 + ...cordContainingVectorsOfAliasesSerializer.m | 27 ++++ .../+test_model/+testing/MockAliasesWriter.m | 13 ++ .../+test_model/+testing/TestAliasesWriter.m | 5 + .../+test_model/AcquisitionOrImage.m | 2 +- .../+test_model/AliasedClosedGeneric.m | 3 +- .../+test_model/AliasedGenericDynamicArray.m | 5 - .../+test_model/AliasedGenericFixedArray.m | 5 - .../+test_model/AliasedGenericFixedVector.m | 5 - .../+test_model/AliasedGenericOptional.m | 3 +- .../+test_model/AliasedGenericRank2Array.m | 5 - .../+test_model/AliasedGenericVector.m | 5 - .../AliasedIntOrAliasedSimpleRecord.m | 2 +- .../+test_model/AliasedIntOrSimpleRecord.m | 2 +- matlab/generated/+test_model/AliasedMap.m | 3 +- .../+test_model/AliasedMultiGenericOptional.m | 2 +- .../AliasedNullableIntSimpleRecord.m | 2 +- .../+test_model/AliasedOpenGeneric.m | 3 +- .../generated/+test_model/AliasedOptional.m | 6 +- .../+test_model/AliasedSimpleRecord.m | 3 +- matlab/generated/+test_model/AliasedString.m | 5 - matlab/generated/+test_model/AliasedTuple.m | 3 +- .../AliasedVectorOfGenericRecords.m | 5 - .../generated/+test_model/AliasesReaderBase.m | 16 +- .../generated/+test_model/AliasesWriterBase.m | 17 ++- matlab/generated/+test_model/ArrayOrScalar.m | 2 +- .../ArrayWithKeywordDimensionNames.m | 8 - matlab/generated/+test_model/GenericRecord.m | 26 +++- matlab/generated/+test_model/GenericUnion3.m | 2 +- .../+test_model/GenericUnion3Alternate.m | 2 +- .../GenericUnionWithRepeatedTypeParameters.m | 2 +- matlab/generated/+test_model/Image.m | 5 - .../+test_model/ImageFloatOrImageDouble.m | 2 +- matlab/generated/+test_model/Int32OrFloat32.m | 2 +- ...rStringOrSimpleRecordOrNamedFixedNDArray.m | 2 +- .../+test_model/Int32OrRecordWithVlens.m | 2 +- .../+test_model/Int32OrSimpleRecord.m | 2 +- matlab/generated/+test_model/IntArray.m | 8 - matlab/generated/+test_model/IntFixedArray.m | 8 - .../IntOrGenericRecordWithComputedFields.m | 2 +- matlab/generated/+test_model/IntRank2Array.m | 8 - matlab/generated/+test_model/MapOrScalar.m | 2 +- matlab/generated/+test_model/MyTuple.m | 3 +- .../generated/+test_model/NamedFixedNDArray.m | 8 - matlab/generated/+test_model/NamedNDArray.m | 8 - .../RecordContainingGenericRecords.m | 38 +++-- .../RecordContainingNestedGenericRecords.m | 16 +- .../RecordContainingVectorsOfAliases.m | 57 +++++++ .../+test_model/RecordNotUsedInProtocol.m | 8 +- .../+test_model/RecordWithAliasedGenerics.m | 8 +- .../RecordWithAliasedOptionalGenericField.m | 6 +- ...cordWithAliasedOptionalGenericUnionField.m | 6 +- .../generated/+test_model/RecordWithArrays.m | 28 ++-- .../RecordWithArraysSimpleSyntax.m | 28 ++-- .../+test_model/RecordWithComputedFields.m | 74 ++++----- .../+test_model/RecordWithDynamicNDArrays.m | 10 +- .../generated/+test_model/RecordWithEnums.m | 26 +++- .../+test_model/RecordWithFixedArrays.m | 10 +- .../+test_model/RecordWithFixedCollections.m | 8 +- .../+test_model/RecordWithFixedVectors.m | 10 +- .../+test_model/RecordWithFloatArrays.m | 3 +- .../+test_model/RecordWithGenericArrays.m | 30 +++- .../RecordWithGenericFixedVectors.m | 22 ++- .../+test_model/RecordWithGenericMaps.m | 12 +- .../RecordWithGenericVectorOfRecords.m | 20 ++- .../+test_model/RecordWithGenericVectors.m | 22 ++- .../+test_model/RecordWithIntVectors.m | 3 +- .../+test_model/RecordWithKeywordFields.m | 28 +++- matlab/generated/+test_model/RecordWithMaps.m | 12 +- .../+test_model/RecordWithNDArrays.m | 16 +- .../RecordWithNDArraysSingleDimension.m | 16 +- .../+test_model/RecordWithNamedFixedArrays.m | 10 +- .../+test_model/RecordWithNoDefaultEnum.m | 20 ++- .../+test_model/RecordWithOptionalDate.m | 6 +- .../+test_model/RecordWithOptionalFields.m | 10 +- .../RecordWithOptionalGenericField.m | 6 +- .../RecordWithOptionalGenericUnionField.m | 6 +- .../+test_model/RecordWithOptionalVector.m | 6 +- .../+test_model/RecordWithPrimitiveAliases.m | 22 +-- .../+test_model/RecordWithPrimitives.m | 38 ++--- .../generated/+test_model/RecordWithStrings.m | 8 +- .../RecordWithUnionsOfContainers.m | 12 +- .../+test_model/RecordWithVectorOfTimes.m | 6 +- .../generated/+test_model/RecordWithVectors.m | 10 +- .../+test_model/RecordWithVlenCollections.m | 10 +- .../generated/+test_model/RecordWithVlens.m | 10 +- .../+test_model/RecordWithVlensFixedArray.m | 8 - .../generated/+test_model/SimpleAcquisition.m | 16 +- .../+test_model/SimpleEncodingCounters.m | 12 +- matlab/generated/+test_model/SimpleRecord.m | 10 +- .../+test_model/SimpleRecordFixedArray.m | 8 - .../+test_model/SmallBenchmarkRecord.m | 10 +- matlab/generated/+test_model/StringOrInt32.m | 2 +- .../generated/+test_model/TupleWithRecords.m | 8 +- matlab/generated/+test_model/UOrV.m | 2 +- .../+test_model/UnionOfContainerRecords.m | 2 +- .../+test_model/VectorOfGenericRecords.m | 5 - matlab/generated/+test_model/VectorOrScalar.m | 2 +- matlab/generated/+tuples/Tuple.m | 22 ++- matlab/test/ComputedFieldsTest.m | 4 +- matlab/test/GeneratedTypesTest.m | 7 +- matlab/test/RoundTripTest.m | 40 +++-- models/test/unittests.yml | 8 + python/test_model/__init__.py | 1 + python/test_model/binary.py | 24 +++ python/test_model/ndjson.py | 66 ++++++++ python/test_model/protocols.py | 47 ++++-- python/test_model/types.py | 34 +++++ python/tests/test_protocol_roundtrip.py | 13 ++ tooling/internal/matlab/common/common.go | 2 +- .../static_files/+binary/MapSerializer.m | 8 +- tooling/internal/matlab/static_files/Date.m | 8 +- .../internal/matlab/static_files/DateTime.m | 8 +- tooling/internal/matlab/static_files/Map.m | 73 +++++++++ tooling/internal/matlab/static_files/Time.m | 8 +- tooling/internal/matlab/static_files/Union.m | 4 + tooling/internal/matlab/types/types.go | 143 ++++++++---------- 145 files changed, 1419 insertions(+), 530 deletions(-) delete mode 100644 matlab/generated/+basic_types/GenericVector.m delete mode 100644 matlab/generated/+image/FloatImage.m delete mode 100644 matlab/generated/+image/Image.m delete mode 100644 matlab/generated/+image/IntImage.m create mode 100644 matlab/generated/+test_model/+binary/RecordContainingVectorsOfAliasesSerializer.m delete mode 100644 matlab/generated/+test_model/AliasedGenericDynamicArray.m delete mode 100644 matlab/generated/+test_model/AliasedGenericFixedArray.m delete mode 100644 matlab/generated/+test_model/AliasedGenericFixedVector.m delete mode 100644 matlab/generated/+test_model/AliasedGenericRank2Array.m delete mode 100644 matlab/generated/+test_model/AliasedGenericVector.m delete mode 100644 matlab/generated/+test_model/AliasedString.m delete mode 100644 matlab/generated/+test_model/AliasedVectorOfGenericRecords.m delete mode 100644 matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m delete mode 100644 matlab/generated/+test_model/Image.m delete mode 100644 matlab/generated/+test_model/IntArray.m delete mode 100644 matlab/generated/+test_model/IntFixedArray.m delete mode 100644 matlab/generated/+test_model/IntRank2Array.m delete mode 100644 matlab/generated/+test_model/NamedFixedNDArray.m delete mode 100644 matlab/generated/+test_model/NamedNDArray.m create mode 100644 matlab/generated/+test_model/RecordContainingVectorsOfAliases.m delete mode 100644 matlab/generated/+test_model/RecordWithVlensFixedArray.m delete mode 100644 matlab/generated/+test_model/SimpleRecordFixedArray.m delete mode 100644 matlab/generated/+test_model/VectorOfGenericRecords.m create mode 100644 tooling/internal/matlab/static_files/Map.m diff --git a/cpp/test/generated/binary/protocols.cc b/cpp/test/generated/binary/protocols.cc index 656c5712..276c62c1 100644 --- a/cpp/test/generated/binary/protocols.cc +++ b/cpp/test/generated/binary/protocols.cc @@ -551,6 +551,19 @@ struct IsTriviallySerializable offsetof(__T__, f1) < offsetof(__T__, f1a) && offsetof(__T__, f1a) < offsetof(__T__, f2) && offsetof(__T__, f2) < offsetof(__T__, f2a) && offsetof(__T__, f2a) < offsetof(__T__, nested); }; +template <> +struct IsTriviallySerializable { + using __T__ = test_model::RecordContainingVectorsOfAliases; + static constexpr bool value = + std::is_standard_layout_v<__T__> && + IsTriviallySerializable::value && + IsTriviallySerializable::value && + IsTriviallySerializable::value && + IsTriviallySerializable::value && + (sizeof(__T__) == (sizeof(__T__::strings) + sizeof(__T__::maps) + sizeof(__T__::arrays) + sizeof(__T__::tuples))) && + offsetof(__T__, strings) < offsetof(__T__, maps) && offsetof(__T__, maps) < offsetof(__T__, arrays) && offsetof(__T__, arrays) < offsetof(__T__, tuples); +}; + template <> struct IsTriviallySerializable { using __T__ = test_model::RecordWithComputedFields; @@ -2566,6 +2579,30 @@ template ReadA, typename B, yardl::binary:: test_model::binary::ReadRecordContainingGenericRecords(stream, value.nested); } +[[maybe_unused]] void WriteRecordContainingVectorsOfAliases(yardl::binary::CodedOutputStream& stream, test_model::RecordContainingVectorsOfAliases const& value) { + if constexpr (yardl::binary::IsTriviallySerializable::value) { + yardl::binary::WriteTriviallySerializable(stream, value); + return; + } + + yardl::binary::WriteVector(stream, value.strings); + yardl::binary::WriteVector, test_model::binary::WriteAliasedMap>(stream, value.maps); + yardl::binary::WriteVector, test_model::binary::WriteImage>(stream, value.arrays); + yardl::binary::WriteVector, test_model::binary::WriteMyTuple>(stream, value.tuples); +} + +[[maybe_unused]] void ReadRecordContainingVectorsOfAliases(yardl::binary::CodedInputStream& stream, test_model::RecordContainingVectorsOfAliases& value) { + if constexpr (yardl::binary::IsTriviallySerializable::value) { + yardl::binary::ReadTriviallySerializable(stream, value); + return; + } + + yardl::binary::ReadVector(stream, value.strings); + yardl::binary::ReadVector, test_model::binary::ReadAliasedMap>(stream, value.maps); + yardl::binary::ReadVector, test_model::binary::ReadImage>(stream, value.arrays); + yardl::binary::ReadVector, test_model::binary::ReadMyTuple>(stream, value.tuples); +} + [[maybe_unused]] void WriteAliasedIntOrSimpleRecord(yardl::binary::CodedOutputStream& stream, test_model::AliasedIntOrSimpleRecord const& value) { if constexpr (yardl::binary::IsTriviallySerializable::value) { yardl::binary::WriteTriviallySerializable(stream, value); @@ -4387,6 +4424,10 @@ void AliasesWriter::EndStreamOfAliasedGenericUnion2Impl() { yardl::binary::WriteInteger(stream_, 0U); } +void AliasesWriter::WriteVectorsImpl(std::vector const& value) { + yardl::binary::WriteVector(stream_, value); +} + void AliasesWriter::Flush() { stream_.Flush(); } @@ -4442,6 +4483,10 @@ bool AliasesReader::ReadStreamOfAliasedGenericUnion2Impl(std::vector& value) { + yardl::binary::ReadVector(stream_, value); +} + void AliasesReader::CloseImpl() { stream_.VerifyFinished(); } diff --git a/cpp/test/generated/binary/protocols.h b/cpp/test/generated/binary/protocols.h index f5cbe401..c391ec65 100644 --- a/cpp/test/generated/binary/protocols.h +++ b/cpp/test/generated/binary/protocols.h @@ -1341,6 +1341,7 @@ class AliasesWriter : public test_model::AliasesWriterBase, yardl::binary::Binar void WriteStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2 const& value) override; void WriteStreamOfAliasedGenericUnion2Impl(std::vector> const& values) override; void EndStreamOfAliasedGenericUnion2Impl() override; + void WriteVectorsImpl(std::vector const& value) override; void CloseImpl() override; Version version_; @@ -1369,6 +1370,7 @@ class AliasesReader : public test_model::AliasesReaderBase, yardl::binary::Binar void ReadAliasedGenericFixedVectorImpl(test_model::AliasedGenericFixedVector& value) override; bool ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2& value) override; bool ReadStreamOfAliasedGenericUnion2Impl(std::vector>& values) override; + void ReadVectorsImpl(std::vector& value) override; void CloseImpl() override; Version version_; diff --git a/cpp/test/generated/hdf5/protocols.cc b/cpp/test/generated/hdf5/protocols.cc index c2d786b4..7d1cbdcb 100644 --- a/cpp/test/generated/hdf5/protocols.cc +++ b/cpp/test/generated/hdf5/protocols.cc @@ -1170,6 +1170,28 @@ struct _Inner_RecordContainingNestedGenericRecords { test_model::hdf5::_Inner_RecordContainingGenericRecords nested; }; +struct _Inner_RecordContainingVectorsOfAliases { + _Inner_RecordContainingVectorsOfAliases() {} + _Inner_RecordContainingVectorsOfAliases(test_model::RecordContainingVectorsOfAliases const& o) + : strings(o.strings), + maps(o.maps), + arrays(o.arrays), + tuples(o.tuples) { + } + + void ToOuter (test_model::RecordContainingVectorsOfAliases& o) const { + yardl::hdf5::ToOuter(strings, o.strings); + yardl::hdf5::ToOuter(maps, o.maps); + yardl::hdf5::ToOuter(arrays, o.arrays); + yardl::hdf5::ToOuter(tuples, o.tuples); + } + + yardl::hdf5::InnerVlen strings; + yardl::hdf5::InnerVlen, test_model::AliasedMap> maps; + yardl::hdf5::InnerVlen, test_model::Image> arrays; + yardl::hdf5::InnerVlen, test_model::MyTuple> tuples; +}; + struct _Inner_RecordWithComputedFields { _Inner_RecordWithComputedFields() {} _Inner_RecordWithComputedFields(test_model::RecordWithComputedFields const& o) @@ -1706,6 +1728,16 @@ template return t; } +[[maybe_unused]] H5::CompType GetRecordContainingVectorsOfAliasesHdf5Ddl() { + using RecordType = test_model::hdf5::_Inner_RecordContainingVectorsOfAliases; + H5::CompType t(sizeof(RecordType)); + t.insertMember("strings", HOFFSET(RecordType, strings), yardl::hdf5::InnerVlenDdl(yardl::hdf5::InnerVlenStringDdl())); + t.insertMember("maps", HOFFSET(RecordType, maps), yardl::hdf5::InnerVlenDdl(yardl::hdf5::InnerMapDdl(yardl::hdf5::InnerVlenStringDdl(), H5::PredType::NATIVE_INT32))); + t.insertMember("arrays", HOFFSET(RecordType, arrays), yardl::hdf5::InnerVlenDdl(yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT))); + t.insertMember("tuples", HOFFSET(RecordType, tuples), yardl::hdf5::InnerVlenDdl(tuples::hdf5::GetTupleHdf5Ddl(H5::PredType::NATIVE_INT32, test_model::hdf5::GetSimpleRecordHdf5Ddl()))); + return t; +} + [[maybe_unused]] H5::CompType GetRecordWithComputedFieldsHdf5Ddl() { using RecordType = test_model::hdf5::_Inner_RecordWithComputedFields; H5::CompType t(sizeof(RecordType)); @@ -3709,6 +3741,10 @@ void AliasesWriter::EndStreamOfAliasedGenericUnion2Impl() { streamOfAliasedGenericUnion2_dataset_state_.reset(); } +void AliasesWriter::WriteVectorsImpl(std::vector const& value) { + yardl::hdf5::WriteScalarDataset, std::vector>(group_, "vectors", yardl::hdf5::InnerVlenDdl(test_model::hdf5::GetRecordContainingVectorsOfAliasesHdf5Ddl()), value); +} + void AliasesWriter::Flush() { if (streamOfAliasedGenericUnion2_dataset_state_) { streamOfAliasedGenericUnion2_dataset_state_->Flush(); @@ -3782,6 +3818,10 @@ bool AliasesReader::ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGene return true; } +void AliasesReader::ReadVectorsImpl(std::vector& value) { + yardl::hdf5::ReadScalarDataset, std::vector>(group_, "vectors", yardl::hdf5::InnerVlenDdl(test_model::hdf5::GetRecordContainingVectorsOfAliasesHdf5Ddl()), value); +} + StreamsOfAliasedUnionsWriter::StreamsOfAliasedUnionsWriter(std::string path) : yardl::hdf5::Hdf5Writer::Hdf5Writer(path, "StreamsOfAliasedUnions", schema_) { } diff --git a/cpp/test/generated/hdf5/protocols.h b/cpp/test/generated/hdf5/protocols.h index 4e84b47a..3983e532 100644 --- a/cpp/test/generated/hdf5/protocols.h +++ b/cpp/test/generated/hdf5/protocols.h @@ -1074,6 +1074,8 @@ class AliasesWriter : public test_model::AliasesWriterBase, public yardl::hdf5:: void EndStreamOfAliasedGenericUnion2Impl() override; + void WriteVectorsImpl(std::vector const& value) override; + public: void Flush() override; @@ -1106,6 +1108,8 @@ class AliasesReader : public test_model::AliasesReaderBase, public yardl::hdf5:: bool ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2& value) override; + void ReadVectorsImpl(std::vector& value) override; + private: std::unique_ptr> streamOfAliasedGenericUnion2_dataset_state_; }; diff --git a/cpp/test/generated/mocks.cc b/cpp/test/generated/mocks.cc index 2996f144..d7a389db 100644 --- a/cpp/test/generated/mocks.cc +++ b/cpp/test/generated/mocks.cc @@ -3994,6 +3994,22 @@ class MockAliasesWriter : public AliasesWriterBase { EndStreamOfAliasedGenericUnion2Impl_expected_call_count_++; } + void WriteVectorsImpl (std::vector const& value) override { + if (WriteVectorsImpl_expected_values_.empty()) { + throw std::runtime_error("Unexpected call to WriteVectorsImpl"); + } + if (WriteVectorsImpl_expected_values_.front() != value) { + throw std::runtime_error("Unexpected argument value for call to WriteVectorsImpl"); + } + WriteVectorsImpl_expected_values_.pop(); + } + + std::queue> WriteVectorsImpl_expected_values_; + + void ExpectWriteVectorsImpl (std::vector const& value) { + WriteVectorsImpl_expected_values_.push(value); + } + void Verify() { if (!WriteAliasedStringImpl_expected_values_.empty()) { throw std::runtime_error("Expected call to WriteAliasedStringImpl was not received"); @@ -4028,6 +4044,9 @@ class MockAliasesWriter : public AliasesWriterBase { if (EndStreamOfAliasedGenericUnion2Impl_expected_call_count_ > 0) { throw std::runtime_error("Expected call to EndStreamOfAliasedGenericUnion2Impl was not received"); } + if (!WriteVectorsImpl_expected_values_.empty()) { + throw std::runtime_error("Expected call to WriteVectorsImpl was not received"); + } } }; @@ -4105,6 +4124,11 @@ class TestAliasesWriterBase : public AliasesWriterBase { mock_writer_.ExpectEndStreamOfAliasedGenericUnion2Impl(); } + void WriteVectorsImpl(std::vector const& value) override { + writer_->WriteVectors(value); + mock_writer_.ExpectWriteVectorsImpl(value); + } + void CloseImpl() override { close_called_ = true; writer_->Close(); diff --git a/cpp/test/generated/model.json b/cpp/test/generated/model.json index f95c8dff..0949c1be 100644 --- a/cpp/test/generated/model.json +++ b/cpp/test/generated/model.json @@ -2326,6 +2326,62 @@ ] } }, + { + "record": { + "name": "RecordContainingVectorsOfAliases", + "fields": [ + { + "name": "strings", + "type": { + "vector": { + "items": "TestModel.AliasedString" + } + } + }, + { + "name": "maps", + "type": { + "vector": { + "items": { + "name": "TestModel.AliasedMap", + "typeArguments": [ + "string", + "int32" + ] + } + } + } + }, + { + "name": "arrays", + "type": { + "vector": { + "items": { + "name": "TestModel.Image", + "typeArguments": [ + "float32" + ] + } + } + } + }, + { + "name": "tuples", + "type": { + "vector": { + "items": { + "name": "TestModel.MyTuple", + "typeArguments": [ + "int32", + "TestModel.SimpleRecord" + ] + } + } + } + } + ] + } + }, { "alias": { "name": "AliasedIntOrSimpleRecord", @@ -5435,6 +5491,14 @@ } } } + }, + { + "name": "vectors", + "type": { + "vector": { + "items": "TestModel.RecordContainingVectorsOfAliases" + } + } } ] }, diff --git a/cpp/test/generated/ndjson/protocols.cc b/cpp/test/generated/ndjson/protocols.cc index 36d1c89d..c94733bd 100644 --- a/cpp/test/generated/ndjson/protocols.cc +++ b/cpp/test/generated/ndjson/protocols.cc @@ -197,6 +197,9 @@ void from_json(ordered_json const& j, test_model::RecordContainingGenericRecords void to_json(ordered_json& j, test_model::RecordContainingNestedGenericRecords const& value); void from_json(ordered_json const& j, test_model::RecordContainingNestedGenericRecords& value); +void to_json(ordered_json& j, test_model::RecordContainingVectorsOfAliases const& value); +void from_json(ordered_json const& j, test_model::RecordContainingVectorsOfAliases& value); + void to_json(ordered_json& j, test_model::RecordWithComputedFields const& value); void from_json(ordered_json const& j, test_model::RecordWithComputedFields& value); @@ -2477,6 +2480,37 @@ void from_json(ordered_json const& j, test_model::RecordContainingNestedGenericR } } +void to_json(ordered_json& j, test_model::RecordContainingVectorsOfAliases const& value) { + j = ordered_json::object(); + if (yardl::ndjson::ShouldSerializeFieldValue(value.strings)) { + j.push_back({"strings", value.strings}); + } + if (yardl::ndjson::ShouldSerializeFieldValue(value.maps)) { + j.push_back({"maps", value.maps}); + } + if (yardl::ndjson::ShouldSerializeFieldValue(value.arrays)) { + j.push_back({"arrays", value.arrays}); + } + if (yardl::ndjson::ShouldSerializeFieldValue(value.tuples)) { + j.push_back({"tuples", value.tuples}); + } +} + +void from_json(ordered_json const& j, test_model::RecordContainingVectorsOfAliases& value) { + if (auto it = j.find("strings"); it != j.end()) { + it->get_to(value.strings); + } + if (auto it = j.find("maps"); it != j.end()) { + it->get_to(value.maps); + } + if (auto it = j.find("arrays"); it != j.end()) { + it->get_to(value.arrays); + } + if (auto it = j.find("tuples"); it != j.end()) { + it->get_to(value.tuples); + } +} + void to_json(ordered_json& j, test_model::RecordWithComputedFields const& value) { j = ordered_json::object(); if (yardl::ndjson::ShouldSerializeFieldValue(value.array_field)) { @@ -3915,6 +3949,10 @@ void AliasesWriter::WriteStreamOfAliasedGenericUnion2Impl(test_model::AliasedGen ordered_json json_value = value; yardl::ndjson::WriteProtocolValue(stream_, "streamOfAliasedGenericUnion2", json_value);} +void AliasesWriter::WriteVectorsImpl(std::vector const& value) { + ordered_json json_value = value; + yardl::ndjson::WriteProtocolValue(stream_, "vectors", json_value);} + void AliasesWriter::Flush() { stream_.flush(); } @@ -3963,6 +4001,10 @@ bool AliasesReader::ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGene return yardl::ndjson::ReadProtocolValue(stream_, line_, "streamOfAliasedGenericUnion2", false, unused_step_, value); } +void AliasesReader::ReadVectorsImpl(std::vector& value) { + yardl::ndjson::ReadProtocolValue(stream_, line_, "vectors", true, unused_step_, value); +} + void AliasesReader::CloseImpl() { VerifyFinished(); } diff --git a/cpp/test/generated/ndjson/protocols.h b/cpp/test/generated/ndjson/protocols.h index 7a326a31..762f826d 100644 --- a/cpp/test/generated/ndjson/protocols.h +++ b/cpp/test/generated/ndjson/protocols.h @@ -1208,6 +1208,7 @@ class AliasesWriter : public test_model::AliasesWriterBase, yardl::ndjson::NDJso void WriteAliasedGenericFixedVectorImpl(test_model::AliasedGenericFixedVector const& value) override; void WriteStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2 const& value) override; void EndStreamOfAliasedGenericUnion2Impl() override {} + void WriteVectorsImpl(std::vector const& value) override; void CloseImpl() override; }; @@ -1233,6 +1234,7 @@ class AliasesReader : public test_model::AliasesReaderBase, yardl::ndjson::NDJso void ReadAliasedGenericVectorImpl(test_model::AliasedGenericVector& value) override; void ReadAliasedGenericFixedVectorImpl(test_model::AliasedGenericFixedVector& value) override; bool ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2& value) override; + void ReadVectorsImpl(std::vector& value) override; void CloseImpl() override; }; diff --git a/cpp/test/generated/protocols.cc b/cpp/test/generated/protocols.cc index 7c2d7300..1a66d211 100644 --- a/cpp/test/generated/protocols.cc +++ b/cpp/test/generated/protocols.cc @@ -6006,6 +6006,7 @@ void AliasesWriterBaseInvalidState(uint8_t attempted, [[maybe_unused]] bool end, case 7: expected_method = "WriteAliasedGenericVector()"; break; case 8: expected_method = "WriteAliasedGenericFixedVector()"; break; case 9: expected_method = "WriteStreamOfAliasedGenericUnion2() or EndStreamOfAliasedGenericUnion2()"; break; + case 10: expected_method = "WriteVectors()"; break; } std::string attempted_method; switch (attempted) { @@ -6019,7 +6020,8 @@ void AliasesWriterBaseInvalidState(uint8_t attempted, [[maybe_unused]] bool end, case 7: attempted_method = "WriteAliasedGenericVector()"; break; case 8: attempted_method = "WriteAliasedGenericFixedVector()"; break; case 9: attempted_method = end ? "EndStreamOfAliasedGenericUnion2()" : "WriteStreamOfAliasedGenericUnion2()"; break; - case 10: attempted_method = "Close()"; break; + case 10: attempted_method = "WriteVectors()"; break; + case 11: attempted_method = "Close()"; break; } throw std::runtime_error("Expected call to " + expected_method + " but received call to " + attempted_method + " instead."); } @@ -6037,7 +6039,8 @@ void AliasesReaderBaseInvalidState(uint8_t attempted, uint8_t current) { case 7: return "ReadAliasedGenericVector()"; case 8: return "ReadAliasedGenericFixedVector()"; case 9: return "ReadStreamOfAliasedGenericUnion2()"; - case 10: return "Close()"; + case 10: return "ReadVectors()"; + case 11: return "Close()"; default: return ""; } }; @@ -6046,7 +6049,7 @@ void AliasesReaderBaseInvalidState(uint8_t attempted, uint8_t current) { } // namespace -std::string AliasesWriterBase::schema_ = R"({"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}}]},"types":[{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]})"; +std::string AliasesWriterBase::schema_ = R"({"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}},{"name":"vectors","type":{"vector":{"items":"TestModel.RecordContainingVectorsOfAliases"}}}]},"types":[{"name":"AliasedMap","typeParameters":["K","V"],"type":{"map":{"keys":"K","values":"V"}}},{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedMap","typeParameters":["K","V"],"type":{"name":"BasicTypes.AliasedMap","typeArguments":["K","V"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"RecordContainingVectorsOfAliases","fields":[{"name":"strings","type":{"vector":{"items":"TestModel.AliasedString"}}},{"name":"maps","type":{"vector":{"items":{"name":"TestModel.AliasedMap","typeArguments":["string","int32"]}}}},{"name":"arrays","type":{"vector":{"items":{"name":"TestModel.Image","typeArguments":["float32"]}}}},{"name":"tuples","type":{"vector":{"items":{"name":"TestModel.MyTuple","typeArguments":["int32","TestModel.SimpleRecord"]}}}}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]})"; std::vector AliasesWriterBase::previous_schemas_ = { }; @@ -6171,11 +6174,20 @@ void AliasesWriterBase::WriteStreamOfAliasedGenericUnion2Impl(std::vector const& value) { if (unlikely(state_ != 10)) { AliasesWriterBaseInvalidState(10, false, state_); } + WriteVectorsImpl(value); + state_ = 11; +} + +void AliasesWriterBase::Close() { + if (unlikely(state_ != 11)) { + AliasesWriterBaseInvalidState(11, false, state_); + } + CloseImpl(); } @@ -6324,7 +6336,7 @@ bool AliasesReaderBase::ReadStreamOfAliasedGenericUnion2Impl(std::vector& value) { if (unlikely(state_ != 20)) { if (state_ == 19) { state_ = 20; @@ -6333,6 +6345,15 @@ void AliasesReaderBase::Close() { } } + ReadVectorsImpl(value); + state_ = 22; +} + +void AliasesReaderBase::Close() { + if (unlikely(state_ != 22)) { + AliasesReaderBaseInvalidState(22, state_); + } + CloseImpl(); } void AliasesReaderBase::CopyTo(AliasesWriterBase& writer, size_t stream_of_aliased_generic_union_2_buffer_size) { @@ -6395,6 +6416,11 @@ void AliasesReaderBase::CopyTo(AliasesWriterBase& writer, size_t stream_of_alias } writer.EndStreamOfAliasedGenericUnion2(); } + { + std::vector value; + ReadVectors(value); + writer.WriteVectors(value); + } } namespace { diff --git a/cpp/test/generated/protocols.h b/cpp/test/generated/protocols.h index 5d92ff7d..a9dc7c70 100644 --- a/cpp/test/generated/protocols.h +++ b/cpp/test/generated/protocols.h @@ -2522,6 +2522,9 @@ class AliasesWriterBase { // Marks the end of the `streamOfAliasedGenericUnion2` stream. void EndStreamOfAliasedGenericUnion2(); + // Ordinal 10. + void WriteVectors(std::vector const& value); + // Optionaly close this writer before destructing. Validates that all steps were completed. void Close(); @@ -2543,6 +2546,7 @@ class AliasesWriterBase { virtual void WriteStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2 const& value) = 0; virtual void WriteStreamOfAliasedGenericUnion2Impl(std::vector> const& value); virtual void EndStreamOfAliasedGenericUnion2Impl() = 0; + virtual void WriteVectorsImpl(std::vector const& value) = 0; virtual void CloseImpl() {} static std::string schema_; @@ -2593,6 +2597,9 @@ class AliasesReaderBase { // Ordinal 9. [[nodiscard]] bool ReadStreamOfAliasedGenericUnion2(std::vector>& values); + // Ordinal 10. + void ReadVectors(std::vector& value); + // Optionaly close this writer before destructing. Validates that all steps were completely read. void Close(); @@ -2612,6 +2619,7 @@ class AliasesReaderBase { virtual void ReadAliasedGenericFixedVectorImpl(test_model::AliasedGenericFixedVector& value) = 0; virtual bool ReadStreamOfAliasedGenericUnion2Impl(test_model::AliasedGenericUnion2& value) = 0; virtual bool ReadStreamOfAliasedGenericUnion2Impl(std::vector>& values); + virtual void ReadVectorsImpl(std::vector& value) = 0; virtual void CloseImpl() {} static std::string schema_; diff --git a/cpp/test/generated/types.h b/cpp/test/generated/types.h index 276f5bbf..1f98026b 100644 --- a/cpp/test/generated/types.h +++ b/cpp/test/generated/types.h @@ -925,6 +925,24 @@ struct RecordContainingNestedGenericRecords { } }; +struct RecordContainingVectorsOfAliases { + std::vector strings{}; + std::vector> maps{}; + std::vector> arrays{}; + std::vector> tuples{}; + + bool operator==(const RecordContainingVectorsOfAliases& other) const { + return strings == other.strings && + maps == other.maps && + arrays == other.arrays && + tuples == other.tuples; + } + + bool operator!=(const RecordContainingVectorsOfAliases& other) const { + return !(*this == other); + } +}; + using AliasedIntOrSimpleRecord = std::variant; using AliasedIntOrAliasedSimpleRecord = std::variant; diff --git a/cpp/test/roundtrip_test.cc b/cpp/test/roundtrip_test.cc index 62c0e67c..fd4253b0 100644 --- a/cpp/test/roundtrip_test.cc +++ b/cpp/test/roundtrip_test.cc @@ -596,6 +596,23 @@ TEST_P(RoundTripTests, Aliases) { tw->WriteStreamOfAliasedGenericUnion2(ae); tw->EndStreamOfAliasedGenericUnion2(); + std::vector aliased_strings = {"hello", "world"}; + std::vector> aliased_maps = { + {{"a", 1}, {"b", 2}}, + {{"c", 3}, {"d", 4}}, + }; + Image image = {{1, 2}, {3, 4}}; + std::vector> aliased_arrays{image, image}; + MyTuple my_tuple{42, SimpleRecord{1, 2, 3}}; + std::vector> aliased_tuples{my_tuple, my_tuple}; + RecordContainingVectorsOfAliases vrec{ + aliased_strings, + aliased_maps, + aliased_arrays, + aliased_tuples}; + std::vector vector_records{vrec, vrec}; + tw->WriteVectors(vector_records); + tw->Close(); } diff --git a/matlab/generated/+basic_types/AliasedMap.m b/matlab/generated/+basic_types/AliasedMap.m index c594a04e..99330cb3 100644 --- a/matlab/generated/+basic_types/AliasedMap.m +++ b/matlab/generated/+basic_types/AliasedMap.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function m = AliasedMap(varargin) - m = dictionary(varargin{:}); +classdef AliasedMap < yardl.Map end diff --git a/matlab/generated/+basic_types/GenericNullableUnion2.m b/matlab/generated/+basic_types/GenericNullableUnion2.m index 574e124a..406651df 100644 --- a/matlab/generated/+basic_types/GenericNullableUnion2.m +++ b/matlab/generated/+basic_types/GenericNullableUnion2.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.GenericNullableUnion2") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.GenericNullableUnion2") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+basic_types/GenericRecordWithComputedFields.m b/matlab/generated/+basic_types/GenericRecordWithComputedFields.m index c7781274..30f9bc43 100644 --- a/matlab/generated/+basic_types/GenericRecordWithComputedFields.m +++ b/matlab/generated/+basic_types/GenericRecordWithComputedFields.m @@ -33,12 +33,30 @@ function res = eq(self, other) res = ... isa(other, "basic_types.GenericRecordWithComputedFields") && ... - isequal(self.f1, other.f1); + isequal({self.f1}, {other.f1}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = basic_types.GenericRecordWithComputedFields(f1=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+basic_types/GenericUnion2.m b/matlab/generated/+basic_types/GenericUnion2.m index 610b0703..be97ca4a 100644 --- a/matlab/generated/+basic_types/GenericUnion2.m +++ b/matlab/generated/+basic_types/GenericUnion2.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.GenericUnion2") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.GenericUnion2") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+basic_types/GenericVector.m b/matlab/generated/+basic_types/GenericVector.m deleted file mode 100644 index 09d85a55..00000000 --- a/matlab/generated/+basic_types/GenericVector.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = GenericVector(array) - a = array; -end diff --git a/matlab/generated/+basic_types/Int32OrString.m b/matlab/generated/+basic_types/Int32OrString.m index 0afdbb22..e140c22b 100644 --- a/matlab/generated/+basic_types/Int32OrString.m +++ b/matlab/generated/+basic_types/Int32OrString.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.Int32OrString") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.Int32OrString") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+basic_types/MyTuple.m b/matlab/generated/+basic_types/MyTuple.m index 2487c8c5..931e3385 100644 --- a/matlab/generated/+basic_types/MyTuple.m +++ b/matlab/generated/+basic_types/MyTuple.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = MyTuple(varargin) - c = tuples.Tuple(varargin{:}); +classdef MyTuple < tuples.Tuple end diff --git a/matlab/generated/+basic_types/RecordWithString.m b/matlab/generated/+basic_types/RecordWithString.m index 37982fd8..89ff199e 100644 --- a/matlab/generated/+basic_types/RecordWithString.m +++ b/matlab/generated/+basic_types/RecordWithString.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "basic_types.RecordWithString") && ... - isequal(self.i, other.i); + isequal({self.i}, {other.i}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+basic_types/RecordWithStringOrInt32.m b/matlab/generated/+basic_types/RecordWithStringOrInt32.m index 1a014df2..deb938da 100644 --- a/matlab/generated/+basic_types/RecordWithStringOrInt32.m +++ b/matlab/generated/+basic_types/RecordWithStringOrInt32.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.RecordWithStringOrInt32") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.RecordWithStringOrInt32") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+basic_types/RecordWithUnions.m b/matlab/generated/+basic_types/RecordWithUnions.m index 34b27752..ad659ff7 100644 --- a/matlab/generated/+basic_types/RecordWithUnions.m +++ b/matlab/generated/+basic_types/RecordWithUnions.m @@ -25,15 +25,19 @@ function res = eq(self, other) res = ... isa(other, "basic_types.RecordWithUnions") && ... - isequal(self.null_or_int_or_string, other.null_or_int_or_string) && ... - isequal(self.date_or_datetime, other.date_or_datetime) && ... - isequal(self.null_or_fruits_or_days_of_week, other.null_or_fruits_or_days_of_week) && ... - isequal(self.record_or_int, other.record_or_int); + isequal({self.null_or_int_or_string}, {other.null_or_int_or_string}) && ... + isequal({self.date_or_datetime}, {other.date_or_datetime}) && ... + isequal({self.null_or_fruits_or_days_of_week}, {other.null_or_fruits_or_days_of_week}) && ... + isequal({self.record_or_int}, {other.record_or_int}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+basic_types/T0OrT1.m b/matlab/generated/+basic_types/T0OrT1.m index 6afa0b43..b7aef06e 100644 --- a/matlab/generated/+basic_types/T0OrT1.m +++ b/matlab/generated/+basic_types/T0OrT1.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.T0OrT1") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.T0OrT1") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+basic_types/TimeOrDatetime.m b/matlab/generated/+basic_types/TimeOrDatetime.m index d5d4ae72..69df5a79 100644 --- a/matlab/generated/+basic_types/TimeOrDatetime.m +++ b/matlab/generated/+basic_types/TimeOrDatetime.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "basic_types.TimeOrDatetime") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "basic_types.TimeOrDatetime") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+image/FloatImage.m b/matlab/generated/+image/FloatImage.m deleted file mode 100644 index cf3837f1..00000000 --- a/matlab/generated/+image/FloatImage.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = FloatImage(array) - arguments - array single - end - a = array; -end diff --git a/matlab/generated/+image/Image.m b/matlab/generated/+image/Image.m deleted file mode 100644 index 0332777d..00000000 --- a/matlab/generated/+image/Image.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = Image(array) - a = array; -end diff --git a/matlab/generated/+image/IntImage.m b/matlab/generated/+image/IntImage.m deleted file mode 100644 index a229033a..00000000 --- a/matlab/generated/+image/IntImage.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = IntImage(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/+binary/AliasesReader.m b/matlab/generated/+test_model/+binary/AliasesReader.m index 2edb8961..4af77b47 100644 --- a/matlab/generated/+test_model/+binary/AliasesReader.m +++ b/matlab/generated/+test_model/+binary/AliasesReader.m @@ -13,6 +13,7 @@ aliased_generic_vector_serializer aliased_generic_fixed_vector_serializer stream_of_aliased_generic_union_2_serializer + vectors_serializer end methods @@ -29,6 +30,7 @@ self.aliased_generic_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); self.aliased_generic_fixed_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Float32Serializer, 3); self.stream_of_aliased_generic_union_2_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2})); + self.vectors_serializer = yardl.binary.VectorSerializer(test_model.binary.RecordContainingVectorsOfAliasesSerializer()); end end @@ -76,5 +78,9 @@ function value = read_stream_of_aliased_generic_union_2_(self) value = self.stream_of_aliased_generic_union_2_serializer.read(self.stream_); end + + function value = read_vectors_(self) + value = self.vectors_serializer.read(self.stream_); + end end end diff --git a/matlab/generated/+test_model/+binary/AliasesWriter.m b/matlab/generated/+test_model/+binary/AliasesWriter.m index 543dd046..0f5b3b76 100644 --- a/matlab/generated/+test_model/+binary/AliasesWriter.m +++ b/matlab/generated/+test_model/+binary/AliasesWriter.m @@ -13,6 +13,7 @@ aliased_generic_vector_serializer aliased_generic_fixed_vector_serializer stream_of_aliased_generic_union_2_serializer + vectors_serializer end methods @@ -29,6 +30,7 @@ self.aliased_generic_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); self.aliased_generic_fixed_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Float32Serializer, 3); self.stream_of_aliased_generic_union_2_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2})); + self.vectors_serializer = yardl.binary.VectorSerializer(test_model.binary.RecordContainingVectorsOfAliasesSerializer()); end end @@ -72,5 +74,9 @@ function write_aliased_generic_fixed_vector_(self, value) function write_stream_of_aliased_generic_union_2_(self, value) self.stream_of_aliased_generic_union_2_serializer.write(self.stream_, value); end + + function write_vectors_(self, value) + self.vectors_serializer.write(self.stream_, value); + end end end diff --git a/matlab/generated/+test_model/+binary/RecordContainingVectorsOfAliasesSerializer.m b/matlab/generated/+test_model/+binary/RecordContainingVectorsOfAliasesSerializer.m new file mode 100644 index 00000000..9536b7f4 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordContainingVectorsOfAliasesSerializer.m @@ -0,0 +1,27 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingVectorsOfAliasesSerializer < yardl.binary.RecordSerializer + methods + function self = RecordContainingVectorsOfAliasesSerializer() + field_serializers{1} = yardl.binary.VectorSerializer(yardl.binary.StringSerializer); + field_serializers{2} = yardl.binary.VectorSerializer(yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer)); + field_serializers{3} = yardl.binary.VectorSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)); + field_serializers{4} = yardl.binary.VectorSerializer(tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer())); + self@yardl.binary.RecordSerializer('test_model.RecordContainingVectorsOfAliases', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordContainingVectorsOfAliases + end + self.write_(outstream, value.strings, value.maps, value.arrays, value.tuples); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordContainingVectorsOfAliases(strings=fields{1}, maps=fields{2}, arrays=fields{3}, tuples=fields{4}); + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockAliasesWriter.m b/matlab/generated/+test_model/+testing/MockAliasesWriter.m index 8a7590f5..9ebdead4 100644 --- a/matlab/generated/+test_model/+testing/MockAliasesWriter.m +++ b/matlab/generated/+test_model/+testing/MockAliasesWriter.m @@ -13,6 +13,7 @@ expected_aliased_generic_vector expected_aliased_generic_fixed_vector expected_stream_of_aliased_generic_union_2 + expected_vectors end methods @@ -28,6 +29,7 @@ self.expected_aliased_generic_vector = yardl.None; self.expected_aliased_generic_fixed_vector = yardl.None; self.expected_stream_of_aliased_generic_union_2 = {}; + self.expected_vectors = yardl.None; end function expect_write_aliased_string_(self, value) @@ -82,6 +84,10 @@ function expect_write_stream_of_aliased_generic_union_2_(self, value) end end + function expect_write_vectors_(self, value) + self.expected_vectors = yardl.Optional(value); + end + function verify(self) self.testCase_.verifyEqual(self.expected_aliased_string, yardl.None, "Expected call to write_aliased_string_ was not received"); self.testCase_.verifyEqual(self.expected_aliased_enum, yardl.None, "Expected call to write_aliased_enum_ was not received"); @@ -93,6 +99,7 @@ function verify(self) self.testCase_.verifyEqual(self.expected_aliased_generic_vector, yardl.None, "Expected call to write_aliased_generic_vector_ was not received"); self.testCase_.verifyEqual(self.expected_aliased_generic_fixed_vector, yardl.None, "Expected call to write_aliased_generic_fixed_vector_ was not received"); self.testCase_.verifyTrue(isempty(self.expected_stream_of_aliased_generic_union_2), "Expected call to write_stream_of_aliased_generic_union_2_ was not received"); + self.testCase_.verifyEqual(self.expected_vectors, yardl.None, "Expected call to write_vectors_ was not received"); end end @@ -159,6 +166,12 @@ function write_stream_of_aliased_generic_union_2_(self, value) self.expected_stream_of_aliased_generic_union_2 = self.expected_stream_of_aliased_generic_union_2(2:end); end + function write_vectors_(self, value) + self.testCase_.verifyTrue(self.expected_vectors.has_value(), "Unexpected call to write_vectors_"); + self.testCase_.verifyEqual(value, self.expected_vectors.value, "Unexpected argument value for call to write_vectors_"); + self.expected_vectors = yardl.None; + end + function close_(self) end function end_stream_(self) diff --git a/matlab/generated/+test_model/+testing/TestAliasesWriter.m b/matlab/generated/+test_model/+testing/TestAliasesWriter.m index b25c0a2f..b264ceab 100644 --- a/matlab/generated/+test_model/+testing/TestAliasesWriter.m +++ b/matlab/generated/+test_model/+testing/TestAliasesWriter.m @@ -85,6 +85,11 @@ function write_stream_of_aliased_generic_union_2_(self, value) self.mock_writer_.expect_write_stream_of_aliased_generic_union_2_(value); end + function write_vectors_(self, value) + self.writer_.write_vectors(value); + self.mock_writer_.expect_write_vectors_(value); + end + function close_(self) self.close_called_ = true; self.writer_.close(); diff --git a/matlab/generated/+test_model/AcquisitionOrImage.m b/matlab/generated/+test_model/AcquisitionOrImage.m index 25da646e..7bc46af0 100644 --- a/matlab/generated/+test_model/AcquisitionOrImage.m +++ b/matlab/generated/+test_model/AcquisitionOrImage.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.AcquisitionOrImage") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.AcquisitionOrImage") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/AliasedClosedGeneric.m b/matlab/generated/+test_model/AliasedClosedGeneric.m index 546b8395..48e66144 100644 --- a/matlab/generated/+test_model/AliasedClosedGeneric.m +++ b/matlab/generated/+test_model/AliasedClosedGeneric.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = AliasedClosedGeneric(varargin) - c = test_model.AliasedTuple(varargin{:}); +classdef AliasedClosedGeneric < test_model.AliasedTuple end diff --git a/matlab/generated/+test_model/AliasedGenericDynamicArray.m b/matlab/generated/+test_model/AliasedGenericDynamicArray.m deleted file mode 100644 index 6163aeb5..00000000 --- a/matlab/generated/+test_model/AliasedGenericDynamicArray.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedGenericDynamicArray(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasedGenericFixedArray.m b/matlab/generated/+test_model/AliasedGenericFixedArray.m deleted file mode 100644 index d5eb14ba..00000000 --- a/matlab/generated/+test_model/AliasedGenericFixedArray.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedGenericFixedArray(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasedGenericFixedVector.m b/matlab/generated/+test_model/AliasedGenericFixedVector.m deleted file mode 100644 index c246fa3e..00000000 --- a/matlab/generated/+test_model/AliasedGenericFixedVector.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedGenericFixedVector(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasedGenericOptional.m b/matlab/generated/+test_model/AliasedGenericOptional.m index 522e4e60..ea41575b 100644 --- a/matlab/generated/+test_model/AliasedGenericOptional.m +++ b/matlab/generated/+test_model/AliasedGenericOptional.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function o = AliasedGenericOptional(value) - o = yardl.Optional(value); +classdef AliasedGenericOptional < yardl.Optional end diff --git a/matlab/generated/+test_model/AliasedGenericRank2Array.m b/matlab/generated/+test_model/AliasedGenericRank2Array.m deleted file mode 100644 index ba481775..00000000 --- a/matlab/generated/+test_model/AliasedGenericRank2Array.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedGenericRank2Array(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasedGenericVector.m b/matlab/generated/+test_model/AliasedGenericVector.m deleted file mode 100644 index c6931967..00000000 --- a/matlab/generated/+test_model/AliasedGenericVector.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedGenericVector(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasedIntOrAliasedSimpleRecord.m b/matlab/generated/+test_model/AliasedIntOrAliasedSimpleRecord.m index fe4f0655..9bf93638 100644 --- a/matlab/generated/+test_model/AliasedIntOrAliasedSimpleRecord.m +++ b/matlab/generated/+test_model/AliasedIntOrAliasedSimpleRecord.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.AliasedIntOrAliasedSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.AliasedIntOrAliasedSimpleRecord") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m b/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m index 6bd66c2a..10794038 100644 --- a/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m +++ b/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.AliasedIntOrSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.AliasedIntOrSimpleRecord") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/AliasedMap.m b/matlab/generated/+test_model/AliasedMap.m index fd5134dd..ab6de561 100644 --- a/matlab/generated/+test_model/AliasedMap.m +++ b/matlab/generated/+test_model/AliasedMap.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function m = AliasedMap(varargin) - m = basic_types.AliasedMap(varargin{:}); +classdef AliasedMap < basic_types.AliasedMap end diff --git a/matlab/generated/+test_model/AliasedMultiGenericOptional.m b/matlab/generated/+test_model/AliasedMultiGenericOptional.m index 508d75ae..aa8d2323 100644 --- a/matlab/generated/+test_model/AliasedMultiGenericOptional.m +++ b/matlab/generated/+test_model/AliasedMultiGenericOptional.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.AliasedMultiGenericOptional") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.AliasedMultiGenericOptional") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m b/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m index bba1a9e6..6cda5534 100644 --- a/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m +++ b/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.AliasedNullableIntSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.AliasedNullableIntSimpleRecord") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/AliasedOpenGeneric.m b/matlab/generated/+test_model/AliasedOpenGeneric.m index 75685264..6d31e620 100644 --- a/matlab/generated/+test_model/AliasedOpenGeneric.m +++ b/matlab/generated/+test_model/AliasedOpenGeneric.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = AliasedOpenGeneric(varargin) - c = test_model.AliasedTuple(varargin{:}); +classdef AliasedOpenGeneric < test_model.AliasedTuple end diff --git a/matlab/generated/+test_model/AliasedOptional.m b/matlab/generated/+test_model/AliasedOptional.m index f80a59db..683141d4 100644 --- a/matlab/generated/+test_model/AliasedOptional.m +++ b/matlab/generated/+test_model/AliasedOptional.m @@ -1,8 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function o = AliasedOptional(value) - arguments - value int32 - end - o = yardl.Optional(value); +classdef AliasedOptional < yardl.Optional end diff --git a/matlab/generated/+test_model/AliasedSimpleRecord.m b/matlab/generated/+test_model/AliasedSimpleRecord.m index bffe4286..82c9e3bd 100644 --- a/matlab/generated/+test_model/AliasedSimpleRecord.m +++ b/matlab/generated/+test_model/AliasedSimpleRecord.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = AliasedSimpleRecord(varargin) - c = test_model.SimpleRecord(varargin{:}); +classdef AliasedSimpleRecord < test_model.SimpleRecord end diff --git a/matlab/generated/+test_model/AliasedString.m b/matlab/generated/+test_model/AliasedString.m deleted file mode 100644 index 34c1c4ab..00000000 --- a/matlab/generated/+test_model/AliasedString.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function s = AliasedString(varargin) - s = string(varargin{:}); -end diff --git a/matlab/generated/+test_model/AliasedTuple.m b/matlab/generated/+test_model/AliasedTuple.m index 752b1420..993b6fb7 100644 --- a/matlab/generated/+test_model/AliasedTuple.m +++ b/matlab/generated/+test_model/AliasedTuple.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = AliasedTuple(varargin) - c = test_model.MyTuple(varargin{:}); +classdef AliasedTuple < test_model.MyTuple end diff --git a/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m b/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m deleted file mode 100644 index fed1676b..00000000 --- a/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = AliasedVectorOfGenericRecords(array) - a = array; -end diff --git a/matlab/generated/+test_model/AliasesReaderBase.m b/matlab/generated/+test_model/AliasesReaderBase.m index 20a783ae..4e3451af 100644 --- a/matlab/generated/+test_model/AliasesReaderBase.m +++ b/matlab/generated/+test_model/AliasesReaderBase.m @@ -12,7 +12,7 @@ function close(self) self.close_(); - if self.state_ ~= 10 + if self.state_ ~= 11 expected_method = self.state_to_method_name_(self.state_); throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); end @@ -128,6 +128,16 @@ function close(self) value = self.read_stream_of_aliased_generic_union_2_(); end + % Ordinal 10 + function value = read_vectors(self) + if self.state_ ~= 10 + self.raise_unexpected_state_(10); + end + + value = self.read_vectors_(); + self.state_ = 11; + end + function copy_to(self, writer) writer.write_aliased_string(self.read_aliased_string()); writer.write_aliased_enum(self.read_aliased_enum()); @@ -143,6 +153,7 @@ function copy_to(self, writer) writer.write_stream_of_aliased_generic_union_2({item}); end writer.end_stream_of_aliased_generic_union_2(); + writer.write_vectors(self.read_vectors()); end end @@ -164,6 +175,7 @@ function copy_to(self, writer) read_aliased_generic_fixed_vector_(self) has_stream_of_aliased_generic_union_2_(self) read_stream_of_aliased_generic_union_2_(self) + read_vectors_(self) close_(self) end @@ -196,6 +208,8 @@ function raise_unexpected_state_(self, actual) name = "read_aliased_generic_fixed_vector"; elseif state == 9 name = "read_stream_of_aliased_generic_union_2"; + elseif state == 10 + name = "read_vectors"; else name = ""; end diff --git a/matlab/generated/+test_model/AliasesWriterBase.m b/matlab/generated/+test_model/AliasesWriterBase.m index 3021e01e..c9bfd52a 100644 --- a/matlab/generated/+test_model/AliasesWriterBase.m +++ b/matlab/generated/+test_model/AliasesWriterBase.m @@ -13,7 +13,7 @@ function close(self) self.close_(); - if self.state_ ~= 10 + if self.state_ ~= 11 expected_method = self.state_to_method_name_(self.state_); throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); end @@ -126,11 +126,21 @@ function end_stream_of_aliased_generic_union_2(self) self.end_stream_(); self.state_ = 10; end + + % Ordinal 10 + function write_vectors(self, value) + if self.state_ ~= 10 + self.raise_unexpected_state_(10); + end + + self.write_vectors_(value); + self.state_ = 11; + end end methods (Static) function res = schema() - res = string('{"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}}]},"types":[{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); + res = string('{"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}},{"name":"vectors","type":{"vector":{"items":"TestModel.RecordContainingVectorsOfAliases"}}}]},"types":[{"name":"AliasedMap","typeParameters":["K","V"],"type":{"map":{"keys":"K","values":"V"}}},{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedMap","typeParameters":["K","V"],"type":{"name":"BasicTypes.AliasedMap","typeArguments":["K","V"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"RecordContainingVectorsOfAliases","fields":[{"name":"strings","type":{"vector":{"items":"TestModel.AliasedString"}}},{"name":"maps","type":{"vector":{"items":{"name":"TestModel.AliasedMap","typeArguments":["string","int32"]}}}},{"name":"arrays","type":{"vector":{"items":{"name":"TestModel.Image","typeArguments":["float32"]}}}},{"name":"tuples","type":{"vector":{"items":{"name":"TestModel.MyTuple","typeArguments":["int32","TestModel.SimpleRecord"]}}}}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); end end @@ -145,6 +155,7 @@ function end_stream_of_aliased_generic_union_2(self) write_aliased_generic_vector_(self, value) write_aliased_generic_fixed_vector_(self, value) write_stream_of_aliased_generic_union_2_(self, value) + write_vectors_(self, value) end_stream_(self) close_(self) @@ -178,6 +189,8 @@ function raise_unexpected_state_(self, actual) name = "write_aliased_generic_fixed_vector"; elseif state == 9 name = "write_stream_of_aliased_generic_union_2 or end_stream_of_aliased_generic_union_2"; + elseif state == 10 + name = "write_vectors"; else name = ''; end diff --git a/matlab/generated/+test_model/ArrayOrScalar.m b/matlab/generated/+test_model/ArrayOrScalar.m index e756b2ee..aee96a74 100644 --- a/matlab/generated/+test_model/ArrayOrScalar.m +++ b/matlab/generated/+test_model/ArrayOrScalar.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.ArrayOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.ArrayOrScalar") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m b/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m deleted file mode 100644 index bf2391e8..00000000 --- a/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = ArrayWithKeywordDimensionNames(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/GenericRecord.m b/matlab/generated/+test_model/GenericRecord.m index 7286f700..73e3b797 100644 --- a/matlab/generated/+test_model/GenericRecord.m +++ b/matlab/generated/+test_model/GenericRecord.m @@ -37,15 +37,33 @@ function res = eq(self, other) res = ... isa(other, "test_model.GenericRecord") && ... - isequal(self.scalar_1, other.scalar_1) && ... - isequal(self.scalar_2, other.scalar_2) && ... - isequal(self.vector_1, other.vector_1) && ... - isequal(self.image_2, other.image_2); + isequal({self.scalar_1}, {other.scalar_1}) && ... + isequal({self.scalar_2}, {other.scalar_2}) && ... + isequal({self.vector_1}, {other.vector_1}) && ... + isequal({self.image_2}, {other.image_2}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.GenericRecord(scalar_1=yardl.None, scalar_2=yardl.None, vector_1=yardl.None, image_2=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/GenericUnion3.m b/matlab/generated/+test_model/GenericUnion3.m index 802ca942..0ec9ff58 100644 --- a/matlab/generated/+test_model/GenericUnion3.m +++ b/matlab/generated/+test_model/GenericUnion3.m @@ -42,7 +42,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.GenericUnion3") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.GenericUnion3") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/GenericUnion3Alternate.m b/matlab/generated/+test_model/GenericUnion3Alternate.m index ad7f4a1f..5b1dc021 100644 --- a/matlab/generated/+test_model/GenericUnion3Alternate.m +++ b/matlab/generated/+test_model/GenericUnion3Alternate.m @@ -42,7 +42,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.GenericUnion3Alternate") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.GenericUnion3Alternate") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m b/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m index 40797c2c..6ebc918d 100644 --- a/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m +++ b/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m @@ -42,7 +42,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.GenericUnionWithRepeatedTypeParameters") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.GenericUnionWithRepeatedTypeParameters") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/Image.m b/matlab/generated/+test_model/Image.m deleted file mode 100644 index 0332777d..00000000 --- a/matlab/generated/+test_model/Image.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = Image(array) - a = array; -end diff --git a/matlab/generated/+test_model/ImageFloatOrImageDouble.m b/matlab/generated/+test_model/ImageFloatOrImageDouble.m index 4d03fd94..45c793d9 100644 --- a/matlab/generated/+test_model/ImageFloatOrImageDouble.m +++ b/matlab/generated/+test_model/ImageFloatOrImageDouble.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.ImageFloatOrImageDouble") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.ImageFloatOrImageDouble") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/Int32OrFloat32.m b/matlab/generated/+test_model/Int32OrFloat32.m index c29ac498..3d8586c4 100644 --- a/matlab/generated/+test_model/Int32OrFloat32.m +++ b/matlab/generated/+test_model/Int32OrFloat32.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.Int32OrFloat32") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.Int32OrFloat32") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray.m b/matlab/generated/+test_model/Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray.m index 1cdd852c..c9dd076e 100644 --- a/matlab/generated/+test_model/Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray.m +++ b/matlab/generated/+test_model/Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray.m @@ -58,7 +58,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.Int32OrFloat32OrStringOrSimpleRecordOrNamedFixedNDArray") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/Int32OrRecordWithVlens.m b/matlab/generated/+test_model/Int32OrRecordWithVlens.m index 1371fe86..8ad6e2e2 100644 --- a/matlab/generated/+test_model/Int32OrRecordWithVlens.m +++ b/matlab/generated/+test_model/Int32OrRecordWithVlens.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.Int32OrRecordWithVlens") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.Int32OrRecordWithVlens") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/Int32OrSimpleRecord.m b/matlab/generated/+test_model/Int32OrSimpleRecord.m index d12cd188..f3b1774f 100644 --- a/matlab/generated/+test_model/Int32OrSimpleRecord.m +++ b/matlab/generated/+test_model/Int32OrSimpleRecord.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.Int32OrSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.Int32OrSimpleRecord") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/IntArray.m b/matlab/generated/+test_model/IntArray.m deleted file mode 100644 index 56fc2e5b..00000000 --- a/matlab/generated/+test_model/IntArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = IntArray(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/IntFixedArray.m b/matlab/generated/+test_model/IntFixedArray.m deleted file mode 100644 index c4da18be..00000000 --- a/matlab/generated/+test_model/IntFixedArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = IntFixedArray(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m b/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m index 304e05e1..3949b33d 100644 --- a/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m +++ b/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.IntOrGenericRecordWithComputedFields") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.IntOrGenericRecordWithComputedFields") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/IntRank2Array.m b/matlab/generated/+test_model/IntRank2Array.m deleted file mode 100644 index c043e267..00000000 --- a/matlab/generated/+test_model/IntRank2Array.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = IntRank2Array(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/MapOrScalar.m b/matlab/generated/+test_model/MapOrScalar.m index 6770a2de..8944cf81 100644 --- a/matlab/generated/+test_model/MapOrScalar.m +++ b/matlab/generated/+test_model/MapOrScalar.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.MapOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.MapOrScalar") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/MyTuple.m b/matlab/generated/+test_model/MyTuple.m index bb03cdf3..39a568a5 100644 --- a/matlab/generated/+test_model/MyTuple.m +++ b/matlab/generated/+test_model/MyTuple.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = MyTuple(varargin) - c = basic_types.MyTuple(varargin{:}); +classdef MyTuple < basic_types.MyTuple end diff --git a/matlab/generated/+test_model/NamedFixedNDArray.m b/matlab/generated/+test_model/NamedFixedNDArray.m deleted file mode 100644 index ea3bd33d..00000000 --- a/matlab/generated/+test_model/NamedFixedNDArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = NamedFixedNDArray(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/NamedNDArray.m b/matlab/generated/+test_model/NamedNDArray.m deleted file mode 100644 index 95fd517d..00000000 --- a/matlab/generated/+test_model/NamedNDArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = NamedNDArray(array) - arguments - array int32 - end - a = array; -end diff --git a/matlab/generated/+test_model/RecordContainingGenericRecords.m b/matlab/generated/+test_model/RecordContainingGenericRecords.m index 9633ba75..cfb7317b 100644 --- a/matlab/generated/+test_model/RecordContainingGenericRecords.m +++ b/matlab/generated/+test_model/RecordContainingGenericRecords.m @@ -58,21 +58,39 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordContainingGenericRecords") && ... - isequal(self.g1, other.g1) && ... - isequal(self.g1a, other.g1a) && ... - isequal(self.g2, other.g2) && ... - isequal(self.g2a, other.g2a) && ... - isequal(self.g3, other.g3) && ... - isequal(self.g3a, other.g3a) && ... - isequal(self.g4, other.g4) && ... - isequal(self.g5, other.g5) && ... - isequal(self.g6, other.g6) && ... - isequal(self.g7, other.g7); + isequal({self.g1}, {other.g1}) && ... + isequal({self.g1a}, {other.g1a}) && ... + isequal({self.g2}, {other.g2}) && ... + isequal({self.g2a}, {other.g2a}) && ... + isequal({self.g3}, {other.g3}) && ... + isequal({self.g3a}, {other.g3a}) && ... + isequal({self.g4}, {other.g4}) && ... + isequal({self.g5}, {other.g5}) && ... + isequal({self.g6}, {other.g6}) && ... + isequal({self.g7}, {other.g7}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordContainingGenericRecords(g3=yardl.None, g3a=yardl.None, g4=yardl.None, g5=yardl.None, g6=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m b/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m index aeaa92b3..f1fe4a5d 100644 --- a/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m +++ b/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m @@ -16,7 +16,7 @@ kwargs.f1a = test_model.RecordWithAliasedOptionalGenericField(); kwargs.f2 = test_model.RecordWithOptionalGenericUnionField(); kwargs.f2a = test_model.RecordWithAliasedOptionalGenericUnionField(); - kwargs.nested = test_model.RecordContainingGenericRecords(g3=tuples.Tuple(v1="", v2=int32(0)), g3a=tuples.Tuple(v1="", v2=int32(0)), g4=test_model.RecordWithGenericVectors(v=int32.empty(), av=int32.empty()), g5=test_model.RecordWithGenericFixedVectors(fv=repelem(int32(0), 3), afv=repelem(int32(0), 3)), g6=test_model.RecordWithGenericArrays(nd=int32.empty(0, 0), fixed_nd=repelem(int32(0), 8, 16), dynamic_nd=int32.empty(), aliased_nd=int32.empty(0, 0), aliased_fixed_nd=repelem(int32(0), 8, 16), aliased_dynamic_nd=int32.empty())); + kwargs.nested = test_model.RecordContainingGenericRecords(g3=tuples.Tuple(v1="", v2=int32(0)), g3a=tuples.Tuple(v1="", v2=int32(0)), g4=test_model.RecordWithGenericVectors(v=int32.empty(), av=int32.empty()), g5=test_model.RecordWithGenericFixedVectors(fv=repelem(int32(0), 3), afv=repelem(int32(0), 3)), g6=test_model.RecordWithGenericArrays(nd=int32.empty(), fixed_nd=repelem(int32(0), 8, 16), dynamic_nd=int32.empty(), aliased_nd=int32.empty(), aliased_fixed_nd=repelem(int32(0), 8, 16), aliased_dynamic_nd=int32.empty())); end self.f1 = kwargs.f1; self.f1a = kwargs.f1a; @@ -28,16 +28,20 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordContainingNestedGenericRecords") && ... - isequal(self.f1, other.f1) && ... - isequal(self.f1a, other.f1a) && ... - isequal(self.f2, other.f2) && ... - isequal(self.f2a, other.f2a) && ... - isequal(self.nested, other.nested); + isequal({self.f1}, {other.f1}) && ... + isequal({self.f1a}, {other.f1a}) && ... + isequal({self.f2}, {other.f2}) && ... + isequal({self.f2a}, {other.f2a}) && ... + isequal({self.nested}, {other.nested}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordContainingVectorsOfAliases.m b/matlab/generated/+test_model/RecordContainingVectorsOfAliases.m new file mode 100644 index 00000000..b1027a95 --- /dev/null +++ b/matlab/generated/+test_model/RecordContainingVectorsOfAliases.m @@ -0,0 +1,57 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingVectorsOfAliases < handle + properties + strings + maps + arrays + tuples + end + + methods + function self = RecordContainingVectorsOfAliases(kwargs) + arguments + kwargs.strings = string.empty(); + kwargs.maps = test_model.AliasedMap.empty(); + kwargs.arrays = single.empty(); + kwargs.tuples = test_model.MyTuple.empty(); + end + self.strings = kwargs.strings; + self.maps = kwargs.maps; + self.arrays = kwargs.arrays; + self.tuples = kwargs.tuples; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordContainingVectorsOfAliases") && ... + isequal({self.strings}, {other.strings}) && ... + isequal({self.maps}, {other.maps}) && ... + isequal({self.arrays}, {other.arrays}) && ... + isequal({self.tuples}, {other.tuples}); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + + function res = isequal(self, other) + res = all(eq(self, other)); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordContainingVectorsOfAliases(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordNotUsedInProtocol.m b/matlab/generated/+test_model/RecordNotUsedInProtocol.m index 53cdef1c..a5fcc722 100644 --- a/matlab/generated/+test_model/RecordNotUsedInProtocol.m +++ b/matlab/generated/+test_model/RecordNotUsedInProtocol.m @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordNotUsedInProtocol") && ... - isequal(self.u1, other.u1) && ... - isequal(self.u2, other.u2); + isequal({self.u1}, {other.u1}) && ... + isequal({self.u2}, {other.u2}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithAliasedGenerics.m b/matlab/generated/+test_model/RecordWithAliasedGenerics.m index 68c0e8cc..e68017eb 100644 --- a/matlab/generated/+test_model/RecordWithAliasedGenerics.m +++ b/matlab/generated/+test_model/RecordWithAliasedGenerics.m @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithAliasedGenerics") && ... - isequal(self.my_strings, other.my_strings) && ... - isequal(self.aliased_strings, other.aliased_strings); + isequal({self.my_strings}, {other.my_strings}) && ... + isequal({self.aliased_strings}, {other.aliased_strings}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m index da3619e2..16e07e1c 100644 --- a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m +++ b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithAliasedOptionalGenericField") && ... - isequal(self.v, other.v); + isequal({self.v}, {other.v}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m index d4ff5cbe..01310eaf 100644 --- a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m +++ b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithAliasedOptionalGenericUnionField") && ... - isequal(self.v, other.v); + isequal({self.v}, {other.v}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithArrays.m b/matlab/generated/+test_model/RecordWithArrays.m index 1302988f..960adefb 100644 --- a/matlab/generated/+test_model/RecordWithArrays.m +++ b/matlab/generated/+test_model/RecordWithArrays.m @@ -18,9 +18,9 @@ arguments kwargs.default_array = int32.empty(); kwargs.default_array_with_empty_dimension = int32.empty(); - kwargs.rank_1_array = int32.empty(0); - kwargs.rank_2_array = int32.empty(0, 0); - kwargs.rank_2_array_with_named_dimensions = int32.empty(0, 0); + kwargs.rank_1_array = int32.empty(); + kwargs.rank_2_array = int32.empty(); + kwargs.rank_2_array_with_named_dimensions = int32.empty(); kwargs.rank_2_fixed_array = repelem(int32(0), 4, 3); kwargs.rank_2_fixed_array_with_named_dimensions = repelem(int32(0), 4, 3); kwargs.dynamic_array = int32.empty(); @@ -40,20 +40,24 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithArrays") && ... - isequal(self.default_array, other.default_array) && ... - isequal(self.default_array_with_empty_dimension, other.default_array_with_empty_dimension) && ... - isequal(self.rank_1_array, other.rank_1_array) && ... - isequal(self.rank_2_array, other.rank_2_array) && ... - isequal(self.rank_2_array_with_named_dimensions, other.rank_2_array_with_named_dimensions) && ... - isequal(self.rank_2_fixed_array, other.rank_2_fixed_array) && ... - isequal(self.rank_2_fixed_array_with_named_dimensions, other.rank_2_fixed_array_with_named_dimensions) && ... - isequal(self.dynamic_array, other.dynamic_array) && ... - isequal(self.array_of_vectors, other.array_of_vectors); + isequal({self.default_array}, {other.default_array}) && ... + isequal({self.default_array_with_empty_dimension}, {other.default_array_with_empty_dimension}) && ... + isequal({self.rank_1_array}, {other.rank_1_array}) && ... + isequal({self.rank_2_array}, {other.rank_2_array}) && ... + isequal({self.rank_2_array_with_named_dimensions}, {other.rank_2_array_with_named_dimensions}) && ... + isequal({self.rank_2_fixed_array}, {other.rank_2_fixed_array}) && ... + isequal({self.rank_2_fixed_array_with_named_dimensions}, {other.rank_2_fixed_array_with_named_dimensions}) && ... + isequal({self.dynamic_array}, {other.dynamic_array}) && ... + isequal({self.array_of_vectors}, {other.array_of_vectors}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m b/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m index 8a3a6d2d..cc6fc3d4 100644 --- a/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m +++ b/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m @@ -18,9 +18,9 @@ arguments kwargs.default_array = int32.empty(); kwargs.default_array_with_empty_dimension = int32.empty(); - kwargs.rank_1_array = int32.empty(0); - kwargs.rank_2_array = int32.empty(0, 0); - kwargs.rank_2_array_with_named_dimensions = int32.empty(0, 0); + kwargs.rank_1_array = int32.empty(); + kwargs.rank_2_array = int32.empty(); + kwargs.rank_2_array_with_named_dimensions = int32.empty(); kwargs.rank_2_fixed_array = repelem(int32(0), 4, 3); kwargs.rank_2_fixed_array_with_named_dimensions = repelem(int32(0), 4, 3); kwargs.dynamic_array = int32.empty(); @@ -40,20 +40,24 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithArraysSimpleSyntax") && ... - isequal(self.default_array, other.default_array) && ... - isequal(self.default_array_with_empty_dimension, other.default_array_with_empty_dimension) && ... - isequal(self.rank_1_array, other.rank_1_array) && ... - isequal(self.rank_2_array, other.rank_2_array) && ... - isequal(self.rank_2_array_with_named_dimensions, other.rank_2_array_with_named_dimensions) && ... - isequal(self.rank_2_fixed_array, other.rank_2_fixed_array) && ... - isequal(self.rank_2_fixed_array_with_named_dimensions, other.rank_2_fixed_array_with_named_dimensions) && ... - isequal(self.dynamic_array, other.dynamic_array) && ... - isequal(self.array_of_vectors, other.array_of_vectors); + isequal({self.default_array}, {other.default_array}) && ... + isequal({self.default_array_with_empty_dimension}, {other.default_array_with_empty_dimension}) && ... + isequal({self.rank_1_array}, {other.rank_1_array}) && ... + isequal({self.rank_2_array}, {other.rank_2_array}) && ... + isequal({self.rank_2_array_with_named_dimensions}, {other.rank_2_array_with_named_dimensions}) && ... + isequal({self.rank_2_fixed_array}, {other.rank_2_fixed_array}) && ... + isequal({self.rank_2_fixed_array_with_named_dimensions}, {other.rank_2_fixed_array_with_named_dimensions}) && ... + isequal({self.dynamic_array}, {other.dynamic_array}) && ... + isequal({self.array_of_vectors}, {other.array_of_vectors}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithComputedFields.m b/matlab/generated/+test_model/RecordWithComputedFields.m index a278ba6a..94ea6e39 100644 --- a/matlab/generated/+test_model/RecordWithComputedFields.m +++ b/matlab/generated/+test_model/RecordWithComputedFields.m @@ -35,8 +35,8 @@ methods function self = RecordWithComputedFields(kwargs) arguments - kwargs.array_field = int32.empty(0, 0); - kwargs.array_field_map_dimensions = int32.empty(0, 0); + kwargs.array_field = int32.empty(); + kwargs.array_field_map_dimensions = int32.empty(); kwargs.dynamic_array_field = int32.empty(); kwargs.fixed_array_field = repelem(int32(0), 4, 3); kwargs.int_field = int32(0); @@ -62,7 +62,7 @@ kwargs.int_float_union = test_model.Int32OrFloat32.Int32(int32(0)); kwargs.nullable_int_float_union = yardl.None; kwargs.union_with_nested_generic_union = test_model.IntOrGenericRecordWithComputedFields.Int(int32(0)); - kwargs.map_field = dictionary; + kwargs.map_field = yardl.Map; end self.array_field = kwargs.array_field; self.array_field_map_dimensions = kwargs.array_field_map_dimensions; @@ -320,7 +320,7 @@ end function res = access_map_entry(self) - res = self.map_field("hello"); + res = self.map_field.lookup("hello"); return end @@ -330,17 +330,17 @@ end function res = access_map_entry_with_computed_field(self) - res = self.map_field(self.string_computed_field()); + res = self.map_field.lookup(self.string_computed_field()); return end function res = access_map_entry_with_computed_field_nested(self) - res = self.map_field(self.map_field(self.string_computed_field())); + res = self.map_field.lookup(self.map_field.lookup(self.string_computed_field())); return end function res = access_missing_map_entry(self) - res = self.map_field("missing"); + res = self.map_field.lookup("missing"); return end @@ -527,39 +527,43 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithComputedFields") && ... - isequal(self.array_field, other.array_field) && ... - isequal(self.array_field_map_dimensions, other.array_field_map_dimensions) && ... - isequal(self.dynamic_array_field, other.dynamic_array_field) && ... - isequal(self.fixed_array_field, other.fixed_array_field) && ... - isequal(self.int_field, other.int_field) && ... - isequal(self.int8_field, other.int8_field) && ... - isequal(self.uint8_field, other.uint8_field) && ... - isequal(self.int16_field, other.int16_field) && ... - isequal(self.uint16_field, other.uint16_field) && ... - isequal(self.uint32_field, other.uint32_field) && ... - isequal(self.int64_field, other.int64_field) && ... - isequal(self.uint64_field, other.uint64_field) && ... - isequal(self.size_field, other.size_field) && ... - isequal(self.float32_field, other.float32_field) && ... - isequal(self.float64_field, other.float64_field) && ... - isequal(self.complexfloat32_field, other.complexfloat32_field) && ... - isequal(self.complexfloat64_field, other.complexfloat64_field) && ... - isequal(self.string_field, other.string_field) && ... - isequal(self.tuple_field, other.tuple_field) && ... - isequal(self.vector_field, other.vector_field) && ... - isequal(self.vector_of_vectors_field, other.vector_of_vectors_field) && ... - isequal(self.fixed_vector_field, other.fixed_vector_field) && ... - isequal(self.fixed_vector_of_vectors_field, other.fixed_vector_of_vectors_field) && ... - isequal(self.optional_named_array, other.optional_named_array) && ... - isequal(self.int_float_union, other.int_float_union) && ... - isequal(self.nullable_int_float_union, other.nullable_int_float_union) && ... - isequal(self.union_with_nested_generic_union, other.union_with_nested_generic_union) && ... - isequal(self.map_field, other.map_field); + isequal({self.array_field}, {other.array_field}) && ... + isequal({self.array_field_map_dimensions}, {other.array_field_map_dimensions}) && ... + isequal({self.dynamic_array_field}, {other.dynamic_array_field}) && ... + isequal({self.fixed_array_field}, {other.fixed_array_field}) && ... + isequal({self.int_field}, {other.int_field}) && ... + isequal({self.int8_field}, {other.int8_field}) && ... + isequal({self.uint8_field}, {other.uint8_field}) && ... + isequal({self.int16_field}, {other.int16_field}) && ... + isequal({self.uint16_field}, {other.uint16_field}) && ... + isequal({self.uint32_field}, {other.uint32_field}) && ... + isequal({self.int64_field}, {other.int64_field}) && ... + isequal({self.uint64_field}, {other.uint64_field}) && ... + isequal({self.size_field}, {other.size_field}) && ... + isequal({self.float32_field}, {other.float32_field}) && ... + isequal({self.float64_field}, {other.float64_field}) && ... + isequal({self.complexfloat32_field}, {other.complexfloat32_field}) && ... + isequal({self.complexfloat64_field}, {other.complexfloat64_field}) && ... + isequal({self.string_field}, {other.string_field}) && ... + isequal({self.tuple_field}, {other.tuple_field}) && ... + isequal({self.vector_field}, {other.vector_field}) && ... + isequal({self.vector_of_vectors_field}, {other.vector_of_vectors_field}) && ... + isequal({self.fixed_vector_field}, {other.fixed_vector_field}) && ... + isequal({self.fixed_vector_of_vectors_field}, {other.fixed_vector_of_vectors_field}) && ... + isequal({self.optional_named_array}, {other.optional_named_array}) && ... + isequal({self.int_float_union}, {other.int_float_union}) && ... + isequal({self.nullable_int_float_union}, {other.nullable_int_float_union}) && ... + isequal({self.union_with_nested_generic_union}, {other.union_with_nested_generic_union}) && ... + isequal({self.map_field}, {other.map_field}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithDynamicNDArrays.m b/matlab/generated/+test_model/RecordWithDynamicNDArrays.m index 118cb61f..d357f3f9 100644 --- a/matlab/generated/+test_model/RecordWithDynamicNDArrays.m +++ b/matlab/generated/+test_model/RecordWithDynamicNDArrays.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithDynamicNDArrays") && ... - isequal(self.ints, other.ints) && ... - isequal(self.simple_record_array, other.simple_record_array) && ... - isequal(self.record_with_vlens_array, other.record_with_vlens_array); + isequal({self.ints}, {other.ints}) && ... + isequal({self.simple_record_array}, {other.simple_record_array}) && ... + isequal({self.record_with_vlens_array}, {other.record_with_vlens_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithEnums.m b/matlab/generated/+test_model/RecordWithEnums.m index ef2525c7..2175115d 100644 --- a/matlab/generated/+test_model/RecordWithEnums.m +++ b/matlab/generated/+test_model/RecordWithEnums.m @@ -31,15 +31,33 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithEnums") && ... - isequal(self.enum, other.enum) && ... - isequal(self.flags, other.flags) && ... - isequal(self.flags_2, other.flags_2) && ... - isequal(self.rec, other.rec); + isequal({self.enum}, {other.enum}) && ... + isequal({self.flags}, {other.flags}) && ... + isequal({self.flags_2}, {other.flags_2}) && ... + isequal({self.rec}, {other.rec}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithEnums(enum=yardl.None, rec=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithFixedArrays.m b/matlab/generated/+test_model/RecordWithFixedArrays.m index c60cd0d1..49d025fa 100644 --- a/matlab/generated/+test_model/RecordWithFixedArrays.m +++ b/matlab/generated/+test_model/RecordWithFixedArrays.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithFixedArrays") && ... - isequal(self.ints, other.ints) && ... - isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... - isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + isequal({self.ints}, {other.ints}) && ... + isequal({self.fixed_simple_record_array}, {other.fixed_simple_record_array}) && ... + isequal({self.fixed_record_with_vlens_array}, {other.fixed_record_with_vlens_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithFixedCollections.m b/matlab/generated/+test_model/RecordWithFixedCollections.m index 6f80c8ad..4e3b8482 100644 --- a/matlab/generated/+test_model/RecordWithFixedCollections.m +++ b/matlab/generated/+test_model/RecordWithFixedCollections.m @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithFixedCollections") && ... - isequal(self.fixed_vector, other.fixed_vector) && ... - isequal(self.fixed_array, other.fixed_array); + isequal({self.fixed_vector}, {other.fixed_vector}) && ... + isequal({self.fixed_array}, {other.fixed_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithFixedVectors.m b/matlab/generated/+test_model/RecordWithFixedVectors.m index 4d40cb05..ce591c31 100644 --- a/matlab/generated/+test_model/RecordWithFixedVectors.m +++ b/matlab/generated/+test_model/RecordWithFixedVectors.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithFixedVectors") && ... - isequal(self.fixed_int_vector, other.fixed_int_vector) && ... - isequal(self.fixed_simple_record_vector, other.fixed_simple_record_vector) && ... - isequal(self.fixed_record_with_vlens_vector, other.fixed_record_with_vlens_vector); + isequal({self.fixed_int_vector}, {other.fixed_int_vector}) && ... + isequal({self.fixed_simple_record_vector}, {other.fixed_simple_record_vector}) && ... + isequal({self.fixed_record_with_vlens_vector}, {other.fixed_record_with_vlens_vector}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithFloatArrays.m b/matlab/generated/+test_model/RecordWithFloatArrays.m index 7f8c2f86..527eee98 100644 --- a/matlab/generated/+test_model/RecordWithFloatArrays.m +++ b/matlab/generated/+test_model/RecordWithFloatArrays.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = RecordWithFloatArrays(varargin) - c = test_model.RecordWithGenericArrays(varargin{:}); +classdef RecordWithFloatArrays < test_model.RecordWithGenericArrays end diff --git a/matlab/generated/+test_model/RecordWithGenericArrays.m b/matlab/generated/+test_model/RecordWithGenericArrays.m index b66e3d75..8bafd6a1 100644 --- a/matlab/generated/+test_model/RecordWithGenericArrays.m +++ b/matlab/generated/+test_model/RecordWithGenericArrays.m @@ -49,17 +49,35 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithGenericArrays") && ... - isequal(self.nd, other.nd) && ... - isequal(self.fixed_nd, other.fixed_nd) && ... - isequal(self.dynamic_nd, other.dynamic_nd) && ... - isequal(self.aliased_nd, other.aliased_nd) && ... - isequal(self.aliased_fixed_nd, other.aliased_fixed_nd) && ... - isequal(self.aliased_dynamic_nd, other.aliased_dynamic_nd); + isequal({self.nd}, {other.nd}) && ... + isequal({self.fixed_nd}, {other.fixed_nd}) && ... + isequal({self.dynamic_nd}, {other.dynamic_nd}) && ... + isequal({self.aliased_nd}, {other.aliased_nd}) && ... + isequal({self.aliased_fixed_nd}, {other.aliased_fixed_nd}) && ... + isequal({self.aliased_dynamic_nd}, {other.aliased_dynamic_nd}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithGenericArrays(nd=yardl.None, fixed_nd=yardl.None, dynamic_nd=yardl.None, aliased_nd=yardl.None, aliased_fixed_nd=yardl.None, aliased_dynamic_nd=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithGenericFixedVectors.m b/matlab/generated/+test_model/RecordWithGenericFixedVectors.m index f3298457..3bd60671 100644 --- a/matlab/generated/+test_model/RecordWithGenericFixedVectors.m +++ b/matlab/generated/+test_model/RecordWithGenericFixedVectors.m @@ -25,13 +25,31 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithGenericFixedVectors") && ... - isequal(self.fv, other.fv) && ... - isequal(self.afv, other.afv); + isequal({self.fv}, {other.fv}) && ... + isequal({self.afv}, {other.afv}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithGenericFixedVectors(fv=yardl.None, afv=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithGenericMaps.m b/matlab/generated/+test_model/RecordWithGenericMaps.m index 75598bd9..6744accd 100644 --- a/matlab/generated/+test_model/RecordWithGenericMaps.m +++ b/matlab/generated/+test_model/RecordWithGenericMaps.m @@ -9,8 +9,8 @@ methods function self = RecordWithGenericMaps(kwargs) arguments - kwargs.m = dictionary; - kwargs.am = dictionary; + kwargs.m = yardl.Map; + kwargs.am = yardl.Map; end self.m = kwargs.m; self.am = kwargs.am; @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithGenericMaps") && ... - isequal(self.m, other.m) && ... - isequal(self.am, other.am); + isequal({self.m}, {other.m}) && ... + isequal({self.am}, {other.am}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m b/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m index 52be4792..15d16a46 100644 --- a/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m +++ b/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m @@ -19,12 +19,30 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithGenericVectorOfRecords") && ... - isequal(self.v, other.v); + isequal({self.v}, {other.v}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithGenericVectorOfRecords(v=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithGenericVectors.m b/matlab/generated/+test_model/RecordWithGenericVectors.m index 5eb735c5..3ae1eb61 100644 --- a/matlab/generated/+test_model/RecordWithGenericVectors.m +++ b/matlab/generated/+test_model/RecordWithGenericVectors.m @@ -25,13 +25,31 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithGenericVectors") && ... - isequal(self.v, other.v) && ... - isequal(self.av, other.av); + isequal({self.v}, {other.v}) && ... + isequal({self.av}, {other.av}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithGenericVectors(v=yardl.None, av=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithIntVectors.m b/matlab/generated/+test_model/RecordWithIntVectors.m index fc8a9ec0..68c2a338 100644 --- a/matlab/generated/+test_model/RecordWithIntVectors.m +++ b/matlab/generated/+test_model/RecordWithIntVectors.m @@ -1,5 +1,4 @@ % This file was generated by the "yardl" tool. DO NOT EDIT. -function c = RecordWithIntVectors(varargin) - c = test_model.RecordWithGenericVectors(varargin{:}); +classdef RecordWithIntVectors < test_model.RecordWithGenericVectors end diff --git a/matlab/generated/+test_model/RecordWithKeywordFields.m b/matlab/generated/+test_model/RecordWithKeywordFields.m index 22ec5fa0..73b997a9 100644 --- a/matlab/generated/+test_model/RecordWithKeywordFields.m +++ b/matlab/generated/+test_model/RecordWithKeywordFields.m @@ -11,7 +11,7 @@ function self = RecordWithKeywordFields(kwargs) arguments kwargs.int = ""; - kwargs.sizeof = int32.empty(0, 0); + kwargs.sizeof = int32.empty(); kwargs.if_; end self.int = kwargs.int; @@ -33,7 +33,7 @@ end function res = return_(self) - res = self.sizeof(2, 1); + res = self.sizeof(1+2, 1+1); return end @@ -41,14 +41,32 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithKeywordFields") && ... - isequal(self.int, other.int) && ... - isequal(self.sizeof, other.sizeof) && ... - isequal(self.if_, other.if_); + isequal({self.int}, {other.int}) && ... + isequal({self.sizeof}, {other.sizeof}) && ... + isequal({self.if_}, {other.if_}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithKeywordFields(if_=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithMaps.m b/matlab/generated/+test_model/RecordWithMaps.m index 5b7e2784..a75af92d 100644 --- a/matlab/generated/+test_model/RecordWithMaps.m +++ b/matlab/generated/+test_model/RecordWithMaps.m @@ -9,8 +9,8 @@ methods function self = RecordWithMaps(kwargs) arguments - kwargs.set_1 = dictionary; - kwargs.set_2 = dictionary; + kwargs.set_1 = yardl.Map; + kwargs.set_2 = yardl.Map; end self.set_1 = kwargs.set_1; self.set_2 = kwargs.set_2; @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithMaps") && ... - isequal(self.set_1, other.set_1) && ... - isequal(self.set_2, other.set_2); + isequal({self.set_1}, {other.set_1}) && ... + isequal({self.set_2}, {other.set_2}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithNDArrays.m b/matlab/generated/+test_model/RecordWithNDArrays.m index 209161f9..8a6b3c91 100644 --- a/matlab/generated/+test_model/RecordWithNDArrays.m +++ b/matlab/generated/+test_model/RecordWithNDArrays.m @@ -10,9 +10,9 @@ methods function self = RecordWithNDArrays(kwargs) arguments - kwargs.ints = int32.empty(0, 0); - kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(0, 0); - kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(0, 0); + kwargs.ints = int32.empty(); + kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(); + kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(); end self.ints = kwargs.ints; self.fixed_simple_record_array = kwargs.fixed_simple_record_array; @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithNDArrays") && ... - isequal(self.ints, other.ints) && ... - isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... - isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + isequal({self.ints}, {other.ints}) && ... + isequal({self.fixed_simple_record_array}, {other.fixed_simple_record_array}) && ... + isequal({self.fixed_record_with_vlens_array}, {other.fixed_record_with_vlens_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m b/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m index bb378d98..c9b88ffa 100644 --- a/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m +++ b/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m @@ -10,9 +10,9 @@ methods function self = RecordWithNDArraysSingleDimension(kwargs) arguments - kwargs.ints = int32.empty(0); - kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(0); - kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(0); + kwargs.ints = int32.empty(); + kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(); + kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(); end self.ints = kwargs.ints; self.fixed_simple_record_array = kwargs.fixed_simple_record_array; @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithNDArraysSingleDimension") && ... - isequal(self.ints, other.ints) && ... - isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... - isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + isequal({self.ints}, {other.ints}) && ... + isequal({self.fixed_simple_record_array}, {other.fixed_simple_record_array}) && ... + isequal({self.fixed_record_with_vlens_array}, {other.fixed_record_with_vlens_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithNamedFixedArrays.m b/matlab/generated/+test_model/RecordWithNamedFixedArrays.m index 33e13d11..d46920c8 100644 --- a/matlab/generated/+test_model/RecordWithNamedFixedArrays.m +++ b/matlab/generated/+test_model/RecordWithNamedFixedArrays.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithNamedFixedArrays") && ... - isequal(self.ints, other.ints) && ... - isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... - isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + isequal({self.ints}, {other.ints}) && ... + isequal({self.fixed_simple_record_array}, {other.fixed_simple_record_array}) && ... + isequal({self.fixed_record_with_vlens_array}, {other.fixed_record_with_vlens_array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithNoDefaultEnum.m b/matlab/generated/+test_model/RecordWithNoDefaultEnum.m index 7e026fd0..267506db 100644 --- a/matlab/generated/+test_model/RecordWithNoDefaultEnum.m +++ b/matlab/generated/+test_model/RecordWithNoDefaultEnum.m @@ -19,12 +19,30 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithNoDefaultEnum") && ... - isequal(self.enum, other.enum); + isequal({self.enum}, {other.enum}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithNoDefaultEnum(enum=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/generated/+test_model/RecordWithOptionalDate.m b/matlab/generated/+test_model/RecordWithOptionalDate.m index f888cf9b..7c68cc34 100644 --- a/matlab/generated/+test_model/RecordWithOptionalDate.m +++ b/matlab/generated/+test_model/RecordWithOptionalDate.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithOptionalDate") && ... - isequal(self.date_field, other.date_field); + isequal({self.date_field}, {other.date_field}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithOptionalFields.m b/matlab/generated/+test_model/RecordWithOptionalFields.m index bb159ff8..7ec1bb76 100644 --- a/matlab/generated/+test_model/RecordWithOptionalFields.m +++ b/matlab/generated/+test_model/RecordWithOptionalFields.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithOptionalFields") && ... - isequal(self.optional_int, other.optional_int) && ... - isequal(self.optional_int_alternate_syntax, other.optional_int_alternate_syntax) && ... - isequal(self.optional_time, other.optional_time); + isequal({self.optional_int}, {other.optional_int}) && ... + isequal({self.optional_int_alternate_syntax}, {other.optional_int_alternate_syntax}) && ... + isequal({self.optional_time}, {other.optional_time}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithOptionalGenericField.m b/matlab/generated/+test_model/RecordWithOptionalGenericField.m index 89088836..da741906 100644 --- a/matlab/generated/+test_model/RecordWithOptionalGenericField.m +++ b/matlab/generated/+test_model/RecordWithOptionalGenericField.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithOptionalGenericField") && ... - isequal(self.v, other.v); + isequal({self.v}, {other.v}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m b/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m index 6c57abfd..d905347e 100644 --- a/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m +++ b/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithOptionalGenericUnionField") && ... - isequal(self.v, other.v); + isequal({self.v}, {other.v}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithOptionalVector.m b/matlab/generated/+test_model/RecordWithOptionalVector.m index 14aab0bf..fce9bfab 100644 --- a/matlab/generated/+test_model/RecordWithOptionalVector.m +++ b/matlab/generated/+test_model/RecordWithOptionalVector.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithOptionalVector") && ... - isequal(self.optional_vector, other.optional_vector); + isequal({self.optional_vector}, {other.optional_vector}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithPrimitiveAliases.m b/matlab/generated/+test_model/RecordWithPrimitiveAliases.m index 3dd24585..d887b706 100644 --- a/matlab/generated/+test_model/RecordWithPrimitiveAliases.m +++ b/matlab/generated/+test_model/RecordWithPrimitiveAliases.m @@ -40,20 +40,24 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithPrimitiveAliases") && ... - isequal(self.byte_field, other.byte_field) && ... - isequal(self.int_field, other.int_field) && ... - isequal(self.uint_field, other.uint_field) && ... - isequal(self.long_field, other.long_field) && ... - isequal(self.ulong_field, other.ulong_field) && ... - isequal(self.float_field, other.float_field) && ... - isequal(self.double_field, other.double_field) && ... - isequal(self.complexfloat_field, other.complexfloat_field) && ... - isequal(self.complexdouble_field, other.complexdouble_field); + isequal({self.byte_field}, {other.byte_field}) && ... + isequal({self.int_field}, {other.int_field}) && ... + isequal({self.uint_field}, {other.uint_field}) && ... + isequal({self.long_field}, {other.long_field}) && ... + isequal({self.ulong_field}, {other.ulong_field}) && ... + isequal({self.float_field}, {other.float_field}) && ... + isequal({self.double_field}, {other.double_field}) && ... + isequal({self.complexfloat_field}, {other.complexfloat_field}) && ... + isequal({self.complexdouble_field}, {other.complexdouble_field}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithPrimitives.m b/matlab/generated/+test_model/RecordWithPrimitives.m index 07dc6d91..628a8a2a 100644 --- a/matlab/generated/+test_model/RecordWithPrimitives.m +++ b/matlab/generated/+test_model/RecordWithPrimitives.m @@ -64,28 +64,32 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithPrimitives") && ... - isequal(self.bool_field, other.bool_field) && ... - isequal(self.int8_field, other.int8_field) && ... - isequal(self.uint8_field, other.uint8_field) && ... - isequal(self.int16_field, other.int16_field) && ... - isequal(self.uint16_field, other.uint16_field) && ... - isequal(self.int32_field, other.int32_field) && ... - isequal(self.uint32_field, other.uint32_field) && ... - isequal(self.int64_field, other.int64_field) && ... - isequal(self.uint64_field, other.uint64_field) && ... - isequal(self.size_field, other.size_field) && ... - isequal(self.float32_field, other.float32_field) && ... - isequal(self.float64_field, other.float64_field) && ... - isequal(self.complexfloat32_field, other.complexfloat32_field) && ... - isequal(self.complexfloat64_field, other.complexfloat64_field) && ... - isequal(self.date_field, other.date_field) && ... - isequal(self.time_field, other.time_field) && ... - isequal(self.datetime_field, other.datetime_field); + isequal({self.bool_field}, {other.bool_field}) && ... + isequal({self.int8_field}, {other.int8_field}) && ... + isequal({self.uint8_field}, {other.uint8_field}) && ... + isequal({self.int16_field}, {other.int16_field}) && ... + isequal({self.uint16_field}, {other.uint16_field}) && ... + isequal({self.int32_field}, {other.int32_field}) && ... + isequal({self.uint32_field}, {other.uint32_field}) && ... + isequal({self.int64_field}, {other.int64_field}) && ... + isequal({self.uint64_field}, {other.uint64_field}) && ... + isequal({self.size_field}, {other.size_field}) && ... + isequal({self.float32_field}, {other.float32_field}) && ... + isequal({self.float64_field}, {other.float64_field}) && ... + isequal({self.complexfloat32_field}, {other.complexfloat32_field}) && ... + isequal({self.complexfloat64_field}, {other.complexfloat64_field}) && ... + isequal({self.date_field}, {other.date_field}) && ... + isequal({self.time_field}, {other.time_field}) && ... + isequal({self.datetime_field}, {other.datetime_field}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithStrings.m b/matlab/generated/+test_model/RecordWithStrings.m index ffab134f..d28a6147 100644 --- a/matlab/generated/+test_model/RecordWithStrings.m +++ b/matlab/generated/+test_model/RecordWithStrings.m @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithStrings") && ... - isequal(self.a, other.a) && ... - isequal(self.b, other.b); + isequal({self.a}, {other.a}) && ... + isequal({self.b}, {other.b}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithUnionsOfContainers.m b/matlab/generated/+test_model/RecordWithUnionsOfContainers.m index 95858917..cb3abacc 100644 --- a/matlab/generated/+test_model/RecordWithUnionsOfContainers.m +++ b/matlab/generated/+test_model/RecordWithUnionsOfContainers.m @@ -10,7 +10,7 @@ methods function self = RecordWithUnionsOfContainers(kwargs) arguments - kwargs.map_or_scalar = test_model.MapOrScalar.Map(dictionary); + kwargs.map_or_scalar = test_model.MapOrScalar.Map(yardl.Map); kwargs.vector_or_scalar = test_model.VectorOrScalar.Vector(int32.empty()); kwargs.array_or_scalar = test_model.ArrayOrScalar.Array(int32.empty()); end @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithUnionsOfContainers") && ... - isequal(self.map_or_scalar, other.map_or_scalar) && ... - isequal(self.vector_or_scalar, other.vector_or_scalar) && ... - isequal(self.array_or_scalar, other.array_or_scalar); + isequal({self.map_or_scalar}, {other.map_or_scalar}) && ... + isequal({self.vector_or_scalar}, {other.vector_or_scalar}) && ... + isequal({self.array_or_scalar}, {other.array_or_scalar}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithVectorOfTimes.m b/matlab/generated/+test_model/RecordWithVectorOfTimes.m index 25dc8d4a..77d01b65 100644 --- a/matlab/generated/+test_model/RecordWithVectorOfTimes.m +++ b/matlab/generated/+test_model/RecordWithVectorOfTimes.m @@ -16,12 +16,16 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithVectorOfTimes") && ... - isequal(self.times, other.times); + isequal({self.times}, {other.times}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithVectors.m b/matlab/generated/+test_model/RecordWithVectors.m index fdfd681a..ab195790 100644 --- a/matlab/generated/+test_model/RecordWithVectors.m +++ b/matlab/generated/+test_model/RecordWithVectors.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithVectors") && ... - isequal(self.default_vector, other.default_vector) && ... - isequal(self.default_vector_fixed_length, other.default_vector_fixed_length) && ... - isequal(self.vector_of_vectors, other.vector_of_vectors); + isequal({self.default_vector}, {other.default_vector}) && ... + isequal({self.default_vector_fixed_length}, {other.default_vector_fixed_length}) && ... + isequal({self.vector_of_vectors}, {other.vector_of_vectors}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithVlenCollections.m b/matlab/generated/+test_model/RecordWithVlenCollections.m index 158f5550..1f6014e5 100644 --- a/matlab/generated/+test_model/RecordWithVlenCollections.m +++ b/matlab/generated/+test_model/RecordWithVlenCollections.m @@ -10,7 +10,7 @@ function self = RecordWithVlenCollections(kwargs) arguments kwargs.vector = int32.empty(); - kwargs.array = int32.empty(0, 0); + kwargs.array = int32.empty(); end self.vector = kwargs.vector; self.array = kwargs.array; @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithVlenCollections") && ... - isequal(self.vector, other.vector) && ... - isequal(self.array, other.array); + isequal({self.vector}, {other.vector}) && ... + isequal({self.array}, {other.array}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithVlens.m b/matlab/generated/+test_model/RecordWithVlens.m index 6eb80c63..b55e27ab 100644 --- a/matlab/generated/+test_model/RecordWithVlens.m +++ b/matlab/generated/+test_model/RecordWithVlens.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.RecordWithVlens") && ... - isequal(self.a, other.a) && ... - isequal(self.b, other.b) && ... - isequal(self.c, other.c); + isequal({self.a}, {other.a}) && ... + isequal({self.b}, {other.b}) && ... + isequal({self.c}, {other.c}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/RecordWithVlensFixedArray.m b/matlab/generated/+test_model/RecordWithVlensFixedArray.m deleted file mode 100644 index f4015b1d..00000000 --- a/matlab/generated/+test_model/RecordWithVlensFixedArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = RecordWithVlensFixedArray(array) - arguments - array test_model.RecordWithVlens - end - a = array; -end diff --git a/matlab/generated/+test_model/SimpleAcquisition.m b/matlab/generated/+test_model/SimpleAcquisition.m index 3d502407..d436e0b6 100644 --- a/matlab/generated/+test_model/SimpleAcquisition.m +++ b/matlab/generated/+test_model/SimpleAcquisition.m @@ -13,8 +13,8 @@ arguments kwargs.flags = uint64(0); kwargs.idx = test_model.SimpleEncodingCounters(); - kwargs.data = single.empty(0, 0); - kwargs.trajectory = single.empty(0, 0); + kwargs.data = single.empty(); + kwargs.trajectory = single.empty(); end self.flags = kwargs.flags; self.idx = kwargs.idx; @@ -25,15 +25,19 @@ function res = eq(self, other) res = ... isa(other, "test_model.SimpleAcquisition") && ... - isequal(self.flags, other.flags) && ... - isequal(self.idx, other.idx) && ... - isequal(self.data, other.data) && ... - isequal(self.trajectory, other.trajectory); + isequal({self.flags}, {other.flags}) && ... + isequal({self.idx}, {other.idx}) && ... + isequal({self.data}, {other.data}) && ... + isequal({self.trajectory}, {other.trajectory}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/SimpleEncodingCounters.m b/matlab/generated/+test_model/SimpleEncodingCounters.m index 2cdbe684..0ad9ffb1 100644 --- a/matlab/generated/+test_model/SimpleEncodingCounters.m +++ b/matlab/generated/+test_model/SimpleEncodingCounters.m @@ -25,15 +25,19 @@ function res = eq(self, other) res = ... isa(other, "test_model.SimpleEncodingCounters") && ... - isequal(self.e1, other.e1) && ... - isequal(self.e2, other.e2) && ... - isequal(self.slice, other.slice) && ... - isequal(self.repetition, other.repetition); + isequal({self.e1}, {other.e1}) && ... + isequal({self.e2}, {other.e2}) && ... + isequal({self.slice}, {other.slice}) && ... + isequal({self.repetition}, {other.repetition}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/SimpleRecord.m b/matlab/generated/+test_model/SimpleRecord.m index fc3930ad..c5959ab7 100644 --- a/matlab/generated/+test_model/SimpleRecord.m +++ b/matlab/generated/+test_model/SimpleRecord.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.SimpleRecord") && ... - isequal(self.x, other.x) && ... - isequal(self.y, other.y) && ... - isequal(self.z, other.z); + isequal({self.x}, {other.x}) && ... + isequal({self.y}, {other.y}) && ... + isequal({self.z}, {other.z}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/SimpleRecordFixedArray.m b/matlab/generated/+test_model/SimpleRecordFixedArray.m deleted file mode 100644 index c89409e7..00000000 --- a/matlab/generated/+test_model/SimpleRecordFixedArray.m +++ /dev/null @@ -1,8 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = SimpleRecordFixedArray(array) - arguments - array test_model.SimpleRecord - end - a = array; -end diff --git a/matlab/generated/+test_model/SmallBenchmarkRecord.m b/matlab/generated/+test_model/SmallBenchmarkRecord.m index b9e62a52..3dde9ea4 100644 --- a/matlab/generated/+test_model/SmallBenchmarkRecord.m +++ b/matlab/generated/+test_model/SmallBenchmarkRecord.m @@ -22,14 +22,18 @@ function res = eq(self, other) res = ... isa(other, "test_model.SmallBenchmarkRecord") && ... - isequal(self.a, other.a) && ... - isequal(self.b, other.b) && ... - isequal(self.c, other.c); + isequal({self.a}, {other.a}) && ... + isequal({self.b}, {other.b}) && ... + isequal({self.c}, {other.c}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/StringOrInt32.m b/matlab/generated/+test_model/StringOrInt32.m index 58bb97eb..963df62f 100644 --- a/matlab/generated/+test_model/StringOrInt32.m +++ b/matlab/generated/+test_model/StringOrInt32.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.StringOrInt32") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.StringOrInt32") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/TupleWithRecords.m b/matlab/generated/+test_model/TupleWithRecords.m index dbc507d8..79b56b3e 100644 --- a/matlab/generated/+test_model/TupleWithRecords.m +++ b/matlab/generated/+test_model/TupleWithRecords.m @@ -19,13 +19,17 @@ function res = eq(self, other) res = ... isa(other, "test_model.TupleWithRecords") && ... - isequal(self.a, other.a) && ... - isequal(self.b, other.b); + isequal({self.a}, {other.a}) && ... + isequal({self.b}, {other.b}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end methods (Static) diff --git a/matlab/generated/+test_model/UOrV.m b/matlab/generated/+test_model/UOrV.m index 9f6a006e..f560cf65 100644 --- a/matlab/generated/+test_model/UOrV.m +++ b/matlab/generated/+test_model/UOrV.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.UOrV") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.UOrV") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/UnionOfContainerRecords.m b/matlab/generated/+test_model/UnionOfContainerRecords.m index 15f1236f..15e86e4d 100644 --- a/matlab/generated/+test_model/UnionOfContainerRecords.m +++ b/matlab/generated/+test_model/UnionOfContainerRecords.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.UnionOfContainerRecords") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.UnionOfContainerRecords") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+test_model/VectorOfGenericRecords.m b/matlab/generated/+test_model/VectorOfGenericRecords.m deleted file mode 100644 index a8f035c4..00000000 --- a/matlab/generated/+test_model/VectorOfGenericRecords.m +++ /dev/null @@ -1,5 +0,0 @@ -% This file was generated by the "yardl" tool. DO NOT EDIT. - -function a = VectorOfGenericRecords(array) - a = array; -end diff --git a/matlab/generated/+test_model/VectorOrScalar.m b/matlab/generated/+test_model/VectorOrScalar.m index a51eca2c..07141e37 100644 --- a/matlab/generated/+test_model/VectorOrScalar.m +++ b/matlab/generated/+test_model/VectorOrScalar.m @@ -34,7 +34,7 @@ end function eq = eq(self, other) - eq = isa(other, "test_model.VectorOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + eq = isa(other, "test_model.VectorOrScalar") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all'); end function ne = ne(self, other) diff --git a/matlab/generated/+tuples/Tuple.m b/matlab/generated/+tuples/Tuple.m index 6e0f491b..5b8a7aab 100644 --- a/matlab/generated/+tuples/Tuple.m +++ b/matlab/generated/+tuples/Tuple.m @@ -25,13 +25,31 @@ function res = eq(self, other) res = ... isa(other, "tuples.Tuple") && ... - isequal(self.v1, other.v1) && ... - isequal(self.v2, other.v2); + isequal({self.v1}, {other.v1}) && ... + isequal({self.v2}, {other.v2}); end function res = ne(self, other) res = ~self.eq(other); end + + function res = isequal(self, other) + res = all(eq(self, other)); + end end + methods (Static) + function z = zeros(varargin) + elem = tuples.Tuple(v1=yardl.None, v2=yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end end diff --git a/matlab/test/ComputedFieldsTest.m b/matlab/test/ComputedFieldsTest.m index 25a8b00c..98fa816a 100644 --- a/matlab/test/ComputedFieldsTest.m +++ b/matlab/test/ComputedFieldsTest.m @@ -31,7 +31,7 @@ function testFieldAccess(testCase) r.fixed_vector_of_vectors_field = int32([[1; 2; 3], [4; 5; 6]]); testCase.verifyEqual(r.access_fixed_vector_of_vectors_field(), r.fixed_vector_of_vectors_field(3, 2)); - r.map_field = dictionary(["hello", "world"], ["world", "bye"]); + r.map_field = yardl.Map(["hello", "world"], ["world", "bye"]); testCase.verifyEqual(r.access_map(), r.map_field); testCase.verifyEqual(r.access_map_entry(), "world"); testCase.verifyEqual(r.access_map_entry_with_computed_field(), "world"); @@ -85,7 +85,7 @@ function testVectorSize(testCase) function testMapSize(testCase) r = test_model.RecordWithComputedFields(); testCase.verifyEqual(r.map_size(), 0); - r.map_field = dictionary(["hello", "bonjour"], ["world", "monde"]); + r.map_field = yardl.Map(["hello", "bonjour"], ["world", "monde"]); testCase.verifyEqual(r.map_size(), 2); end diff --git a/matlab/test/GeneratedTypesTest.m b/matlab/test/GeneratedTypesTest.m index 47eeb227..a9a2e399 100644 --- a/matlab/test/GeneratedTypesTest.m +++ b/matlab/test/GeneratedTypesTest.m @@ -55,7 +55,7 @@ function testDefaultRecordWithOptionalFields(testCase) function testDefaultRecordWithUnionsOfContainers(testCase) r = test_model.RecordWithUnionsOfContainers(); - testCase.verifyEqual(r.map_or_scalar, test_model.MapOrScalar.Map(dictionary)); + testCase.verifyEqual(r.map_or_scalar, test_model.MapOrScalar.Map(yardl.Map())); testCase.verifyEqual(r.vector_or_scalar, test_model.VectorOrScalar.Vector(int32([]))); testCase.verifyEqual(r.array_or_scalar, test_model.ArrayOrScalar.Array(int32([]))); end @@ -82,12 +82,11 @@ function testDefaultRecordGenericEmpty(testCase) g2a = test_model.RecordWithAliasedOptionalGenericUnionField(); testCase.verifyEqual(g2a.v, g2.v) - % testCase.verifyError(@() test_model.MyTuple(), 'MATLAB:minrhs'); testCase.verifyError(@() test_model.MyTuple(), 'yardl:TypeError'); t = test_model.MyTuple(v1="a", v2=42); rm = test_model.RecordWithGenericMaps(); - testCase.verifyEqual(rm.m, dictionary); + testCase.verifyEqual(rm.m, yardl.Map()); testCase.verifyEqual(rm.am, rm.m); end @@ -142,7 +141,7 @@ function testDefaultRecordContainingNestedGenericRecords(testCase) function testYardlAllocate(testCase) rs = yardl.allocate('test_model.RecordWithPrimitives', 5); testCase.verifyEqual(size(rs), [5, 5]); - testCase.verifyTrue(all(rs == test_model.RecordWithPrimitives())); + testCase.verifyTrue(all(rs == repelem(test_model.RecordWithPrimitives(), 5, 5))); os = yardl.allocate('yardl.Optional', 1, 4); testCase.verifyEqual(size(os), [1, 4]); diff --git a/matlab/test/RoundTripTest.m b/matlab/test/RoundTripTest.m index ade046ab..d9587507 100644 --- a/matlab/test/RoundTripTest.m +++ b/matlab/test/RoundTripTest.m @@ -298,34 +298,34 @@ function testMultiDArrays(testCase, format) end function testMaps(testCase, format) - d = dictionary(); - d("a") = int32(1); - d("b") = 2; - d("c") = 3; + d = yardl.Map(); + d.insert("a", int32(1)); + d.insert("b", 2); + d.insert("c", 3); w = create_validating_writer(testCase, format, 'Maps'); w.write_string_to_int(d); - w.write_int_to_string(dictionary(int32([1, 2, 3]), ["a", "b", "c"])); + w.write_int_to_string(yardl.Map(int32([1, 2, 3]), ["a", "b", "c"])); w.write_string_to_union(... - dictionary(... + yardl.Map(... ["a", "b"], ... [test_model.StringOrInt32.Int32(1), test_model.StringOrInt32.String("2")] ... ) ... ); w.write_aliased_generic(d); - r1 = test_model.RecordWithMaps(set_1=dictionary(uint32(1), uint32(1), uint32(2), uint32(2)), set_2=dictionary(int32(-1), true, int32(3), false)); - r2 = test_model.RecordWithMaps(set_1=dictionary(uint32(1), uint32(2), uint32(2), uint32(1)), set_2=dictionary(int32(-1), false, int32(3), true)); + r1 = test_model.RecordWithMaps(set_1=yardl.Map(uint32(1), uint32(1), uint32(2), uint32(2)), set_2=yardl.Map(int32(-1), true, int32(3), false)); + r2 = test_model.RecordWithMaps(set_1=yardl.Map(uint32(1), uint32(2), uint32(2), uint32(1)), set_2=yardl.Map(int32(-1), false, int32(3), true)); w.write_records([r1, r2]); w.close(); % Now again for "empty" maps w = create_validating_writer(testCase, format, 'Maps'); - w.write_string_to_int(dictionary()); - w.write_int_to_string(dictionary()); - w.write_string_to_union(dictionary()); - w.write_aliased_generic(dictionary()); - w.write_records([test_model.RecordWithMaps(set_1=dictionary(), set_2=dictionary())]); + w.write_string_to_int(yardl.Map()); + w.write_int_to_string(yardl.Map()); + w.write_string_to_union(yardl.Map()); + w.write_aliased_generic(yardl.Map()); + w.write_records([test_model.RecordWithMaps(set_1=yardl.Map(), set_2=yardl.Map())]); w.close(); end @@ -553,6 +553,20 @@ function testAliases(testCase, format) test_model.AliasedGenericUnion2.T2(test_model.Fruits.APPLE) ... ]); w.end_stream_of_aliased_generic_union_2(); + + strings = ["hello", "world"]; + maps = [yardl.Map("a", 1, "b", 2), yardl.Map("c", 3, "d", 4)]; + my_tuple = test_model.MyTuple(v1=42, v2=test_model.SimpleRecord(x=1, y=2, z=3)); + image = single([1 2; 3 4]); + + vectors_record = test_model.RecordContainingVectorsOfAliases(... + strings=strings, ... + maps=maps, ... + arrays={image, image}, ... + tuples=[my_tuple, my_tuple] ... + ); + w.write_vectors([vectors_record, vectors_record]); + w.close(); end end diff --git a/models/test/unittests.yml b/models/test/unittests.yml index faeedbd8..a9264e5d 100644 --- a/models/test/unittests.yml +++ b/models/test/unittests.yml @@ -533,6 +533,13 @@ RecordContainingNestedGenericRecords: !record # END nested generic records +RecordContainingVectorsOfAliases: !record + fields: + strings: AliasedString* + maps: AliasedMap* + arrays: Image* + tuples: MyTuple* + Aliases: !protocol sequence: aliasedString: AliasedString @@ -546,6 +553,7 @@ Aliases: !protocol aliasedGenericFixedVector: AliasedGenericFixedVector streamOfAliasedGenericUnion2: !stream items: AliasedGenericUnion2 + vectors: RecordContainingVectorsOfAliases* AliasedIntOrSimpleRecord: [int, SimpleRecord] AliasedIntOrAliasedSimpleRecord: [int, AliasedSimpleRecord] diff --git a/python/test_model/__init__.py b/python/test_model/__init__.py index 31101df7..f6a4ccbd 100644 --- a/python/test_model/__init__.py +++ b/python/test_model/__init__.py @@ -70,6 +70,7 @@ def _parse_version(version: str) -> _Tuple[int, ...]: NamedNDArray, RecordContainingGenericRecords, RecordContainingNestedGenericRecords, + RecordContainingVectorsOfAliases, RecordNotUsedInProtocol, RecordWithAliasedGenerics, RecordWithAliasedOptionalGenericField, diff --git a/python/test_model/binary.py b/python/test_model/binary.py index dbacc36a..86ce6355 100644 --- a/python/test_model/binary.py +++ b/python/test_model/binary.py @@ -1143,6 +1143,9 @@ def _write_aliased_generic_fixed_vector(self, value: AliasedGenericFixedVector[y def _write_stream_of_aliased_generic_union_2(self, value: collections.abc.Iterable[AliasedGenericUnion2[AliasedString, AliasedEnum]]) -> None: _binary.StreamSerializer(_binary.UnionSerializer(basic_types.GenericUnion2, [(basic_types.GenericUnion2.T1, _binary.string_serializer), (basic_types.GenericUnion2.T2, _binary.EnumSerializer(_binary.int32_serializer, basic_types.Fruits))])).write(self._stream, value) + def _write_vectors(self, value: list[RecordContainingVectorsOfAliases]) -> None: + _binary.VectorSerializer(RecordContainingVectorsOfAliasesSerializer()).write(self._stream, value) + class BinaryAliasesReader(_binary.BinaryProtocolReader, AliasesReaderBase): """Binary writer for the Aliases protocol.""" @@ -1182,6 +1185,9 @@ def _read_aliased_generic_fixed_vector(self) -> AliasedGenericFixedVector[yardl. def _read_stream_of_aliased_generic_union_2(self) -> collections.abc.Iterable[AliasedGenericUnion2[AliasedString, AliasedEnum]]: return _binary.StreamSerializer(_binary.UnionSerializer(basic_types.GenericUnion2, [(basic_types.GenericUnion2.T1, _binary.string_serializer), (basic_types.GenericUnion2.T2, _binary.EnumSerializer(_binary.int32_serializer, basic_types.Fruits))])).read(self._stream) + def _read_vectors(self) -> list[RecordContainingVectorsOfAliases]: + return _binary.VectorSerializer(RecordContainingVectorsOfAliasesSerializer()).read(self._stream) + class BinaryStreamsOfAliasedUnionsWriter(_binary.BinaryProtocolWriter, StreamsOfAliasedUnionsWriterBase): """Binary writer for the StreamsOfAliasedUnions protocol.""" @@ -2006,6 +2012,24 @@ def read(self, stream: _binary.CodedInputStream) -> RecordContainingNestedGeneri return RecordContainingNestedGenericRecords(f1=field_values[0], f1a=field_values[1], f2=field_values[2], f2a=field_values[3], nested=field_values[4]) +class RecordContainingVectorsOfAliasesSerializer(_binary.RecordSerializer[RecordContainingVectorsOfAliases]): + def __init__(self) -> None: + super().__init__([("strings", _binary.VectorSerializer(_binary.string_serializer)), ("maps", _binary.VectorSerializer(_binary.MapSerializer(_binary.string_serializer, _binary.int32_serializer))), ("arrays", _binary.VectorSerializer(_binary.NDArraySerializer(_binary.float32_serializer, 2))), ("tuples", _binary.VectorSerializer(tuples.binary.TupleSerializer(_binary.int32_serializer, SimpleRecordSerializer())))]) + + def write(self, stream: _binary.CodedOutputStream, value: RecordContainingVectorsOfAliases) -> None: + if isinstance(value, np.void): + self.write_numpy(stream, value) + return + self._write(stream, value.strings, value.maps, value.arrays, value.tuples) + + def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None: + self._write(stream, value['strings'], value['maps'], value['arrays'], value['tuples']) + + def read(self, stream: _binary.CodedInputStream) -> RecordContainingVectorsOfAliases: + field_values = self._read(stream) + return RecordContainingVectorsOfAliases(strings=field_values[0], maps=field_values[1], arrays=field_values[2], tuples=field_values[3]) + + class RecordWithComputedFieldsSerializer(_binary.RecordSerializer[RecordWithComputedFields]): def __init__(self) -> None: super().__init__([("array_field", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("array_field_map_dimensions", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("dynamic_array_field", _binary.DynamicNDArraySerializer(_binary.int32_serializer)), ("fixed_array_field", _binary.FixedNDArraySerializer(_binary.int32_serializer, (3, 4,))), ("int_field", _binary.int32_serializer), ("int8_field", _binary.int8_serializer), ("uint8_field", _binary.uint8_serializer), ("int16_field", _binary.int16_serializer), ("uint16_field", _binary.uint16_serializer), ("uint32_field", _binary.uint32_serializer), ("int64_field", _binary.int64_serializer), ("uint64_field", _binary.uint64_serializer), ("size_field", _binary.size_serializer), ("float32_field", _binary.float32_serializer), ("float64_field", _binary.float64_serializer), ("complexfloat32_field", _binary.complexfloat32_serializer), ("complexfloat64_field", _binary.complexfloat64_serializer), ("string_field", _binary.string_serializer), ("tuple_field", tuples.binary.TupleSerializer(_binary.int32_serializer, _binary.int32_serializer)), ("vector_field", _binary.VectorSerializer(_binary.int32_serializer)), ("vector_of_vectors_field", _binary.VectorSerializer(_binary.VectorSerializer(_binary.int32_serializer))), ("fixed_vector_field", _binary.FixedVectorSerializer(_binary.int32_serializer, 3)), ("fixed_vector_of_vectors_field", _binary.FixedVectorSerializer(_binary.FixedVectorSerializer(_binary.int32_serializer, 3), 2)), ("optional_named_array", _binary.OptionalSerializer(_binary.NDArraySerializer(_binary.int32_serializer, 2))), ("int_float_union", _binary.UnionSerializer(Int32OrFloat32, [(Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("nullable_int_float_union", _binary.UnionSerializer(Int32OrFloat32, [None, (Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("union_with_nested_generic_union", _binary.UnionSerializer(IntOrGenericRecordWithComputedFields, [(IntOrGenericRecordWithComputedFields.Int, _binary.int32_serializer), (IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields, basic_types.binary.GenericRecordWithComputedFieldsSerializer(_binary.string_serializer, _binary.float32_serializer))])), ("map_field", _binary.MapSerializer(_binary.string_serializer, _binary.string_serializer))]) diff --git a/python/test_model/ndjson.py b/python/test_model/ndjson.py index 105dab12..7b9667ed 100644 --- a/python/test_model/ndjson.py +++ b/python/test_model/ndjson.py @@ -2204,6 +2204,62 @@ def from_json_to_numpy(self, json_object: object) -> np.void: ) # type:ignore +class RecordContainingVectorsOfAliasesConverter(_ndjson.JsonConverter[RecordContainingVectorsOfAliases, np.void]): + def __init__(self) -> None: + self._strings_converter = _ndjson.VectorConverter(_ndjson.string_converter) + self._maps_converter = _ndjson.VectorConverter(_ndjson.MapConverter(_ndjson.string_converter, _ndjson.int32_converter)) + self._arrays_converter = _ndjson.VectorConverter(_ndjson.NDArrayConverter(_ndjson.float32_converter, 2)) + self._tuples_converter = _ndjson.VectorConverter(tuples.ndjson.TupleConverter(_ndjson.int32_converter, SimpleRecordConverter())) + super().__init__(np.dtype([ + ("strings", self._strings_converter.overall_dtype()), + ("maps", self._maps_converter.overall_dtype()), + ("arrays", self._arrays_converter.overall_dtype()), + ("tuples", self._tuples_converter.overall_dtype()), + ])) + + def to_json(self, value: RecordContainingVectorsOfAliases) -> object: + if not isinstance(value, RecordContainingVectorsOfAliases): # pyright: ignore [reportUnnecessaryIsInstance] + raise TypeError("Expected 'RecordContainingVectorsOfAliases' instance") + json_object = {} + + json_object["strings"] = self._strings_converter.to_json(value.strings) + json_object["maps"] = self._maps_converter.to_json(value.maps) + json_object["arrays"] = self._arrays_converter.to_json(value.arrays) + json_object["tuples"] = self._tuples_converter.to_json(value.tuples) + return json_object + + def numpy_to_json(self, value: np.void) -> object: + if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance] + raise TypeError("Expected 'np.void' instance") + json_object = {} + + json_object["strings"] = self._strings_converter.numpy_to_json(value["strings"]) + json_object["maps"] = self._maps_converter.numpy_to_json(value["maps"]) + json_object["arrays"] = self._arrays_converter.numpy_to_json(value["arrays"]) + json_object["tuples"] = self._tuples_converter.numpy_to_json(value["tuples"]) + return json_object + + def from_json(self, json_object: object) -> RecordContainingVectorsOfAliases: + if not isinstance(json_object, dict): + raise TypeError("Expected 'dict' instance") + return RecordContainingVectorsOfAliases( + strings=self._strings_converter.from_json(json_object["strings"],), + maps=self._maps_converter.from_json(json_object["maps"],), + arrays=self._arrays_converter.from_json(json_object["arrays"],), + tuples=self._tuples_converter.from_json(json_object["tuples"],), + ) + + def from_json_to_numpy(self, json_object: object) -> np.void: + if not isinstance(json_object, dict): + raise TypeError("Expected 'dict' instance") + return ( + self._strings_converter.from_json_to_numpy(json_object["strings"]), + self._maps_converter.from_json_to_numpy(json_object["maps"]), + self._arrays_converter.from_json_to_numpy(json_object["arrays"]), + self._tuples_converter.from_json_to_numpy(json_object["tuples"]), + ) # type:ignore + + class RecordWithComputedFieldsConverter(_ndjson.JsonConverter[RecordWithComputedFields, np.void]): def __init__(self) -> None: self._array_field_converter = _ndjson.NDArrayConverter(_ndjson.int32_converter, 2) @@ -4096,6 +4152,11 @@ def _write_stream_of_aliased_generic_union_2(self, value: collections.abc.Iterab json_item = converter.to_json(item) self._write_json_line({"streamOfAliasedGenericUnion2": json_item}) + def _write_vectors(self, value: list[RecordContainingVectorsOfAliases]) -> None: + converter = _ndjson.VectorConverter(RecordContainingVectorsOfAliasesConverter()) + json_value = converter.to_json(value) + self._write_json_line({"vectors": json_value}) + class NDJsonAliasesReader(_ndjson.NDJsonProtocolReader, AliasesReaderBase): """NDJson writer for the Aliases protocol.""" @@ -4155,6 +4216,11 @@ def _read_stream_of_aliased_generic_union_2(self) -> collections.abc.Iterable[Al while (json_object := self._read_json_line("streamOfAliasedGenericUnion2", False)) is not _ndjson.MISSING_SENTINEL: yield converter.from_json(json_object) + def _read_vectors(self) -> list[RecordContainingVectorsOfAliases]: + json_object = self._read_json_line("vectors", True) + converter = _ndjson.VectorConverter(RecordContainingVectorsOfAliasesConverter()) + return converter.from_json(json_object) + class NDJsonStreamsOfAliasedUnionsWriter(_ndjson.NDJsonProtocolWriter, StreamsOfAliasedUnionsWriterBase): """NDJson writer for the StreamsOfAliasedUnions protocol.""" diff --git a/python/test_model/protocols.py b/python/test_model/protocols.py index 92d0a418..089eab6d 100644 --- a/python/test_model/protocols.py +++ b/python/test_model/protocols.py @@ -6003,17 +6003,11 @@ class AliasesWriterBase(abc.ABC): def __init__(self) -> None: self._state = 0 - schema = r"""{"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}}]},"types":[{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}""" + schema = r"""{"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}},{"name":"vectors","type":{"vector":{"items":"TestModel.RecordContainingVectorsOfAliases"}}}]},"types":[{"name":"AliasedMap","typeParameters":["K","V"],"type":{"map":{"keys":"K","values":"V"}}},{"name":"Fruits","values":[{"symbol":"apple","value":1},{"symbol":"banana","value":2},{"symbol":"pear","value":3}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedMap","typeParameters":["K","V"],"type":{"name":"BasicTypes.AliasedMap","typeArguments":["K","V"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"RecordContainingVectorsOfAliases","fields":[{"name":"strings","type":{"vector":{"items":"TestModel.AliasedString"}}},{"name":"maps","type":{"vector":{"items":{"name":"TestModel.AliasedMap","typeArguments":["string","int32"]}}}},{"name":"arrays","type":{"vector":{"items":{"name":"TestModel.Image","typeArguments":["float32"]}}}},{"name":"tuples","type":{"vector":{"items":{"name":"TestModel.MyTuple","typeArguments":["int32","TestModel.SimpleRecord"]}}}}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}""" def close(self) -> None: - if self._state == 19: - try: - self._end_stream() - return - finally: - self._close() self._close() - if self._state != 20: + if self._state != 22: expected_method = self._state_to_method_name((self._state + 1) & ~1) raise ProtocolError(f"Protocol writer closed before all steps were called. Expected to call to '{expected_method}'.") @@ -6117,6 +6111,18 @@ def write_stream_of_aliased_generic_union_2(self, value: collections.abc.Iterabl self._write_stream_of_aliased_generic_union_2(value) self._state = 19 + def write_vectors(self, value: list[RecordContainingVectorsOfAliases]) -> None: + """Ordinal 10""" + + if self._state == 19: + self._end_stream() + self._state = 20 + elif self._state != 20: + self._raise_unexpected_state(20) + + self._write_vectors(value) + self._state = 22 + @abc.abstractmethod def _write_aliased_string(self, value: AliasedString) -> None: raise NotImplementedError() @@ -6157,6 +6163,10 @@ def _write_aliased_generic_fixed_vector(self, value: AliasedGenericFixedVector[y def _write_stream_of_aliased_generic_union_2(self, value: collections.abc.Iterable[AliasedGenericUnion2[AliasedString, AliasedEnum]]) -> None: raise NotImplementedError() + @abc.abstractmethod + def _write_vectors(self, value: list[RecordContainingVectorsOfAliases]) -> None: + raise NotImplementedError() + @abc.abstractmethod def _close(self) -> None: pass @@ -6191,6 +6201,8 @@ def _state_to_method_name(self, state: int) -> str: return 'write_aliased_generic_fixed_vector' if state == 18: return 'write_stream_of_aliased_generic_union_2' + if state == 20: + return 'write_vectors' return "" class AliasesReaderBase(abc.ABC): @@ -6202,7 +6214,7 @@ def __init__(self) -> None: def close(self) -> None: self._close() - if self._state != 20: + if self._state != 22: if self._state % 2 == 1: previous_method = self._state_to_method_name(self._state - 1) raise ProtocolError(f"Protocol reader closed before all data was consumed. The iterable returned by '{previous_method}' was not fully consumed.") @@ -6327,6 +6339,16 @@ def read_stream_of_aliased_generic_union_2(self) -> collections.abc.Iterable[Ali self._state = 19 return self._wrap_iterable(value, 20) + def read_vectors(self) -> list[RecordContainingVectorsOfAliases]: + """Ordinal 10""" + + if self._state != 20: + self._raise_unexpected_state(20) + + value = self._read_vectors() + self._state = 22 + return value + def copy_to(self, writer: AliasesWriterBase) -> None: writer.write_aliased_string(self.read_aliased_string()) writer.write_aliased_enum(self.read_aliased_enum()) @@ -6338,6 +6360,7 @@ def copy_to(self, writer: AliasesWriterBase) -> None: writer.write_aliased_generic_vector(self.read_aliased_generic_vector()) writer.write_aliased_generic_fixed_vector(self.read_aliased_generic_fixed_vector()) writer.write_stream_of_aliased_generic_union_2(self.read_stream_of_aliased_generic_union_2()) + writer.write_vectors(self.read_vectors()) @abc.abstractmethod def _read_aliased_string(self) -> AliasedString: @@ -6379,6 +6402,10 @@ def _read_aliased_generic_fixed_vector(self) -> AliasedGenericFixedVector[yardl. def _read_stream_of_aliased_generic_union_2(self) -> collections.abc.Iterable[AliasedGenericUnion2[AliasedString, AliasedEnum]]: raise NotImplementedError() + @abc.abstractmethod + def _read_vectors(self) -> list[RecordContainingVectorsOfAliases]: + raise NotImplementedError() + T = typing.TypeVar('T') def _wrap_iterable(self, iterable: collections.abc.Iterable[T], final_state: int) -> collections.abc.Iterable[T]: yield from iterable @@ -6414,6 +6441,8 @@ def _state_to_method_name(self, state: int) -> str: return 'read_aliased_generic_fixed_vector' if state == 18: return 'read_stream_of_aliased_generic_union_2' + if state == 20: + return 'read_vectors' return "" class StreamsOfAliasedUnionsWriterBase(abc.ABC): diff --git a/python/test_model/types.py b/python/test_model/types.py index 3439b641..8eb26b02 100644 --- a/python/test_model/types.py +++ b/python/test_model/types.py @@ -1418,6 +1418,39 @@ def __repr__(self) -> str: return f"RecordContainingNestedGenericRecords(f1={repr(self.f1)}, f1a={repr(self.f1a)}, f2={repr(self.f2)}, f2a={repr(self.f2a)}, nested={repr(self.nested)})" +class RecordContainingVectorsOfAliases: + strings: list[AliasedString] + maps: list[AliasedMap[str, yardl.Int32]] + arrays: list[Image[np.float32]] + tuples: list[MyTuple[yardl.Int32, SimpleRecord]] + + def __init__(self, *, + strings: typing.Optional[list[AliasedString]] = None, + maps: typing.Optional[list[AliasedMap[str, yardl.Int32]]] = None, + arrays: typing.Optional[list[Image[np.float32]]] = None, + tuples: typing.Optional[list[MyTuple[yardl.Int32, SimpleRecord]]] = None, + ): + self.strings = strings if strings is not None else [] + self.maps = maps if maps is not None else [] + self.arrays = arrays if arrays is not None else [] + self.tuples = tuples if tuples is not None else [] + + def __eq__(self, other: object) -> bool: + return ( + isinstance(other, RecordContainingVectorsOfAliases) + and self.strings == other.strings + and len(self.maps) == len(other.maps) and all(a == b for a, b in zip(self.maps, other.maps)) + and len(self.arrays) == len(other.arrays) and all(yardl.structural_equal(a, b) for a, b in zip(self.arrays, other.arrays)) + and len(self.tuples) == len(other.tuples) and all(a == b for a, b in zip(self.tuples, other.tuples)) + ) + + def __str__(self) -> str: + return f"RecordContainingVectorsOfAliases(strings={self.strings}, maps={self.maps}, arrays={self.arrays}, tuples={self.tuples})" + + def __repr__(self) -> str: + return f"RecordContainingVectorsOfAliases(strings={repr(self.strings)}, maps={repr(self.maps)}, arrays={repr(self.arrays)}, tuples={repr(self.tuples)})" + + class AliasedIntOrSimpleRecord: Int32: typing.ClassVar[type["AliasedIntOrSimpleRecordUnionCase[yardl.Int32]"]] SimpleRecord: typing.ClassVar[type["AliasedIntOrSimpleRecordUnionCase[SimpleRecord]"]] @@ -2175,6 +2208,7 @@ def _mk_get_dtype(): dtype_map.setdefault(RecordWithGenericMaps, lambda type_args: np.dtype([('m', np.dtype(np.object_)), ('am', np.dtype(np.object_))], align=True)) dtype_map.setdefault(RecordContainingGenericRecords, lambda type_args: np.dtype([('g1', get_dtype(types.GenericAlias(RecordWithOptionalGenericField, (type_args[0],)))), ('g1a', get_dtype(types.GenericAlias(RecordWithAliasedOptionalGenericField, (type_args[0],)))), ('g2', get_dtype(types.GenericAlias(RecordWithOptionalGenericUnionField, (type_args[0], type_args[1],)))), ('g2a', get_dtype(types.GenericAlias(RecordWithAliasedOptionalGenericUnionField, (type_args[0], type_args[1],)))), ('g3', get_dtype(types.GenericAlias(tuples.Tuple, (type_args[0], type_args[1],)))), ('g3a', get_dtype(types.GenericAlias(tuples.Tuple, (type_args[0], type_args[1],)))), ('g4', get_dtype(types.GenericAlias(RecordWithGenericVectors, (type_args[1],)))), ('g5', get_dtype(types.GenericAlias(RecordWithGenericFixedVectors, (type_args[1],)))), ('g6', get_dtype(types.GenericAlias(RecordWithGenericArrays, (type_args[1],)))), ('g7', get_dtype(types.GenericAlias(RecordWithGenericMaps, (type_args[0], type_args[1],))))], align=True)) dtype_map.setdefault(RecordContainingNestedGenericRecords, np.dtype([('f1', get_dtype(types.GenericAlias(RecordWithOptionalGenericField, (str,)))), ('f1a', get_dtype(types.GenericAlias(RecordWithAliasedOptionalGenericField, (str,)))), ('f2', get_dtype(types.GenericAlias(RecordWithOptionalGenericUnionField, (str, yardl.Int32,)))), ('f2a', get_dtype(types.GenericAlias(RecordWithAliasedOptionalGenericUnionField, (str, yardl.Int32,)))), ('nested', get_dtype(types.GenericAlias(RecordContainingGenericRecords, (str, yardl.Int32,))))], align=True)) + dtype_map.setdefault(RecordContainingVectorsOfAliases, np.dtype([('strings', np.dtype(np.object_)), ('maps', np.dtype(np.object_)), ('arrays', np.dtype(np.object_)), ('tuples', np.dtype(np.object_))], align=True)) dtype_map.setdefault(AliasedIntOrSimpleRecord, np.dtype(np.object_)) dtype_map.setdefault(AliasedIntOrAliasedSimpleRecord, np.dtype(np.object_)) dtype_map.setdefault(typing.Optional[AliasedNullableIntSimpleRecord], np.dtype(np.object_)) diff --git a/python/tests/test_protocol_roundtrip.py b/python/tests/test_protocol_roundtrip.py index 68ff8de3..44d5d152 100644 --- a/python/tests/test_protocol_roundtrip.py +++ b/python/tests/test_protocol_roundtrip.py @@ -794,6 +794,19 @@ def test_aliases(format: Format): ] ) + strings = ["hello", "world"] + maps = [{"a": 1, "b": 2}, {"c": 3, "d": 4}] + my_tuple = tm.MyTuple(v1=42, v2=tm.SimpleRecord(x=1, y=2, z=3)) + image = np.array([[1, 2], [3, 4]], dtype=np.float32) + + vectors_record = tm.RecordContainingVectorsOfAliases( + strings=strings, + maps=maps, + arrays=[image, image], + tuples=[my_tuple, my_tuple], + ) + w.write_vectors([vectors_record, vectors_record]) + def test_streams_of_unions_manual_close(format: Format): w = create_validating_writer_class(format, tm.StreamsOfUnionsWriterBase)() diff --git a/tooling/internal/matlab/common/common.go b/tooling/internal/matlab/common/common.go index e94a514c..c24bde0b 100644 --- a/tooling/internal/matlab/common/common.go +++ b/tooling/internal/matlab/common/common.go @@ -102,7 +102,7 @@ var TypeSyntaxWriter dsl.TypeSyntaxWriter[string] = func(self dsl.TypeSyntaxWrit case nil, *dsl.Stream, *dsl.Vector, *dsl.Array: return scalarString case *dsl.Map: - return "dictionary" + return "yardl.Map" default: panic(fmt.Sprintf("unexpected type %T", d)) } diff --git a/tooling/internal/matlab/static_files/+binary/MapSerializer.m b/tooling/internal/matlab/static_files/+binary/MapSerializer.m index 73ad04d4..e8dfcec6 100644 --- a/tooling/internal/matlab/static_files/+binary/MapSerializer.m +++ b/tooling/internal/matlab/static_files/+binary/MapSerializer.m @@ -17,7 +17,7 @@ function write(self, outstream, value) arguments self (1,1) outstream (1,1) yardl.binary.CodedOutputStream - value (1,1) dictionary + value (1,1) yardl.Map end count = numEntries(value); @@ -36,16 +36,16 @@ function write(self, outstream, value) function res = read(self, instream) count = instream.read_unsigned_varint(); - res = dictionary(); + res = yardl.Map(); for i = 1:count k = self.key_serializer_.read(instream); v = self.value_serializer_.read(instream); - res(k) = v; + insert(res, k, v); end end function c = get_class(~) - c = "dictionary"; + c = "yardl.Map"; end end end diff --git a/tooling/internal/matlab/static_files/Date.m b/tooling/internal/matlab/static_files/Date.m index ed28ebd9..cbae0f57 100644 --- a/tooling/internal/matlab/static_files/Date.m +++ b/tooling/internal/matlab/static_files/Date.m @@ -30,12 +30,16 @@ end eq = isa(other, 'yardl.Date') && ... - all([self.value] == [other.value]); + all([self.days_since_epoch] == [other.days_since_epoch]); end - function ne = new(self, other) + function ne = ne(self, other) ne = ~self.eq(other); end + + function isequal = isequal(self, other) + isequal = all(eq(self, other)); + end end methods (Static) diff --git a/tooling/internal/matlab/static_files/DateTime.m b/tooling/internal/matlab/static_files/DateTime.m index 5a5ba903..af710ec0 100644 --- a/tooling/internal/matlab/static_files/DateTime.m +++ b/tooling/internal/matlab/static_files/DateTime.m @@ -31,12 +31,16 @@ end eq = isa(other, 'yardl.DateTime') && ... - all([self.value] == [other.value]); + all([self.nanoseconds_since_epoch] == [other.nanoseconds_since_epoch]); end - function ne = new(self, other) + function ne = ne(self, other) ne = ~self.eq(other); end + + function isequal = isequal(self, other) + isequal = all(eq(self, other)); + end end methods (Static) diff --git a/tooling/internal/matlab/static_files/Map.m b/tooling/internal/matlab/static_files/Map.m new file mode 100644 index 00000000..0095046d --- /dev/null +++ b/tooling/internal/matlab/static_files/Map.m @@ -0,0 +1,73 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Map < handle + properties (SetAccess=protected) + dict + end + + methods + + function self = Map(varargin) + self.dict = dictionary(varargin{:}); + end + + function k = keys(self) + k = keys(self.dict); + end + + function v = values(self) + v = values(self.dict); + end + + function v = lookup(self, key) + v = self.dict(key); + end + + function insert(self, key, value) + self.dict(key) = value; + end + + function remove(self, key) + self.dict(key) = []; + end + + function n = numEntries(self) + n = numEntries(self.dict); + end + + function res = eq(a, b) + if isa(b, 'yardl.Map') + res = isequal({a.dict}, {b.dict}); + elseif isa(b, 'dictionary') + res = isequal({a.dict}, {b}); + else + res = false; + end + end + + function ne = ne(a, b) + ne = ~eq(a, b); + end + + function isequal = isequal(self, other) + isequal = all(eq(self, other)); + end + end + + methods (Static) + function z = zeros(varargin) + elem = yardl.Map(); + if nargin == 0 + z = elem; + return + end + + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/tooling/internal/matlab/static_files/Time.m b/tooling/internal/matlab/static_files/Time.m index e00dea4d..533d5de1 100644 --- a/tooling/internal/matlab/static_files/Time.m +++ b/tooling/internal/matlab/static_files/Time.m @@ -35,12 +35,16 @@ end eq = isa(other, 'yardl.Time') && ... - all([self.value] == [other.value]); + all([self.nanoseconds_since_midnight] == [other.nanoseconds_since_midnight]); end - function ne = new(self, other) + function ne = ne(self, other) ne = ~self.eq(other); end + + function isequal = isequal(self, other) + isequal = all(eq(self, other)); + end end methods (Static) diff --git a/tooling/internal/matlab/static_files/Union.m b/tooling/internal/matlab/static_files/Union.m index 60b2750a..7079c97b 100644 --- a/tooling/internal/matlab/static_files/Union.m +++ b/tooling/internal/matlab/static_files/Union.m @@ -19,6 +19,10 @@ function i = index(self) i = self.index_; end + + function isequal = isequal(self, other) + isequal = all(eq(self, other)); + end end methods (Abstract) diff --git a/tooling/internal/matlab/types/types.go b/tooling/internal/matlab/types/types.go index 182105c9..7a647084 100644 --- a/tooling/internal/matlab/types/types.go +++ b/tooling/internal/matlab/types/types.go @@ -123,7 +123,7 @@ func writeUnionClass(w *formatting.IndentedWriter, className string, generalized w.WriteStringln("function eq = eq(self, other)") common.WriteBlockBody(w, func() { - fmt.Fprintf(w, "eq = isa(other, \"%s\") && isequal(self.index, other.index) && isequal(self.value, other.value);\n", qualifiedClassName) + fmt.Fprintf(w, "eq = isa(other, \"%s\") && all([self.index_] == [other.index_], 'all') && all([self.value] == [other.value], 'all');\n", qualifiedClassName) }) w.WriteStringln("") w.WriteStringln("function ne = ne(self, other)") @@ -143,72 +143,33 @@ func writeUnionClass(w *formatting.IndentedWriter, className string, generalized return nil } -func writeNamedType(fw *common.MatlabFileWriter, td *dsl.NamedType) error { - return fw.WriteFile(common.TypeIdentifierName(td.Name), func(w *formatting.IndentedWriter) { - ut := dsl.GetUnderlyingType(td.Type) - // If the underlying type is a RecordDefinition, PrimitiveString, Optional, - // Vector, Array, or Map - we will generate a "function" alias - if st, ok := ut.(*dsl.SimpleType); ok { - if _, ok := st.ResolvedDefinition.(*dsl.RecordDefinition); ok { - fmt.Fprintf(w, "function c = %s(varargin)\n", common.TypeIdentifierName(td.Name)) - common.WriteBlockBody(w, func() { - common.WriteComment(w, td.Comment) - fmt.Fprintf(w, "c = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) - }) - return - } else if pd, ok := st.ResolvedDefinition.(dsl.PrimitiveDefinition); ok { - if pd == dsl.PrimitiveString { - fmt.Fprintf(w, "function s = %s(varargin)\n", common.TypeIdentifierName(td.Name)) - common.WriteBlockBody(w, func() { - common.WriteComment(w, td.Comment) - fmt.Fprintf(w, "s = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) - }) - return - } - } - } else if gt, ok := ut.(*dsl.GeneralizedType); ok { - if gt.Cases.IsOptional() { - innerType := gt.Cases[1].Type - fmt.Fprintf(w, "function o = %s(value)\n", common.TypeIdentifierName(td.Name)) - common.WriteBlockBody(w, func() { - common.WriteComment(w, td.Comment) - if !dsl.TypeContainsGenericTypeParameter(innerType) { - w.WriteStringln("arguments") - common.WriteBlockBody(w, func() { - fmt.Fprintf(w, "value %s\n", common.TypeSyntax(innerType, td.Namespace)) - }) - } - fmt.Fprintf(w, "o = %s(value);\n", common.TypeSyntax(td.Type, td.Namespace)) - }) - return - } - - switch gt.Dimensionality.(type) { - case *dsl.Vector, *dsl.Array: - scalar := gt.ToScalar() - fmt.Fprintf(w, "function a = %s(array)\n", common.TypeIdentifierName(td.Name)) - common.WriteBlockBody(w, func() { - common.WriteComment(w, td.Comment) - if !dsl.TypeContainsGenericTypeParameter(scalar) { - w.WriteStringln("arguments") - common.WriteBlockBody(w, func() { - fmt.Fprintf(w, "array %s\n", common.TypeSyntax(scalar, td.Namespace)) - }) - } - w.WriteStringln("a = array;") - }) - return - case *dsl.Map: - fmt.Fprintf(w, "function m = %s(varargin)\n", common.TypeIdentifierName(td.Name)) - common.WriteBlockBody(w, func() { - common.WriteComment(w, td.Comment) - fmt.Fprintf(w, "m = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) - }) - return +func typeCanBeAliased(t dsl.Type) bool { + if st, ok := t.(*dsl.SimpleType); ok { + if pd, ok := st.ResolvedDefinition.(dsl.PrimitiveDefinition); ok { + switch pd { + case dsl.PrimitiveString: + return false } } + } else if gt, ok := t.(*dsl.GeneralizedType); ok { + switch gt.Dimensionality.(type) { + case *dsl.Vector, *dsl.Array: + return false + } + } + return true +} - // Otherwise, it's a subclass of the underlying type +func writeNamedType(fw *common.MatlabFileWriter, td *dsl.NamedType) error { + // If the underlying type is a PrimitiveString, Vector, Array, or Map... + // it is not possible to generate an alias type definition in MATLAB. + ut := dsl.GetUnderlyingType(td.Type) + if !typeCanBeAliased(ut) { + return nil + } + + // Otherwise, generate a subclass of the underlying type + return fw.WriteFile(common.TypeIdentifierName(td.Name), func(w *formatting.IndentedWriter) { fmt.Fprintf(w, "classdef %s < %s\n", common.TypeIdentifierName(td.Name), common.TypeSyntax(td.Type, td.Namespace)) common.WriteBlockBody(w, func() { common.WriteComment(w, td.Comment) @@ -300,7 +261,7 @@ func writeRecord(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, st dsl. w.WriteStringln("properties") var fieldNames []string - requiresArgsToConstruct := false + var zerosMethodArgs []string common.WriteBlockBody(w, func() { for _, field := range rec.Fields { common.WriteComment(w, field.Comment) @@ -310,7 +271,7 @@ func writeRecord(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, st dsl. _, defaultExpressionKind := typeDefault(field.Type, rec.Namespace, "", st) switch defaultExpressionKind { case defaultValueKindNone: - requiresArgsToConstruct = true + zerosMethodArgs = append(zerosMethodArgs, fmt.Sprintf("%s=yardl.None", fieldName)) } } }) @@ -373,7 +334,9 @@ func writeRecord(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, st dsl. for _, field := range rec.Fields { w.WriteStringln(" && ...") fieldIdentifier := common.FieldIdentifierName(field.Name) - fmt.Fprintf(w, "isequal(%s, %s)", "self."+fieldIdentifier, "other."+fieldIdentifier) + // Instead of `isequal`, we could use `all([self.field] == [other.field], 'all')`, + // except it won't work for fields stored as cell arrays (e.g. a vector of NDArrays) + fmt.Fprintf(w, "isequal({%s}, {%s})", "self."+fieldIdentifier, "other."+fieldIdentifier) } w.WriteStringln(";") }) @@ -385,15 +348,20 @@ func writeRecord(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, st dsl. common.WriteBlockBody(w, func() { w.WriteStringln("res = ~self.eq(other);") }) - }) - w.WriteStringln("") + w.WriteStringln("") - if !requiresArgsToConstruct { - w.WriteStringln("methods (Static)") + // isequal method + w.WriteStringln("function res = isequal(self, other)") common.WriteBlockBody(w, func() { - writeZerosStaticMethod(w, common.TypeSyntax(rec, rec.Namespace), []string{}) + w.WriteStringln("res = all(eq(self, other));") }) - } + }) + w.WriteStringln("") + + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + writeZerosStaticMethod(w, common.TypeSyntax(rec, rec.Namespace), zerosMethodArgs) + }) }) }) } @@ -610,7 +578,13 @@ func writeComputedFieldExpression(w *formatting.IndentedWriter, expression dsl.E startSubscript = "(1+" delimeter = ", 1+" return + case *dsl.Map: + startSubscript = ".lookup(" + delimeter = "," + return } + case *dsl.SimpleType: + self.Visit(t.ResolvedDefinition) } self.VisitChildren(node) }) @@ -897,6 +871,19 @@ const ( ) func typeDefault(t dsl.Type, contextNamespace string, namedType string, st dsl.SymbolTable) (string, defaultValueKind) { + + getScalarDtype := func(scalar dsl.Type) string { + // Some types CANNOT be aliased in MATLAB, so we need to extract their underlying type + // in order to generate specific syntax, such as the `.empty()` constructor for vectors/arrays + dtype := common.TypeSyntax(scalar, contextNamespace) + if ut := dsl.GetUnderlyingType(scalar); ut != scalar { + if !typeCanBeAliased(ut) { + dtype = common.TypeSyntax(ut, contextNamespace) + } + } + return dtype + } + switch t := t.(type) { case nil: return "yardl.None", defaultValueKindImmutable @@ -932,7 +919,7 @@ func typeDefault(t dsl.Type, contextNamespace string, namedType string, st dsl.S return "", defaultValueKindNone } - dtype := common.TypeSyntax(scalar, contextNamespace) + dtype := getScalarDtype(scalar) if td.Length == nil { return fmt.Sprintf("%s.empty()", dtype), defaultValueKindMutable } @@ -971,15 +958,11 @@ func typeDefault(t dsl.Type, contextNamespace string, namedType string, st dsl.S return fmt.Sprintf("repelem(%s, %s)", scalarDefault, strings.Join(dims, ", ")), defaultValueKindMutable } - dtype := common.TypeSyntax(scalar, contextNamespace) - if td.HasKnownNumberOfDimensions() { - shape := strings.Repeat("0, ", len(*td.Dimensions))[0 : len(*td.Dimensions)*3-2] - return fmt.Sprintf("%s.empty(%s)", dtype, shape), defaultValueKindMutable - } + dtype := getScalarDtype(scalar) return fmt.Sprintf("%s.empty()", dtype), defaultValueKindMutable case *dsl.Map: - return "dictionary", defaultValueKindMutable + return "yardl.Map", defaultValueKindMutable } }