;; by Fu Jie Huang, May 2003
;; the IOBin class in Torch3 only reads files with "real"
;; in "real world", you also need to read binary files with int, or unsigned char
;; the C++ files in this directory, IOIdx2Ubyte.h(cc) and DiskIdx2UbyteDataSet.h(cc),
;; are modified from IOBin and DiskMatDataSet to read idx2-ubyte data
;; the lush interfaces of these classes are in level2_extra.lsh and level3_extra.lsh

(libload "torch/torch")
(libload "torch/level2_extra")
(libload "torch/level3_extra")

(setq x (ubyte-matrix 4 4))
(x () () (range 1 16))
(save-matrix x "test.mat")
(printf "\ncreate a idx2-ubyte matrix:\n")
(print x)
(printf "and save into test.mat\n")

(setq a (new torch_IOIdx2Ubyte () "test.mat" () -1 ()))
(==> a getTotalNumberOfFrames)
(setq b (new torch_Sequence () 1 4))
(==> a getSequence 2 :b:p)
(printf "\n read with IOIdx2Ubyte: x[2][3] = %d\n\n" (==> b frames_getval 0 3))
(delete a)
(delete b)

(setq c (new torch_DiskIdx2UbyteDataSet () "test.mat" -1 1 () -1 t))
(==> c  get_n_examples)
(==> c  setexample 2 t t)
(printf "read with DiskIdx2UbyteDataSet: x[2][3] = %d\n" 
	(==> (==> c get_targets) frames_getval 0 0))
(delete c)
