12#ifndef OAKFIELD_FIELD_H
13#define OAKFIELD_FIELD_H
24#ifndef OAKFIELD_SIM_RESULT_DEFINED
25#define OAKFIELD_SIM_RESULT_DEFINED
128typedef void *(*SimFieldAllocFn)(
void *userdata,
size_t size);
180#ifndef SIM_HAVE_SIMCOMPLEXDOUBLE
181#define SIM_HAVE_SIMCOMPLEXDOUBLE 1
409const double *sim_field_real_data_const(
const SimField *field);
410int8_t *sim_field_i8_data(
SimField *field);
411const int8_t *sim_field_i8_data_const(
const SimField *field);
412int32_t *sim_field_i32_data(
SimField *field);
413const int32_t *sim_field_i32_data_const(
const SimField *field);
414int64_t *sim_field_i64_data(
SimField *field);
415const int64_t *sim_field_i64_data_const(
const SimField *field);
416uint8_t *sim_field_u8_data(
SimField *field);
417const uint8_t *sim_field_u8_data_const(
const SimField *field);
418uint32_t *sim_field_u32_data(
SimField *field);
419const uint32_t *sim_field_u32_data_const(
const SimField *field);
420uint64_t *sim_field_u64_data(
SimField *field);
421const uint64_t *sim_field_u64_data_const(
const SimField *field);
443bool sim_field_storage_matches_scalar_domain(
size_t element_size,
SimScalarDomain domain);
453SimScalarDomain sim_scalar_domain_from_legacy_complex_flag(
bool is_complex);
459bool sim_scalar_domain_from_name(
const char *text,
SimScalarDomain *out_domain);
465bool sim_scalar_domain_supports(
SimScalarDomain domain, uint32_t capability_mask);
468bool sim_field_domain_from_name(
const char *text,
SimFieldDomain *out_domain);
469bool sim_field_value_kind_from_name(
const char *text,
SimFieldValueKind *out_kind);
size_t sim_field_bytes(const SimField *field)
Compute the total number of bytes occupied by the field.
SimResult sim_field_xy_to_index(const SimField *field, size_t x, size_t y, size_t *out_index)
Convert 2D coordinates into a linear element index.
bool sim_field_is_complex(const SimField *field)
Legacy compatibility alias for complex-storage checks.
SimScalarCapability
Bitmask describing operations supported by a scalar domain.
Definition field.h:96
@ SIM_SCALAR_CAP_NONE
Definition field.h:97
@ SIM_SCALAR_CAP_MODULO
Definition field.h:103
@ SIM_SCALAR_CAP_MULTIPLICATIVE_ARITHMETIC
Definition field.h:99
@ SIM_SCALAR_CAP_FLOOR
Definition field.h:102
@ SIM_SCALAR_CAP_CONJUGATION
Definition field.h:105
@ SIM_SCALAR_CAP_ANALYTIC_CALL
Definition field.h:104
@ SIM_SCALAR_CAP_COMPLEX_ROTATION
Definition field.h:106
@ SIM_SCALAR_CAP_ADDITIVE_ARITHMETIC
Definition field.h:98
@ SIM_SCALAR_CAP_ORDERING
Definition field.h:101
@ SIM_SCALAR_CAP_DIVISION
Definition field.h:100
@ SIM_SCALAR_CAP_POWER
Definition field.h:107
bool sim_field_storage_is_complex(const SimField *field)
Returns whether the field storage is complex (SimComplexDouble).
SimComplexDouble * sim_field_complex_data(SimField *field)
Convenience accessor for fields with complex double elements.
size_t sim_field_rank(const SimField *field)
Access the field rank.
SimResult sim_field_index_offset(const SimField *field, const size_t *indices, size_t *out_offset)
Compute the linear offset for provided indices.
const size_t * sim_field_shape(const SimField *field)
Access the shape array.
const void * sim_field_data_const(const SimField *field)
Obtain the raw data pointer (const-qualified).
double * sim_field_real_data(SimField *field)
Convenience accessor for fields with scalar double elements.
SimResult sim_field_element_index(const SimField *field, const size_t *indices, size_t rank, size_t *out_index)
Compute the linear element index for the provided indices.
void * sim_field_data(SimField *field)
Obtain the raw data pointer.
SimResult sim_field_require_complex(SimField *field)
Force a field into complex storage if it is not already using it.
size_t sim_field_components(const SimField *field)
Returns the number of scalar components per logical element.
SimScalarDomainKind
Scalar algebra domain used by IR typing and legality rules.
Definition field.h:85
@ SIM_SCALAR_DOMAIN_COMPLEX
Definition field.h:88
@ SIM_SCALAR_DOMAIN_MODULAR
Definition field.h:90
@ SIM_SCALAR_DOMAIN_UNKNOWN
Definition field.h:86
@ SIM_SCALAR_DOMAIN_INTEGER
Definition field.h:89
@ SIM_SCALAR_DOMAIN_REAL
Definition field.h:87
size_t sim_field_width(const SimField *field)
Convenience width accessor for the fastest-varying axis.
SimResult sim_field_index_to_xy(const SimField *field, size_t index, size_t *out_x, size_t *out_y)
Convert a linear element index into 2D coordinates.
void(* SimFieldFreeFn)(void *userdata, void *ptr)
Deallocation callback used by fields.
Definition field.h:133
struct SimComplexDouble SimComplexDouble
Explicit in-memory representation for a complex double scalar (re, im)
SimResult sim_field_init(SimField *field, size_t rank, const size_t *shape, size_t element_size, SimFieldStorage storage, const SimFieldAllocator *allocator)
Initialize an owning field and allocate storage.
SimFieldDomain
Domain for field representation (physical vs spectral).
Definition field.h:51
@ SIM_FIELD_DOMAIN_PHYSICAL
Definition field.h:53
@ SIM_FIELD_DOMAIN_SPECTRAL
Definition field.h:54
@ SIM_FIELD_DOMAIN_HYBRID
Definition field.h:55
@ SIM_FIELD_DOMAIN_UNKNOWN
Definition field.h:52
const size_t * sim_field_strides(const SimField *field)
Access the stride array.
size_t sim_field_height(const SimField *field)
Convenience height accessor for the next-to-fastest axis.
bool sim_field_complex_mode(const SimField *field)
Returns true if the field must behave as complex.
SimFieldStorage
Supported field storage ordering schemes.
Definition field.h:44
@ SIM_FIELD_STORAGE_ROW_MAJOR
Definition field.h:45
size_t sim_field_element_count(const SimFieldLayout *layout)
Returns the total number of scalar elements in the field layout.
SimFieldValueKind
Value kind for field scalars.
Definition field.h:61
@ SIM_FIELD_VALUE_REAL_SCALAR
Definition field.h:62
@ SIM_FIELD_VALUE_COMPLEX_SCALAR
Definition field.h:63
@ SIM_FIELD_VALUE_COMPLEX_IMAG_ZERO_CONSTRAINT
Definition field.h:66
@ SIM_FIELD_VALUE_UNKNOWN
Definition field.h:68
@ SIM_FIELD_VALUE_COMPLEX_REAL_CONSTRAINT
Definition field.h:64
SimResult sim_field_wrap(SimField *field, const SimFieldLayout *layout, size_t element_size, SimFieldStorage storage, void *data)
Initialize a non-owning view over existing data.
SimResult sim_field_allocator_default(SimFieldAllocator *allocator)
Populate allocator with libc malloc/free.
void sim_field_destroy(SimField *field)
Release all resources held by a field.
SimResult sim_field_init_typed(SimField *field, size_t rank, const size_t *shape, SimScalarDomain scalar_domain, SimFieldStorage storage, const SimFieldAllocator *allocator)
Initialize an owning field with an explicit scalar domain.
SimResult
Return codes shared by libsimcore modules.
Definition field.h:29
@ SIM_RESULT_OK
Definition field.h:30
@ SIM_RESULT_NOT_SUPPORTED
Definition field.h:35
@ SIM_RESULT_DEPENDENCY_ERROR
Definition field.h:36
@ SIM_RESULT_INVALID_STATE
Definition field.h:32
@ SIM_RESULT_TYPE_MISMATCH
Definition field.h:37
@ SIM_RESULT_NOT_FOUND
Definition field.h:34
@ SIM_RESULT_INVALID_ARGUMENT
Definition field.h:31
@ SIM_RESULT_OUT_OF_MEMORY
Definition field.h:33
void *(* SimFieldAllocFn)(void *userdata, size_t size)
Allocation callbacks used by fields.
Definition field.h:128
bool sim_field_domain_is_complex(const SimField *field)
Returns whether the field scalar-domain semantics are complex.
SimResult sim_field_wrap_typed(SimField *field, const SimFieldLayout *layout, SimScalarDomain scalar_domain, SimFieldStorage storage, void *data)
Initialize a non-owning view with an explicit scalar domain.
Explicit in-memory representation for a complex double scalar (re, im)
Definition field.h:175
double im
Definition field.h:177
double re
Definition field.h:176
Custom allocator description for field memory.
Definition field.h:138
SimFieldFreeFn release
Definition field.h:140
void * userdata
Definition field.h:141
SimFieldAllocFn allocate
Definition field.h:139
Layout description for a field.
Definition field.h:147
size_t * strides
Definition field.h:150
bool contiguous
Definition field.h:151
size_t * shape
Definition field.h:149
size_t rank
Definition field.h:148
Authoritative representation description for a field.
Definition field.h:74
SimFieldDomain domain
Definition field.h:75
SimFieldValueKind value_kind
Definition field.h:76
Owning multidimensional field.
Definition field.h:157
uint64_t magic
Definition field.h:167
SimFieldRepresentation repr
Definition field.h:165
bool owns_data
Definition field.h:163
size_t element_size
Definition field.h:159
SimFieldLayout layout
Definition field.h:158
SimFieldAllocator allocator
Definition field.h:162
SimFieldStorage storage
Definition field.h:161
void * data
Definition field.h:160
SimScalarDomain scalar_domain
Definition field.h:166
bool complex_mode
Definition field.h:164
Unified scalar-domain descriptor.
Definition field.h:116
uint64_t modulus
Definition field.h:120
bool is_signed
Definition field.h:119
uint16_t bit_width
Definition field.h:118
SimScalarDomainKind kind
Definition field.h:117