Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
VEBER Philippe
codepi
Commits
ce9c40f6
Commit
ce9c40f6
authored
Nov 17, 2020
by
Philippe Veber
Browse files
tk: new Cpt module
parent
9dcc49a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
lib/tk/cpt.ml
lib/tk/cpt.ml
+60
-0
lib/tk/cpt.mli
lib/tk/cpt.mli
+12
-0
No files found.
lib/tk/cpt.ml
0 → 100644
View file @
ce9c40f6
open
Rresult
open
Core_kernel
open
Let_syntax
.
Result
type
t
=
{
nrows
:
int
;
cols
:
(
string
*
float
option
array
)
list
;
}
let
of_file
fn
=
let
*
df
=
Dataframe
.
from_file
fn
in
let
+
cols
=
Dataframe
.
columns
df
|>
List
.
map
~
f
:
(
fun
(
label
,
col
)
->
let
+
data
=
match
(
col
:
Dataframe
.
column
)
with
|
Floats
xs
->
Ok
(
Array
.
map
xs
~
f
:
Option
.
some
)
|
Float_opts
xs
->
Ok
xs
|
Ints
xs
->
Ok
(
Array
.
map
xs
~
f
:
(
fun
i
->
Some
(
Float
.
of_int
i
)))
|
Int_opts
xs
->
Ok
(
Array
.
map
xs
~
f
:
(
Option
.
map
~
f
:
Float
.
of_int
))
|
_
->
R
.
error_msgf
"column %s is not numeric"
label
in
label
,
data
)
|>
Result
.
all
in
let
cols
=
List
.
filter
cols
~
f
:
(
fun
(
label
,
_
)
->
not
(
String
.
equal
label
"Site"
))
in
let
nrows
=
match
cols
with
|
[]
->
assert
false
|
(
_
,
h
)
::
_
->
Array
.
length
h
in
{
nrows
;
cols
}
let
columns
x
=
x
.
cols
let
make
=
function
|
[]
->
Error
(
`Msg
"empty column list"
)
|
(
_
,
h
)
::
t
as
cols
->
let
nrows
=
Array
.
length
h
in
if
List
.
for_all
t
~
f
:
(
fun
(
_
,
col
)
->
Array
.
length
col
=
nrows
)
then
Ok
{
nrows
;
cols
}
else
R
.
error_msg
"Columns with different lengths"
let
write_row
oc
fields
=
String
.
concat
~
sep
:
"
\t
"
fields
|>
Out_channel
.
fprintf
oc
"%s
\n
"
let
write_columns
oc
res
=
Utils
.
range_iter
0
res
.
nrows
~
f
:
(
fun
i
->
Int
.
to_string
i
::
List
.
map
res
.
cols
~
f
:
(
fun
(
_
,
col
)
->
Option
.
value_map
~
default
:
"NA"
~
f
:
Float
.
to_string
col
.
(
i
)
)
|>
write_row
oc
)
let
to_file
table
~
output
=
Out_channel
.
with_file
output
~
f
:
(
fun
oc
->
write_row
oc
(
"Site"
::
List
.
map
table
.
cols
~
f
:
fst
)
;
write_columns
oc
table
)
lib/tk/cpt.mli
0 → 100644
View file @
ce9c40f6
(** Convergence Prediction Table format *)
type
t
val
of_file
:
string
->
(
t
,
[
>
`Msg
of
string
])
result
val
to_file
:
t
->
output
:
string
->
unit
val
make
:
(
string
*
float
option
array
)
list
->
(
t
,
[
>
`Msg
of
string
])
result
val
columns
:
t
->
(
string
*
float
option
array
)
list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment