Skip to content

Commit

Permalink
chore: Little Npy improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcl committed Feb 25, 2025
1 parent b5630e0 commit e918294
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions TensorLib/Npy.lean
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ deriving BEq, Repr, Inhabited

namespace ByteOrder

def toByteOrder (x : ByteOrder) (default : TensorLib.ByteOrder): TensorLib.ByteOrder := match x with
| .native => default
| .littleEndian => .littleEndian
| .bigEndian => .bigEndian
| .notApplicable => .oneByte
def toByteOrder (x : ByteOrder) : Option TensorLib.ByteOrder := match x with
| .native => none
| .littleEndian => some .littleEndian
| .bigEndian => some .bigEndian
| .notApplicable => some .oneByte

def toChar (x : ByteOrder) := match x with
| native => '='
Expand Down Expand Up @@ -150,7 +150,15 @@ structure Ndarray where
startIndex : Nat -- First byte of non-header data
deriving Repr, Inhabited

def Ndarray.nbytes (x : Ndarray) : Nat := x.header.descr.itemsize * x.header.shape.count
namespace Ndarray

def nbytes (x : Ndarray) : Nat := x.header.descr.itemsize * x.header.shape.count

def dtype (arr : Ndarray) : Dtype := arr.header.descr

def order (arr : Ndarray) : ByteOrder := arr.dtype.order

end Ndarray

section Parse

Expand Down

0 comments on commit e918294

Please sign in to comment.