Skip to content

Commit

Permalink
Add methods to append data to a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Isaza committed Jan 20, 2016
1 parent 2027223 commit ce8c927
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Source/DoubleDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public class DoubleDataset: Dataset {
try write(data, memSpace: Dataspace(dims: filespace.selectionDims), fileSpace: filespace)
}

/// Append data to the table
public func append(data: [Double], dimensions: [Int], axis: Int = 0) throws {
let oldExtent = extent
extent[axis] += dimensions[axis]
for (index, dim) in dimensions.enumerate() {
if dim > oldExtent[index] {
extent[index] = dim
}
}

var start = [Int](count: oldExtent.count, repeatedValue: 0)
start[axis] = oldExtent[axis]

let fileSpace = space
fileSpace.select(start: start, stride: nil, count: dimensions, block: nil)

try write(data, memSpace: Dataspace(dims: dimensions), fileSpace: fileSpace)
}

/// Read data using an optional memory Dataspace and an optional file Dataspace
///
/// - precondition: The `selectionSize` of the memory Dataspace is the same as for the file Dataspace
Expand Down
19 changes: 19 additions & 0 deletions Source/FloatDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public class FloatDataset: Dataset {
try write(data, memSpace: Dataspace(dims: filespace.selectionDims), fileSpace: filespace)
}

/// Append data to the table
public func append(data: [Float], dimensions: [Int], axis: Int = 0) throws {
let oldExtent = extent
extent[axis] += dimensions[axis]
for (index, dim) in dimensions.enumerate() {
if dim > oldExtent[index] {
extent[index] = dim
}
}

var start = [Int](count: oldExtent.count, repeatedValue: 0)
start[axis] = oldExtent[axis]

let fileSpace = space
fileSpace.select(start: start, stride: nil, count: dimensions, block: nil)

try write(data, memSpace: Dataspace(dims: dimensions), fileSpace: fileSpace)
}

/// Read data using an optional memory Dataspace and an optional file Dataspace
///
/// - precondition: The `selectionSize` of the memory Dataspace is the same as for the file Dataspace
Expand Down
19 changes: 19 additions & 0 deletions Source/IntDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public class IntDataset: Dataset {
try write(data, memSpace: Dataspace(dims: filespace.selectionDims), fileSpace: filespace)
}

/// Append data to the table
public func append(data: [Int], dimensions: [Int], axis: Int = 0) throws {
let oldExtent = extent
extent[axis] += dimensions[axis]
for (index, dim) in dimensions.enumerate() {
if dim > oldExtent[index] {
extent[index] = dim
}
}

var start = [Int](count: oldExtent.count, repeatedValue: 0)
start[axis] = oldExtent[axis]

let fileSpace = space
fileSpace.select(start: start, stride: nil, count: dimensions, block: nil)

try write(data, memSpace: Dataspace(dims: dimensions), fileSpace: fileSpace)
}

/// Read data using an optional memory Dataspace and an optional file Dataspace
///
/// - precondition: The `selectionSize` of the memory Dataspace is the same as for the file Dataspace
Expand Down
14 changes: 14 additions & 0 deletions Source/StringDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public class StringDataset: Dataset {
try write(data, fileSpace: filespace)
}

/// Append data to the table
public func append(data: [String], dimensions: [Int]) throws {
let oldExtent = extent
extent[0] += dimensions[0]

var start = [Int](count: oldExtent.count, repeatedValue: 0)
start[0] = oldExtent[0]

let fileSpace = space
fileSpace.select(start: start, stride: nil, count: dimensions, block: nil)

try write(data, fileSpace: fileSpace)
}

/// Read string data using an optional file Dataspace
public func read(fileSpace fileSpace: Dataspace? = nil) throws -> [String] {
let size: Int
Expand Down

0 comments on commit ce8c927

Please sign in to comment.