Main Content

isPartitionable

Determine whether datastore is partitionable

Description

example

tf = isPartitionable(ds) returns logical 1 (true) if the datastore ds is partitionable. Otherwise, the result is logical 0 (false).

  • TransformedDatastore is partitionable if all underlying datastores are partitionable.

  • CombinedDatastore is partitionable if all underlying datastores have a subset method or are transformations/combinations of datastores that have subset methods.

  • Custom datastore classes are partitionable if they subclass from matlab.io.datastore.Partitionable.

You can use the partition function on partitionable datastores to create partitions for parallel processing with Parallel Computing Toolbox™.

Examples

collapse all

Create a TabularTextDatastore, and then write an if/else statement that partitions the datastore only if it is partitionable.

ttds = tabularTextDatastore('outages.csv');
if isPartitionable(ttds)
    newds = partition(ttds,3,1);
    disp('Partitioning successful.')
else 
    disp('Datastore is not partitionable.')
end
Partitioning successful.

Now create a CombinedDatastore object comprised of two copies of ttds. Use the same if/else test to partition the datastore.

cds = combine(ttds,ttds);
if isPartitionable(cds)
    newds = partition(cds,3,1);
    disp('Partitioning successful.')
else 
    disp('Datastore is not partitionable.')
end
Datastore is not partitionable.

In this case, the combined datastore cds is not partitionable because the underlying TabularTextDatastore objects do not have subset methods.

Create another CombinedDatastore object, but this time construct it out of ImageDatastore objects. In this case the combined datastore is partitionable because the underlying ImageDatastore objects have subset methods.

imageFiles = {'street1.jpg','street2.jpg','peppers.png','corn.tif'};
imds = imageDatastore(imageFiles);
cds = combine(imds,imds);
if isPartitionable(cds)
    newds = partition(cds,3,1);
    disp('Partitioning successful.')
else 
    disp('Datastore is not partitionable.')
end
Partitioning successful.

Input Arguments

collapse all

Input datastore. You can use these datastores as input:

  • MATLAB® datastores — Datastores created using MATLAB datastore functions. For example, create a datastore for a collection of images using ImageDatastore. For a complete list of datastores, see Select Datastore for File Format or Application.

  • Combined and transformed datastores — Datastores created using the combine and transform functions.

  • Custom datastores — Datastores created using the custom datastore framework. Any datastore that subclasses from matlab.io.Datastore supports the isPartitionable function. See Develop Custom Datastore for more information.

Introduced in R2020a