Core Plot (iOS and tvOS)
Cocoa plotting framework for macOS, iOS, and tvOS
CPTNumericData Class Reference

An annotated NSData type. More...

#import <CPTNumericData.h>

+ Inheritance diagram for CPTNumericData:
+ Collaboration diagram for CPTNumericData:

Public Class Methods

Factory Methods
(nonnull instancetype) + numericDataWithData:dataType:shape:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithData:dataTypeString:shape:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithArray:dataType:shape:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithArray:dataTypeString:shape:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithData:dataType:shape:dataOrder:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithData:dataTypeString:shape:dataOrder:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithArray:dataType:shape:dataOrder:
 Creates and returns a new CPTNumericData instance. More...
 
(nonnull instancetype) + numericDataWithArray:dataTypeString:shape:dataOrder:
 Creates and returns a new CPTNumericData instance. More...
 
- Public Class Methods inherited from NSObject
(id+ alloc
 
(Class+ class
 
(void) + initialize
 
(void) + load
 
(id+ new
 
- Public Class Methods inherited from <NSSecureCoding>
(BOOL+ supportsSecureCoding:
 

Public Instance Methods

Initialization
(nonnull instancetype) - initWithData:dataType:shape:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithData:dataTypeString:shape:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithArray:dataType:shape:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithArray:dataTypeString:shape:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithData:dataType:shape:dataOrder:
 Initializes a newly allocated CPTNumericData object with the provided data. This is the designated initializer. More...
 
(nonnull instancetype) - initWithData:dataTypeString:shape:dataOrder:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithArray:dataType:shape:dataOrder:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nonnull instancetype) - initWithArray:dataTypeString:shape:dataOrder:
 Initializes a newly allocated CPTNumericData object with the provided data. More...
 
(nullable instancetype) - initWithCoder:
 Returns an object initialized from data in a given unarchiver. More...
 
Samples
(NSUInteger- sampleIndex:
 Gets the offset of a given sample in the data buffer. More...
 
(nullable const void *) - samplePointer:
 Gets a pointer to a given sample in the data buffer. More...
 
(nullable const void *) - samplePointerAtIndex:
 Gets a pointer to a given sample in the data buffer. More...
 
(nullable NSNumber *) - sampleValue:
 Gets the value of a given sample in the data buffer. More...
 
(nullable NSNumber *) - sampleValueAtIndex:
 Gets the value of a given sample in the data buffer. More...
 
(nonnull CPTNumberArray *) - sampleArray
 Gets an array data samples from the receiver. More...
 
Type Conversion
(nonnull CPTNumericData *) - dataByConvertingToDataType:
 Copies the current numeric data and converts the data to a new data type. More...
 
(nonnull CPTNumericData *) - dataByConvertingToType:sampleBytes:byteOrder:
 Copies the current numeric data and converts the data to a new data type. More...
 
Data Conversion Utilities
(void) - convertData:dataType:toData:dataType:
 Copies a data buffer and converts the data to a new data type without changing the byte order. More...
 
(void) - swapByteOrderForData:sampleSize:
 Swaps the byte order for each sample stored in a data buffer. More...
 
- Public Instance Methods inherited from NSObject
(Class- classForCoder
 
(id- copy
 
(void) - dealloc
 
(void) - finalize
 
(id- init
 
(id- mutableCopy
 
- Public Instance Methods inherited from <NSObject>
(NSString *) - description
 
(NSUInteger- hash
 
(BOOL- isEqual:
 
- Public Instance Methods inherited from <NSCopying>
(id- copyWithZone:
 
- Public Instance Methods inherited from <NSMutableCopying>
(id- mutableCopyWithZone:
 
- Public Instance Methods inherited from <NSCoding>
(id- initWithCoder:
 
(void) - encodeWithCoder:
 

Properties

Data Buffer
NSDatadata
 The data buffer. More...
 
const void * bytes
 Returns a pointer to the data buffer’s contents. More...
 
NSUInteger length
 Returns the number of bytes contained in the data buffer. More...
 
Data Format
CPTNumericDataType dataType
 The type of data stored in the data buffer. More...
 
CPTDataTypeFormat dataTypeFormat
 The format of the data stored in the data buffer. More...
 
size_t sampleBytes
 The number of bytes in a single sample of data. More...
 
CFByteOrder byteOrder
 The byte order used to store each sample in the data buffer. More...
 
Dimensions
CPTNumberArrayshape
 The shape of the data buffer array. More...
 
NSUInteger numberOfDimensions
 The number dimensions in the data buffer array. More...
 
NSUInteger numberOfSamples
 The number of samples of dataType stored in the data buffer. More...
 
CPTDataOrder dataOrder
 The order that numbers are stored in a multi-dimensional data array. More...
 

Detailed Description

An annotated NSData type.

CPTNumericData combines a data buffer with information about the data (shape, data type, size, etc.). The data is assumed to be an array of one or more dimensions of a single type of numeric data. Each numeric value in the array, which can be more than one byte in size, is referred to as a “sample”. The structure of this object is similar to the NumPy ndarray object.

The supported data types are:

  • 1, 2, 4, and 8-byte signed integers
  • 1, 2, 4, and 8-byte unsigned integers
  • float and double floating point numbers
  • float complex and double complex floating point complex numbers
  • NSDecimal base-10 numbers

All integer and floating point types can be represented using big endian or little endian byte order. Complex and decimal types support only the the host system’s native byte order.

Method Documentation

◆ convertData:dataType:toData:dataType:

- (void) convertData: (nonnull NSData *)  sourceData
dataType: (nonnull CPTNumericDataType *)  sourceDataType
toData: (nonnull NSMutableData *)  destData
dataType: (nonnull CPTNumericDataType *)  destDataType 

Copies a data buffer and converts the data to a new data type without changing the byte order.

The data is assumed to be in host byte order and no byte order conversion is performed.

Parameters
sourceDataThe source data buffer.
sourceDataTypeThe data type of the source.
destDataThe destination data buffer.
destDataTypeThe new data type.

Provided by category CPTNumericData(TypeConversion).

◆ dataByConvertingToDataType:

- (nonnull CPTNumericData *) dataByConvertingToDataType: (CPTNumericDataType newDataType

Copies the current numeric data and converts the data to a new data type.

Parameters
newDataTypeThe new data type.
Returns
A copy of the current numeric data converted to the new data type.

Provided by category CPTNumericData(TypeConversion).

◆ dataByConvertingToType:sampleBytes:byteOrder:

- (nonnull CPTNumericData *) dataByConvertingToType: (CPTDataTypeFormat newDataType
sampleBytes: (size_t)  newSampleBytes
byteOrder: (CFByteOrder newByteOrder 

Copies the current numeric data and converts the data to a new data type.

Parameters
newDataTypeThe new data type format.
newSampleBytesThe number of bytes used to store each sample.
newByteOrderThe new byte order.
Returns
A copy of the current numeric data converted to the new data type.

Provided by category CPTNumericData(TypeConversion).

◆ initWithArray:dataType:shape:

- (nonnull instancetype) initWithArray: (nonnull CPTNumberArray *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray 

Initializes a newly allocated CPTNumericData object with the provided data.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataType and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
The initialized CPTNumericData instance.

◆ initWithArray:dataType:shape:dataOrder:

- (nonnull instancetype) initWithArray: (nonnull CPTNumberArray *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Initializes a newly allocated CPTNumericData object with the provided data.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataType and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
The initialized CPTNumericData instance.

◆ initWithArray:dataTypeString:shape:

- (nonnull instancetype) initWithArray: (nonnull CPTNumberArray *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray 

Initializes a newly allocated CPTNumericData object with the provided data.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataTypeString and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
The initialized CPTNumericData instance.

◆ initWithArray:dataTypeString:shape:dataOrder:

- (nonnull instancetype) initWithArray: (nonnull CPTNumberArray *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Initializes a newly allocated CPTNumericData object with the provided data.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataTypeString and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
The initialized CPTNumericData instance.

◆ initWithCoder:

- (nullable instancetype) initWithCoder: (nonnull NSCoder *)  decoder

Returns an object initialized from data in a given unarchiver.

Parameters
decoderAn unarchiver object.
Returns
An object initialized from data in a given unarchiver.

◆ initWithData:dataType:shape:

- (nonnull instancetype) initWithData: (nonnull NSData *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray 

Initializes a newly allocated CPTNumericData object with the provided data.

Parameters
newDataThe data buffer.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
The initialized CPTNumericData instance.

◆ initWithData:dataType:shape:dataOrder:

- (nonnull instancetype) initWithData: (nonnull NSData *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Initializes a newly allocated CPTNumericData object with the provided data. This is the designated initializer.

Parameters
newDataThe data buffer.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
The initialized CPTNumericData instance.

◆ initWithData:dataTypeString:shape:

- (nonnull instancetype) initWithData: (nonnull NSData *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray 

Initializes a newly allocated CPTNumericData object with the provided data.

Parameters
newDataThe data buffer.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
The initialized CPTNumericData instance.

◆ initWithData:dataTypeString:shape:dataOrder:

- (nonnull instancetype) initWithData: (nonnull NSData *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Initializes a newly allocated CPTNumericData object with the provided data.

Parameters
newDataThe data buffer.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
The initialized CPTNumericData instance.

◆ numericDataWithArray:dataType:shape:

+ (nonnull instancetype) numericDataWithArray: (nonnull CPTNumberArray *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray 

Creates and returns a new CPTNumericData instance.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataType and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
A new CPTNumericData instance.

◆ numericDataWithArray:dataType:shape:dataOrder:

+ (nonnull instancetype) numericDataWithArray: (nonnull CPTNumberArray *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Creates and returns a new CPTNumericData instance.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataType and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
A new CPTNumericData instance.

◆ numericDataWithArray:dataTypeString:shape:

+ (nonnull instancetype) numericDataWithArray: (nonnull CPTNumberArray *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray 

Creates and returns a new CPTNumericData instance.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataTypeString and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
A new CPTNumericData instance.

◆ numericDataWithArray:dataTypeString:shape:dataOrder:

+ (nonnull instancetype) numericDataWithArray: (nonnull CPTNumberArray *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Creates and returns a new CPTNumericData instance.

Objects in newData should be instances of NSNumber, NSDecimalNumber, NSString, or NSNull. Numbers and strings will be converted to newDataTypeString and stored in the receiver. Any instances of NSNull will be treated as “not a number” (NaN) values for floating point types and zero (0) for integer types.

Parameters
newDataAn array of numbers.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
A new CPTNumericData instance.

◆ numericDataWithData:dataType:shape:

+ (nonnull instancetype) numericDataWithData: (nonnull NSData *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray 

Creates and returns a new CPTNumericData instance.

Parameters
newDataThe data buffer.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
A new CPTNumericData instance.

◆ numericDataWithData:dataType:shape:dataOrder:

+ (nonnull instancetype) numericDataWithData: (nonnull NSData *)  newData
dataType: (CPTNumericDataType newDataType
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Creates and returns a new CPTNumericData instance.

Parameters
newDataThe data buffer.
newDataTypeThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
A new CPTNumericData instance.

◆ numericDataWithData:dataTypeString:shape:

+ (nonnull instancetype) numericDataWithData: (nonnull NSData *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray 

Creates and returns a new CPTNumericData instance.

Parameters
newDataThe data buffer.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array. Multi-dimensional data arrays will be assumed to be stored in CPTDataOrderRowsFirst.
Returns
A new CPTNumericData instance.

◆ numericDataWithData:dataTypeString:shape:dataOrder:

+ (nonnull instancetype) numericDataWithData: (nonnull NSData *)  newData
dataTypeString: (nonnull NSString *)  newDataTypeString
shape: (nullable CPTNumberArray *)  shapeArray
dataOrder: (CPTDataOrder order 

Creates and returns a new CPTNumericData instance.

Parameters
newDataThe data buffer.
newDataTypeStringThe type of data stored in the buffer.
shapeArrayThe shape of the data buffer array.
orderThe data order for a multi-dimensional data array (row-major or column-major).
Returns
A new CPTNumericData instance.

◆ sampleArray

- (nonnull CPTNumberArray *) sampleArray

Gets an array data samples from the receiver.

Returns
An NSArray of NSNumber objects representing the data from the receiver.
Note
NSNumber does not support complex numbers. Complex number types will be cast to float or double before being wrapped in an instance of NSNumber.

◆ sampleIndex:

- (NSUInteger) sampleIndex: (NSUInteger idx
,   ... 

Gets the offset of a given sample in the data buffer.

Parameters
idxThe zero-based indices into a multi-dimensional sample array. Each index should of type NSUInteger and the number of indices (including idx) should match the numberOfDimensions.
Returns
The sample offset in the data buffer. To get the byte offset, multiply this value by sampleBytes. If any index is greater than or equal to the corresponding dimension of the data buffer, this method returns NSNotFound.

◆ samplePointer:

- (nullable const void *) samplePointer: (NSUInteger sample

Gets a pointer to a given sample in the data buffer.

Parameters
sampleThe zero-based index into the sample array. The array is treated as if it only has one dimension.
Returns
A pointer to the sample or NULL if the sample index is out of bounds.

◆ samplePointerAtIndex:

- (nullable const void *) samplePointerAtIndex: (NSUInteger idx
,   ... 

Gets a pointer to a given sample in the data buffer.

Parameters
idxThe zero-based indices into a multi-dimensional sample array. Each index should of type NSUInteger and the number of indices (including idx) should match the numberOfDimensions.
Returns
A pointer to the sample or NULL if any of the sample indices are out of bounds.

◆ sampleValue:

- (NSNumber *) sampleValue: (NSUInteger sample

Gets the value of a given sample in the data buffer.

Parameters
sampleThe zero-based index into the sample array. The array is treated as if it only has one dimension.
Returns
The sample value wrapped in an instance of NSNumber or nil if the sample index is out of bounds.
Note
NSNumber does not support complex numbers. Complex number types will be cast to float or double before being wrapped in an instance of NSNumber.

◆ sampleValueAtIndex:

- (NSNumber *) sampleValueAtIndex: (NSUInteger idx
,   ... 

Gets the value of a given sample in the data buffer.

Parameters
idxThe zero-based indices into a multi-dimensional sample array. Each index should of type NSUInteger and the number of indices (including idx) should match the numberOfDimensions.
Returns
The sample value wrapped in an instance of NSNumber or nil if any of the sample indices are out of bounds.
Note
NSNumber does not support complex numbers. Complex number types will be cast to float or double before being wrapped in an instance of NSNumber.

◆ swapByteOrderForData:sampleSize:

- (void) swapByteOrderForData: (nonnull NSMutableData *)  sourceData
sampleSize: (size_t)  sampleSize 

Swaps the byte order for each sample stored in a data buffer.

Parameters
sourceDataThe data buffer.
sampleSizeThe number of bytes in each sample stored in sourceData.

Provided by category CPTNumericData(TypeConversion).

Property Documentation

◆ byteOrder

- (CFByteOrder) byteOrder
readnonatomicassign

The byte order used to store each sample in the data buffer.

◆ bytes

- (nonnull const void *) bytes
readnonatomicassign

Returns a pointer to the data buffer’s contents.

◆ data

- (nonnull NSData *) data
readnonatomiccopy

The data buffer.

◆ dataOrder

- (CPTDataOrder) dataOrder
readnonatomicassign

The order that numbers are stored in a multi-dimensional data array.

◆ dataType

- (CPTNumericDataType) dataType
readnonatomicassign

The type of data stored in the data buffer.

◆ dataTypeFormat

- (CPTDataTypeFormat) dataTypeFormat
readnonatomicassign

The format of the data stored in the data buffer.

◆ length

- (NSUInteger) length
readnonatomicassign

Returns the number of bytes contained in the data buffer.

◆ numberOfDimensions

- (NSUInteger) numberOfDimensions
readnonatomicassign

The number dimensions in the data buffer array.

◆ numberOfSamples

- (NSUInteger) numberOfSamples
readnonatomicassign

The number of samples of dataType stored in the data buffer.

◆ sampleBytes

- (size_t) sampleBytes
readnonatomicassign

The number of bytes in a single sample of data.

◆ shape

- (nonnull CPTNumberArray *) shape
readnonatomiccopy

The shape of the data buffer array.

The shape describes the dimensions of the sample array stored in the data buffer. Each entry in the shape array represents the size of the corresponding array dimension and should be an unsigned integer encoded in an instance of NSNumber.


The documentation for this class was generated from the following files: