From 70c22b460e028a96c9a5c600fc70216670a0542b Mon Sep 17 00:00:00 2001 From: Alfredo Sanchez Garcia Date: Wed, 14 Feb 2024 09:31:22 +0100 Subject: [PATCH] Rename dims to shape throughout dlite (#774) Rename dims to shape throughout dlite --- bindings/fortran/dlite.f90 | 28 ++-- bindings/fortran/tests/Person.json | 4 +- bindings/fortran/tests/Scan3D.json | 2 +- bindings/python/datamodel.py | 18 +-- bindings/python/dlite-entity-python.i | 22 +-- bindings/python/dlite-entity.i | 33 ++-- bindings/python/dlite-python.i | 92 +++++------ bindings/python/factory.py | 2 +- bindings/python/mappings.py | 4 +- bindings/python/numpy.i | 68 ++++----- bindings/python/rdf.py | 4 +- bindings/python/tests/entities/MyEntity.json | 14 +- bindings/python/tests/entities/PersonOld.json | 2 +- bindings/python/tests/test_collection.py | 0 bindings/python/tests/test_datamodel.py | 4 +- bindings/python/tests/test_entity.py | 4 +- bindings/python/tests/test_factory.py | 0 bindings/python/tests/test_pydantic.py | 7 +- bindings/python/tests/test_python_storage.py | 2 +- bindings/python/tests/test_utils.py | 16 +- bindings/python/utils.py | 16 +- .../1-simple-workflow/calculate_reaction.py | 2 +- .../1-simple-workflow/molecular_energies.py | 2 +- .../2-instance-mappings/reaction_energy.py | 2 +- .../dehydrogenation/entities/Molecule.json | 6 +- .../dehydrogenation/entities/Reaction.json | 8 +- examples/entities/Chemistry-0.1.json | 14 +- examples/ex1/Chemistry-0.1.json | 14 +- examples/ex2/Chemistry-0.1.json | 14 +- examples/ex3/PhilibTable.json | 22 +-- examples/ex4/Chemistry-0.1.json | 14 +- examples/storages/Chemistry-0.1.json | 14 +- examples/storages/Person.json | 2 +- src/dlite-arrays.c | 70 ++++----- src/dlite-arrays.h | 18 +-- src/dlite-bson.c | 22 +-- src/dlite-codegen.c | 4 +- src/dlite-collection.c | 4 +- src/dlite-datamodel.c | 24 +-- src/dlite-datamodel.h | 12 +- src/dlite-entity.c | 144 +++++++++--------- src/dlite-entity.h | 40 ++--- src/dlite-json.c | 8 +- src/dlite-schemas.c | 28 ++-- src/dlite-storage-plugins.h | 8 +- src/dlite-type.c | 29 ++-- src/dlite-type.h | 2 +- src/tests/test-entity.json | 2 +- src/tests/test-read-data.json | 2 +- src/tests/test_arrays.c | 40 ++--- src/tests/test_datamodel.c | 46 +++--- src/tests/test_entity.c | 14 +- src/tests/test_json.c | 9 +- src/tests/test_property.c | 28 ++-- src/tests/test_type.c | 16 +- src/utils/tests/test_jsmnx.c | 4 +- storages/hdf5/dh5lite.c | 48 +++--- storages/json/dlite-json-storage.c | 2 +- .../python/python-storage-plugins/blob.py | 2 +- storages/python/python-storage-plugins/csv.py | 2 +- storages/python/tests-c/Person.json | 2 +- .../python/tests-python/input/test_meta.json | 2 +- storages/python/tests-python/test_http.py | 8 +- .../test_postgresql_storage_python.py | 8 +- storages/rdf/dlite-rdf.c | 14 +- tools/templates/c-header.txt | 5 +- tools/templates/c-meta-header.txt | 4 +- tools/templates/c-source.txt | 6 +- tools/templates/fortran-module.txt | 24 +-- tools/tests/Chemistry-0.1.json | 14 +- 70 files changed, 596 insertions(+), 575 deletions(-) mode change 100755 => 100644 bindings/python/tests/test_collection.py mode change 100755 => 100644 bindings/python/tests/test_entity.py mode change 100755 => 100644 bindings/python/tests/test_factory.py mode change 100755 => 100644 bindings/python/tests/test_python_storage.py mode change 100755 => 100644 examples/dehydrogenation/1-simple-workflow/calculate_reaction.py mode change 100755 => 100644 examples/dehydrogenation/1-simple-workflow/molecular_energies.py diff --git a/bindings/fortran/dlite.f90 b/bindings/fortran/dlite.f90 index 22796b188..8bb00f3b5 100644 --- a/bindings/fortran/dlite.f90 +++ b/bindings/fortran/dlite.f90 @@ -405,7 +405,7 @@ function dlite_instance_create_from_id(metaid, ndim, dims, id) result(instance) ! copy metaid in a C string call f_c_string(metaid, metaid_c) - ! copy dims in a C pointer (size_t*) + ! copy shape in a C pointer (size_t*) allocate(dims1(ndim)) do i=1, ndim dims1(i) = dims(i) @@ -530,7 +530,7 @@ function dlite_instance_get_property_by_index(instance, i) result(ptr) ptr = dlite_instance_get_property_by_index_c(instance%cinst, i_c) end function dlite_instance_get_property_by_index - subroutine dlite_instance_get_property_dims_by_index(instance, i, dims, reverse) + subroutine dlite_instance_get_property_dims_by_index(instance, i, shape, reverse) class(DLiteInstance), intent(in) :: instance integer, intent(in) :: i integer(kind=c_size_t) :: i_c @@ -538,24 +538,24 @@ subroutine dlite_instance_get_property_dims_by_index(instance, i, dims, reverse) integer(c_size_t), pointer :: dims_p(:) integer(c_int) :: ndim_c integer(8) :: ndim, j - integer(8), allocatable, intent(out) :: dims(:) + integer(8), allocatable, intent(out) :: shape(:) logical, optional :: reverse i_c = i ndim_c = dlite_instance_get_property_ndims_by_index_c(instance%cinst, i_c) ndim = ndim_c ptr = dlite_instance_get_property_dims_by_index_c(instance%cinst, i_c) call c_f_pointer(ptr, dims_p, [ndim]) - allocate(dims(ndim)) + allocate( shape(ndim)) if (present(reverse)) then if (reverse .and. (ndim .gt. 1)) then do j = 1, ndim - dims(j) = dims_p(ndim - j + 1) + shape(j) = dims_p(ndim - j + 1) end do else - dims = dims_p + shape = dims_p endif else - dims = dims_p + shape = dims_p endif call free_c(ptr) end subroutine dlite_instance_get_property_dims_by_index @@ -726,16 +726,16 @@ subroutine set_property_array_string(inst, index, prop) character(*), dimension(*), intent(in) :: prop(:) type(c_ptr) :: cptr character(kind=c_char), pointer :: prop_p(:,:) - integer(8), dimension(*), allocatable :: dims(:), dims2(:) + integer(8), dimension(*), allocatable :: shape(:), shape2(:) integer(8) :: i - call dlite_instance_get_property_dims_by_index(inst, index, dims) - allocate(dims2(2)) - dims2(1) = len(prop(1))+1 - dims2(2) = dims(1) + call dlite_instance_get_property_dims_by_index(inst, index, shape) + allocate(shape2(2)) + shape2(1) = len(prop(1))+1 + shape2(2) = shape(1) cptr = inst%get_property_by_index(index) - call c_f_pointer(cptr, prop_p, dims2) - do i = 1, dims(1) + call c_f_pointer(cptr, prop_p, shape2) + do i = 1, shape(1) call f_c_string(prop(i), prop_p(:,i)) end do diff --git a/bindings/fortran/tests/Person.json b/bindings/fortran/tests/Person.json index 6e54782f8..569c031dd 100644 --- a/bindings/fortran/tests/Person.json +++ b/bindings/fortran/tests/Person.json @@ -29,7 +29,7 @@ { "name": "skills", "type": "string10", - "dims": [ + "shape": [ "N" ], "description": "List of skills." @@ -38,7 +38,7 @@ "name": "temperature", "type": "float", "unit": "degC", - "dims": [ + "shape": [ "M" ], "description": "Temperature on the body." diff --git a/bindings/fortran/tests/Scan3D.json b/bindings/fortran/tests/Scan3D.json index 04e82aed4..319867e89 100644 --- a/bindings/fortran/tests/Scan3D.json +++ b/bindings/fortran/tests/Scan3D.json @@ -24,7 +24,7 @@ "name": "points", "type": "float", "unit": "mm", - "dims": ["P", "N"], + "shape": ["P", "N"], "description": "Point cloud." } ] diff --git a/bindings/python/datamodel.py b/bindings/python/datamodel.py index d446aecf9..d193d229e 100644 --- a/bindings/python/datamodel.py +++ b/bindings/python/datamodel.py @@ -87,7 +87,7 @@ def add_property( self.properties[name] = dlite.Property( name=name, type=type, - dims=shape, + shape=shape, unit=unit, description=description, ) @@ -130,9 +130,9 @@ def validate(self): def get(self): """Returns a DLite Metadata created from the datamodel.""" self.validate() - dims = [len(self.dimensions), len(self.properties)] - if "nrelations" in self.schema: - dims.append(len(self.relations)) + shape = [len(self.dimensions), len(self.properties)] + if 'nrelations' in self.schema: + shape.append(len(self.relations)) # Hmm, there seems to be a bug when instantiating from schema. # The returned metadata seems not to be initialised, i.e. @@ -144,11 +144,11 @@ def get(self): f"Currently only entity schema is supported" ) - # meta = self.schema(dims, id=self.uri) - # meta.description = self.description - # meta['dimensions'] = list(self.dimensions.values()) - # meta['properties'] = list(self.properties.values()) - # if 'relations' in meta: + #meta = self.schema(shape, id=self.uri) + #meta.description = self.description + #meta['dimensions'] = list(self.dimensions.values()) + #meta['properties'] = list(self.properties.values()) + #if 'relations' in meta: # meta['relations'] = self.relations # return meta diff --git a/bindings/python/dlite-entity-python.i b/bindings/python/dlite-entity-python.i index c6bf3d159..d07c34f38 100644 --- a/bindings/python/dlite-entity-python.i +++ b/bindings/python/dlite-entity-python.i @@ -381,20 +381,21 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I doc='Whether this is a meta-metadata instance.') @classmethod - def from_metaid(cls, metaid, dims, id=None): - """Create a new instance of metadata `metaid`. `dims` must be a + def from_metaid(cls, metaid, dimensions, id=None): + """Create a new instance of metadata `metaid`. `dimensions` must be a sequence with the size of each dimension. All values initialized to zero. If `id` is None, a random UUID is generated. Otherwise the UUID is derived from `id`. """ - if isinstance(dims, dict): + if isinstance(dimensions, dict): meta = get_instance(metaid) - dims = [dims[dim.name] for dim in meta.properties['dimensions']] + dimensions = [dimensions[dim.name] + for dim in meta.properties['dimensions']] # Allow metaid to be an Instance if isinstance(metaid, Instance): metaid = metaid.uri return Instance( - metaid=metaid, dims=dims, id=id, + metaid=metaid, dims=dimensions, id=id, dimensions=(), properties=() # arrays must not be None ) @@ -499,8 +500,8 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I ) @classmethod - def create_from_metaid(cls, metaid, dims, id=None): - """Create a new instance of metadata `metaid`. `dims` must be a + def create_from_metaid(cls, metaid, dimensions, id=None): + """Create a new instance of metadata `metaid`. `dimensions` must be a sequence with the size of each dimension. All values initialized to zero. If `id` is None, a random UUID is generated. Otherwise the UUID is derived from `id`. @@ -508,11 +509,12 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I warnings.warn( "create_from_metaid() is deprecated, use from_metaid() instead.", DeprecationWarning, stacklevel=2) - if isinstance(dims, dict): + if isinstance(dimensions, dict): meta = get_instance(metaid) - dims = [dims[dim.name] for dim in meta.properties['dimensions']] + dimensions = [dimensions[dim.name] + for dim in meta.properties['dimensions']] return Instance( - metaid=metaid, dims=dims, id=id, + metaid=metaid, dims=dimensions, id=id, dimensions=(), properties=() # arrays must not be None ) diff --git a/bindings/python/dlite-entity.i b/bindings/python/dlite-entity.i index b2bc647a2..57d7c15b4 100644 --- a/bindings/python/dlite-entity.i +++ b/bindings/python/dlite-entity.i @@ -15,7 +15,7 @@ DLiteProperty * dlite_swig_create_property(const char *name, enum _DLiteType type, size_t size, const char *ref, - obj_t *dims, const char *unit, + obj_t *shape, const char *unit, const char *description) { DLiteProperty *p = calloc(1, sizeof(DLiteProperty)); @@ -23,17 +23,17 @@ dlite_swig_create_property(const char *name, enum _DLiteType type, p->type = type; p->size = size; if (ref && *ref) p->ref = strdup(ref); - if (dims && dims != DLiteSwigNone) { - p->ndims = (int)PySequence_Length(dims); - if (!(p->dims = dlite_swig_copy_array(1, &p->ndims, dliteStringPtr, - sizeof(char *), dims))) { + if (shape && shape != DLiteSwigNone) { + p->ndims = (int)PySequence_Length(shape); + if (!(p->shape = dlite_swig_copy_array(1, &p->ndims, dliteStringPtr, + sizeof(char *), shape))) { free(p->name); free(p); return NULL; } } else { p->ndims = 0; - p->dims = NULL; + p->shape = NULL; } if (unit) p->unit = strdup(unit); if (description) p->description = strdup(description); @@ -139,18 +139,18 @@ struct _DLiteProperty { %extend _DLiteProperty { _DLiteProperty(const char *name, const char *type, const char *ref=NULL, - obj_t *dims=NULL, const char *unit=NULL, + obj_t *shape=NULL, const char *unit=NULL, const char *description=NULL) { DLiteType dtype; size_t size; if (dlite_type_set_dtype_and_size(type, &dtype, &size)) return NULL; - return dlite_swig_create_property(name, dtype, size, ref, dims, unit, + return dlite_swig_create_property(name, dtype, size, ref, shape, unit, description); } ~_DLiteProperty() { free($self->name); if ($self->ref) free($self->ref); - if ($self->dims) free_str_array($self->dims, $self->ndims); + if ($self->shape) free_str_array($self->shape, $self->ndims); if ($self->unit) free($self->unit); if ($self->description) free($self->description); free($self); @@ -165,7 +165,7 @@ struct _DLiteProperty { } obj_t *get_shape(void) { return dlite_swig_get_array(NULL, 1, &$self->ndims, - dliteStringPtr, sizeof(char *), $self->dims); + dliteStringPtr, sizeof(char *), $self->shape); } void set_shape(obj_t *arr) { int i, n = dlite_swig_length(arr); @@ -174,10 +174,10 @@ struct _DLiteProperty { FAIL("allocation failure"); if (dlite_swig_set_array(&new, 1, &n, dliteStringPtr, sizeof(char *), arr)) FAIL("cannot set new shape"); - for (i=0; i < $self->ndims; i++) free($self->dims[i]); - free($self->dims); + for (i=0; i < $self->ndims; i++) free($self->shape[i]); + free($self->shape); $self->ndims = n; - $self->dims = new; + $self->shape = new; return; fail: if (new) { @@ -246,10 +246,13 @@ struct _Triple { %feature("docstring", "\ Returns a new instance. -Instance(metaid=None, dims=None, id=None, url=None, storage=None, driver=None, location=None, options=None, dimensions=None, properties=None, description=None) +Instance(metaid=None, dims=None, id=None, url=None, storage=None, driver=None, + location=None, options=None, dimensions=None, properties=None, + description=None) + Is called from one of the following class methods defined in dlite.py: - - from_metaid(cls, metaid, dims, id=None) + - from_metaid(cls, metaid, dimensions, id=None) - from_url(cls, url, metaid=None) - from_storage(cls, storage, id=None, metaid=None) - from_location(cls, driver, location, options=None, id=None) diff --git a/bindings/python/dlite-python.i b/bindings/python/dlite-python.i index 61a12f1cc..1bdaa6481 100644 --- a/bindings/python/dlite-python.i +++ b/bindings/python/dlite-python.i @@ -257,12 +257,12 @@ void dlite_swig_errclr(void) `inst` : The DLite instance that own the data. If NULL, the returned array takes over the ownership. `ndims`: Number of dimensions. - `dims` : Length of each dimension. + `shape`: Length of each dimension. `type` : Type of the data. `size` : Size of each data element. `data` : Pointer to data, which should be C-ordered and continuous. */ -obj_t *dlite_swig_get_array(DLiteInstance *inst, int ndims, int *dims, +obj_t *dlite_swig_get_array(DLiteInstance *inst, int ndims, int *shape, DLiteType type, size_t size, void *data) { int i; @@ -272,7 +272,7 @@ obj_t *dlite_swig_get_array(DLiteInstance *inst, int ndims, int *dims, if (typecode < 0) goto fail; if (!(d = malloc(ndims*sizeof(npy_intp)))) FAIL("allocation failure"); - for (i=0; iname) free(dest->name); if (dest->ref) free(dest->ref); - if (dest->dims) free_str_array(dest->dims, dest->ndims); + if (dest->shape) free_str_array(dest->shape, dest->ndims); if (dest->unit) free(dest->unit); if (dest->description) free(dest->description); dest->name = strdup(src->name); dest->type = src->type; dest->size = src->size; - if (src->ref) dest->ref = strdup(src->ref); + if (src->ref) dest->ref = strdup(src->ref); dest->ndims = src->ndims; if (src->ndims > 0) { int j; - dest->dims = malloc(src->ndims*sizeof(char *)); + dest->shape = malloc(src->ndims*sizeof(char *)); for (j=0; j < src->ndims; j++) - dest->dims[j] = strdup(src->dims[j]); + dest->shape[j] = strdup(src->shape[j]); } else - dest->dims = NULL; + dest->shape = NULL; dest->unit = (src->unit) ? strdup(src->unit) : NULL; dest->description = (src->description) ? strdup(src->description) :NULL; @@ -874,7 +874,7 @@ int dlite_swig_set_scalar(void *ptr, DLiteType type, size_t size, obj_t *obj) PyObject *name = PySequence_GetItem(obj, 0); PyObject *type = PySequence_GetItem(obj, 1); PyObject *ref = PySequence_GetItem(obj, 2); - PyObject *dims = PySequence_GetItem(obj, 3); + PyObject *shape = PySequence_GetItem(obj, 3); PyObject *unit = PySequence_GetItem(obj, 4); PyObject *descr = PySequence_GetItem(obj, 5); DLiteType t; @@ -885,25 +885,25 @@ int dlite_swig_set_scalar(void *ptr, DLiteType type, size_t size, obj_t *obj) &t, &size) == 0) { if (dest->name) free(dest->name); if (dest->ref) free(dest->ref); - if (dest->dims) free_str_array(dest->dims, dest->ndims); + if (dest->shape) free_str_array(dest->shape, dest->ndims); if (dest->unit) free(dest->unit); if (dest->description) free(dest->description); dest->name = strdup(PyUnicode_AsUTF8(name)); dest->type = t; dest->size = size; if (ref != Py_None) dest->ref = strdup(PyUnicode_AsUTF8(ref)); - if (dims && PyUnicode_Check(dims)) { - const char *s = PyUnicode_AsUTF8(dims); + if (shape && PyUnicode_Check(shape)) { + const char *s = PyUnicode_AsUTF8(shape); int j=0, ndims=(s && *s) ? 1 : 0; while (s[j]) if (s[j++] == ',') ndims++; dest->ndims = ndims; - dest->dims = malloc(ndims*sizeof(char *)); + dest->shape = malloc(ndims*sizeof(char *)); s += strspn(s, " \t\n["); for (j=0; jdims[j] = strndup(s, len); + dest->shape[j] = strndup(s, len); s += len + 1; } } @@ -916,7 +916,7 @@ int dlite_swig_set_scalar(void *ptr, DLiteType type, size_t size, obj_t *obj) } Py_XDECREF(name); Py_XDECREF(type); - Py_XDECREF(dims); + Py_XDECREF(shape); Py_XDECREF(unit); Py_XDECREF(descr); @@ -1026,7 +1026,7 @@ int dlite_swig_set_scalar(void *ptr, DLiteType type, size_t size, obj_t *obj) NULL on error. */ obj_t *dlite_swig_get_property_by_index(DLiteInstance *inst, int i) { - int j, n=i, *dims=NULL; + int j, n=i, *shape=NULL; void **ptr; DLiteProperty *p; obj_t *obj=NULL; @@ -1048,16 +1048,16 @@ obj_t *dlite_swig_get_property_by_index(DLiteInstance *inst, int i) if (p->ndims == 0) { obj = dlite_swig_get_scalar(p->type, p->size, ptr); } else { - if (!(dims = malloc(p->ndims*sizeof(int)))) FAIL("allocation failure"); + if (!(shape = malloc(p->ndims*sizeof(int)))) FAIL("allocation failure"); for (j=0; jndims; j++) { - if (!p->dims[j]) + if (!p->shape[j]) FAIL2("missing dimension %d of property %d", j, i); - dims[j] = (int)DLITE_PROP_DIM(inst, i, j); + shape[j] = (int)DLITE_PROP_DIM(inst, i, j); } - obj = dlite_swig_get_array(inst, p->ndims, dims, p->type, p->size, *ptr); + obj = dlite_swig_get_array(inst, p->ndims, shape, p->type, p->size, *ptr); } fail: - if (dims) free(dims); + if (shape) free(shape); return obj; } @@ -1067,7 +1067,7 @@ obj_t *dlite_swig_get_property_by_index(DLiteInstance *inst, int i) object `obj`. Returns non-zero on error. */ int dlite_swig_set_property_by_index(DLiteInstance *inst, int i, obj_t *obj) { - int j, *dims=NULL, status=-1, n=i; + int j, *shape=NULL, status=-1, n=i; void *ptr; DLiteProperty *p; @@ -1081,20 +1081,20 @@ int dlite_swig_set_property_by_index(DLiteInstance *inst, int i, obj_t *obj) if (p->ndims == 0) { if (dlite_swig_set_scalar(ptr, p->type, p->size, obj)) goto fail; } else { - if (!(dims = malloc(p->ndims*sizeof(int)))) FAIL("allocation failure"); + if (!(shape = malloc(p->ndims*sizeof(int)))) FAIL("allocation failure"); for (j=0; jndims; j++) { - if (!p->dims[j]) + if (!p->shape[j]) FAIL2("missing dimension %d of property %d", j, i); - dims[j] = (int)DLITE_PROP_DIM(inst, i, j); + shape[j] = (int)DLITE_PROP_DIM(inst, i, j); } - if (dlite_swig_set_array(ptr, p->ndims, dims, p->type, p->size, obj)) + if (dlite_swig_set_array(ptr, p->ndims, shape, p->type, p->size, obj)) goto fail; } if (dlite_instance_sync_from_properties(inst)) goto fail; status = 0; fail: - if (dims) free(dims); + if (shape) free(shape); return status; } @@ -1200,7 +1200,7 @@ int dlite_swig_set_property_by_index(DLiteInstance *inst, int i, obj_t *obj) for (i=0; i<$2; i++) { DLiteProperty *p = $1 + i; free(p->name); - if (p->dims) free_str_array(p->dims, p->ndims); + if (p->shape) free_str_array(p->shape, p->ndims); if (p->unit) free(p->unit); if (p->description) free(p->description); } diff --git a/bindings/python/factory.py b/bindings/python/factory.py index 65c9d7b50..88eb10b5c 100644 --- a/bindings/python/factory.py +++ b/bindings/python/factory.py @@ -129,7 +129,7 @@ def _dlite_infer_dimensions( f"Expected {prop.ndims} dimensions for array property " f"{prop.name!r}; got {array.ndim}" ) - for i, pdim in enumerate(prop.dims): + for i, pdim in enumerate(prop.shape): if pdim in dimnames: n = dimnames.index(pdim) if dims[n] == -1: diff --git a/bindings/python/mappings.py b/bindings/python/mappings.py index 6529240a0..34f912ec6 100644 --- a/bindings/python/mappings.py +++ b/bindings/python/mappings.py @@ -151,8 +151,8 @@ def instantiate_from_routes( unit=prop.unit, quantity=quantity, ) - dims = infer_dimensions(meta, values) - inst = meta(dimensions=dims, id=id) + dimensions = infer_dimensions(meta, values) + inst = meta(dimensions=dimensions, id=id) for key, value in routes.items(): inst[key] = value.eval(magnitude=True, unit=meta.getprop(key).unit) diff --git a/bindings/python/numpy.i b/bindings/python/numpy.i index 99ed073ab..18ea253e0 100644 --- a/bindings/python/numpy.i +++ b/bindings/python/numpy.i @@ -1984,7 +1984,7 @@ (PyObject* array = NULL) { npy_intp dims[1] = { $1_dim0 }; - array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(1, dims,DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } @@ -2013,7 +2013,7 @@ $2 = (DIM_TYPE) PyLong_AsSsize_t($input); if ($2 == -1 && PyErr_Occurred()) SWIG_fail; dims[0] = (npy_intp) $2; - array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(1, dims,DATA_TYPECODE); if (!array) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); } @@ -2042,7 +2042,7 @@ $1 = (DIM_TYPE) PyLong_AsSsize_t($input); if ($1 == -1 && PyErr_Occurred()) SWIG_fail; dims[0] = (npy_intp) $1; - array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(1, dims,DATA_TYPECODE); if (!array) SWIG_fail; $2 = (DATA_TYPE*) array_data(array); } @@ -2060,7 +2060,7 @@ (PyObject* array = NULL) { npy_intp dims[2] = { $1_dim0, $1_dim1 }; - array = PyArray_SimpleNew(2, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(2, dims,DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } @@ -2078,7 +2078,7 @@ (PyObject* array = NULL) { npy_intp dims[3] = { $1_dim0, $1_dim1, $1_dim2 }; - array = PyArray_SimpleNew(3, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(3, dims,DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } @@ -2096,7 +2096,7 @@ (PyObject* array = NULL) { npy_intp dims[4] = { $1_dim0, $1_dim1, $1_dim2, $1_dim3 }; - array = PyArray_SimpleNew(4, dims, DATA_TYPECODE); + array = PyArray_SimpleNew(4, dims,DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } @@ -2124,7 +2124,7 @@ (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1) { npy_intp dims[1] = { *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(1, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2145,7 +2145,7 @@ (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1) { npy_intp dims[1] = { *$1 }; - PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2)); + PyObject* obj = PyArray_SimpleNewFromData(1, dims,DATA_TYPECODE, (void*)(*$2)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2167,7 +2167,7 @@ (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2189,7 +2189,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2) { npy_intp dims[2] = { *$1, *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$3)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2211,7 +2211,7 @@ (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2233,7 +2233,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2) { npy_intp dims[2] = { *$1, *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$3)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2257,7 +2257,7 @@ (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2281,7 +2281,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$4)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2305,7 +2305,7 @@ (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2329,7 +2329,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$4)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2354,7 +2354,7 @@ (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4) { npy_intp dims[4] = { *$2, *$3, *$4 , *$5 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2379,7 +2379,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_ARRAY4) { npy_intp dims[4] = { *$1, *$2, *$3 , *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$5)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2404,7 +2404,7 @@ (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4) { npy_intp dims[4] = { *$2, *$3, *$4 , *$5 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2429,7 +2429,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_FARRAY4) { npy_intp dims[4] = { *$1, *$2, *$3 , *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$5)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2454,7 +2454,7 @@ (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1) { npy_intp dims[1] = { *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(1, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2488,7 +2488,7 @@ (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1) { npy_intp dims[1] = { *$1 }; - PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2)); + PyObject* obj = PyArray_SimpleNewFromData(1, dims,DATA_TYPECODE, (void*)(*$2)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2523,7 +2523,7 @@ (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2558,7 +2558,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2) { npy_intp dims[2] = { *$1, *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$3)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2593,7 +2593,7 @@ (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2628,7 +2628,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2) { npy_intp dims[2] = { *$1, *$2 }; - PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); + PyObject* obj = PyArray_SimpleNewFromData(2, dims,DATA_TYPECODE, (void*)(*$3)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2665,7 +2665,7 @@ (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2702,7 +2702,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_ARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; - PyObject* obj= PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4)); + PyObject* obj= PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$4)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2739,7 +2739,7 @@ (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2776,7 +2776,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_FARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; - PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4)); + PyObject* obj = PyArray_SimpleNewFromData(3, dims,DATA_TYPECODE, (void*)(*$4)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2814,7 +2814,7 @@ (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4) { npy_intp dims[4] = { *$2, *$3, *$4 , *$5 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2852,7 +2852,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4) { npy_intp dims[4] = { *$1, *$2, *$3 , *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$5)); PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; @@ -2890,7 +2890,7 @@ (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4) { npy_intp dims[4] = { *$2, *$3, *$4 , *$5 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; @@ -2928,7 +2928,7 @@ (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4) { npy_intp dims[4] = { *$1, *$2, *$3 , *$4 }; - PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5)); + PyObject* obj = PyArray_SimpleNewFromData(4, dims,DATA_TYPECODE, (void*)(*$5)); PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; diff --git a/bindings/python/rdf.py b/bindings/python/rdf.py index 677db4791..a5b408efa 100644 --- a/bindings/python/rdf.py +++ b/bindings/python/rdf.py @@ -149,7 +149,7 @@ def to_graph( graph.add((prop, DM.hasShape, shape)) graph.add((shape, RDF.type, DM.Shape)) prev, rel = shape, DM.hasFirst - for i, expr in enumerate(p.dims): + for i, expr in enumerate(p.shape): dimexpr = URIRef(f"{shape}_{i}") graph.add((prev, rel, dimexpr)) graph.add((dimexpr, RDF.type, DM.DimensionExpression)) @@ -299,7 +299,7 @@ def from_graph(graph, id=None): dlite.Property( name=_value(graph, prop, DM.hasLabel), type=_value(graph, prop, DM.hasType), - dims=dlite_shape, + shape=dlite_shape, unit=graph.value(prop, DM.hasUnit), description=graph.value(prop, DM.hasDescription), ) diff --git a/bindings/python/tests/entities/MyEntity.json b/bindings/python/tests/entities/MyEntity.json index 31d7d1a70..b9ddfc40a 100644 --- a/bindings/python/tests/entities/MyEntity.json +++ b/bindings/python/tests/entities/MyEntity.json @@ -23,7 +23,7 @@ { "name": "a-blob-array", "type": "blob4", - "dims": [ + "shape": [ "N", "N" ], @@ -37,7 +37,7 @@ { "name": "a-bool-array", "type": "bool", - "dims": [ + "shape": [ "N" ], "description": "A bool array." @@ -50,7 +50,7 @@ { "name": "an-int-array", "type": "int", - "dims": [ + "shape": [ "M" ], "description": "An int array." @@ -65,7 +65,7 @@ "name": "a-float64-array", "type": "float64", "unit": "K", - "dims": [ + "shape": [ "M" ], "description": "The temperature." @@ -78,7 +78,7 @@ { "name": "a-fixstring-array", "type": "string3", - "dims": [ + "shape": [ "N", "N" ], @@ -92,7 +92,7 @@ { "name": "a-string-array", "type": "string", - "dims": [ + "shape": [ "N", "M" ], @@ -106,7 +106,7 @@ { "name": "a-relation-array", "type": "relation", - "dims": [ + "shape": [ "N" ], "description": "A relation array" diff --git a/bindings/python/tests/entities/PersonOld.json b/bindings/python/tests/entities/PersonOld.json index 5af8c8d73..413c1be86 100644 --- a/bindings/python/tests/entities/PersonOld.json +++ b/bindings/python/tests/entities/PersonOld.json @@ -24,7 +24,7 @@ { "name": "skills", "type": "string", - "dims": ["N"], + "shape": ["N"], "description": "List of skills." } ] diff --git a/bindings/python/tests/test_collection.py b/bindings/python/tests/test_collection.py old mode 100755 new mode 100644 diff --git a/bindings/python/tests/test_datamodel.py b/bindings/python/tests/test_datamodel.py index ec33df6bd..df9738e3b 100644 --- a/bindings/python/tests/test_datamodel.py +++ b/bindings/python/tests/test_datamodel.py @@ -25,5 +25,5 @@ Atoms = datamodel.get() -# atoms = Atoms(dims=[2, 3, 3]) -atoms = Atoms(dims=dict(nvecs=3, ncoords=3, natoms=2)) +#atoms = Atoms(dimensions=[2, 3, 3]) +atoms = Atoms(dimensions=dict(nvecs=3, ncoords=3, natoms=2)) diff --git a/bindings/python/tests/test_entity.py b/bindings/python/tests/test_entity.py old mode 100755 new mode 100644 index 4378b5cb9..297b0e336 --- a/bindings/python/tests/test_entity.py +++ b/bindings/python/tests/test_entity.py @@ -165,7 +165,7 @@ prop2 = Property( "b", type="string10", - dims=["I", "J", "K"], + shape=["I", "J", "K"], description="something enlightening...", ) assert any(prop2.shape) @@ -184,7 +184,7 @@ [Dimension("N", "Number of something")], [ Property("name", type="string", description="Name of something."), - Property("arr", type="int", dims=["N+2"], description="An array."), + Property("arr", type="int", shape=["N+2"], description="An array."), Property("v", type="double", unit="m/s", description="Velocity"), ], "Something new...", diff --git a/bindings/python/tests/test_factory.py b/bindings/python/tests/test_factory.py old mode 100755 new mode 100644 diff --git a/bindings/python/tests/test_pydantic.py b/bindings/python/tests/test_pydantic.py index 71034f15d..a2980583b 100644 --- a/bindings/python/tests/test_pydantic.py +++ b/bindings/python/tests/test_pydantic.py @@ -12,6 +12,7 @@ sys.exit(44) +import pdb class TransformationStatus(BaseModel): """Return from transformation status.""" @@ -61,9 +62,13 @@ class TransformationStatus(BaseModel): utc = timezone(timedelta(hours=0)) dt = datetime.fromtimestamp(now - 600).astimezone(utc) + # Timezone may is printed differently depending on Python version. # Strip it off when testing finishTime -assert inst.finishTime.split("+")[0] == str(dt).split("+")[0] + +# writing it in this form should work for python version < 3.8.18 +assert inst.finishTime.split(".")[0].split("+")[0] == str(dt).split(".")[0].split("+")[0] + # ============================================================== diff --git a/bindings/python/tests/test_python_storage.py b/bindings/python/tests/test_python_storage.py old mode 100755 new mode 100644 index 903ac6fe9..6ad829702 --- a/bindings/python/tests/test_python_storage.py +++ b/bindings/python/tests/test_python_storage.py @@ -63,7 +63,7 @@ def equal_rdf_files(path1, path2): inst = s.load(id=person.uuid) -person2 = Person(dims=[3]) +person2 = Person(dimensions=[3]) person2.name = "Berry" person2.age = 24.3 person2.skills = ["eating", "sleeping", "reading"] diff --git a/bindings/python/tests/test_utils.py b/bindings/python/tests/test_utils.py index d346bf5d8..fd5d1ccff 100644 --- a/bindings/python/tests/test_utils.py +++ b/bindings/python/tests/test_utils.py @@ -95,12 +95,12 @@ properties={ "symbols": { "type": "string", - "dims": ["natoms"], + "shape": ["natoms"], "description": "Chemical symbol of each atom.", }, "positions": { "type": "float", - "dims": ["natoms", "ncoords"], + "shape": ["natoms", "ncoords"], "unit": "Å", "description": "Position of each atom.", }, @@ -125,12 +125,12 @@ properties={ "symbols": { "type": "string", - "dims": ["natoms"], + "shape": ["natoms"], "description": "Chemical symbol of each atom.", }, "positions": { "type": "float", - "dims": ["natoms", "ncoords"], + "shape": ["natoms", "ncoords"], "unit": "Å", "description": "Position of each atom.", }, @@ -149,7 +149,7 @@ ) assert dims == dict(N=3, M=2) -dims = infer_dimensions( +shape = infer_dimensions( meta=inst.meta, values={ "a-string-array": [("a", "b"), ("c", "d"), ("e", "f")], @@ -160,16 +160,16 @@ ], }, ) -assert dims == dict(N=3, M=2) +assert shape == dict(N=3, M=2) -dims = infer_dimensions( +shape = infer_dimensions( meta=inst.meta, values={ "an-int-array": [1, 2, 3, 4], "a-fixstring-array": [("Al", "Mg"), ("Si", "Cu")], }, ) -assert dims == dict(N=2, M=4) +assert shape == dict(N=2, M=4) # PR #677: test that infer_dimensions() correctly handles ref types diff --git a/bindings/python/utils.py b/bindings/python/utils.py index 7c075bdea..386b70f4a 100644 --- a/bindings/python/utils.py +++ b/bindings/python/utils.py @@ -167,7 +167,7 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): dlite.Property( name=p["name"], type=p["type"], - dims=p.get("shape", p.get("dims")), + shape=p.get("shape", p.get("dims")), unit=p.get("unit"), description=p.get("description"), ) @@ -178,7 +178,7 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): dlite.Property( name=k, type=v["type"], - dims=v.get("shape", v.get("dims")), + shape=v.get("shape", v.get("dims")), unit=v.get("unit"), description=v.get("description"), ) @@ -196,7 +196,7 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): d["dimensions"][dim.name] for dim in meta.properties["dimensions"] ] inst_id = d.get("uri", d.get("uuid", id)) - inst = dlite.Instance.from_metaid(meta.uri, dims=dims, id=inst_id) + inst = dlite.Instance.from_metaid(meta.uri, dimensions=dims, id=inst_id) for p in meta["properties"]: value = d["properties"][p.name] inst.set_property(p.name, value) @@ -341,7 +341,7 @@ def pydantic_to_property( name, subprop.type, ref=subprop.ref, - dims=shape, + shape=shape, unit=unit, description=descr, ) @@ -394,10 +394,10 @@ def pydantic_to_metadata( ) dims = [dlite.Dimension(k, v) for k, v in dimensions.items()] return dlite.Instance.create_metadata( - uri, - dims, - properties, - d.get("description", ""), + uri=uri, + dimensions=dims, + properties=properties, + description=d.get("description", ""), ) diff --git a/examples/dehydrogenation/1-simple-workflow/calculate_reaction.py b/examples/dehydrogenation/1-simple-workflow/calculate_reaction.py old mode 100755 new mode 100644 index 50be9f119..8400a0d66 --- a/examples/dehydrogenation/1-simple-workflow/calculate_reaction.py +++ b/examples/dehydrogenation/1-simple-workflow/calculate_reaction.py @@ -21,7 +21,7 @@ Reaction = dlite.Instance.from_url(f'json://{entitydir}/Reaction.json') -reaction = Reaction(dims=[len(reactants), len(products)]) +reaction = Reaction(dimensions=[len(reactants), len(products)]) reaction.reactants = list(reactants.keys()) reaction.products = list(products.keys()) diff --git a/examples/dehydrogenation/1-simple-workflow/molecular_energies.py b/examples/dehydrogenation/1-simple-workflow/molecular_energies.py old mode 100755 new mode 100644 index e38cc74c1..e25b2bc07 --- a/examples/dehydrogenation/1-simple-workflow/molecular_energies.py +++ b/examples/dehydrogenation/1-simple-workflow/molecular_energies.py @@ -22,7 +22,7 @@ def readMolecule(filename): atoms = ase.io.read(filename) # ASE Atoms object atoms.calc = EMT() molname = Path(filename).stem - inst = Molecule(dims=[len(atoms), 3], id=molname) # DLite instance + inst = Molecule(dimensions=[len(atoms), 3], id=molname) # DLite instance inst.name = molname inst.positions = atoms.positions inst.symbols = atoms.get_chemical_symbols() diff --git a/examples/dehydrogenation/2-instance-mappings/reaction_energy.py b/examples/dehydrogenation/2-instance-mappings/reaction_energy.py index 05a83b945..5e9eb6fb1 100755 --- a/examples/dehydrogenation/2-instance-mappings/reaction_energy.py +++ b/examples/dehydrogenation/2-instance-mappings/reaction_energy.py @@ -39,7 +39,7 @@ def reaction_energy(coll, reactants, products): # Instantiate a new Reaction instance Reaction = dlite.get_instance(reaction_id) - reaction = Reaction(dims=[len(reactants), len(products)]) + reaction = Reaction(dimensions=[len(reactants), len(products)]) reaction.reactants = list(reactants.keys()) reaction.products = list(products.keys()) reaction.reactant_stoichiometric_coefficient = list(reactants.values()) diff --git a/examples/dehydrogenation/entities/Molecule.json b/examples/dehydrogenation/entities/Molecule.json index 90313f168..dacc2a958 100644 --- a/examples/dehydrogenation/entities/Molecule.json +++ b/examples/dehydrogenation/entities/Molecule.json @@ -20,20 +20,20 @@ { "name": "positions", "type": "double", - "dims": ["natoms", "ncoords"], + "shape": ["natoms", "ncoords"], "unit": "Ångström", "description": "Atomic positions in Cartesian coordinates." }, { "name": "symbols", "type": "string", - "dims": ["natoms"], + "shape": ["natoms"], "description": "Chemical symbols." }, { "name": "masses", "type": "double", - "dims": ["natoms"], + "shape": ["natoms"], "unit": "u", "description": "Atomic masses." }, diff --git a/examples/dehydrogenation/entities/Reaction.json b/examples/dehydrogenation/entities/Reaction.json index 374e139c5..75a3da6cf 100644 --- a/examples/dehydrogenation/entities/Reaction.json +++ b/examples/dehydrogenation/entities/Reaction.json @@ -15,25 +15,25 @@ { "name": "reactants", "type": "string", - "dims": ["nreactants"], + "shape": ["nreactants"], "description": "Name of the reactant." }, { "name": "products", "type": "string", - "dims": ["nproducts"], + "shape": ["nproducts"], "description": "Name of the product." }, { "name": "reactant_stoichiometric_coefficient", "type": "double", - "dims": ["nreactants"], + "shape": ["nreactants"], "description": "Stoichiometric coefficient of the reactant." }, { "name": "product_stoichiometric_coefficient", "type": "double", - "dims": ["nproducts"], + "shape": ["nproducts"], "description": "Stoichiometric coefficient of the product." }, { diff --git a/examples/entities/Chemistry-0.1.json b/examples/entities/Chemistry-0.1.json index 7f0449662..9ca9ed1ef 100644 --- a/examples/entities/Chemistry-0.1.json +++ b/examples/entities/Chemistry-0.1.json @@ -13,41 +13,41 @@ }, "elements": { "type": "string", - "dims": ["nelements"], + "shape": ["nelements"], "description": "Chemical symbol of each chemical element. By convection the dependent element (e.g. Al) is listed first." }, "phases": { "type": "string", - "dims": ["nphases"], + "shape": ["nphases"], "description": "Name of each phase." }, "X0": { "type": "double", "unit": "atom-fraction", - "dims": ["nelements"], + "shape": ["nelements"], "description": "Nominal composition. Should sum to one." }, "Xp": { "type": "double", "unit": "atom-fraction", - "dims": ["nphases", "nelements"], + "shape": ["nphases", "nelements"], "description": "Average composition of each phase, excluding matrix. Each row should sum to one." }, "volfrac": { "type": "double", - "dims": ["nphases"], + "shape": ["nphases"], "description": "Volume fraction of each phase, excluding matrix." }, "rpart": { "type": "double", "unit": "m", - "dims": ["nphases"], + "shape": ["nphases"], "description": "Average particle radius of each phase, excluding matrix." }, "atvol": { "type": "double", "unit": "m^3", - "dims": ["nphases"], + "shape": ["nphases"], "description": "Average volume per atom for each phase." } } diff --git a/examples/ex1/Chemistry-0.1.json b/examples/ex1/Chemistry-0.1.json index b25b800cd..3fac7ccf1 100644 --- a/examples/ex1/Chemistry-0.1.json +++ b/examples/ex1/Chemistry-0.1.json @@ -23,7 +23,7 @@ { "name": "elements", "type": "string", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each chemical element. By convension the dependent element (e.g. Al) is listed first." @@ -31,7 +31,7 @@ { "name": "phases", "type": "string", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -40,7 +40,7 @@ "name": "X0", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nelements" ], "description": "Nominal composition. Should sum to one." @@ -49,7 +49,7 @@ "name": "Xp", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nphases", "nelements" ], @@ -58,7 +58,7 @@ { "name": "volfrac", "type": "double", - "dims": [ + "shape": [ "nphases" ], "description": "Volume fraction of each phase, excluding matrix." @@ -67,7 +67,7 @@ "name": "rpart", "type": "double", "unit": "m", - "dims": [ + "shape": [ "nphases" ], "description": "Average particle radius of each phase, excluding matrix." @@ -76,7 +76,7 @@ "name": "atvol", "type": "double", "unit": "m^3", - "dims": [ + "shape": [ "nphases" ], "description": "Average volume per atom for each phase." diff --git a/examples/ex2/Chemistry-0.1.json b/examples/ex2/Chemistry-0.1.json index b25b800cd..3fac7ccf1 100644 --- a/examples/ex2/Chemistry-0.1.json +++ b/examples/ex2/Chemistry-0.1.json @@ -23,7 +23,7 @@ { "name": "elements", "type": "string", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each chemical element. By convension the dependent element (e.g. Al) is listed first." @@ -31,7 +31,7 @@ { "name": "phases", "type": "string", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -40,7 +40,7 @@ "name": "X0", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nelements" ], "description": "Nominal composition. Should sum to one." @@ -49,7 +49,7 @@ "name": "Xp", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nphases", "nelements" ], @@ -58,7 +58,7 @@ { "name": "volfrac", "type": "double", - "dims": [ + "shape": [ "nphases" ], "description": "Volume fraction of each phase, excluding matrix." @@ -67,7 +67,7 @@ "name": "rpart", "type": "double", "unit": "m", - "dims": [ + "shape": [ "nphases" ], "description": "Average particle radius of each phase, excluding matrix." @@ -76,7 +76,7 @@ "name": "atvol", "type": "double", "unit": "m^3", - "dims": [ + "shape": [ "nphases" ], "description": "Average volume per atom for each phase." diff --git a/examples/ex3/PhilibTable.json b/examples/ex3/PhilibTable.json index 5dc1476ef..8017f157c 100644 --- a/examples/ex3/PhilibTable.json +++ b/examples/ex3/PhilibTable.json @@ -43,7 +43,7 @@ { "name": "elements", "type": "string", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each element." @@ -51,7 +51,7 @@ { "name": "phases", "type": "string", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -59,7 +59,7 @@ { "name": "phaseselementdep", "type": "int32", - "dims": [ + "shape": [ "nphases" ], "description": "Indicia of the dependent element of each phase." @@ -67,7 +67,7 @@ { "name": "varnames", "type": "string", - "dims": [ + "shape": [ "nvars" ], "description": "Name of each free variable." @@ -75,7 +75,7 @@ { "name": "varranges", "type": "float64", - "dims": [ + "shape": [ "nvars", "nbounds" ], @@ -84,7 +84,7 @@ { "name": "condnames", "type": "string", - "dims": [ + "shape": [ "nconds" ], "description": "Name/expression for each condition." @@ -92,7 +92,7 @@ { "name": "condvalues", "type": "float64", - "dims": [ + "shape": [ "nconds" ], "description": "Value of each condition." @@ -100,7 +100,7 @@ { "name": "calcnames", "type": "string", - "dims": [ + "shape": [ "ncalc" ], "description": "Name of each calculated variable." @@ -108,7 +108,7 @@ { "name": "calcvalues", "type": "float64", - "dims": [ + "shape": [ "npoints", "ncalc" ], @@ -122,7 +122,7 @@ { "name": "ticks", "type": "int32", - "dims": [ + "shape": [ "nvars" ], "description": "For a regular grid, the number of tabulated points along each free variable. Unused if iregular grid." @@ -130,7 +130,7 @@ { "name": "points", "type": "float64", - "dims": [ + "shape": [ "npoints", "nvars" ], diff --git a/examples/ex4/Chemistry-0.1.json b/examples/ex4/Chemistry-0.1.json index 38ea6992f..4865ff1e7 100644 --- a/examples/ex4/Chemistry-0.1.json +++ b/examples/ex4/Chemistry-0.1.json @@ -23,7 +23,7 @@ { "name": "elements", "type": "string4", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each chemical element. By convension the dependent element (e.g. Al) is listed first." @@ -31,7 +31,7 @@ { "name": "phases", "type": "string255", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -40,7 +40,7 @@ "name": "X0", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nelements" ], "description": "Nominal composition. Should sum to one." @@ -49,7 +49,7 @@ "name": "Xp", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nphases", "nelements" ], @@ -58,7 +58,7 @@ { "name": "volfrac", "type": "double", - "dims": [ + "shape": [ "nphases" ], "description": "Volume fraction of each phase, excluding matrix." @@ -67,7 +67,7 @@ "name": "rpart", "type": "double", "unit": "m", - "dims": [ + "shape": [ "nphases" ], "description": "Average particle radius of each phase, excluding matrix." @@ -76,7 +76,7 @@ "name": "atvol", "type": "double", "unit": "m^3", - "dims": [ + "shape": [ "nphases" ], "description": "Average volume per atom for each phase." diff --git a/examples/storages/Chemistry-0.1.json b/examples/storages/Chemistry-0.1.json index b25b800cd..3fac7ccf1 100644 --- a/examples/storages/Chemistry-0.1.json +++ b/examples/storages/Chemistry-0.1.json @@ -23,7 +23,7 @@ { "name": "elements", "type": "string", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each chemical element. By convension the dependent element (e.g. Al) is listed first." @@ -31,7 +31,7 @@ { "name": "phases", "type": "string", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -40,7 +40,7 @@ "name": "X0", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nelements" ], "description": "Nominal composition. Should sum to one." @@ -49,7 +49,7 @@ "name": "Xp", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nphases", "nelements" ], @@ -58,7 +58,7 @@ { "name": "volfrac", "type": "double", - "dims": [ + "shape": [ "nphases" ], "description": "Volume fraction of each phase, excluding matrix." @@ -67,7 +67,7 @@ "name": "rpart", "type": "double", "unit": "m", - "dims": [ + "shape": [ "nphases" ], "description": "Average particle radius of each phase, excluding matrix." @@ -76,7 +76,7 @@ "name": "atvol", "type": "double", "unit": "m^3", - "dims": [ + "shape": [ "nphases" ], "description": "Average volume per atom for each phase." diff --git a/examples/storages/Person.json b/examples/storages/Person.json index 329d13508..dd5f7b96b 100644 --- a/examples/storages/Person.json +++ b/examples/storages/Person.json @@ -25,7 +25,7 @@ { "name": "skills", "type": "string", - "dims": [ + "shape": [ "N" ], "description": "List of skills." diff --git a/src/dlite-arrays.c b/src/dlite-arrays.c index c0f5e93ec..3a9f105ba 100644 --- a/src/dlite-arrays.c +++ b/src/dlite-arrays.c @@ -20,12 +20,12 @@ `type` is the type of each element. `size` is the size of each element. `ndims` is the number of dimensions. - `dims` is the size of each dimensions. Length: `ndims`. + `shape` is the size of each dimensions. Length: `ndims`. Returns the new array or NULL on error. */ DLiteArray *dlite_array_create(void *data, DLiteType type, size_t size, - int ndims, const size_t *dims) + int ndims, const size_t *shape) { DLiteArray *arr; int i, asize = sizeof(DLiteArray) + ndims*sizeof(size_t) + ndims*sizeof(int); @@ -33,17 +33,17 @@ DLiteArray *dlite_array_create(void *data, DLiteType type, size_t size, /* allocate the array object (except the data) in one chunk */ if (!(arr = calloc(1, asize))) return err(dliteMemoryError, "allocation failure"), NULL; - arr->dims = (size_t *)((char *)arr + sizeof(DLiteArray)); - arr->strides = (int *)((char *)arr->dims + ndims*sizeof(size_t)); + arr->shape = (size_t *)((char *)arr + sizeof(DLiteArray)); + arr->strides = (int *)((char *)arr->shape + ndims*sizeof(size_t)); arr->data = data; arr->type = type; arr->size = size; arr->ndims = ndims; - memcpy(arr->dims, dims, ndims*sizeof(size_t)); + memcpy(arr->shape, shape, ndims*sizeof(size_t)); for (i=ndims-1; i>=0; i--) { arr->strides[i] = size; - size *= dims[i]; + size *= shape[i]; } return arr; } @@ -55,9 +55,9 @@ DLiteArray *dlite_array_create(void *data, DLiteType type, size_t size, 'F': coloumn-major (Fortran-style) order, transposed order. */ DLiteArray *dlite_array_create_order(void *data, DLiteType type, size_t size, - int ndims, const size_t *dims, int order) + int ndims, const size_t *shape, int order) { - DLiteArray *arr2, *arr = dlite_array_create(data, type, size, ndims, dims); + DLiteArray *arr2, *arr = dlite_array_create(data, type, size, ndims, shape); if (!arr) return NULL; switch (order) { case 'C': @@ -92,7 +92,7 @@ size_t dlite_array_size(const DLiteArray *arr) { int n, size, maxsize=0; for (n=0; n < arr->ndims; n++) - if ((size = arr->strides[n]*arr->dims[n]) > maxsize) maxsize = size; + if ((size = arr->strides[n]*arr->shape[n]) > maxsize) maxsize = size; return maxsize; } @@ -104,7 +104,7 @@ int dlite_array_is_continuous(const DLiteArray *arr) int n, size = arr->size; for (n=arr->ndims-1; n >= 0; n--) { if (arr->strides[n] != size) return 0; - size *= arr->dims[n]; + size *= arr->shape[n]; } return 1; } @@ -171,10 +171,10 @@ void *dlite_array_iter_next(DLiteArrayIter *iter) DLiteArray *arr = (DLiteArray *)iter->arr; if (iter->ind[0] < 0) return NULL; /* check stop indicator */ for (n=arr->ndims-1; n>=0; n--) - if (arr->dims[n] <= 0) return NULL; /* check that all dimensions has + if (arr->shape[n] <= 0) return NULL; /* check that all dimensions has positive length */ for (n=arr->ndims-1; n>=0; n--) { - if (++iter->ind[n] < (int)arr->dims[n]) break; + if (++iter->ind[n] < (int)arr->shape[n]) break; iter->ind[n] = 0; } if (n < 0) { @@ -196,7 +196,7 @@ int dlite_array_compare(const DLiteArray *a, const DLiteArray *b) if (a->size != b->size) return 0; if (a->ndims != b->ndims) return 0; for (i=0; i < a->ndims; i++) { - if (a->dims[i] != b->dims[i]) return 0; + if (a->shape[i] != b->shape[i]) return 0; if (a->strides[i] != b->strides[i]) return 0; } /* check whether the array data are equal */ @@ -221,13 +221,13 @@ int dlite_array_compare(const DLiteArray *a, const DLiteArray *b) start[n]-1, start[n]-2, ... stop[n]+1, stop[n] Like Python, negative values of `start` or `stop` from the back. - Hence index `-k` is equivalent to `arr->dims[n]-k`. + Hence index `-k` is equivalent to `arr->shape[n]-k`. If `start` is NULL, it will default to zero for dimensions `n` with - positive `step` and `arr->dims[n]` for dimensions with negative + positive `step` and `arr->shape[n]` for dimensions with negative `step`. - If `stop` is NULL, it will default to `arr->dims[n]` for dimensions `n` + If `stop` is NULL, it will default to `arr->shape[n]` for dimensions `n` with positive `step` and zero for dimensions with negative `step`. If `step` is NULL, it defaults to one. @@ -251,22 +251,22 @@ DLiteArray *dlite_array_slice(const DLiteArray *arr, int n, offset=0; DLiteArray *new; if (!(new = dlite_array_create(arr->data, arr->type, arr->size, - arr->ndims, arr->dims))) return NULL; + arr->ndims, arr->shape))) return NULL; for (n = arr->ndims-1; n >= 0; n--) { int s1, s2; int d = (step) ? step[n] : 1; if (d == 0) return err(1, "dim %d: slice step cannot be zero", n), NULL; if (d > 0) { - s1 = (start) ? start[n] % arr->dims[n] : 0; - s2 = (stop) ? stop[n] % arr->dims[n] - 1 : arr->dims[n] - 1; + s1 = (start) ? start[n] % arr->shape[n] : 0; + s2 = (stop) ? stop[n] % arr->shape[n] - 1 : arr->shape[n] - 1; } else { - s1 = (start) ? start[n] % arr->dims[n] - 1 : arr->dims[n] - 1; - s2 = (stop) ? stop[n] % arr->dims[n] : 0; + s1 = (start) ? start[n] % arr->shape[n] - 1 : arr->shape[n] - 1; + s2 = (stop) ? stop[n] % arr->shape[n] : 0; } - if (s1 < 0) s1 += arr->dims[n]; - if (s2 < 0) s2 += arr->dims[n]; + if (s1 < 0) s1 += arr->shape[n]; + if (s2 < 0) s2 += arr->shape[n]; offset += s1 * arr->strides[n]; - new->dims[n] = (abs(s2 - s1) + 1 + d/2) / abs(d); + new->shape[n] = (abs(s2 - s1) + 1 + d/2) / abs(d); new->strides[n] *= d; } new->data = ((char *)arr->data) + offset; @@ -276,22 +276,22 @@ DLiteArray *dlite_array_slice(const DLiteArray *arr, /* Returns a new array object representing `arr` with a new shape specified - with `ndims` and `dims`. `dims` should be compatible with the old shape. + with `ndims` and `shape`. `shape` should be compatible with the old shape. The current implementation also requires that `arr` is C-continuous. Returns NULL on error. */ DLiteArray *dlite_array_reshape(const DLiteArray *arr, - int ndims, const size_t *dims) + int ndims, const size_t *shape) { int i, prod1=1, prod2=1;; if (!dlite_array_is_continuous(arr)) return err(1, "can only reshape C-continuous arrays"), NULL; - for (i=0; i < arr->ndims; i++) prod1 *= arr->dims[i]; - for (i=0; i < ndims; i++) prod2 *= dims[i]; + for (i=0; i < arr->ndims; i++) prod1 *= arr->shape[i]; + for (i=0; i < ndims; i++) prod2 *= shape[i]; if (prod1 != prod2) return err(1, "cannot reshape to an incompatible shape"), NULL; - return dlite_array_create(arr->data, arr->type, arr->size, ndims, dims); + return dlite_array_create(arr->data, arr->type, arr->size, ndims, shape); } @@ -306,10 +306,10 @@ DLiteArray *dlite_array_transpose(DLiteArray *arr) int i; DLiteArray *new; if (!(new = dlite_array_create(arr->data, arr->type, arr->size, - arr->ndims, arr->dims))) return NULL; + arr->ndims, arr->shape))) return NULL; for (i=0; i < arr->ndims; i++) { int j = arr->ndims - 1 - i; - new->dims[i] = arr->dims[j]; + new->shape[i] = arr->shape[j]; new->strides[i] = arr->strides[j]; } return new; @@ -328,7 +328,7 @@ void *dlite_array_make_continuous(DLiteArray *arr) void *data, *p; char *q; DLiteArrayIter iter; - for (n=0; n < arr->ndims; n++) size *= arr->dims[n]; + for (n=0; n < arr->ndims; n++) size *= arr->shape[n]; if (!(data = malloc(size))) return err(dliteMemoryError, "allocation failure"), NULL; if (dlite_array_is_continuous(arr)) return memcpy(data, arr->data, size); @@ -345,7 +345,7 @@ void *dlite_array_make_continuous(DLiteArray *arr) size = arr->size; for (n=arr->ndims-1; n>=0; n--) { arr->strides[n] = size; - size *= arr->dims[n]; + size *= arr->shape[n]; } return data; } @@ -364,7 +364,7 @@ void *dlite_array_make_continuous(DLiteArray *arr) int dlite_array_printf(FILE *fp, const DLiteArray *arr, int width, int prec) { void *p; - int i, N=arr->ndims-1, NN=arr->dims[N]-1; + int i, N=arr->ndims-1, NN=arr->shape[N]-1; DLiteArrayIter iter; char buf[80]; dlite_array_iter_init(&iter, arr); @@ -377,7 +377,7 @@ int dlite_array_printf(FILE *fp, const DLiteArray *arr, int width, int prec) for (i=0; itype, arr->size, width, prec, 0); fprintf(fp, "%s%s", buf, sep); - for (i=N; i >= 0 && iter.ind[i] == (int)arr->dims[i]-1; i--) + for (i=N; i >= 0 && iter.ind[i] == (int)arr->shape[i]-1; i--) fprintf(fp, "]"); if (iter.ind[N] == NN) fprintf(fp, "\n"); } diff --git a/src/dlite-arrays.h b/src/dlite-arrays.h index 6de58ede6..91372a157 100644 --- a/src/dlite-arrays.h +++ b/src/dlite-arrays.h @@ -32,7 +32,7 @@ typedef struct _DLiteArray { DLiteType type; /*!< data type of elements */ size_t size; /*!< size of each element in bytes */ int ndims; /*!< number of dimensions */ - size_t *dims; /*!< dimension sizes [ndims] */ + size_t *shape; /*!< dimension sizes [ndims] */ int *strides; /*!< strides, that is number of bytes between two following elements along each dimension [ndims] Note: strides can be negative, so we must use @@ -54,12 +54,12 @@ typedef struct _DLiteArrayIter { `type` is the type of each element. `size` is the size of each element. `ndims` is the number of dimensions. - `dims` is the size of each dimensions. Length: `ndims`. + `shape` is the size of each dimensions. Length: `ndims`. Returns the new array or NULL on error. */ DLiteArray *dlite_array_create(void *data, DLiteType type, size_t size, - int ndims, const size_t *dims); + int ndims, const size_t *shape); /** Like dlite_array_create(), but with argument `order`, which can have @@ -68,7 +68,7 @@ DLiteArray *dlite_array_create(void *data, DLiteType type, size_t size, 'F': coloumn-major (Fortran-style) order, transposed order. */ DLiteArray *dlite_array_create_order(void *data, DLiteType type, size_t size, - int ndims, const size_t *dims, int order); + int ndims, const size_t *shape, int order); /** Free an array object, but not the associated data. @@ -142,13 +142,13 @@ int dlite_array_compare(const DLiteArray *a, const DLiteArray *b); start[n]-1, start[n]-2, ... stop[n]+1, stop[n] Like Python, negative values of `start` or `stop` counts from the back. - Hence index `-k` is equivalent to `arr->dims[n]-|k|`. + Hence index `-k` is equivalent to `arr->shape[n]-|k|`. If `start` is NULL, it will default to zero for dimensions `n` with - positive `step` and `arr->dims[n]` for dimensions with negative + positive `step` and `arr->shape[n]` for dimensions with negative `step`. - If `stop` is NULL, it will default to `arr->dims[n]` for dimensions `n` + If `stop` is NULL, it will default to `arr->shape[n]` for dimensions `n` with positive `step` and zero for dimensions with negative `step`. If `step` is NULL, it defaults to one. @@ -172,13 +172,13 @@ DLiteArray *dlite_array_slice(const DLiteArray *arr, /** Returns a new array object representing `arr` with a new shape specified - with `ndims` and `dims`. `dims` should be compatible with the old shape. + with `ndims` and `shape`. `shape` should be compatible with the old shape. The current implementation also requires that `arr` is C-continuous. Returns NULL on error. */ DLiteArray *dlite_array_reshape(const DLiteArray *arr, - int ndims, const size_t *dims); + int ndims, const size_t *shape); /** diff --git a/src/dlite-bson.c b/src/dlite-bson.c index 174637b14..68ae99ceb 100644 --- a/src/dlite-bson.c +++ b/src/dlite-bson.c @@ -22,9 +22,9 @@ n += m; \ } while (0) -#define APPEND_PROPERTY(buf, p, dims, ptr) \ +#define APPEND_PROPERTY(buf, p, shape, ptr) \ do { \ - int m = append_property(buf, bufsize-n, p, dims, ptr); \ + int m = append_property(buf, bufsize-n, p, shape, ptr); \ if (m < 0) return m; \ n += m; \ } while (0) @@ -87,7 +87,7 @@ static BsonType bsontype(DLiteType dtype, size_t size) - bufsize: Size of memory segment pointed to by `buf`. No more than `bufsize` bytes will be written. - p: Property to append. - - dims: Values of property dimensions. + - shape: Values of property dimensions. - ptr: Pointer to data to serialise. Returns: @@ -95,7 +95,7 @@ static BsonType bsontype(DLiteType dtype, size_t size) A negative error code is returned on error. */ static int append_property(unsigned char *buf, int bufsize, - DLiteProperty *p, size_t *dims, void *ptr) + DLiteProperty *p, size_t *shape, void *ptr) { int n=0; int32_t i32; @@ -106,11 +106,11 @@ static int append_property(unsigned char *buf, int bufsize, float128_t f128; #endif - if (p->dims) { + if (p->shape) { /* Array - treated as binary using host byte order */ int i, nmemb=1; - for (i=0; i < p->ndims; i++) nmemb *= dims[i]; + for (i=0; i < p->ndims; i++) nmemb *= shape[i]; switch (p->type) { case dliteBlob: case dliteBool: @@ -349,7 +349,7 @@ int dlite_bson_append_instance(unsigned char *buf, int bufsize, for (j=0; j < p->ndims; j++) { char index[20]; snprintf(index, sizeof(index), "%d", j); - APPEND(arr, bsonString, index, -1, p->dims[j]); + APPEND(arr, bsonString, index, -1, p->shape[j]); } END_SUBDOC(prop, bsonArray); } @@ -373,9 +373,9 @@ int dlite_bson_append_instance(unsigned char *buf, int bufsize, BEGIN_SUBDOC(buf, "properties", &subdoc); for (i=0; i < inst->meta->_nproperties; i++) { DLiteProperty *p = inst->meta->_properties + i; - size_t *dims = DLITE_PROP_DIMS(inst, i); + size_t *shape = DLITE_PROP_DIMS(inst, i); void *ptr = dlite_instance_get_property_by_index(inst, i); - APPEND_PROPERTY(subdoc, p, dims, ptr); + APPEND_PROPERTY(subdoc, p, shape, ptr); } END_SUBDOC(buf, bsonDocument); } @@ -503,9 +503,9 @@ static int set_meta_dimensions(DLiteMeta *meta, unsigned char *subdoc) int ndims, i=0; TYPECHECK("shape", bsonArray); if ((ndims = bson_nelements(b)) < 0) return ndims; - p->dims = calloc(ndims, sizeof(char *)); + p->shape = calloc(ndims, sizeof(char *)); while ((type = bson_parse(b, NULL, (void **)&v, NULL, &ep))) - p->dims[i++] = strdup(v); + p->shape[i++] = strdup(v); p->ndims = ndims; } else if (strcmp(ename, "unit") == 0) { TYPECHECK("unit", bsonString); diff --git a/src/dlite-codegen.c b/src/dlite-codegen.c index 81d84dfca..503d7ed18 100644 --- a/src/dlite-codegen.c +++ b/src/dlite-codegen.c @@ -161,7 +161,7 @@ static int list_dims(TGenBuf *s, const char *template, int len, if (tgen_subs_copy(&psubs, subs)) goto fail; psubs.parent = subs; for (i=0; i < p->ndims; i++) { - tgen_subs_set(&psubs, "dim.name", p->dims[i] , NULL); + tgen_subs_set(&psubs, "dim.name", p->shape[i] , NULL); tgen_subs_set_fmt(&psubs, "dim.i", NULL, "%d", i); tgen_subs_set(&psubs, ",", (i < p->ndims-1) ? "," : "", NULL); tgen_subs_set(&psubs, ", ", (i < p->ndims-1) ? ", " : "", NULL); @@ -228,7 +228,7 @@ static int list_properties_helper(TGenBuf *s, const char *template, int len, tgen_subs_set(&psubs, "prop.ref", ref, NULL); tgen_subs_set(&psubs, "prop.unit", unit, NULL); tgen_subs_set(&psubs, "prop.descr", descr, NULL); - tgen_subs_set(&psubs, "prop.dims", NULL, list_dims); + tgen_subs_set(&psubs, "prop.shape", NULL, list_dims); tgen_subs_set_fmt(&psubs, "prop.typeno", NULL, "%d", p->type); tgen_subs_set_fmt(&psubs, "prop.size", NULL, "%u",(unsigned)p->size); tgen_subs_set_fmt(&psubs, "prop.ndims", NULL, "%d", p->ndims); diff --git a/src/dlite-collection.c b/src/dlite-collection.c index 9b8bbe77f..87a0c0ca7 100644 --- a/src/dlite-collection.c +++ b/src/dlite-collection.c @@ -222,8 +222,8 @@ int dlite_collection_saveprop(DLiteInstance *inst, size_t i) DLiteCollection *dlite_collection_create(const char *id) { DLiteMeta *meta = dlite_meta_get(DLITE_COLLECTION_ENTITY); - size_t dims[] = {0}; - return (DLiteCollection *)dlite_instance_create(meta, dims, id); + size_t dims[] = {0}; + return (DLiteCollection *)dlite_instance_create(meta, dims, id); } diff --git a/src/dlite-datamodel.c b/src/dlite-datamodel.c index ba7ddebc1..ded8ed9dd 100644 --- a/src/dlite-datamodel.c +++ b/src/dlite-datamodel.c @@ -117,9 +117,9 @@ int dlite_datamodel_get_dimension_size(const DLiteDataModel *d, */ int dlite_datamodel_get_property(const DLiteDataModel *d, const char *name, void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims) + size_t ndims, const size_t *shape) { - return d->api->getProperty(d, name, ptr, type, size, ndims, dims); + return d->api->getProperty(d, name, ptr, type, size, ndims, shape); } @@ -133,11 +133,11 @@ int dlite_datamodel_get_property(const DLiteDataModel *d, const char *name, */ int dlite_datamodel_set_property(DLiteDataModel *d, const char *name, const void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims) + size_t ndims, const size_t *shape) { if (!d->api->setProperty) return errx(1, "driver '%s' does not support set_property", d->api->name); - return d->api->setProperty(d, name, ptr, type, size, ndims, dims); + return d->api->setProperty(d, name, ptr, type, size, ndims, shape); } @@ -211,7 +211,7 @@ char *dlite_datamodel_get_dataname(DLiteDataModel *d) flat continuous C-ordered array \a dst. The size of dest must be sufficient large. Returns non-zero on error. */ int dlite_copy_to_flat(void *dst, const void *src, size_t size, - size_t ndims, const size_t *dims) + size_t ndims, const size_t *shape) { int i, n=0, ntot=1, retval=1, *ind=NULL; char *q=dst; @@ -221,16 +221,16 @@ int dlite_copy_to_flat(void *dst, const void *src, size_t size, FAILCODE(dliteMemoryError, "allocation failure"); for (i=0; i<(int)ndims-1; i++) p = p[ind[i]]; - for (i=0; i<(int)ndims; i++) ntot *= (dims) ? (int)dims[i] : 1; + for (i=0; i<(int)ndims; i++) ntot *= (shape) ? (int)shape[i] : 1; while (n++ < ntot) { memcpy(q, *p, size); p++; q += size; - if (++ind[ndims-1] >= ((dims) ? (int)dims[ndims-1] : 1)) { + if (++ind[ndims-1] >= ((shape) ? (int)shape[ndims-1] : 1)) { ind[ndims-1] = 0; for (i=ndims-2; i>=0; i--) { - if (++ind[i] < ((dims) ? (int)dims[i] : i)) + if (++ind[i] < ((shape) ? (int)shape[i] : i)) break; else ind[i] = 0; @@ -249,7 +249,7 @@ int dlite_copy_to_flat(void *dst, const void *src, size_t size, pointer to pointers array \a src. The size of dest must be sufficient large. Returns non-zero on error. */ int dlite_copy_to_nested(void *dst, const void *src, size_t size, - size_t ndims, const size_t *dims) + size_t ndims, const size_t *shape) { int i, n=0, ntot=1, *ind=NULL, retval=1; const char *q=src; @@ -259,16 +259,16 @@ int dlite_copy_to_nested(void *dst, const void *src, size_t size, FAILCODE(dliteMemoryError, "allocation failure"); for (i=0; i<(int)ndims-1; i++) p = p[ind[i]]; - for (i=0; i<(int)ndims; i++) ntot *= (dims) ? (int)dims[i] : 1; + for (i=0; i<(int)ndims; i++) ntot *= (shape) ? (int)shape[i] : 1; while (n++ < ntot) { memcpy(*p, q, size); p++; q += size; - if (++ind[ndims-1] >= ((dims) ? (int)dims[ndims-1] : 1)) { + if (++ind[ndims-1] >= ((shape) ? (int)shape[ndims-1] : 1)) { ind[ndims-1] = 0; for (i=ndims-2; i>=0; i--) { - if (++ind[i] < ((dims) ? (int)dims[i] : i)) + if (++ind[i] < ((shape) ? (int)shape[i] : i)) break; else ind[i] = 0; diff --git a/src/dlite-datamodel.h b/src/dlite-datamodel.h index d8fcb9fbc..7ff94e1c7 100644 --- a/src/dlite-datamodel.h +++ b/src/dlite-datamodel.h @@ -71,14 +71,14 @@ int dlite_datamodel_get_dimension_size(const DLiteDataModel *d, \param type Type of data elements. \param size Size of each data element. \param ndims Number of dimensions. - \param dims Array of dimension sizes of length \p ndims. + \param shape Array of dimension sizes of length \p ndims. Returns non-zero on error. @note The memory pointed to by \a ptr must be at least of size - size * dims[0] * ... * dims[ndim-1] + size * shape[0] * ... * shape[ndim-1] In contrast to the other data types, getting data of DTStringPtr type only writes (char *) pointers to the actual strings in memory @@ -88,7 +88,7 @@ int dlite_datamodel_get_dimension_size(const DLiteDataModel *d, */ int dlite_datamodel_get_property(const DLiteDataModel *d, const char *name, void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** @} */ @@ -116,7 +116,7 @@ int dlite_datamodel_get_property(const DLiteDataModel *d, const char *name, */ int dlite_datamodel_set_property(DLiteDataModel *d, const char *name, const void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** @@ -168,7 +168,7 @@ char *dlite_datamodel_get_dataname(DLiteDataModel *d); sufficient large. Returns non-zero on error. */ int dlite_copy_to_flat(void *dst, const void *src, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** Copies data from flat continuous C-ordered array `src` to nested @@ -176,7 +176,7 @@ int dlite_copy_to_flat(void *dst, const void *src, size_t size, sufficient large. Returns non-zero on error. */ int dlite_copy_to_nested(void *dst, const void *src, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** @} */ diff --git a/src/dlite-entity.c b/src/dlite-entity.c index 2dc1a4e41..7d941437a 100644 --- a/src/dlite-entity.c +++ b/src/dlite-entity.c @@ -258,7 +258,7 @@ void dlite_instance_debug(const DLiteInstance *inst) dlite_type_get_dtypename(p->type), (unsigned long)p->size); for (j=0, sep=""; j < p->ndims; j++, sep=", ") - fprintf(fp, "%s%s=%lu", sep, p->dims[j], + fprintf(fp, "%s%s=%lu", sep, p->shape[j], (unsigned long)DLITE_PROP_DIM(inst, i, j)); fprintf(fp, "]\n"); } @@ -389,7 +389,7 @@ static int _instance_propdims_eval(DLiteInstance *inst, const size_t *dims) int j; char errmsg[256] = ""; for (j=0; j < p->ndims; j++) - propdims[n++] = infixcalc(p->dims[j], vars, meta->_ndimensions, + propdims[n++] = infixcalc(p->shape[j], vars, meta->_ndimensions, errmsg, sizeof(errmsg)); if (errmsg[0]) FAILCODE1(dliteSyntaxError, "invalid property dimension expression: %s", errmsg); } @@ -460,7 +460,7 @@ static DLiteInstance *_instance_create(const DLiteMeta *meta, for (i=0; i_nproperties; i++) { DLiteProperty *p = DLITE_PROP_DESCR(inst, i); void **ptr = DLITE_PROP(inst, i); - if (p->ndims > 0 && p->dims) { + if (p->ndims > 0 && p->shape) { size_t nmemb=1, size=p->size; for (j=0; jndims; j++) nmemb *= DLITE_PROP_DIM(inst, i, j); @@ -575,7 +575,7 @@ static int dlite_instance_free(DLiteInstance *inst) for (i=0; i_properties + i; void *ptr = DLITE_PROP(inst, i); - if (p->ndims > 0 && p->dims) { + if (p->ndims > 0 && p->shape) { if (dlite_type_is_allocated(p->type)) { int j; size_t n, nmemb=1; @@ -1369,10 +1369,10 @@ int dlite_instance_get_property_ndims_by_index(const DLiteInstance *inst, } /* - Returns size of dimension `j` in property `i` or -1 on error. + Returns size of shape `j` in property `i` or -1 on error. */ -int dlite_instance_get_property_dimsize_by_index(const DLiteInstance *inst, - size_t i, size_t j) +int dlite_instance_get_property_shape_by_index(const DLiteInstance *inst, + size_t i, size_t j) { const DLiteProperty *p; if (!inst->meta) @@ -1480,7 +1480,7 @@ size_t dlite_instance_get_property_dimssize(const DLiteInstance *inst, if (!inst->meta) return errx(dliteMissingMetadataError, "no metadata available"); if ((i = dlite_meta_get_property_index(inst->meta, name)) < 0) return -1; - return dlite_instance_get_property_dimsize_by_index(inst, i, j); + return dlite_instance_get_property_shape_by_index(inst, i, j); } /* @@ -1561,15 +1561,15 @@ int dlite_instance_print_property_by_index(char *dest, size_t n, { void *ptr; const DLiteProperty *p; - size_t *dims; + size_t *shape; if (i >= inst->meta->_nproperties) return errx(dliteIndexError, "index %d exceeds number of properties (%d) in %s", (int)i, (int)inst->meta->_nproperties, inst->meta->uri); if (!(ptr = dlite_instance_get_property_by_index(inst, i))) return -1; if (!(p = dlite_meta_get_property_by_index(inst->meta, i))) return -1; - dims = DLITE_PROP_DIMS(inst, i); - assert(dims); - return dlite_property_print(dest, n, ptr, p, dims, width, prec, flags); + shape = DLITE_PROP_DIMS(inst, i); + assert(shape); + return dlite_property_print(dest, n, ptr, p, shape, width, prec, flags); } /* @@ -1604,15 +1604,15 @@ int dlite_instance_aprint_property_by_index(char **dest, size_t *n, { void *ptr; const DLiteProperty *p; - size_t *dims; + size_t *shape; if (i >= inst->meta->_nproperties) return errx(dliteIndexError, "index %d exceeds number of properties (%d) in %s", (int)i, (int)inst->meta->_nproperties, inst->meta->uri); if (!(ptr = dlite_instance_get_property_by_index(inst, i))) return -1; if (!(p = dlite_meta_get_property_by_index(inst->meta, i))) return -1; - dims = DLITE_PROP_DIMS(inst, i); - assert(dims); - return dlite_property_aprint(dest, n, pos, ptr, p, dims, width, prec, + shape = DLITE_PROP_DIMS(inst, i); + assert(shape); + return dlite_property_aprint(dest, n, pos, ptr, p, shape, width, prec, flags); } @@ -1643,15 +1643,15 @@ int dlite_instance_scan_property_by_index(const char *src, { void *ptr; const DLiteProperty *p; - const size_t *dims; + const size_t *shape; if (i >= inst->meta->_nproperties) return errx(dliteIndexError, "index %d exceeds number of properties (%d) in %s", (int)i, (int)inst->meta->_nproperties, inst->meta->uri); if (!(ptr = dlite_instance_get_property_by_index(inst, i))) return -1; if (!(p = dlite_meta_get_property_by_index(inst->meta, i))) return -1; - dims = DLITE_PROP_DIMS(inst, i); - assert(dims); - return dlite_property_scan(src, ptr, p, dims, flags); + shape = DLITE_PROP_DIMS(inst, i); + assert(shape); + return dlite_property_scan(src, ptr, p, shape, flags); } @@ -1926,20 +1926,20 @@ dlite_instance_get_property_array_by_index(const DLiteInstance *inst, { void *ptr; int ndims=1; - size_t dim=1, *dims=&dim; + size_t dim=1, *shape=&dim; DLiteProperty *p = DLITE_PROP_DESCR(inst, i); DLiteArray *arr = NULL; if (!(ptr = dlite_instance_get_property_by_index(inst, i))) goto fail; if (p->ndims > 0) { int j; - if (!(dims = malloc(p->ndims*sizeof(size_t)))) goto fail; + if (!(shape = malloc(p->ndims*sizeof(size_t)))) goto fail; ndims = p->ndims; for (j=0; j < p->ndims; j++) - dims[j] = DLITE_PROP_DIM(inst, i, j); + shape[j] = DLITE_PROP_DIM(inst, i, j); } - arr = dlite_array_create_order(ptr, p->type, p->size, ndims, dims, order); + arr = dlite_array_create_order(ptr, p->type, p->size, ndims, shape, order); fail: - if (dims && dims != &dim) free(dims); + if (shape && shape != &dim) free(shape); return arr; } @@ -1996,7 +1996,7 @@ int dlite_instance_copy_property_by_index(const DLiteInstance *inst, int i, DLiteArray *arr = dlite_instance_get_property_array(inst, p->name, order); if (!arr) return 1; retval = dlite_instance_cast_property_by_index(inst, i, p->type, p->size, - arr->dims, arr->strides, + arr->shape, arr->strides, dest, NULL); dlite_array_free(arr); return retval; @@ -2006,7 +2006,7 @@ int dlite_instance_copy_property_by_index(const DLiteInstance *inst, int i, /* Copies and possible type-cast value of property number `i` to memory pointed to by `dest` using `castfun`. The destination memory is - described by arguments `type`, `size` `dims` and `strides`. It must + described by arguments `type`, `size` `shape` and `strides`. It must be large enough to hole all the data. If `castfun` is NULL, it defaults to dlite_type_copy_cast(). @@ -2017,7 +2017,7 @@ int dlite_instance_cast_property_by_index(const DLiteInstance *inst, int i, DLiteType type, size_t size, - const size_t *dims, + const size_t *shape, const int *strides, void *dest, DLiteTypeCast castfun) @@ -2026,7 +2026,7 @@ int dlite_instance_cast_property_by_index(const DLiteInstance *inst, DLiteProperty *p = inst->meta->_properties + i; size_t *sdims = DLITE_PROP_DIMS(inst, i); return dlite_type_ndcast(p->ndims, - dest, type, size, dims, strides, + dest, type, size, shape, strides, src, p->type, p->size, sdims, NULL, castfun); } @@ -2052,7 +2052,7 @@ int dlite_instance_assign_property(const DLiteInstance *inst, const char *name, return 1; retval = dlite_instance_assign_casted_property_by_index(inst, i, p->type, p->size, - arr->dims, arr->strides, + arr->shape, arr->strides, src, NULL); dlite_array_free(arr); return retval; @@ -2062,7 +2062,7 @@ int dlite_instance_assign_property(const DLiteInstance *inst, const char *name, /* Assigns property `i` by copying and possible type-cast memory pointed to by `src` using `castfun`. The memory pointed to by `src` - is described by arguments `type`, `size` `dims` and `strides`. + is described by arguments `type`, `size` `shape` and `strides`. If `castfun` is NULL, it defaults to dlite_type_copy_cast(). @@ -2072,17 +2072,17 @@ int dlite_instance_assign_casted_property_by_index(const DLiteInstance *inst, int i, DLiteType type, size_t size, - const size_t *dims, + const size_t *shape, const int *strides, const void *src, DLiteTypeCast castfun) { void *dest = dlite_instance_get_property_by_index(inst, i); DLiteProperty *p = inst->meta->_properties + i; - size_t *ddims = DLITE_PROP_DIMS(inst, i); + size_t *dims = DLITE_PROP_DIMS(inst, i); return dlite_type_ndcast(p->ndims, - dest, p->type, p->size, ddims, NULL, - src, type, size, dims, strides, + dest, p->type, p->size, dims, NULL, + src, type, size, shape, strides, castfun); } @@ -3005,11 +3005,11 @@ DLiteProperty *dlite_property_create(const char *name, void dlite_property_clear(DLiteProperty *prop) { int i; - for (i=0; i < prop->ndims; i++) free(prop->dims[i]); - if (prop->name) free(prop->name); - if (prop->ref) free(prop->ref); - if (prop->dims) free(prop->dims); - if (prop->unit) free(prop->unit); + for (i=0; i < prop->ndims; i++) free(prop->shape[i]); + if (prop->name) free(prop->name); + if (prop->ref) free(prop->ref); + if (prop->shape) free(prop->shape); + if (prop->unit) free(prop->unit); if (prop->description) free(prop->description); memset(prop, 0, sizeof(DLiteProperty)); } @@ -3028,9 +3028,9 @@ void dlite_property_free(DLiteProperty *prop) */ int dlite_property_add_dim(DLiteProperty *prop, const char *expr) { - if (!(prop->dims = realloc(prop->dims, sizeof(char *)*(prop->ndims+1)))) + if (!(prop->shape = realloc(prop->shape, sizeof(char *)*(prop->ndims+1)))) goto fail; - if (!(prop->dims[prop->ndims] = strdup(expr))) goto fail; + if (!(prop->shape[prop->ndims] = strdup(expr))) goto fail; prop->ndims++; return 0; fail: @@ -3051,7 +3051,7 @@ int dlite_property_add_dim(DLiteProperty *prop, const char *expr) n size of `dest` pptr pointer to pointer to memory with the data to be written p property describing the data - dims array of property dimension values + shape array of property dimension values width printf() field width prec printf() precision @@ -3059,7 +3059,7 @@ int dlite_property_add_dim(DLiteProperty *prop, const char *expr) to `dest` if it is not big enough. Returns -1 on error. */ static int writedim(int d, char *dest, size_t n, const void **pptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, int width, int prec, DLiteTypeFlag flags) { int N=0, m; @@ -3071,11 +3071,11 @@ static int writedim(int d, char *dest, size_t n, const void **pptr, if (d < p->ndims) { if ((m = snprintf(dest+N, PDIFF(n, N), "%s", start)) < 0) goto fail; N += m; - for (i=0; i < dims[d]; i++) { - if ((m = writedim(d+1, dest+N, PDIFF(n, N), pptr, p, dims, + for (i=0; i < shape[d]; i++) { + if ((m = writedim(d+1, dest+N, PDIFF(n, N), pptr, p, shape, width, prec, flags)) < 0) return -1; N += m; - if (i < dims[d]-1) { + if (i < shape[d]-1) { if ((m = snprintf(dest+N, PDIFF(n, N), "%s", sep)) < 0) goto fail; N += m; } @@ -3098,9 +3098,9 @@ static int writedim(int d, char *dest, size_t n, const void **pptr, The pointer `ptr` should point to the memory where the data is stored. The meaning and layout of the data is described by property `p`. - The actual sizes of the property dimension is provided by `dims`. Use + The actual sizes of the property dimension is provided by `shape`. Use dlite_instance_get_property_dims_by_index() or the DLITE_PROP_DIMS macro - for accessing `dims`. + for accessing `shape`. No more than `n` bytes are written to `dest` (incl. the terminating NUL). Arrays will be written with a JSON-like syntax. @@ -3119,12 +3119,12 @@ static int writedim(int d, char *dest, size_t n, const void **pptr, negative value is returned. */ int dlite_property_print(char *dest, size_t n, const void *ptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, int width, int prec, DLiteTypeFlag flags) { if (flags == dliteFlagDefault) flags = dliteFlagQuoted; if (p->ndims) - return writedim(0, dest, n, &ptr, p, dims, width, prec, flags); + return writedim(0, dest, n, &ptr, p, shape, width, prec, flags); else return dlite_type_print(dest, n, ptr, p->type, p->size, width, prec, flags); } @@ -3138,14 +3138,14 @@ int dlite_property_print(char *dest, size_t n, const void *ptr, Returns number or bytes written or a negative number on error. */ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, int width, int prec, DLiteTypeFlag flags) { int m; void *q; size_t newsize; if (!dest && !*dest) *n = 0; - m = dlite_property_print(*dest + pos, PDIFF(*n, pos), ptr, p, dims, + m = dlite_property_print(*dest + pos, PDIFF(*n, pos), ptr, p, shape, width, prec, flags); if (m < 0) return m; /* failure */ if (m < (int)PDIFF(*n, pos)) return m; // success, buffer is large enough @@ -3155,7 +3155,7 @@ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, if (!(q = realloc(*dest, newsize))) return -1; *dest = q; *n = newsize; - m = dlite_property_print(*dest + pos, PDIFF(*n, pos), ptr, p, dims, + m = dlite_property_print(*dest + pos, PDIFF(*n, pos), ptr, p, shape, width, prec, flags); assert(0 <= m && m < (int)*n); return m; @@ -3171,13 +3171,13 @@ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, - src buffer to read from - pptr pointer to pointer to memory to write to - p property describing the data - - dims array of property dimension values + - shape array of property dimension values - t pointer to a jsmn token Returns zero on success and a negative number on error. */ static int scandim(int d, const char *src, void **pptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, DLiteTypeFlag flags, jsmntok_t **t) { int m; @@ -3185,12 +3185,12 @@ static int scandim(int d, const char *src, void **pptr, if (d < p->ndims) { if ((*t)->type != JSMN_ARRAY) return err(dliteValueError, "expected JSON array"); - if ((*t)->size != (int)dims[d]) + if ((*t)->size != (int)shape[d]) return err(dliteIndexError, "for dimension %d, expected %d elements, got %d", - d, (int)dims[d], (*t)->size); - for (i=0; i < dims[d]; i++) { + d, (int)shape[d], (*t)->size); + for (i=0; i < shape[d]; i++) { (*t)++; - if (scandim(d+1, src, pptr, p, dims, flags, t)) goto fail; + if (scandim(d+1, src, pptr, p, shape, flags, t)) goto fail; } } else { if ((m = dlite_type_scan(src+(*t)->start, (*t)->end-(*t)->start, *pptr, @@ -3301,11 +3301,11 @@ int scanobj(const char *src, const jsmntok_t *item, const char *key, if (t->type != JSMN_ARRAY) { dlite_property_clear(prop); return errx(dliteIndexError, - "property \"%.*s\": dims should be an array", + "property \"%.*s\": shape should be an array", keylen, key); } prop->ndims = t->size; - prop->dims = calloc(prop->ndims, sizeof(char *)); + prop->shape = calloc(prop->ndims, sizeof(char *)); for (j=0; j < prop->ndims; j++) { if (!(d = jsmn_element(src, t, j))) { dlite_property_clear(prop); @@ -3314,7 +3314,7 @@ int scanobj(const char *src, const jsmntok_t *item, const char *key, "\"%.*s\"", t->end - t->start, src + t->start, keylen, key); } - prop->dims[j] = strndup(src + d->start, d->end - d->start); + prop->shape[j] = strndup(src + d->start, d->end - d->start); } } @@ -3344,7 +3344,7 @@ int scanobj(const char *src, const jsmntok_t *item, const char *key, The property is described by `p`. For arrays, `ptr` should points to the first element and will not be - not dereferenced. Evaluated dimension sizes are given by `dims`. + not dereferenced. Evaluated dimension sizes are given by `shape`. The `flags` provides some format options. If zero (default) strings are expected to be quoted. @@ -3353,7 +3353,7 @@ int scanobj(const char *src, const jsmntok_t *item, const char *key, number on error. */ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, - const size_t *dims, DLiteTypeFlag flags) + const size_t *shape, DLiteTypeFlag flags) { if (p->ndims) { int r, n; @@ -3365,7 +3365,7 @@ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, r = jsmn_parse_alloc(&parser, src, strlen(src), &tokens, &ntokens); if (r < 0) return err(dliteValueError, "error parsing input: %s", jsmn_strerror(r)); t = tokens; - r = scandim(0, src, &q, p, dims, flags, &t); + r = scandim(0, src, &q, p, shape, flags, &t); n = tokens[0].end; free(tokens); if (r < 0) return r; @@ -3389,7 +3389,7 @@ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, For arrays, `ptr` should points to the first element and will not be not dereferenced. - p: DLite property describing the data to scan. - - dims: Evaluated shape of property to scan. + - shape: Evaluated shape of property to scan. - flags: Format options. If zero (default) strings are expected to be quoted. @@ -3398,7 +3398,7 @@ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, */ int dlite_property_jscan(const char *src, const jsmntok_t *item, const char *key, void *ptr, const DLiteProperty *p, - const size_t *dims, DLiteTypeFlag flags) + const size_t *shape, DLiteTypeFlag flags) { if (p->ndims) { void *q = ptr; @@ -3406,7 +3406,7 @@ int dlite_property_jscan(const char *src, const jsmntok_t *item, int len = item->end - item->start; switch (item->type) { case JSMN_ARRAY: - if (scandim(0, src, &q, p, dims, flags, &t)) return -1; + if (scandim(0, src, &q, p, shape, flags, &t)) return -1; break; case JSMN_OBJECT: return scanobj(src, item, key, ptr, p); @@ -3847,7 +3847,7 @@ DLiteMeta *dlite_meta_create_from_metamodel(DLiteMetaModel *model) const void *src; void *dest; DLiteProperty *p = model->meta->_properties + i; - size_t *dims = (p->ndims) ? DLITE_PROP_DIMS(meta, i) : NULL; + size_t *shape = (p->ndims) ? DLITE_PROP_DIMS(meta, i) : NULL; src = dlite_metamodel_get_property(model, p->name); dest = dlite_instance_get_property_by_index((DLiteInstance *)meta, i); @@ -3856,8 +3856,8 @@ DLiteMeta *dlite_meta_create_from_metamodel(DLiteMetaModel *model) } else if ((src != NULL) && (dest != NULL)) { if (dlite_type_ndcast(p->ndims, - dest, p->type, p->size, dims, NULL, - src, p->type, p->size, dims, NULL, + dest, p->type, p->size, shape, NULL, + src, p->type, p->size, shape, NULL, NULL)) goto fail; } else { goto fail; diff --git a/src/dlite-entity.h b/src/dlite-entity.h index acf625988..ed75858f7 100644 --- a/src/dlite-entity.h +++ b/src/dlite-entity.h @@ -307,7 +307,7 @@ struct _DLiteProperty { char *ref; /*!< Reference to metadata URI for type=dliteRef. */ int ndims; /*!< Number of dimension of the described data. Zero if scalar. */ - char **dims; /*!< Array of dimension strings. May be NULL. */ + char **shape; /*!< Array of dimension strings. May be NULL. */ char *unit; /*!< Unit of the described data. May be NULL. */ char *description; /*!< Human described of the described data. */ }; @@ -441,7 +441,7 @@ void dlite_instance_debug(const DLiteInstance *inst); Returns -1 on error. */ -size_t dlite_instance_size(const DLiteMeta *meta, const size_t *dims); +size_t dlite_instance_size(const DLiteMeta *meta, const size_t *shape); /** Returns a newly allocated NULL-terminated array of string pointers @@ -462,7 +462,7 @@ char** dlite_istore_get_uuids(int* nuuids); /** Returns a new dlite instance from Entiry `meta` and dimensions - `dims`. The lengths of `dims` is found in `meta->ndims`. + `dims`. The lengths of `dims` is found in `meta->_ndimensions`. The `id` argment may be NULL, a valid UUID or an unique identifier to this instance (e.g. an uri). In the first case, a random UUID @@ -712,10 +712,10 @@ int dlite_instance_get_property_ndims_by_index(const DLiteInstance *inst, size_t i); /** - Returns size of dimension `j` in property `i` or -1 on error. + Returns size of shape `j` in property `i` or -1 on error. */ -int dlite_instance_get_property_dimsize_by_index(const DLiteInstance *inst, - size_t i, size_t j); +int dlite_instance_get_property_shape_by_index(const DLiteInstance *inst, + size_t i, size_t j); /** Returns a malloc'ed array of dimensions of property `i` or NULL on error. @@ -895,9 +895,9 @@ int dlite_instance_sync_from_properties(DLiteInstance *inst); /** Updates the size of all dimensions in `inst`. The new dimension - sizes are provided in `dims`, which must be of length + sizes are provided in `shape`, which must be of length `inst->ndimensions`. Dimensions corresponding to negative elements - in `dims` will remain unchanged. + in `shape` will remain unchanged. All properties whos dimension are changed will be reallocated and new memory will be zeroed. The values of properties with two or @@ -991,7 +991,7 @@ int dlite_instance_copy_property_by_index(const DLiteInstance *inst, int i, /** Copies and possible type-cast value of property number `i` to memory pointed to by `dest` using `castfun`. The destination memory is - described by arguments `type`, `size` `dims` and `strides`. It must + described by arguments `type`, `size` `shape` and `strides`. It must be large enough to hole all the data. If `castfun` is NULL, it defaults to dlite_type_copy_cast(). @@ -1002,7 +1002,7 @@ int dlite_instance_cast_property_by_index(const DLiteInstance *inst, int i, DLiteType type, size_t size, - const size_t *dims, + const size_t *shape, const int *strides, void *dest, DLiteTypeCast castfun); @@ -1023,7 +1023,7 @@ int dlite_instance_assign_property(const DLiteInstance *inst, const char *name, /** Assigns property `i` by copying and possible type-cast memory pointed to by `src` using `castfun`. The memory pointed to by `src` - is described by arguments `type`, `size` `dims` and `strides`. + is described by arguments `type`, `size` `shape` and `strides`. If `castfun` is NULL, it defaults to dlite_type_copy_cast(). @@ -1033,7 +1033,7 @@ int dlite_instance_assign_casted_property_by_index(const DLiteInstance *inst, int i, DLiteType type, size_t size, - const size_t *dims, + const size_t *shape, const int *strides, const void *src, DLiteTypeCast castfun); @@ -1416,9 +1416,9 @@ int dlite_property_add_dim(DLiteProperty *prop, const char *expr); The pointer `ptr` should point to the memory where the data is stored. The meaning and layout of the data is described by property `p`. - The actual sizes of the property dimension is provided by `dims`. Use + The actual sizes of the property dimension is provided by `shape`. Use dlite_instance_get_property_dims_by_index() or the DLITE_PROP_DIMS macro - for accessing `dims`. + for accessing `shape`. No more than `n` bytes are written to `dest` (incl. the terminating NUL). Arrays will be written with a JSON-like syntax. @@ -1434,7 +1434,7 @@ int dlite_property_add_dim(DLiteProperty *prop, const char *expr); negative value is returned. */ int dlite_property_print(char *dest, size_t n, const void *ptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, int width, int prec, DLiteTypeFlag flags); /** @@ -1446,7 +1446,7 @@ int dlite_property_print(char *dest, size_t n, const void *ptr, Returns number or bytes written or a negative number on error. */ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, - const DLiteProperty *p, const size_t *dims, + const DLiteProperty *p, const size_t *shape, int width, int prec, DLiteTypeFlag flags); @@ -1456,7 +1456,7 @@ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, The property is described by `p`. For arrays, `ptr` should points to the first element and will not be - not dereferenced. Evaluated dimension sizes are given by `dims`. + not dereferenced. Evaluated dimension sizes are given by `shape`. The `flags` provides some format options. If zero (default) bools and strings are expected to be quoted. @@ -1465,7 +1465,7 @@ int dlite_property_aprint(char **dest, size_t *n, size_t pos, const void *ptr, number on error. */ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, - const size_t *dims, DLiteTypeFlag flags); + const size_t *shape, DLiteTypeFlag flags); /** @@ -1481,7 +1481,7 @@ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, For arrays, `ptr` should points to the first element and will not be not dereferenced. - p: DLite property describing the data to scan. - - dims: Evaluated shape of property to scan. + - shape: Evaluated shape of property to scan. - flags: Format options. If zero (default) strings are expected to be quoted. @@ -1490,7 +1490,7 @@ int dlite_property_scan(const char *src, void *ptr, const DLiteProperty *p, */ int dlite_property_jscan(const char *src, const jsmntok_t *item, const char *key, void *ptr, const DLiteProperty *p, - const size_t *dims, DLiteTypeFlag flags); + const size_t *shape, DLiteTypeFlag flags); /** @} */ diff --git a/src/dlite-json.c b/src/dlite-json.c index 2761408c8..554b9fcfb 100644 --- a/src/dlite-json.c +++ b/src/dlite-json.c @@ -104,9 +104,9 @@ int _dlite_json_sprint(char *dest, size_t size, const DLiteInstance *inst, char *c = (i < inst->meta->_nproperties - 1) ? "," : ""; DLiteProperty *p = inst->meta->_properties + i; void *ptr = dlite_instance_get_property_by_index(inst, i); - size_t *dims = DLITE_PROP_DIMS(inst, i); + size_t *shape= DLITE_PROP_DIMS(inst, i); PRINT2("%s \"%s\": ", in, p->name); - m = dlite_property_print(dest+n, PDIFF(size, n), ptr, p, dims, 0, -2, f); + m = dlite_property_print(dest+n, PDIFF(size, n), ptr, p, shape, 0, -2, f); if (m < 0) return -1; n += m; PRINT1("%s\n", c); @@ -147,7 +147,7 @@ int _dlite_json_sprint(char *dest, size_t size, const DLiteInstance *inst, PRINT1(",\n%s \"dims\": [", in); for (j=0; j < p->ndims; j++) { char *cc = (j < p->ndims - 1) ? ", " : ""; - PRINT2("\"%s\"%s", p->dims[j], cc); + PRINT2("\"%s\"%s", p->shape[j], cc); } PRINT("]"); } @@ -212,7 +212,7 @@ int _dlite_json_sprint(char *dest, size_t size, const DLiteInstance *inst, PRINT1(",\n%s \"shape\": [", in); for (j=0; j < p->ndims; j++) { char *cc = (j < p->ndims - 1) ? ", " : ""; - PRINT2("\"%s\"%s", p->dims[j], cc); + PRINT2("\"%s\"%s", p->shape[j], cc); } PRINT("]"); } diff --git a/src/dlite-schemas.c b/src/dlite-schemas.c index a94a8bd7e..26b6c615a 100644 --- a/src/dlite-schemas.c +++ b/src/dlite-schemas.c @@ -25,7 +25,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Schema name." /* description */ }, @@ -35,7 +35,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Schema version." /* description */ }, @@ -45,7 +45,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Schema namespace." /* description */ }, @@ -55,7 +55,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Description of schema." /* description */ }, @@ -65,7 +65,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(DLiteDimension), /* size */ NULL, /* ref */ 1, /* ndims */ - basic_metadata_schema_prop_dimensions_dims,/* dims */ + basic_metadata_schema_prop_dimensions_dims,/* shape */ NULL, /* unit */ "Schema dimensions." /* description */ }, @@ -75,7 +75,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(DLiteProperty), /* size */ NULL, /* ref */ 1, /* ndims */ - basic_metadata_schema_prop_properties_dims,/* dims */ + basic_metadata_schema_prop_properties_dims,/* shape */ NULL, /* unit */ "Schema properties." /* description */ }, @@ -85,7 +85,7 @@ static DLiteProperty basic_metadata_schema_properties[] = { sizeof(DLiteRelation), /* size */ NULL, /* ref */ 1, /* ndims */ - basic_metadata_schema_prop_relations_dims, /* dims */ + basic_metadata_schema_prop_relations_dims, /* shape */ NULL, /* unit */ "Schema relations." /* description */ } @@ -193,7 +193,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Entity name." /* description */ }, @@ -203,7 +203,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Entity version." /* description */ }, @@ -213,7 +213,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Entity namespace." /* description */ }, @@ -223,7 +223,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(char *), /* size */ NULL, /* ref */ 0, /* ndims */ - NULL, /* dims */ + NULL, /* shape */ NULL, /* unit */ "Description of entity." /* description */ }, @@ -233,7 +233,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(DLiteDimension), /* size */ NULL, /* ref */ 1, /* ndims */ - entity_schema_prop_dimensions_dims, /* dims */ + entity_schema_prop_dimensions_dims, /* shape */ NULL, /* unit */ "Entity dimensions." /* description */ }, @@ -243,7 +243,7 @@ static DLiteProperty entity_schema_properties[] = { sizeof(DLiteProperty), /* size */ NULL, /* ref */ 1, /* ndims */ - entity_schema_prop_properties_dims, /* dims */ + entity_schema_prop_properties_dims, /* shape */ NULL, /* unit */ "Entity properties." /* description */ } @@ -345,7 +345,7 @@ static DLiteProperty collection_entity_properties[] = { sizeof(DLiteRelation), /* size */ NULL, /* ref */ 1, /* ndims */ - collection_entity_prop_relations_dims, /* dims */ + collection_entity_prop_relations_dims, /* shape */ NULL, /* unit */ "Array of relations (s-p-o triples)." /* description */ } diff --git a/src/dlite-storage-plugins.h b/src/dlite-storage-plugins.h index 4a441d5aa..0909b321c 100644 --- a/src/dlite-storage-plugins.h +++ b/src/dlite-storage-plugins.h @@ -452,13 +452,13 @@ typedef int (*GetDimensionSize)(const DLiteDataModel *d, const char *name); The expected type, size, number of dimensions and size of each dimension of the memory is described by `type`, `size`, `ndims` and - `dims`, respectively. + `shape`, respectively. Returns non-zero on error. */ typedef int (*GetProperty)(const DLiteDataModel *d, const char *name, void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** @} */ @@ -488,13 +488,13 @@ typedef int (*SetDimensionSize)(DLiteDataModel *d, const char *name, The expected type, size, number of dimensions and size of each dimension of the memory is described by `type`, `size`, `ndims` and - `dims`, respectively. + `shape`, respectively. Returns non-zero on error. */ typedef int (*SetProperty)(DLiteDataModel *d, const char *name, const void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims); + size_t ndims, const size_t *shape); /** diff --git a/src/dlite-type.c b/src/dlite-type.c index da4c3530e..9a5179011 100644 --- a/src/dlite-type.c +++ b/src/dlite-type.c @@ -601,12 +601,12 @@ void *dlite_type_copy(void *dest, const void *src, DLiteType dtype, size_t size) d->ndims = s->ndims; if (d->ndims) { int i; - if (!(d->dims = malloc(d->ndims*sizeof(char *)))) + if (!(d->shape = malloc(d->ndims*sizeof(char *)))) return err(dliteMemoryError, "allocation failure"), NULL; for (i=0; indims; i++) - d->dims[i] = strdup(s->dims[i]); + d->shape[i] = strdup(s->shape[i]); } else { - d->dims = NULL; + d->shape = NULL; } d->unit = (s->unit) ? strdup(s->unit) : NULL; d->description = (s->description) ? strdup(s->description) : NULL; @@ -655,12 +655,12 @@ void *dlite_type_clear(void *p, DLiteType dtype, size_t size) case dliteProperty: free(((DLiteProperty *)p)->name); if (((DLiteProperty *)p)->ref) free(((DLiteProperty *)p)->ref); - if (((DLiteProperty *)p)->dims) { + if (((DLiteProperty *)p)->shape) { int i; for (i=0; i < ((DLiteProperty *)p)->ndims; i++) - if (((DLiteProperty *)p)->dims[i]) - free(((DLiteProperty *)p)->dims[i]); - free(((DLiteProperty *)p)->dims); + if (((DLiteProperty *)p)->shape[i]) + free(((DLiteProperty *)p)->shape[i]); + free(((DLiteProperty *)p)->shape); } if (((DLiteProperty *)p)->unit) free(((DLiteProperty *)p)->unit); if (((DLiteProperty *)p)->description) @@ -845,9 +845,9 @@ int dlite_type_print(char *dest, size_t n, const void *p, DLiteType dtype, "\"ndims\": %d", prop->name, typename, prop->ndims); if (prop->ndims) { - m += snprintf(dest+m, PDIFF(n, m), ", \"dims\": ["); + m += snprintf(dest+m, PDIFF(n, m), ", \"shape\": ["); for (i=0; i < prop->ndims; i++) - m += snprintf(dest+m, PDIFF(n, m), "\"%s\"%s", prop->dims[i], + m += snprintf(dest+m, PDIFF(n, m), "\"%s\"%s", prop->shape[i], (i < prop->ndims-1) ? ", " : ""); m += snprintf(dest+m, PDIFF(n, m), "]"); } @@ -1171,18 +1171,19 @@ int dlite_type_scan(const char *src, int len, void *p, DLiteType dtype, if ((t = jsmn_item(src, tokens, "$ref"))) prop->ref = strndup(src + t->start, t->end - t->start); - if ((t = jsmn_item(src, tokens, "dims"))) { + if ((t = jsmn_item(src, tokens, "shape")) || + (t = jsmn_item(src, tokens, "dims"))) { if (t->type != JSMN_ARRAY) return dlite_property_clear(prop), - errx(dliteParseError, "property dims should be an array"); + errx(dliteParseError, "property shape should be an array"); prop->ndims = t->size; - prop->dims = calloc(prop->ndims, sizeof(char *)); + prop->shape = calloc(prop->ndims, sizeof(char *)); for (i=0; i < prop->ndims; i++) { if (!(d = jsmn_element(src, t, i))) return dlite_property_clear(prop), err(dliteParseError, "error parsing property dimensions: %.*s", t->end - t->start, src + t->start); - prop->dims[i] = strndup(src + d->start, d->end - d->start); + prop->shape[i] = strndup(src + d->start, d->end - d->start); } } @@ -1302,7 +1303,7 @@ int dlite_type_update_sha3(sha3_context *c, const void *ptr, sha3_Update(c, &p->size, sizeof(size_t)); sha3_Update(c, &p->ndims, sizeof(int)); for (i=0; indims; i++) - sha3_Update(c, p->dims[i], strlen(p->dims[i])); + sha3_Update(c, p->shape[i], strlen(p->shape[i])); if (p->unit) sha3_Update(c, p->unit, strlen(p->unit)); //if (p->description) // sha3_Update(c, p->description, strlen(p->description)); diff --git a/src/dlite-type.h b/src/dlite-type.h index e02926430..f2ffc5416 100644 --- a/src/dlite-type.h +++ b/src/dlite-type.h @@ -10,7 +10,7 @@ data point). Note that the type (`dtype` and `size`) concerns a single data - point. The dimensionality (`ndims` and `dims`) of a property comes + point. The dimensionality (`ndims` and `shape`) of a property comes in addition and is not treated by the functions in this file. The properties can have most of the basic types found in C, with diff --git a/src/tests/test-entity.json b/src/tests/test-entity.json index 302c1446b..618a58db1 100644 --- a/src/tests/test-entity.json +++ b/src/tests/test-entity.json @@ -47,7 +47,7 @@ { "name": "myarray", "type": "int", - "dims": [ + "shape": [ "L", "M", "N" diff --git a/src/tests/test-read-data.json b/src/tests/test-read-data.json index a9a3b2068..e4df3baff 100644 --- a/src/tests/test-read-data.json +++ b/src/tests/test-read-data.json @@ -14,7 +14,7 @@ { "name": "P2", "type": "float", - "dims": ["N"], + "shape": ["N"], "description": "array" } ] diff --git a/src/tests/test_arrays.c b/src/tests/test_arrays.c index ab419f7f2..cf894887e 100644 --- a/src/tests/test_arrays.c +++ b/src/tests/test_arrays.c @@ -15,14 +15,14 @@ DLiteArray *arr; MU_TEST(test_array_create) { size_t i; - size_t ndims=2, dims[]={3, 4}; + size_t ndims=2, shape[]={3, 4}; for (i=0; indims); - printf("dims: [%2d, %2d]\n", (int)arr->dims[0], (int)arr->dims[1]); + printf("shape: [%2d, %2d]\n", (int)arr->shape[0], (int)arr->shape[1]); printf("strides: [%2d, %2d]\n", arr->strides[0], arr->strides[1]); printf("\n"); } @@ -85,8 +85,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, start, stop, NULL); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(2, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(2, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(4, a->strides[1]); mu_assert_int_eq(1, *((int *)dlite_array_vindex(a, 0, 0))); @@ -95,8 +95,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, NULL, NULL, step); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(2, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(2, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(8, a->strides[1]); mu_assert_int_eq(0, *((int *)dlite_array_vindex(a, 0, 0))); @@ -105,8 +105,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, start, NULL, step); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(2, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(2, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(8, a->strides[1]); mu_assert_int_eq(1, *((int *)dlite_array_vindex(a, 0, 0))); @@ -115,8 +115,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, NULL, stop, step); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(2, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(2, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(8, a->strides[1]); mu_assert_int_eq(0, *((int *)dlite_array_vindex(a, 0, 0))); @@ -127,8 +127,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, NULL, NULL, step); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(4, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(4, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(-4, a->strides[1]); mu_assert_int_eq(3, *((int *)dlite_array_vindex(a, 0, 0))); @@ -139,8 +139,8 @@ MU_TEST(test_array_slice) printf("\n"); a = dlite_array_slice(arr, start, NULL, step); - mu_assert_int_eq(3, a->dims[0]); - mu_assert_int_eq(4, a->dims[1]); + mu_assert_int_eq(3, a->shape[0]); + mu_assert_int_eq(4, a->shape[1]); mu_assert_int_eq(16, a->strides[0]); mu_assert_int_eq(-4, a->strides[1]); mu_assert_int_eq(3, *((int *)dlite_array_vindex(a, 0, 0))); @@ -160,13 +160,13 @@ MU_TEST(test_array_slice) dlite_array_printf(stdout, a, 2, 0); printf("ndims: %d\n", a->ndims); - printf("dims: [%2d, %2d]\n", (int)a->dims[0], (int)a->dims[1]); + printf("shape: [%2d, %2d]\n", (int)a->shape[0], (int)a->shape[1]); printf("strides: [%2d, %2d]\n", a->strides[0], a->strides[1]); printf("\n"); - mu_assert_int_eq(2, a->dims[0]); - mu_assert_int_eq(3, a->dims[1]); + mu_assert_int_eq(2, a->shape[0]); + mu_assert_int_eq(3, a->shape[1]); mu_assert_int_eq(32, a->strides[0]); mu_assert_int_eq(-4, a->strides[1]); mu_assert_int_eq(2, *((int *)dlite_array_vindex(a, 0, 0))); @@ -178,9 +178,9 @@ MU_TEST(test_array_slice) MU_TEST(test_array_reshape) { int ndims = 4; - size_t dims[] = {2, 1, 3, 2}; + size_t shape[] = {2, 1, 3, 2}; DLiteArray *a; - mu_check((a = dlite_array_reshape(arr, ndims, dims))); + mu_check((a = dlite_array_reshape(arr, ndims, shape))); mu_check(0 != dlite_array_is_continuous(a)); //printf("\nreshaped:\n"); //dlite_array_printf(stdout, a, -1, -1); diff --git a/src/tests/test_datamodel.c b/src/tests/test_datamodel.c index a893011ed..d340f026d 100644 --- a/src/tests/test_datamodel.c +++ b/src/tests/test_datamodel.c @@ -130,13 +130,13 @@ MU_TEST(test_bool_vec_property) MU_TEST(test_int_arr_property) { int v[2][3] = {{-4, 5, 7}, {42, 0, -13}}, w[2][3]; - size_t i, j, dims[] = {2, 3}; + size_t i, j, shape[] = {2, 3}; mu_check(dlite_datamodel_set_property(d, "myint", v, dliteInt, - sizeof(int), 2, dims) == 0); + sizeof(int), 2, shape) == 0); mu_check(dlite_datamodel_get_property(d, "myint", w, dliteInt, - sizeof(int), 2, dims) == 0); - for (i=0; itype); mu_assert_int_eq(4, tokens->size); - t = jsmn_item(js, tokens, "dims"); + t = jsmn_item(js, tokens, "shape"); mu_assert_int_eq(JSMN_ARRAY, t->type); mu_assert_int_eq(2, t->size); diff --git a/storages/hdf5/dh5lite.c b/storages/hdf5/dh5lite.c index 0aeac2b0c..0866a6eb0 100644 --- a/storages/hdf5/dh5lite.c +++ b/storages/hdf5/dh5lite.c @@ -99,19 +99,19 @@ static hid_t get_memtype(DLiteType type, size_t size) } -/* Returns the HDF5 data space identifier corresponding to `ndims` and `dims`. - If `dims` is NULL, length of all dimensions are assumed to be one. +/* Returns the HDF5 data space identifier corresponding to `ndims` and `shape`. + If ` shape` is NULL, length of all dimensions are assumed to be one. Returns -1 on error. On success, the returned identifier should be closed with H5Sclose(). */ -static hid_t get_space(size_t ndims, const size_t *dims) +static hid_t get_space(size_t ndims, const size_t *shape) { hid_t space=-1; hsize_t *hdims=NULL; size_t i; if (!(hdims = calloc(ndims, sizeof(hsize_t)))) return err(dliteMemoryError, "allocation failure"); - for (i=0; iproperties, name, ptr, type, size, ndims, dims); + return get_data(d, dh5->properties, name, ptr, type, size, ndims, shape); } @@ -627,18 +627,18 @@ int dh5_get_property(const DLiteDataModel *d, const char *name, void *ptr, int dh5_set_meta_uri(DLiteDataModel *d, const char *uri) { DH5DataModel *dh5 = (DH5DataModel *)d; - size_t dims[1]={1}; + size_t shape[1]={1}; char *name, *version, *namespace; if (dlite_split_meta_uri(uri, &name, &version, &namespace)) return 1; set_data(d, dh5->meta, "name", name, dliteFixString, - strlen(name), 1, dims); + strlen(name), 1, shape); set_data(d, dh5->meta, "version", version, dliteFixString, - strlen(version), 1, dims); + strlen(version), 1, shape); set_data(d, dh5->meta, "namespace", namespace, dliteFixString, - strlen(namespace), 1, dims); + strlen(namespace), 1, shape); free(name); free(version); @@ -653,11 +653,11 @@ int dh5_set_meta_uri(DLiteDataModel *d, const char *uri) int dh5_set_dimension_size(DLiteDataModel *d, const char *name, size_t size) { DH5DataModel *dh5 = (DH5DataModel *)d; - size_t dims[1]={1}; + size_t shape[1]={1}; int64_t dsize=size; return set_data(d, dh5->dimensions, name, &dsize, dliteInt, - sizeof(int64_t), 1, dims); + sizeof(int64_t), 1, shape); } @@ -667,10 +667,10 @@ int dh5_set_dimension_size(DLiteDataModel *d, const char *name, size_t size) */ int dh5_set_property(DLiteDataModel *d, const char *name, const void *ptr, DLiteType type, size_t size, - size_t ndims, const size_t *dims) + size_t ndims, const size_t *shape) { DH5DataModel *dh5 = (DH5DataModel *)d; - return set_data(d, dh5->properties, name, ptr, type, size, ndims, dims); + return set_data(d, dh5->properties, name, ptr, type, size, ndims, shape); } diff --git a/storages/json/dlite-json-storage.c b/storages/json/dlite-json-storage.c index 2741e7947..9472b33ed 100644 --- a/storages/json/dlite-json-storage.c +++ b/storages/json/dlite-json-storage.c @@ -94,7 +94,7 @@ DLiteStorage *json_open(const DLiteStoragePlugin *api, const char *uri, {'s', "uri-key", "false", "Whether to use uri as json key"}, {'u', "with-uuid", "false", "Whether to include uuid in output"}, {'M', "with-meta", "false", "Always include meta in output"}, - {'a', "arrays", "true", "Serialise metadata dims and props as arrays"}, + {'a', "arrays", "true", "Serialise metadata dimensions and properties as arrays"}, {'d', "as-data", "false", "Alias for `single=false` (deprecated)"}, {'c', "compact", "false", "Alias for `single` (deprecated)"}, {'U', "useid", "", "Unused (deprecated)"}, diff --git a/storages/python/python-storage-plugins/blob.py b/storages/python/python-storage-plugins/blob.py index f5bbdb4bc..fc50c3b60 100644 --- a/storages/python/python-storage-plugins/blob.py +++ b/storages/python/python-storage-plugins/blob.py @@ -23,7 +23,7 @@ def load(self, id): with open(self.uri, "rb") as f: content = f.read() meta = dlite.get_instance(metaid) - inst = meta(dims=[len(content)]) + inst = meta(dimensions=[len(content)]) inst.content = np.frombuffer(content, dtype="uint8") return inst diff --git a/storages/python/python-storage-plugins/csv.py b/storages/python/python-storage-plugins/csv.py index 5be33464f..e6adf1198 100644 --- a/storages/python/python-storage-plugins/csv.py +++ b/storages/python/python-storage-plugins/csv.py @@ -208,7 +208,7 @@ def infer_meta(data: pd.DataFrame, metauri: str, uri: str) -> dlite.Metadata: dlite.Property( name=name, type=type, - dims=col_shape, + shape=col_shape, unit=unit, description=None, ) diff --git a/storages/python/tests-c/Person.json b/storages/python/tests-c/Person.json index 329d13508..dd5f7b96b 100644 --- a/storages/python/tests-c/Person.json +++ b/storages/python/tests-c/Person.json @@ -25,7 +25,7 @@ { "name": "skills", "type": "string", - "dims": [ + "shape": [ "N" ], "description": "List of skills." diff --git a/storages/python/tests-python/input/test_meta.json b/storages/python/tests-python/input/test_meta.json index 59b23f7c0..c7dcca571 100644 --- a/storages/python/tests-python/input/test_meta.json +++ b/storages/python/tests-python/input/test_meta.json @@ -44,7 +44,7 @@ { "name": "myarray", "type": "int32", - "dims": ["L", "M", "N"], + "shape": ["L", "M", "N"], "description": "An array string pointer." } ] diff --git a/storages/python/tests-python/test_http.py b/storages/python/tests-python/test_http.py index d2a27d71d..2708745bd 100644 --- a/storages/python/tests-python/test_http.py +++ b/storages/python/tests-python/test_http.py @@ -1,3 +1,8 @@ +import os +import subprocess + +current_branch = 'master' + try: import requests except ModuleNotFoundError: @@ -7,10 +12,11 @@ import dlite -url = "https://raw.githubusercontent.com/SINTEF/dlite/master/storages/python/tests-python/input/test_meta.json" +url = f"https://raw.githubusercontent.com/SINTEF/dlite/{current_branch}/storages/python/tests-python/input/test_meta.json" meta = dlite.Instance.from_location("http", url) + assert str(meta) == """ { "uri": "http://onto-ns.com/meta/0.1/TestEntity", diff --git a/storages/python/tests-python/test_postgresql_storage_python.py b/storages/python/tests-python/test_postgresql_storage_python.py index 5a459b09f..83be9530c 100644 --- a/storages/python/tests-python/test_postgresql_storage_python.py +++ b/storages/python/tests-python/test_postgresql_storage_python.py @@ -210,15 +210,15 @@ def load_pgsql(data, uuid, dims_keys=None): for n in range(len(prop)): d['properties'].append({}) single_prop = prop[n] - dims = None + shape = None if single_prop[2] != '': - dims = single_prop[2:-3] + shape = single_prop[2:-3] single_prop[2:-3] = [''] for m in range(len(single_prop)): if single_prop[m] != '': d['properties'][n][keys[m]] = single_prop[m] - elif m == 2 and dims: - d['properties'][n]['dims'] = dims + elif m == 2 and shape: + d['properties'][n]['shape'] = shape if metadata: del d['dims'] diff --git a/storages/rdf/dlite-rdf.c b/storages/rdf/dlite-rdf.c index bbbd51db7..99b345ced 100644 --- a/storages/rdf/dlite-rdf.c +++ b/storages/rdf/dlite-rdf.c @@ -497,7 +497,7 @@ DLiteInstance *rdf_load_instance(const DLiteStorage *storage, const char *id) p->ndims++; shape = getobj(s, shape, _P ":hasNextShape", 0); } - p->dims = calloc(p->ndims, sizeof(char *)); + p->shape = calloc(p->ndims, sizeof(char *)); /* assign property dimensions */ i = 0; @@ -508,7 +508,7 @@ DLiteInstance *rdf_load_instance(const DLiteStorage *storage, const char *id) strncpy(buf, shape, sizeof(buf)); if (!(expr = getobj(s, buf, _P ":hasDimensionExpression", 1))) FAIL2("%s has no dimension expression: %s", t2->s, s->location); - p->dims[i++] = strdup(expr); + p->shape[i++] = strdup(expr); shape = getobj(s, buf, _P ":hasNextShape", 0); } p++; @@ -611,9 +611,9 @@ int rdf_save_instance(DLiteStorage *storage, const DLiteInstance *inst) if (p->description) triplestore_add_en(ts, b1, _P ":hasDescription", p->description); - if (p->dims) { + if (p->shape) { triplestore_add_uri(ts, b2, "rdf:type", _P ":Shape"); - triplestore_add(ts, b2, _P ":hasDimensionExpression", p->dims[0], + triplestore_add(ts, b2, _P ":hasDimensionExpression", p->shape[0], "xsd:string"); } for (j=1; j < p->ndims; j++) { @@ -622,7 +622,7 @@ int rdf_save_instance(DLiteStorage *storage, const DLiteInstance *inst) if (!(b = get_blank_node(ts, buf2))) goto fail; triplestore_add_uri(ts, b2, _P ":hasNextShape", b); triplestore_add_uri(ts, b, "rdf:type", _P ":Shape"); - triplestore_add(ts, b, _P ":hasDimensionExpression", p->dims[j], + triplestore_add(ts, b, _P ":hasDimensionExpression", p->shape[j], "xsd:string"); free(b2); b2 = b; @@ -651,14 +651,14 @@ int rdf_save_instance(DLiteStorage *storage, const DLiteInstance *inst) const DLiteProperty *p = dlite_meta_get_property_by_index(inst->meta, i); const void *ptr = dlite_instance_get_property_by_index(inst, i); const char *name = inst->meta->_properties[i].name; - const size_t *dims = DLITE_PROP_DIMS(inst, i); + const size_t *shape = DLITE_PROP_DIMS(inst, i); asnprintf(&buf, &bufsize, "%s/val_%s", inst->uuid, name); if (!(b1 = get_blank_node(ts, buf))) goto fail; triplestore_add_uri(ts, inst->uuid, _P ":hasPropertyValue", b1); triplestore_add_uri(ts, b1, "rdf:type", "owl:NamedIndividual"); triplestore_add_uri(ts, b1, "rdf:type", _P ":PropertyValue"); triplestore_add(ts, b1, _P ":hasLabel", name, "xsd:Name"); - dlite_property_aprint(&buf, &bufsize, 0, ptr, p, dims, 0, -2, + dlite_property_aprint(&buf, &bufsize, 0, ptr, p, shape, 0, -2, dliteFlagRaw | dliteFlagStrip); triplestore_add(ts, b1, _P ":hasValue", buf, "rdf:PlainLiteral"); free(b1); diff --git a/tools/templates/c-header.txt b/tools/templates/c-header.txt index 3084db39c..725bdbaca 100644 --- a/tools/templates/c-header.txt +++ b/tools/templates/c-header.txt @@ -70,8 +70,9 @@ typedef struct {{ char *name; DLiteType type; size_t size; + char *ref; int ndims; - char **dims, *unit, *description; + char **shape, *unit, *description; }} DLiteProperty; typedef void DLiteInstance; #define DLiteInstance_HEAD @@ -102,7 +103,7 @@ typedef struct _{name%M} {{ /* -- dimension values */ {list_dimensions: size_t {dim.name}; {@30}/*!< {dim.descr} */\n} /* -- property values */ -{list_properties: {prop.cdecl}; {@30}/*!< {prop.descr} {@if:{prop.ndims}!0}; [{prop.dims:{dim.name}{,}\.}]{@endif} */\n} \ +{list_properties: {prop.cdecl}; {@30}/*!< {prop.descr} {@if:{prop.ndims}!0}; [{prop.shape:{dim.name}{,}\.}]{@endif} */\n} \ {@if:{_nrelations}!0} /* -- relation values */ DLiteRelation __relations[{_nrelations}]; diff --git a/tools/templates/c-meta-header.txt b/tools/templates/c-meta-header.txt index 1f5dc70ef..b04c7a7ca 100644 --- a/tools/templates/c-meta-header.txt +++ b/tools/templates/c-meta-header.txt @@ -85,7 +85,7 @@ typedef struct {{ DLiteType type; size_t size; int ndims; - char **dims, *unit, *description; + char **shape, *unit, *description; }} DLiteProperty; typedef void DLiteInstance; #define DLiteInstance_HEAD @@ -116,7 +116,7 @@ typedef struct _{struct_name} {{ /* -- dimension values */ {list_meta_dimensions: size_t {dim.name};{@30}/*!< {dim.descr} */\n} /* -- property values */ -{list_meta_properties: {prop.cdecl};{@30}/*!< {prop.descr} {@if:{prop.ndims}!0}; [{prop.dims:{dim.name}{,}\.}]{@endif} */\n} \ +{list_meta_properties: {prop.cdecl};{@30}/*!< {prop.descr} {@if:{prop.ndims}!0}; [{prop.shape:{dim.name}{,}\.}]{@endif} */\n} \ {@if:{_nrelations}!0} /* -- relation values */ DLiteRelation __relations[{_nrelations}]; diff --git a/tools/templates/c-source.txt b/tools/templates/c-source.txt index da3379e4c..70caacbca 100644 --- a/tools/templates/c-source.txt +++ b/tools/templates/c-source.txt @@ -88,7 +88,7 @@ static DLiteDimension {name%u}_dimensions[] = {{ {list_properties:\ {@if:{prop.ndims}!0}\ static char *{name%u}_prop_{prop.name}_dims[] = {{\ -{prop.dims:"{dim.name}"{, }\.}\ +{prop.shape:"{dim.name}"{, }\.}\ }}; {@endif}\.}\ @@ -100,9 +100,9 @@ static DLiteProperty {name%u}_properties[] = {{ {prop.ref}, {@40}/* ref */ {prop.ndims}, {@40}/* ndims */ {@if:{prop.ndims}=0}\ - NULL, {@40}/* dims */ + NULL, {@40}/* shape */ {@else}\ - {name%u}_prop_{prop.name}_dims, {@40}/* dims */ + {name%u}_prop_{prop.name}_dims, {@40}/* shape */ {@endif}\ {@if:"{prop.unit}"}\ "{prop.unit}", {@40}/* unit */ diff --git a/tools/templates/fortran-module.txt b/tools/templates/fortran-module.txt index b3d9d725c..425894d39 100644 --- a/tools/templates/fortran-module.txt +++ b/tools/templates/fortran-module.txt @@ -39,8 +39,8 @@ module {name} ! -- property values {list_properties:\ {@6}{prop.ftype}{@if:{prop.ndims}!0}, allocatable{@endif}\ -{@40}:: {prop.name}{@if:{prop.ndims}!0}({prop.dims::{,}\.}){@endif}\ - ! {prop.descr} {@if:{prop.ndims}!0} [{prop.dims:{dim.name}{,}\.}]{@endif}\n} +{@40}:: {prop.name}{@if:{prop.ndims}!0}({prop.shape::{,}\.}){@endif}\ + ! {prop.descr} {@if:{prop.ndims}!0} [{prop.shape:{dim.name}{,}\.}]{@endif}\n} contains procedure :: check => check procedure :: writeToURL => writeToURL @@ -76,7 +76,7 @@ module {name} i = model%add_string('description', '{descr}') {list_dimensions:{@6}i = model%add_dimension('{dim.name}', '{dim.descr}')\n} {list_properties:{@6}i = model%add_property('{prop.name}', '{prop.typename}', '{prop.unit}', '{prop.descr}')\ -{@if:{prop.ndims}!0}\n{prop.dims:{@6}i = model%add_property_dim('{prop.name}', '{dim.name}')\n}{@endif}\n} +{@if:{prop.ndims}!0}\n{prop.shape:{@6}i = model%add_property_dim('{prop.name}', '{dim.name}')\n}{@endif}\n} meta_{name%c} = DLiteMeta(model) call model%destroy() endif @@ -90,7 +90,7 @@ module {name} {name%c}%instance%cinst = c_null_ptr {name%c}%uuid(:) = ' ' {list_dimensions:{@4}{name%c}%{dim.name} = {dim.name}\n} -{list_properties:{@4}! {prop.name}\n{@if:{prop.ndims}!0}{@4}allocate({name%c}%{prop.name}({prop.dims:{dim.name}{,}\.}))\n{@endif}\ } +{list_properties:{@4}! {prop.name}\n{@if:{prop.ndims}!0}{@4}allocate({name%c}%{prop.name}({prop.shape:{dim.name}{,}\.}))\n{@endif}\ } end function create32 {@if:{_ndimensions}>0} function create64({list_dimensions:{dim.name}{, }\.}) result({name%c}) @@ -101,14 +101,14 @@ module {name} {name%c}%instance%cinst = c_null_ptr {name%c}%uuid(:) = ' ' {list_dimensions:{@4}{name%c}%{dim.name} = {dim.name}\n} -{list_properties:{@4}! {prop.name}\n{@if:{prop.ndims}!0}{@4}allocate({name%c}%{prop.name}({prop.dims:{dim.name}{,}\.}))\n{@endif}\ } +{list_properties:{@4}! {prop.name}\n{@if:{prop.ndims}!0}{@4}allocate({name%c}%{prop.name}({prop.shape:{dim.name}{,}\.}))\n{@endif}\ } end function create64 {@endif} subroutine readFromInstance({name%c}, instance) class(T{name}) :: {name%c} type(DLiteInstance), intent(in) :: instance {@if:{_ndimensions}>0}{@3}type(c_ptr){@42}:: cptr{@endif} - {@if:{_ndimensions}>0}{@3}integer(8), dimension(*), allocatable :: dims(:){@endif} + {@if:{_ndimensions}>0}{@3}integer(8), dimension(*), allocatable :: shape(:){@endif} {@if:{have_fixstring_arr}\.}\ integer(8) :: strlen, nstring, i {@endif}\ @@ -119,7 +119,7 @@ module {name} {@elif:({prop.typeno}=5)&({prop.ndims}=1)}\ {@4}character(kind=c_char), pointer {@42}:: {prop.name}_p(:,:)\n\ {@elif:{prop.ndims}!0}\ -{@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p({prop.dims::{,}\.})\n\ +{@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p({prop.shape::{,}\.})\n\ {@else}\ {@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p\n\ {@endif}\ } @@ -134,8 +134,8 @@ module {name} {@6}call c_f_string(instance%get_property_by_index({prop.i}), {name%c}%{prop.name})\n\ {@elif:({prop.typeno}=5)&({prop.ndims}=1)}\ {@6}cptr = instance%get_property_by_index({prop.i})\n\ -{@6}call instance%get_property_dims_by_index({prop.i}, dims)\n\ -{@6}nstring = dims(1)\n\ +{@6}call instance%get_property_dims_by_index({prop.i}, shape)\n\ +{@6}nstring = shape(1)\n\ {@6}strlen = {prop.size}\n\ {@6}call c_f_pointer(cptr, {prop.name}_p, [strlen, nstring])\n\ {@6}allocate({name%c}%{prop.name}(nstring))\n\ @@ -144,8 +144,8 @@ module {name} {@6}end do {@elif:{prop.ndims}!0}\ {@6}cptr = instance%get_property_by_index({prop.i})\n\ -{@6}call instance%get_property_dims_by_index({prop.i}, dims, .true.)\n\ -{@6}call c_f_pointer(cptr, {prop.name}_p, dims)\n\ +{@6}call instance%get_property_dims_by_index({prop.i}, shape, .true.)\n\ +{@6}call c_f_pointer(cptr, {prop.name}_p, shape)\n\ {@else}\ {@6}cptr = instance%get_property_by_index({prop.i})\n\ {@6}call c_f_pointer(cptr, {prop.name}_p)\n\ @@ -171,7 +171,7 @@ module {name} {@if:{prop.typeno}=5}\ {@4}! {prop.isoctype} {@42}:: {prop.name}\n\ {@elif:{prop.ndims}!0}\ -{@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p({prop.dims::{,}\.})\n\ +{@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p({prop.shape::{,}\.})\n\ {@else}\ {@4}{prop.isoctype}, pointer {@42}:: {prop.name}_p\n\ {@endif}\ } diff --git a/tools/tests/Chemistry-0.1.json b/tools/tests/Chemistry-0.1.json index ef79a4e6b..1c3cfa061 100644 --- a/tools/tests/Chemistry-0.1.json +++ b/tools/tests/Chemistry-0.1.json @@ -23,7 +23,7 @@ { "name": "elements", "type": "string", - "dims": [ + "shape": [ "nelements" ], "description": "Chemical symbol of each chemical element. By convension the dependent element (e.g. Al) is listed first." @@ -31,7 +31,7 @@ { "name": "phases", "type": "string", - "dims": [ + "shape": [ "nphases" ], "description": "Name of each phase." @@ -40,7 +40,7 @@ "name": "X0", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nelements" ], "description": "Nominal composition. Should sum to one." @@ -49,7 +49,7 @@ "name": "Xp", "type": "double", "unit": "atom-fraction", - "dims": [ + "shape": [ "nphases", "nelements" ], @@ -58,7 +58,7 @@ { "name": "volfrac", "type": "double", - "dims": [ + "shape": [ "nphases" ], "description": "Volume fraction of each phase, excluding matrix." @@ -67,7 +67,7 @@ "name": "rpart", "type": "double", "unit": "m", - "dims": [ + "shape": [ "nphases" ], "description": "Average particle radius of each phase, excluding matrix." @@ -76,7 +76,7 @@ "name": "atvol", "type": "double", "unit": "m^3", - "dims": [ + "shape": [ "nphases" ], "description": "Average volume per atom for each phase."