Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter/buffer type introspection #172

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/neml2/tensors/TensorValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// THE SOFTWARE.
#pragma once

#include "neml2/tensors/Tensor.h"
#include "neml2/tensors/tensors.h"

namespace neml2
{
Expand All @@ -48,6 +48,9 @@ class TensorValueBase

/// assignment operator
virtual void operator=(const Tensor & val) = 0;

/// Tensor type
virtual TensorType type() const = 0;
};

/// Concrete definition of tensor value
Expand All @@ -70,6 +73,8 @@ class TensorValue : public TensorValueBase

virtual void operator=(const Tensor & val) override { _value = T(val); }

virtual TensorType type() const override { return TensorTypeEnum<T>::value; }

T & value() { return _value; }

private:
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/models/test_ParameterStore.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ TEST_CASE("ParameterStore", "[models]")
REQUIRE(Tensor(E).batch_sizes() == TensorShape());
REQUIRE(Tensor(nu).batch_sizes() == TensorShape());

REQUIRE(E.type() == TensorType::kScalar);
REQUIRE(nu.type() == TensorType::kScalar);

// Modifying the individual parameter references should affect values stored in the parameter
// dictionary.
E = Scalar::full({1, 2}, 1.0);
Expand Down
Loading