File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # Creating a special object for calculating properties of matrix
2
+ # # e.g. inverse with caching options
3
3
4
- # # Write a short comment describing this function
4
+ # # Class for creating matrices with
5
+ # # ability to cache results of operations
5
6
6
- makeCacheMatrix <- function (x = matrix ()) {
7
+ CachedOpsMatrix <- setRefClass(" CachedOpsMatrix" ,
8
+ fields = list (
9
+ value = " matrix" ,
10
+ inverse = function (){
11
+ if (is.null(my.inverse ))
12
+ my.inverse <<- solve(value )
13
+ else message(" getting cached data" )
14
+ my.inverse
15
+ }),
16
+ methods = list (
17
+ initialize = function (... ){
18
+ my.inverse <<- NULL
19
+ callSuper(... )
20
+ })
21
+ )
22
+
23
+ # # Creating new caching object
7
24
25
+ makeCacheMatrix <- function (x = matrix ()) {
26
+ CachedOpsMatrix $ new(value = x )
8
27
}
9
28
10
29
11
- # # Write a short comment describing this function
30
+ # # Calculating inverse of matrix
31
+ # # once it was calculated result is cached
32
+ # # and returned in any consecutive call
12
33
13
34
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
35
+ x $ inverse
15
36
}
You can’t perform that action at this time.
0 commit comments