4
4
# mci <- makeCacheMatrix(m, func = function(m){message("calculating");solve(m)})
5
5
# cacheSolve(mci)
6
6
# cacheSolve(mci) # should not print message again, should insted inform about cache use
7
- # mcs <- makeCacheMatrix(m, c(1,1))
7
+ # mcs <- makeCacheMatrix(m, c(1,1), tol = .001 )
8
8
# cacheSolve(mcs)
9
9
10
10
# Class for creating matrices with
11
11
# ability to cache results of operations
12
+ # see CacheOps$help(getResult)
12
13
CachedOps <- setRefClass(" CachedOps" ,
13
14
fields = list (func = " function" , cache = " ANY" ),
14
15
15
16
methods = list (
16
- initialize = function (... , func ){
17
+ initialize = function (expr , ... ){
17
18
cache <<- NULL
18
19
func <<- function (){
19
- func( ... )
20
+ expr
20
21
}
21
22
callSuper()
22
23
},
@@ -31,15 +32,15 @@ Once it was calculated result is cached and returned in any consecutive call"
31
32
})
32
33
)
33
34
34
- makeCacheMatrix <- function (... , func = solve ) {
35
+ makeCacheMatrix <- function (expr , ... ) {
35
36
# Creating new caching object
36
37
# Args:
37
38
# func - function, result of calculation is need to cache
38
39
# ... - parameters for function calling
39
- CachedOps $ new(... , func = func )
40
+ CachedOps $ new(expr , ... )
40
41
}
41
42
42
- cacheSolve <- function (x , ... ) {
43
+ cacheSolve <- function (x ) {
43
44
# Calculating result of function on matrix
44
45
# once it was calculated result is cached
45
46
# and returned in any consecutive call
0 commit comments