Module: Npy

Defined in:
lib/npy.rb,
lib/npy/file.rb,
lib/npy/version.rb

Defined Under Namespace

Classes: Error, File

Constant Summary collapse

MAGIC_STR =
"\x93NUMPY".b
TYPE_MAP =
{
  "|i1" => Numo::Int8,
  "<i2" => Numo::Int16,
  "<i4" => Numo::Int32,
  "<i8" => Numo::Int64,
  "|u1" => Numo::UInt8,
  "<u2" => Numo::UInt16,
  "<u4" => Numo::UInt32,
  "<u8" => Numo::UInt64,
  "<f4" => Numo::SFloat,
  "<f8" => Numo::DFloat,
  "<c8" => Numo::SComplex,
  "<c16" => Numo::DComplex,
  # must come last
  # as save uses first match
  "|b1" => Numo::UInt8
}
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.load(file) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/npy.rb', line 36

def load(file)
  if file.respond_to?(:read)
    load_io(file)
  else
    load_file(file)
  end
end

.load_npz(file) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/npy.rb', line 44

def load_npz(file)
  if file.respond_to?(:read)
    load_npz_io(file)
  else
    load_npz_file(file)
  end
end

.load_npz_string(byte_str) ⇒ Object



56
57
58
# File 'lib/npy.rb', line 56

def load_npz_string(byte_str)
  load_npz_io(StringIO.new(byte_str))
end

.load_string(byte_str) ⇒ Object



52
53
54
# File 'lib/npy.rb', line 52

def load_string(byte_str)
  load_io(StringIO.new(byte_str))
end

.save(file, arr) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/npy.rb', line 60

def save(file, arr)
  if file.respond_to?(:write)
    save_io(file, arr)
  else
    save_file(file, arr)
  end
  true
end

.save_npz(file, arrs) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/npy.rb', line 69

def save_npz(file, arrs)
  if file.respond_to?(:write)
    save_npz_io(file, arrs)
  else
    save_npz_file(file, arrs)
  end
  true
end